Skip to content

Crash: PackageManager$NameNotFoundException in AppManager.queryInstalledApps

We are receiving crash reports in google play. One that we have already received several reports of is related to a crash in the app in org.torproject.vpn.ui.approuting.data.AppManager.queryInstalledApps with:

org.torproject.vpn.ui.approuting.data.AppManager.queryInstalledApps android.content.pm.PackageManager$NameNotFoundException

It appears the crash happens when PackageManager lookups are performed for packages that are not visible due to Android 11+ package-visibility rules or when a package has been uninstalled/disabled since the last run and there are some unhandled exceptions from getApplicationInfo(...) / getPackageInfo(...) which propagate and crash the app. I've looked through the different crashes, and it appears to happen from Android 11 on up, here is stack trace:

Exception android.content.pm.PackageManager$NameNotFoundException:
  at android.app.ApplicationPackageManager.getPackageInfoAsUser (ApplicationPackageManager.java:319)
  at android.app.ApplicationPackageManager.getPackageInfo (ApplicationPackageManager.java:279)
  at android.app.ApplicationPackageManager.getPackageInfo (ApplicationPackageManager.java:273)
  at org.torproject.vpn.ui.approuting.data.AppManager.queryInstalledApps (AppManager.kt:126)
  at org.torproject.vpn.ui.approuting.data.AppManager$onAppIdChanged$1.invokeSuspend (AppManager.kt:293)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:100)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:124)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:89)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:586)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:820)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:717)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:704)

Probably this could be reproduced if you run the app, then uninstall or disable one of the apps that was listed previously, and then open the per-app routing screen. We should be skipping missing/invisible packages, and build a list of visible apps without crashing.