mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
fix: update status receiver only acts on DroidDeck's own install session (#1015)
* fix: the update status receiver only acts on this app's own install session Before Android 13 the receiver was exported, so any app could send a fake PENDING_USER_ACTION broadcast and have DroidDeck launch an arbitrary intent. The receiver now ignores broadcasts whose session id does not match the running install, launches only a system installer activity, and strips URI grant flags. * fix: record the install session id before committing it CodeRabbit: the status broadcast could arrive between commit() and install() returning, while session was still -1, and be dropped. The id is now reported through a callback before commit, and reset to -1 at the start of each attempt so a late broadcast from an earlier session is ignored. * fix: declare package installer confirmation query * Query current PackageInstaller confirmation action --------- Co-authored-by: ovurrsl <ovurrsl@users.noreply.github.com> Co-authored-by: xXJsonDeruloXx <danielhimebauch@gmail.com> Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
3 files changed
+31
-4
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