3

I'm trying to get a list of apps (on Android 8.0+) that have REQUEST_INSTALL_PACKAGES permissions marked as granted.

context.packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS or PackageManager.GET_META_DATA).forEach { pi ->
    if (pi.requestedPermissions != null) {
        for (i in pi.requestedPermissions.indices) {
            if (pi.requestedPermissions[i] == android.Manifest.permission.REQUEST_INSTALL_PACKAGES) {
                if ((pi.requestedPermissionsFlags[i] and PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
                    // permission is granted, do stuff here
                }
            }
        }
    }
}

The problem is, that corresponding requestedPermissionsFlags entry is always 1, which means REQUESTED_PERMISSION_REQUIRED and that is obviously wrong.

I tried different api: context.packageManager.checkPermission(android.Manifest.permission.REQUEST_INSTALL_PACKAGES, pi.packageName) == PackageManager.PERMISSION_GRANTED with the same result.

In tried this on Android 8, 9 and 10 on different devices and the only success I had was on Pixel 3a that came positive for com.android.nfc. Others were always false even when I can see in system settings that chrome and other apps have this permission granted.

Am I missing something for this API? Is it private? There is not much to find about it.

kober
  • 832
  • 7
  • 13

1 Answers1

3

Because this permmission has a signature protection level. According to documentation:

A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission

So requestedPermissionsFlags is correct - only com.android.nfc is granted.

Actually REQUEST_INSTALL_PACKAGES has a signature|appop protection level, that's why not only system apps can use it although this perrmission is not granted for them. For a little bit more details - Acquiring Android Permission with Signature Protection Level.

Dmitrii Nechepurenko
  • 1,414
  • 1
  • 11
  • 13