From 387159b5af1f8eed50f7ab565a13fd689f037e7e Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sun, 17 Dec 2023 21:56:33 +0700 Subject: [PATCH] PackageInstallerInstaller: Fix intent used for install session (#10240) Use explicit intent as it's a requirement when targeting v34+ --- .../installer/PackageInstallerInstaller.kt | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt index dbc1fa50f0..222ff02d01 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/installer/PackageInstallerInstaller.kt @@ -9,6 +9,7 @@ import android.content.IntentFilter import android.content.pm.PackageInstaller import android.os.Build import androidx.core.content.ContextCompat +import androidx.core.content.IntentSanitizer import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.util.lang.use import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat @@ -25,6 +26,20 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) { PackageInstaller.STATUS_PENDING_USER_ACTION -> { val userAction = intent.getParcelableExtraCompat(Intent.EXTRA_INTENT) + ?.run { + // Doesn't actually needed as the receiver is actually not exported + // But the warnings can't be suppressed without this + IntentSanitizer.Builder() + .allowAction(this.action!!) + .allowExtra(PackageInstaller.EXTRA_SESSION_ID) { id -> id == activeSession?.second } + .allowAnyComponent() + .allowPackage { + // There is no way to check the actual installer name so allow all. + true + } + .build() + .sanitizeByFiltering(this) + } if (userAction == null) { logcat(LogPriority.ERROR) { "Fatal error for $intent" } continueQueue(InstallStep.Error) @@ -71,13 +86,13 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic val intentSender = PendingIntent.getBroadcast( service, activeSession!!.second, - Intent(INSTALL_ACTION), + Intent(INSTALL_ACTION).setPackage(service.packageName), if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0, ).intentSender session.commit(intentSender) } } catch (e: Exception) { - logcat(LogPriority.ERROR) { "Failed to install extension ${entry.downloadId} ${entry.uri}" } + logcat(LogPriority.ERROR, e) { "Failed to install extension ${entry.downloadId} ${entry.uri}" } activeSession?.let { (_, sessionId) -> packageInstaller.abandonSession(sessionId) } @@ -105,7 +120,7 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic service, packageActionReceiver, IntentFilter(INSTALL_ACTION), - ContextCompat.RECEIVER_EXPORTED, + ContextCompat.RECEIVER_NOT_EXPORTED, ) } }