Reputation: 703
I'm an Android application developer for an OEM and I'm building a MediaPlayer application that needs to access external storage to play audio located in it. (I add my application to AOSP build system then build whole Android image including my MediaPlayer application). Note that i use AOSP version 9 (Android Pie)
My implementation steps are as below
Declare required permissions in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Create Privileged Permission Whitelisting: privapp-permissions-test.xml
<?xml version="1.0" encoding="utf-8"?>
<permissions>
<privapp-permissions package="com.example.mediaplayer">
<permission name="android.permission.READ_EXTERNAL_STORAGE" />
<permission name="android.permission.WRITE_EXTERNAL_STORAGE" />
</privapp-permissions>
</permissions>
But when a booted device and start my application, it was crashed and logcat displayed like this
com.example.mediaplayer.service.MusicService: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media from pid=3452, uid=10021 requires android.permission.READ_EXTERNAL_STORAGE
Does anyone have any idea to help me ?? Any help is highly appreciated.
Upvotes: 1
Views: 1516
Reputation: 568
According to relative doc, to auto-grant runtime-permission, you need to add/edit items of method grantDefaultSystemHandlerPermissions(int userId)
in
/frameworks/base/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
You can follow the source code's pattern to add other permission-granted logic on your demand.
Upvotes: 0
Reputation: 703
Finally, I solved my problem. Below is the solution
<?xml version="1.0" encoding="utf-8"?>
<exceptions>
<exception package="com.example.mediaplayer">
<permission name="android.permission.READ_EXTERNAL_STORAGE"/>
<permission name="android.permission.WRITE_EXTERNAL_STORAGE"/>
</exception>
</exceptions>
Done. When I launch my application the first time, it no longer ask for permission.
Upvotes: 2