'Finding installed android applications that can install other applications

I want to find applications that the user has allowed to install other applications. I know that if I look for "android.permission.INSTALL_PACKAGES" I would find mainly system packages that can install applications but I'd like to find applications (like the browser, or email) that the user allowed to install applications.

I'm trying the following code to loop through all applications which is obviously wrong as I can not find Chrome, who I allowed to install applications. Any suggestion how to achieve this?

final PackageManager pm = getPackageManager();
for (final PackageInfo pi : pm.getInstalledPackages(GET_PERMISSIONS)) {
  try {
    Context pcontext = createPackageContext(pi.packageName, 0);
    if (ContextCompat.checkSelfPermission(pcontext, Manifest.permission.INSTALL_PACKAGES) == PackageManager.PERMISSION_GRANTED) {
       Log.d(TAG, "Application able to install other apps: " + pi.packageName);
    }
  }catch (SecurityException|PackageManager.NameNotFoundException ex){
    Log.d(TAG, "Exception " + ex);
  }
}


Solution 1:[1]

If I'm understanding your question correctly, the answer is "that's not allowed."

Third-party apps can't actually install applications (see https://developer.android.com/reference/android/Manifest.permission#INSTALL_PACKAGES). Apps like Chrome call the system installer, they don't get install privileges themselves, so that's why you don't see them on the list.

And there's no way to check which other apps have launched an installer process. That would be a security/privacy issue, as it would mean any app could retrieve a list of other apps a user has installed on their device! Each process is assigned its own linux id and can't directly access data for any other app (i.e. it's sandboxed), using the exact same mechanism, in fact, that prevents one user from querying another user's data on a standard linux system.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kaitlyn