What does QUERY_ALL_PACKAGES permission do?

Viewed 56169

Android R Preview 1 introduced a new permission called QUERY_ALL_PACKAGES. The documentation for the permission says the following:

Allows query of any normal app on the device, regardless of manifest declarations.

Has anyone worked out what this actually does?

I've tried running the following on the emulator image, and the permission had no effect on either of them:

  • packageManager.queryIntentActivities(intent, 0)
  • packageManager.getInstalledPackages(0)
4 Answers

Even when permission QUERY_ALL_PACKAGES is added, you still need to add <queries> filter to your AndroidManifest.

E.g. for the launcher app it might be:

<permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
    </intent>
</queries>

They cover this more now that DP2 is out.

Quoting myself:

While I haven't tested this aspect of R DP2 yet, it appears that your app now can't find out what other apps are installed, on a general basis. The cited example is queryIntentActivities(), but to make this really work you would need to seriously lobotomize PackageManager. You can whitelist certain packages and certain <intent-filter> structures to try to get by this for certain use cases. And, this is where the mysterious QUERY_ALL_PACKAGES permission seen in DP1 comes into play — this permission removes these new restrictions. Given the "look for Google Play to provide guidelines for apps that need this permission" caveat, it is safest to assume that if you try using it, eventually you will be banned from the Play Store by a bot.

So, you might want to re-try your experiments on DP2. I plan to do the same in the coming weeks.

Android 11 introduces changes related to package visibility. These changes affect apps only if they target Android 11. For more information on these changes, view the guides about package visibility on Android.

https://developer.android.com/training/package-visibility

https://developer.android.com/about/versions/11/privacy/package-visibility

https://developer.android.com/training/package-visibility

For my case, Cordova-android 10.1.1, targetSdkVersion 30

I added

 <queries>
                <package android:name="com.google.android.gm" />
                <package android:name="com.facebook.katana" />
                <intent>
                    <action android:name="android.intent.action.VIEW" />
                    <data android:scheme="https" />
                </intent>
                <intent>
                    <action android:name="android.intent.action.DIAL" />
                    <data android:scheme="tel" />
                </intent>
                <intent>
                    <action android:name="android.intent.action.SEND" />
                    <data android:mimeType="*/*" />
                </intent>
            </queries>

in AndroidManifest.xml

If the app tries to communicate to another app then this permission should be added for Android 11+, else those apps won't work/trigger

Related