mirror of
https://github.com/YTVanced/VancedManager
synced 2024-11-04 18:05:04 +00:00
attempt to fix stub installation
This commit is contained in:
parent
33108f8333
commit
e0b1fcdd3f
1 changed files with 25 additions and 4 deletions
|
@ -8,16 +8,19 @@ import android.util.Log
|
|||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.vanced.manager.ui.fragments.HomeFragment
|
||||
import java.io.*
|
||||
|
||||
class StubInstaller: Service() {
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
val apkFile = assets.openFd("stub.apk")
|
||||
val apkFile = File(filesDir, "stub.apk")
|
||||
if (!apkFile.exists()) {
|
||||
copyStub()
|
||||
}
|
||||
Log.d("AppLog", "Installing stub...")
|
||||
val installResult = Shell.su("cat \"${apkFile}\" | pm install -t -S ${apkFile.length}").exec()
|
||||
val installResult = Shell.su("cat \"${apkFile.absolutePath}\" | pm install -t -S ${apkFile.length()}").exec()
|
||||
Log.d("AppLog", "succeeded installing?${installResult.isSuccess}")
|
||||
if (installResult.isSuccess) {
|
||||
getSharedPreferences("installPrefs", Context.MODE_PRIVATE).edit().putBoolean("isInstalling", false).apply()
|
||||
val mIntent = Intent(HomeFragment.SIGNATURE_DISABLED)
|
||||
mIntent.action = HomeFragment.SIGNATURE_DISABLED
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(mIntent)
|
||||
|
@ -30,7 +33,25 @@ class StubInstaller: Service() {
|
|||
return START_NOT_STICKY
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
private fun copyStub() {
|
||||
try {
|
||||
val stubName = "stub.apk"
|
||||
val inAssset = assets.open(stubName)
|
||||
val outFile = File(filesDir, stubName)
|
||||
val out: OutputStream = FileOutputStream(outFile)
|
||||
val buffer = ByteArray(1024)
|
||||
var read: Int
|
||||
while (inAssset.read(buffer).also { read = it } != -1) {
|
||||
out.write(buffer, 0, read)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.d("VMStub", "Failed to copy stub")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue