Some Permissions' protectionLevel seems wrongly documented or implemented

痴心易碎 提交于 2019-12-21 21:36:00

问题


I'm running through many permissions tagged PROTECTION_NORMAL and PROTECTION_DANGEROUS in a ListView. Upon click my application calls ActivityCompat.requestPermission().

All permissions I tested (by that I mean all normal and dangerous permissions for API-7 and above I could find) are working fine on my Emulator, except for some:

  • CHANGE_NETWORK_STATE

Requesting CHANGE_NETWORK_STATE always returns PackageManager.PERMISSION_DENIED (without even prompting). I would expect it granted by default since it's flagged normal, or if the documentation is wrong, to be prompted for it then.

  • GET_ACCOUNTS

Requesting GET_ACCOUNTS works after prompting, but the documentation lists this permission as normal not dangerous (the dialog asks for "access your contacts"). I would expect it granted by default since it's flagged normal and not to be prompted for it.

  • READ_CELL_BROADCASTS

Is listed as a permission from the SMS permission group, but that permission does not exists in the Manifest.permission package.

Yes, all permissions are in my AndroidManifest.xml.

Questions

  1. Am I the only one to have this?
  2. Is it emulator-specific?
  3. Is the documentation faulty or is the preview build wrong?

回答1:


Indeed they are.

Turns out those are work-in-progress and mostly acknowledge bugs.

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

I posted a new bug for GET_ACCOUNTS, that was yet to be reported.

Mostly to be fixed for final release / documentation (aka NOT preview).




回答2:


As of Marshmallow (since preview 3), introspection shows CHANGE_NETWORK_STATE has been moved to protection level signature|appop|pre23|preinstalled. Using requestPermissions() will not work on this. It seems the documentation is not up-to-date. Actually, CHANGE_NETWORK_STATE has also been merged with WRITE_SETTINGS, as suggested by the logcat output:

was not granted  either of these permissions: android.permission.CHANGE_NETWORK_STATE, android.permission.WRITE_SETTINGS.

As a user, you may grant both permissions by going into "Settings / Apps / Configure apps / Modify system settings" and turn on "Allow modify system settings". Your app may trigger the right activity directly (although that's a pretty rude user experience):

Uri selfPackageUri = Uri.parse("package:" + getApplicationContext().getPackageName());
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, selfPackageUri);
startActivity(intent);

Finally, you may check if this is allowed by calling Settings.System.canWrite().




回答3:


The docs for requestPermission() state that it should only be called for permissions which are dangerous protection level and not already granted. Are you calling checkSelfPermission() first and only requesting if it fails?

The current images are still previews, so it is possible that something is misbehaving. However, it stands to reason that if the docs state the APIs should only be called under certain conditions, they may misbehave if those conditions aren't met.



来源:https://stackoverflow.com/questions/32208863/some-permissions-protectionlevel-seems-wrongly-documented-or-implemented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!