Home > database >  Android TargetSDK 30 package visibility restrictions don't apply to "com.google.android.gm
Android TargetSDK 30 package visibility restrictions don't apply to "com.google.android.gm

Time:09-24

I am migrating my Android app to be TargetSDK 30 compliant. One of the limitations\changes for this is the package visibility restrictions: https://developer.android.com/about/versions/11/privacy/package-visibility

and google requires the apps to declare the queries element in the manifest like so:

<queries>
<!-- Specific apps you interact with, eg: -->
<package android:name="packageid" />

Without this entry, function calls like

context.getPackageManager.getApplicationInfo("packageid",0);

will result in a NameNotFouncException.

I have verified this to be true for most apps which I explicitly query including the google maps app and adding those app's package id to the manifest resolves the issue.

However I saw that calling this function for the gms packageId: viz

context.getPackageManager.getApplicationInfo("com.google.android.gms",0)

I did NOT need to declare it in the <queries> as part of the manifest!! The functions returned correct value despite the app being migrated to targetSdk = 30 and running on Android-11/Android-12 device.

I thought some of the android libraries are auto-injecting the <queries> for com.google.android.gms via manifest merger, but decompiling the manifest revealed no such entries.

I am curious to know why this package is skipped from the tarsget30 SDK package visibility restrictions and if there are any other such packages. Is this a bug or an undocumented feature?

CodePudding user response:

Package visibility filtering minimizes the package visibility, it does not completely eliminate it. Most of the apps are need to be explicitly declared but some packages are already available without any declaration.

You can find the complete list of packages available on a device using

adb shell dumpsys package queries

Excerpts from official docs

Some packages are still visible automatically. Your app can always see these packages in its queries for other installed apps. To view other packages, declare your app's need for increased package visibility using the <queries> element.

Types of apps that are visible automatically

The following types of apps are always visible to your app, even when your app targets Android 11 (API level 30) or higher:

  • Your own app.
  • Certain system packages, such as the media provider, that implement core Android functionality.
  • The app that installed your app.
  • Any app that launches an activity in your app using the startActivityForResult() method, as described in the guide about how to get a result from an activity.
  • Any app that starts or binds to a service in your app.
  • Any app that accesses a content provider in your app.
  • Any app that has a content provider, where your app has been granted URI permissions to access that content provider.
  • Any app that receives input from your app. This case applies only when your app provides input as an input method editor.
  • Related