Skip to content

Commit

Permalink
Fix crash when a package we try to get installer infos for has alread…
Browse files Browse the repository at this point in the history
…y been uninstalled.
  • Loading branch information
d4rken committed Nov 1, 2022
1 parent 5522ad5 commit 9ffa87c
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import eu.darken.myperm.apps.core.Pkg
import eu.darken.myperm.apps.core.known.AKnownPkg
import eu.darken.myperm.apps.core.known.toKnownPkg
import eu.darken.myperm.apps.core.toContainer
import eu.darken.myperm.common.debug.logging.Logging.Priority.WARN
import eu.darken.myperm.common.debug.logging.asLog
import eu.darken.myperm.common.debug.logging.log
import eu.darken.myperm.common.hasApiLevel

data class InstallerInfo(
Expand Down Expand Up @@ -82,9 +85,14 @@ private fun PackageInfo.getInstallerInfoApi30(packageManager: PackageManager): I

@Suppress("DEPRECATION")
private fun PackageInfo.getInstallerInfoLegacy(packageManager: PackageManager): InstallerInfo {
val installingPkg = packageManager.getInstallerPackageName(packageName)
?.let { Pkg.Id(it) }
?.let { it.toKnownPkg() ?: it.toContainer() }
val installingPkg = try {
packageManager.getInstallerPackageName(packageName)
?.let { Pkg.Id(it) }
?.let { it.toKnownPkg() ?: it.toContainer() }
} catch (e: IllegalArgumentException) {
log(WARN) { "OS race condition, package ($packageName) was uninstalled?: ${e.asLog()}" }
null
}

return InstallerInfo(
installingPkg = installingPkg,
Expand Down

0 comments on commit 9ffa87c

Please sign in to comment.