handle PM dying when fetching all packages

This commit is contained in:
Thibault Deckers 2022-04-17 12:59:22 +09:00
parent 2cb8c44c5e
commit 33c36fc1de

View file

@ -110,8 +110,29 @@ class AppAdapterHandler(private val context: Context) : MethodCallHandler {
} }
} }
addPackageDetails(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)) // identify launcher category packages, which typically include user apps
addPackageDetails(Intent(Intent.ACTION_MAIN)) // they should be fetched before the other packages, to be marked as launcher packages
try {
addPackageDetails(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER))
} catch (e: Exception) {
Log.w(LOG_TAG, "failed to list launcher packages", e)
}
try {
// complete with all the other packages
addPackageDetails(Intent(Intent.ACTION_MAIN))
} catch (e: Exception) {
// `PackageManager.queryIntentActivities()` may kill the package manager if the response is too large
Log.w(LOG_TAG, "failed to list all packages", e)
// fallback to the default category packages, which typically include system and OEM tools
try {
addPackageDetails(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_DEFAULT))
} catch (e: Exception) {
Log.w(LOG_TAG, "failed to list default packages", e)
}
}
result.success(ArrayList(packages.values)) result.success(ArrayList(packages.values))
} }