Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come a GCM permission isn't granted on Android 6?

Background

I'm trying to investigate what an app at the office needs to change about its permissions, in order to support Android 6 nicely.

The problem

I've found which permission needs confirmation and which isn't, except for one :

<uses-permission android:name=".permission.C2D_MESSAGE"/>

It seems that this permission isn't mentioned anywhere that I look for, as one that's not granted automatically and yet I can't find where the user can enable it as a confirmation.

What I tried

In order to find which permissions are granted by default and which aren't , I just called this code:

private void checkPermissionsOfApp(String packageName) {
    PackageManager pm = getPackageManager();
    try {
        final ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        Log.d("AppLog", "Listing all permissions of app with PackageName: " + applicationInfo.packageName);
        PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS);
        //Get Permissions
        String[] requestedPermissions = packageInfo.requestedPermissions;
        if (requestedPermissions != null) {
            for (String permission : requestedPermissions) {
                boolean permissionGranted = pm.checkPermission(permission, packageName) == PackageManager.PERMISSION_GRANTED;
                Log.d("AppLog", "permission:" + permission + " permissionGranted:" + permissionGranted);
            }
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}

And the call:

checkPermissionsOfApp(getPackageName());

Using the above code, it crashes for the problematic permission, but when using ContextCompat.checkSelfPermission it says it's not granted.

The question

How could it be? How can I grant the app this permission? Is it mentioned anywhere?

like image 841
android developer Avatar asked Oct 31 '22 16:10

android developer


1 Answers

The documentation, which was updated in October of 2015, still indicates that you need the signature permission.

See also Not receiving push notifications from GCM (Android)

As @CommonsWare mentioned, this does not appear to be part of the new runtime permission checking, or at least is not considered a "dangerous" permission, and so should be automatically granted.

like image 107
GreyBeardedGeek Avatar answered Nov 09 '22 08:11

GreyBeardedGeek