4

In my app, I need the following permissions for creating an account:

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>

It is my understanding that in the M, these should be granted automatically.

However, what I'm seeing is that only GET_ACCOUNTS is granted. I've checked this with the following code:

@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  logPermissionStatus(Manifest.permission.GET_ACCOUNTS);
  logPermissionStatus(Manifest.permission.MANAGE_ACCOUNTS);
  logPermissionStatus(Manifest.permission.AUTHENTICATE_ACCOUNTS);
  logPermissionStatus(Manifest.permission.USE_CREDENTIALS);
}

private void logPermissionStatus(String permission) {
  if (checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
    Log.d("AccountPermissions", "Granted: " + permission);
  } else {
    Log.d("AccountPermissions", "Denied:  " + permission);
  }
}

Which prints:

D/AccountPermissions﹕ Granted: android.permission.GET_ACCOUNTS
D/AccountPermissions﹕ Denied:  android.permission.MANAGE_ACCOUNTS
D/AccountPermissions﹕ Denied:  android.permission.AUTHENTICATE_ACCOUNTS
D/AccountPermissions﹕ Denied:  android.permission.USE_CREDENTIALS

If I try to request the permissions

requestPermissions(new String[] {
    Manifest.permission.GET_ACCOUNTS,
    Manifest.permission.MANAGE_ACCOUNTS,
    Manifest.permission.AUTHENTICATE_ACCOUNTS,
    Manifest.permission.USE_CREDENTIALS,
}, 1);

The dialog says "Allow AccountPermissions to perform an unknown action?", leading me to believe that these are not intended to be requested from the user. Additionally, the ACCOUNT permission group shows up under legacy permissions on the app info page.

Do I need to do something to get Android to grant me these permissions automatically, or am I really supposed to request them from the user?

SimonVT
  • 1,080
  • 10
  • 12
  • 1
    I think that there is a lot of cleanup work to be done related to the new permission system between now and when Android M ships, as there are a lot of permissions that are in this same boat. I wouldn't fret too much yet, and try again with future MNC previews if and when they are released. – CommonsWare Jun 21 '15 at 11:15
  • 1
    @CommonsWare I figured that might be the case, but I was hoping I missed something. Would be nice if this feature was more complete, as it's arguably what requires the most changes to apps. – SimonVT Jun 21 '15 at 16:21
  • 1
    I think the best thing to do in this case is to open a bug report – greywolf82 Jun 22 '15 at 16:04

2 Answers2

0

This was fixed in the latest M preview.

SimonVT
  • 1,080
  • 10
  • 12
0

AUTHENTICATE_ACCOUNTS, MANAGE_ACCOUNTS, USE_CREDENTIALS no longer exist. We scoped the APIs such that only the authenticator's UID can perform the operations that were protected by these permissions. Normal apps do not have a valid use case for using these operations.

https://code.google.com/p/android-developer-preview/issues/detail?id=2592