What happens when permission is disabled with OS 4

2019-02-17 16:23发布

问题:

I heard that OS 4.3 has hidden feature to disable some permissions w/o repackaging APK. When we release app, we add necessary permissions and make app work. But that feature can disable permissions. I know some app have been doing this though it's a hack and I don't need to care. But with OS 4.3, user can easily can do this.

Now my question is, when permission is disabled, does corresponding API throws exception? (I guess so.) If this is true, I should add try-catch for some operations otherwise novice user may end up thinking my app is poorly designed.

Or, I will add some code to check permissions are there for my app to work and if not I will show some rude, no polite message to tell don't do this and quit app.

(Someone may close this question saying this is not a true question.)

回答1:

I heard that OS 4.3 has hidden feature to disable some permissions w/o repackaging APK.

The working term for this is "App Ops", based upon the title of the activity that allows user to control these operations.

Now my question is, when permission is disabled, does corresponding API throws exception?

That will depend upon the particular operation that was blocked. For example, trying to open() a Camera, when that has been blocked by App Ops, will throw a RuntimeException. But querying contacts, when the user blocked that in App Ops, simply returns empty result sets.

I should add try-catch for some operations otherwise novice user may end up thinking my app is poorly designed

Perhaps. It depends on what your app does that can be blocked and what the blocking behavior is.

I will add some code to check permissions are there for my app to work and if not I will show some rude, no polite message to tell don't do this and quit app.

App Ops does not revoke permissions. PackageManager and checkPermissions() will still report that you hold the permission, even if App Ops blocks some operation tied to that permission.

At present, I know of no direct way to determine if you have been blocked by App Ops.

I have started a FAQ on my blog to try to collect information about this, until such time as official details emerge (if ever).