Reputation: 3444
I'm trying the new android 10 and checking its differences with previous versions. I tried to grant some permissions through ADB
that used to work on Android 9 but to no avail.
Since it is ADB related, I'm not sure where to check it documentation, but here is what I tried:
pm grant my.package.app android.permission.ACCESS_BACKGROUND_LOCATION // permission granted
pm grant my.package.app android.permission.READ_PHONE_STATE // no error no permission granted
pm grant my.package.app android.permission.RECORD_AUDIO // no error no permission granted
pm grant my.package.app android.permission.WRITE_EXTERNAL_STORAGE // no error no permission granted
pm revoke my.package.app android.permission.READ_PHONE_STATE // permission revoked
pm revoke my.package.app android.permission.RECEIVE_SMS // permission revoked
Those are all permissions declared in the AndroidManifest.xml
file, it is strange that only the new ACCESS_BACKGROUND_LOCATION
worked but none of the existing permissions did.
I believe the permission's names are correct because it works when revoking it.
Alternatively, I tried to find the string for those permissions and use the appops
command but it didn't work either.
Any help appreciated.
EDIT:
After further investigation, I noticed that when an app is Freshly installed then I use pm grant
every thing works as expected. However after denying the permission manually (from settings) pm grant
is not working anymore
Upvotes: 1
Views: 7781
Reputation: 3444
Maybe this will help other coming across this question. As mentioned on my edit:
After further investigation, I noticed that when an app is Freshly installed then I use pm grant every thing works as expected. However after denying the permission manually (from settings) pm grant is not working anymore
A solution (that worked for me) is to reset the permissions before trying to set them again. Call:
cmd appops reset my.package.app
Then:
pm grant my.package.app android.permission.ACCESS_BACKGROUND_LOCATION
pm grant my.package.app android.permission.READ_PHONE_STATE
pm grant my.package.app android.permission.RECORD_AUDIO
pm grant my.package.app android.permission.WRITE_EXTERNAL_STORAGE
Upvotes: 6
Reputation: 4340
I came across the privacy changes document for Android 10. Seams that Android stop supporting to read phone state starting with Android 10.
Copped from Android Website
If your app targets Android 10 or higher, a SecurityException occurs.
If your app targets Android 9 (API level 28) or lower, the method returns null or placeholder data if the app has the READ_PHONE_STATE permission. Otherwise, a SecurityException occurs.
Please refer bellow link for more details.
https://developer.android.com/about/versions/10/privacy/changes#proc-net-filesystem
Upvotes: 0