mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
Merge remote-tracking branch 'origin/main' into pr1067
This commit is contained in:
commit
1ee597e07f
538 files changed
+38465
-3751
No files matched your search
@@ -91,7 +91,8 @@ object SelfInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
fun install(context: Context, apk: File) {
|
||||
/** Reports the session id before the commit, so a status broadcast that arrives right away is recognised. */
|
||||
fun install(context: Context, apk: File, onSession: (Int) -> Unit = {}) {
|
||||
val installer = context.packageManager.packageInstaller
|
||||
val params = PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL).apply {
|
||||
setAppPackageName(context.packageName)
|
||||
@@ -108,10 +109,23 @@ object SelfInstaller {
|
||||
}
|
||||
val status = Intent(ACTION_STATUS).setPackage(context.packageName)
|
||||
val flags = PendingIntent.FLAG_UPDATE_CURRENT or (if (Build.VERSION.SDK_INT >= 31) PendingIntent.FLAG_MUTABLE else 0)
|
||||
onSession(id)
|
||||
session.commit(PendingIntent.getBroadcast(context, id, status, flags).intentSender)
|
||||
}
|
||||
}
|
||||
|
||||
/** Only a system installer activity may be launched from the status broadcast, without URI grants. */
|
||||
fun safeConfirmIntent(context: Context, confirm: Intent): Intent? {
|
||||
val target = confirm.resolveActivity(context.packageManager) ?: return null
|
||||
val info = runCatching { context.packageManager.getApplicationInfo(target.packageName, 0) }.getOrNull() ?: return null
|
||||
if (info.flags and android.content.pm.ApplicationInfo.FLAG_SYSTEM == 0) return null
|
||||
return Intent(confirm).setComponent(target).apply {
|
||||
flags = flags and (Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION or
|
||||
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION or Intent.FLAG_GRANT_PREFIX_URI_PERMISSION).inv()
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
}
|
||||
|
||||
fun describeFailure(context: Context, status: Int, message: String?): String = when {
|
||||
message?.contains("VERSION_DOWNGRADE") == true -> context.getString(R.string.upd_fail_downgrade)
|
||||
status == PackageInstaller.STATUS_FAILURE_CONFLICT || message?.contains("UPDATE_INCOMPATIBLE") == true ->
|
||||
|
||||
Reference in new issue
Block a user