mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
PackageInstallerInstaller: Fix intent used for install session (#10240)
Use explicit intent as it's a requirement when targeting v34+
This commit is contained in:
parent
09531e7f5a
commit
387159b5af
@ -9,6 +9,7 @@ import android.content.IntentFilter
|
|||||||
import android.content.pm.PackageInstaller
|
import android.content.pm.PackageInstaller
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.content.IntentSanitizer
|
||||||
import eu.kanade.tachiyomi.extension.model.InstallStep
|
import eu.kanade.tachiyomi.extension.model.InstallStep
|
||||||
import eu.kanade.tachiyomi.util.lang.use
|
import eu.kanade.tachiyomi.util.lang.use
|
||||||
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
|
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)) {
|
when (intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE)) {
|
||||||
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
PackageInstaller.STATUS_PENDING_USER_ACTION -> {
|
||||||
val userAction = intent.getParcelableExtraCompat<Intent>(Intent.EXTRA_INTENT)
|
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) {
|
if (userAction == null) {
|
||||||
logcat(LogPriority.ERROR) { "Fatal error for $intent" }
|
logcat(LogPriority.ERROR) { "Fatal error for $intent" }
|
||||||
continueQueue(InstallStep.Error)
|
continueQueue(InstallStep.Error)
|
||||||
@ -71,13 +86,13 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic
|
|||||||
val intentSender = PendingIntent.getBroadcast(
|
val intentSender = PendingIntent.getBroadcast(
|
||||||
service,
|
service,
|
||||||
activeSession!!.second,
|
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,
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0,
|
||||||
).intentSender
|
).intentSender
|
||||||
session.commit(intentSender)
|
session.commit(intentSender)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} 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) ->
|
activeSession?.let { (_, sessionId) ->
|
||||||
packageInstaller.abandonSession(sessionId)
|
packageInstaller.abandonSession(sessionId)
|
||||||
}
|
}
|
||||||
@ -105,7 +120,7 @@ class PackageInstallerInstaller(private val service: Service) : Installer(servic
|
|||||||
service,
|
service,
|
||||||
packageActionReceiver,
|
packageActionReceiver,
|
||||||
IntentFilter(INSTALL_ACTION),
|
IntentFilter(INSTALL_ACTION),
|
||||||
ContextCompat.RECEIVER_EXPORTED,
|
ContextCompat.RECEIVER_NOT_EXPORTED,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user