Skip to content

Commit

Permalink
fix pm grant permission, split long command into one for each permission
Browse files Browse the repository at this point in the history
  • Loading branch information
hg42 committed Apr 14, 2024
1 parent 81312e4 commit a6d9ffe
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,24 @@ open class RestoreAppAction(context: Context, work: AppActionWork?, shell: Shell
}
success = runAsRoot(sb.toString()).isSuccess // TODO integrate permissionsResult too

val permissionsCmd = mutableListOf<String>()
if (!isRestoreAllPermissions && pref_restorePermissions.value) {
backup.permissions
.filterNot { it.isEmpty() }
.forEach { p ->
permissionsCmd.addAll(listOf("pm", "grant", backup.packageName, p, ";"))
try {
runAsRoot("pm grant ${backup.packageName} $p")
} catch (e: ShellCommandFailedException) {
val details = e.shellResult.err
.joinToString("\n")
.splitToSequence("\n\tat ")
.first()
val error = "Restoring permission $p failed: $details"
Timber.e(error)
// TODO integrate this exception in the result
}
}
try {
runAsRoot(permissionsCmd.joinToString(" "))
} catch (e: ShellCommandFailedException) {
val error = e.shellResult.err.joinToString { "\n" }
Timber.e("Restoring permissions failed: $error")
// TODO integrate this exception in the result
}
}


// re-enable verify apps over usb
if (disableVerification)
runAsRoot("settings put global verifier_verify_adb_installs 1")
Expand Down Expand Up @@ -403,9 +404,7 @@ open class RestoreAppAction(context: Context, work: AppActionWork?, shell: Shell
} catch (e: ShellCommandFailedException) {
Timber.w(
"<$packageName> Cleanup after failure failed: ${
e.shellResult.err.joinToString(
"; "
)
e.shellResult.err.joinToString("\n").trim()
}"
)
}
Expand Down

0 comments on commit a6d9ffe

Please sign in to comment.