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