Browse Source

PackageInstallerInstaller: Fix intent used for install session (#10240)

Use explicit intent as it's a requirement when targeting v34+
Ivan Iskandar 1 year ago
parent
commit
387159b5af

+ 18 - 3
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>(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,
         )
     }
 }