Why does requesting some permissions reject instantly with no dialog, while others do ask?

66 Views Asked by At

On a blank/wiped AVD (AAOS), I have list of permissions that I need to be accepted. When I try this, currently only CAR_SPEED is granted (should I accept) and all others are rejected with no dialog box and no indication in settings that they were ever requested.

For example: android.car.permission.CAR_SPEED and android.car.permission.CAR_MILEAGE. When I request these 2 using androidx.car.app.CarContext.requestPermisions, I get a dialog box asking for location access permission (android:permissionGroup="android.permission-group.LOCATION" for android.car.permission.CAR_SPEED). Speed is accepted but mileage is not. Note: mileage does not state itself to be in any group. The permissions are set up in the same way in

Only location permission request shows up in the app's settings. If I request these again, nothing is asked. It fails silently and the listener shows all of the other permissions (car mileage in this example) rejected.

Why is the behavior different and how can I ensure that all of the permissions are asked for instead of being instantly rejected?

Thank you!

1

There are 1 best solutions below

1
hcl2000 On

In Android, different permissions have different protection levels. Here's a list of some of these. You can CTRL+F to find the permission you are looking for.

This can affect their behavior when they are requested at runtime.

For android.car.permission.CAR_MILEAGE, the protection level is signature|privileged

Per Android Docs, the signature base permission type is defined as follows:

A permission that the system grants only if the requesting application is signed with the same certificate as the application that declared the permission. If the certificates match, the system automatically grants the permission without notifying the user or asking for the user's explicit approval.

By definition, the protection level of this permission means it will never prompt or notify the user. Google states that this is because these permissions are best not handled by the user.

The privileged protection level means that system apps are not subject to the above, and obtain it automatically.

Assuming you don't want to/don't have the means to make it a system app (usually you do not), and it is silently failing as opposed to silently succeeding, ensure the following:

  1. Check that the permission is declared first in AndroidManifest.xml before requesting it, and
  2. Make sure that the requesting app and the declaring app are signed with the same signing key. If they are the same app, they will be.

Hope this helps!