0
0
Fork 0
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:
X1nto 2020-06-09 15:20:05 +04:00
parent 33108f8333
commit e0b1fcdd3f

View file

@ -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")
}
}
}