Background
You can get a list of installed apps using PackageManager.getInstalledPackages.
And, you can reach the app-info screen of each app via :
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:$appPackageName"))
startActivity(intent)
Example:
The problem
Thing is, I've noticed (after someone told me) that for some apps, you can't reach their app-info screen. Example of such package-names of those apps: "com.google.android.ext.services" ("Android Services Library") , "com.google.mainline.tememetry" ("Support components"), com.google.android.modulemetadata" (Main components") . Maybe more.
After reporting it to Google, I was told:
com.google.android.ext.services is mainline module, so Settings doesn't provide detail app info for it.
What I've tried
I've tried to look at various fields and functions of PackageInfo and ApplicationInfo.
I've found "isApex", but it seems to be always false, and the docs don't help about understanding what it is, at all ("Whether the package is an APEX package") . EDIT: it's always false if I check on API 30. On API 29 it's actually sometimes set to true. Reported here.
I've also found a private boolean field (that I can reach via reflection) called "coreApp" , and indeed it's sometimes true, but it's not always that when it's true, it means I can't reach it's app-info screen.
This is the code to get it:
fun isProbablyCoreApp(packageInfo: PackageInfo): Boolean {
return try {
val field = PackageInfo::class.java.getField("coreApp")
field.getBoolean(packageInfo)
} catch (e: Throwable) {
false
}
}
The questions
- What does it mean "mainline module" ? It's a part of the OS that gets updated on its own? Related to "project mainline" of Android 10 and above ?
- Why couldn't I reach its app-info? It's not a real app? But if not, how come it's listed as a part of the list of apps?
- Is there any way to detect that an installed app is in fact a module that you can't reach its app-info screen ? How does the UI of the OS filters out those apps from its list?
- Are there more cases of apps that I can't reach their app-info screen?
The call to
startActivity()
is failing. Ideally, we would trace that call down into the Android system and figure out why it is failing to get some information that may lead to a fix. In lieu of that, I propose the following as a possible solution.I am working off of the assumption that all installed packages can show an "apps-info" screen unless the package is a module that is hidden.
I have looked at an Android emulator running API 30 and the foregoing checks out. I am not convinced that this theory is valid in all cases. You mentioned the "Files" app as an issue. This app appears as a module but not in the list of installed apps as you suggested. The updated code addresses this.
I have put together a small app the can test whether apps-info screens are created or not depending upon the categories mentioned above. I have included it here for a further look. The comments in the code explain how the app works.