Some Permissions' protectionLevel seems wrongly documented or implemented

风流意气都作罢 提交于 2019-12-04 15:49:03

Indeed they are.

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

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).

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().

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.

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