Fix crash
This commit is contained in:
parent
4825c85883
commit
3e4eb34819
|
|
@ -348,8 +348,9 @@ private fun DoPatchBody(modifier: Modifier) {
|
|||
scope.launch {
|
||||
snackbarHost.showSnackbar(shizukuUnavailable)
|
||||
}
|
||||
} else {
|
||||
installing = true
|
||||
}
|
||||
installing = true
|
||||
},
|
||||
content = { Text(stringResource(R.string.patch_install)) }
|
||||
)
|
||||
|
|
@ -384,12 +385,12 @@ private fun InstallDialog(patchApp: AppInfo, onFinish: (Int, String?) -> Unit) {
|
|||
val scope = rememberCoroutineScope()
|
||||
|
||||
var uninstallFirst by remember { mutableStateOf(ShizukuApi.isPackageInstalled(patchApp.app.packageName)) }
|
||||
var installing by remember { mutableStateOf(false) }
|
||||
var installing by remember { mutableStateOf(0) }
|
||||
val doInstall = suspend {
|
||||
Log.i(TAG, "Installing app ${patchApp.app.packageName}")
|
||||
installing = true
|
||||
installing = 1
|
||||
val (status, message) = LSPPackageInstaller.install()
|
||||
installing = false
|
||||
installing = 0
|
||||
Log.i(TAG, "Installation end: $status, $message")
|
||||
onFinish(status, message)
|
||||
}
|
||||
|
|
@ -402,11 +403,16 @@ private fun InstallDialog(patchApp: AppInfo, onFinish: (Int, String?) -> Unit) {
|
|||
onClick = {
|
||||
scope.launch {
|
||||
Log.i(TAG, "Uninstalling app ${patchApp.app.packageName}")
|
||||
val (status, message) = LSPPackageInstaller.uninstall(patchApp.app.packageName)
|
||||
Log.i(TAG, "Uninstallation end: $status, $message")
|
||||
if (status != PackageInstaller.STATUS_SUCCESS) onFinish(status, message)
|
||||
uninstallFirst = false
|
||||
doInstall()
|
||||
installing = 2
|
||||
val (status, message) = LSPPackageInstaller.uninstall(patchApp.app.packageName)
|
||||
installing = 0
|
||||
Log.i(TAG, "Uninstallation end: $status, $message")
|
||||
if (status == PackageInstaller.STATUS_SUCCESS) {
|
||||
doInstall()
|
||||
} else {
|
||||
onFinish(status, message)
|
||||
}
|
||||
}
|
||||
},
|
||||
content = { Text(stringResource(android.R.string.ok)) }
|
||||
|
|
@ -429,14 +435,14 @@ private fun InstallDialog(patchApp: AppInfo, onFinish: (Int, String?) -> Unit) {
|
|||
)
|
||||
}
|
||||
|
||||
if (installing) {
|
||||
if (installing != 0) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {},
|
||||
confirmButton = {},
|
||||
title = {
|
||||
Text(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = stringResource(R.string.patch_installing),
|
||||
text = stringResource(if (installing == 1) R.string.patch_installing else R.string.patch_uninstalling),
|
||||
fontFamily = FontFamily.Serif,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ object LSPPackageInstaller {
|
|||
} ?: throw IOException("Intent is null")
|
||||
}.onFailure {
|
||||
status = PackageInstaller.STATUS_FAILURE
|
||||
message = it.message + "\n" + it.stackTraceToString()
|
||||
message = "Exception happened\n$it"
|
||||
}
|
||||
}
|
||||
return Pair(status, message)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.lsposed.lspatch.util
|
|||
|
||||
import android.content.IntentSender
|
||||
import android.content.pm.*
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.os.IInterface
|
||||
import androidx.compose.runtime.getValue
|
||||
|
|
@ -25,8 +26,20 @@ object ShizukuApi {
|
|||
}
|
||||
|
||||
private val packageInstaller: PackageInstaller by lazy {
|
||||
PackageInstaller::class.java.getConstructor(IPackageInstaller::class.java, String::class.java, Int::class.javaPrimitiveType)
|
||||
.newInstance(iPackageInstaller, "com.android.shell", 0)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
PackageInstaller::class.java.getConstructor(
|
||||
IPackageInstaller::class.java,
|
||||
String::class.java,
|
||||
String::class.java,
|
||||
Int::class.javaPrimitiveType
|
||||
).newInstance(iPackageInstaller, "com.android.shell", null, 0)
|
||||
} else {
|
||||
PackageInstaller::class.java.getConstructor(
|
||||
IPackageInstaller::class.java,
|
||||
String::class.java,
|
||||
Int::class.javaPrimitiveType
|
||||
).newInstance(iPackageInstaller, "com.android.shell", 0)
|
||||
}
|
||||
}
|
||||
|
||||
var isBinderAvalable = false
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
<string name="patch_installing">Installing</string>
|
||||
<string name="patch_uninstall">Uninstall</string>
|
||||
<string name="patch_uninstall_text">Due to different signatures, you need to uninstall the original app before installing the patched one.\nMake sure you have backed up personal data.</string>
|
||||
<string name="patch_uninstalling">Uninstalling</string>
|
||||
<string name="patch_install_successfully">Install successfully</string>
|
||||
<string name="patch_install_failed">Install failed</string>
|
||||
<string name="patch_copy_error">Copy error</string>
|
||||
|
|
|
|||
Loading…
Reference in New Issue