This commit is contained in:
Administrator 2025-07-05 15:45:37 +08:00
parent 2ed86fb2b7
commit b504984268
1 changed files with 18 additions and 50 deletions

View File

@ -130,75 +130,44 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
).build()
)
unlockInstallation()
// Toast.makeText(getContext(),"Installation failed",Toast.LENGTH_SHORT).show();
Util.setInstallRet(false)
return
}
androidSessionId = createSession()
//todo params.apkSource().apkLocalPath?
val path = "/sdcard/apks/" + "com.zhiliaoapp.musically"
val path = "/sdcard/apks/${Util.recordPackageName}"
val file = File(path)
val files = file.listFiles()
var currentApkFile = 0
for (f in files) {
if (f.length() <= 0) {
setSessionState(
sessionId,
SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLATION_FAILED).appTempName(
appTempName
).error(
MainApplication.instance.getString(R.string.installer_error_unknown_apk_size),
null
).build()
)
unlockInstallation()
// Toast.makeText(getContext(),"Installation failed",Toast.LENGTH_SHORT).show();
Util.setInstallRet(false)
return
files?.let {
for (f in files) {
if (f.length() <= 0) {
setSessionState(sessionId, SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLATION_FAILED).appTempName(appTempName).error(MainApplication.instance.getString(R.string.installer_error_unknown_apk_size), null).build())
unlockInstallation()
Util.setInstallRet(false)
return
}
ensureCommandSucceeded(shell.exec(Shell.Command("pm", "install-write", f.length().toString(), androidSessionId.toString(), String.format("%d.apk", currentApkFile++), f.path)))
}
ensureCommandSucceeded(
shell.exec(
Shell.Command(
"pm",
"install-write",
f.length().toString(),
androidSessionId.toString(),
String.format("%d.apk", currentApkFile++),
f.path
)
)
)
}
mAwaitingBroadcast.set(true)
val installationResult: Shell.Result =
shell.exec(Shell.Command("pm", "install-commit", androidSessionId.toString()))
val installationResult: Shell.Result = shell.exec(Shell.Command("pm", "install-commit", androidSessionId.toString()))
Log.i(tag(), "installationResult:" + installationResult.isSuccessful)
if (!installationResult.isSuccessful) {
mAwaitingBroadcast.set(false)
val shortError: String = MainApplication.instance.getString(
R.string.installer_error_shell,
installerName, """
val shortError: String = MainApplication.instance.getString(R.string.installer_error_shell, installerName, """
${getSessionInfo(apkSource)}
${parseError(installationResult)}
""".trimIndent()
)
setSessionState(
sessionId, SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLATION_FAILED)
.appTempName(appTempName)
.error(
""".trimIndent())
setSessionState(sessionId, SaiPiSessionState.Builder(sessionId, SaiPiSessionStatus.INSTALLATION_FAILED).appTempName(appTempName).error(
shortError, """
$shortError
${installationResult.toString()}
""".trimIndent()
)
.build()
)
""".trimIndent()).build())
unlockInstallation()
Util.setInstallRet(false)
@ -207,7 +176,6 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
}
}
} catch (e: Exception) {
//TODO this catches resources close exception causing a crash, same in rootless installer
Log.w(tag(), e)
if (androidSessionId != null) {
@ -292,7 +260,7 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
DbgPreferencesHelper.customInstallCreateCommand
if (customInstallCreateCommand != null) {
val args = ArrayList(
Arrays.asList(
listOf(
*customInstallCreateCommand.split(" ".toRegex()).dropLastWhile { it.isEmpty() }
.toTypedArray()))
val command = args.removeAt(0)
@ -357,7 +325,7 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
val sessionIdPattern = Pattern.compile("(\\d+)")
val sessionIdMatcher = sessionIdPattern.matcher(commandResult)
sessionIdMatcher.find()
return sessionIdMatcher.group(1).toInt()
return sessionIdMatcher.group(1)?.toInt()
} catch (e: Exception) {
Log.w(tag(), commandResult, e)
return null
@ -366,7 +334,7 @@ abstract class ShellSaiPackageInstaller protected constructor(c: Context?) :
private fun parseError(installCommitResult: Shell.Result): String {
var matchedError: AndroidPackageInstallerError = AndroidPackageInstallerError.UNKNOWN
for (error in AndroidPackageInstallerError.values()) {
for (error in AndroidPackageInstallerError.entries) {
if (installCommitResult.out.contains(error.error)) {
matchedError = error
break