Taylor Courtney
Taylor Courtney

Reputation: 813

Security Exception: Permission Denial

The app used to run. However, just recently it began to stop working. The device is running Android Nutella. Below is the LogCat.

 java.lang.SecurityException: Permission Denial: reading com.google.android.music.store.ConfigContentProvider uri content://com.google.android.music.ConfigContent/one-key/2/ExplicitRestrictedByParentControl from pid=2500, uid=10373 requires the provider be exported, or grantUriPermission()

The app crashes in the the following code snippet on the last line(contained in a SongParser method).

 String[] projection2 = {MediaStore.Audio.Media.ARTIST};
    Uri songUri=null;
    try {
        songUri = Uri.parse("content://com.google.android.music.MusicContent/audio");
    } catch (NullPointerException e){
        e.printStackTrace();
    }
    if (songUri!=null) {
        CursorLoader cl2 = new CursorLoader(context,
                songUri, projection2, null, null, null);
        cursor = cl2.loadInBackground();

I grant the Uri permissions in the following method after asking for permissions through the runtime permissions methods.

 private void startService() {
    //start intent to RssService for feedback
    intent = new Intent(getActivity(), SongService.class);
    intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    getContext().grantUriPermission("xxx.xxx.xxx.SongService",Uri.parse("content://com.google.android.music.MusicContent/audio"),Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra(SongService.RECEIVER, resultReceiver);
    getActivity().startService(intent);

}

Here is where SongService calls SongParser.

@Override
protected void onHandleIntent(Intent intent) {

        List<String> eventItems= null;
    if (haveNetworkConnection()) {
        parser = new SongParser();
        eventItems = parser.getAllArtists(getApplicationContext());
    }
        Bundle bundle = new Bundle();
        bundle.putSerializable(ITEMS, (Serializable) eventItems);
        ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);
        receiver.send(0, bundle);}}

I have contained the permissions in the manifest as well. Again, this exception seemingly happened on its own.

<permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Upvotes: 1

Views: 1950

Answers (2)

geecko
geecko

Reputation: 667

What's happening is that for some reason, the (exported) MusicContent provider will redirect to ConfigContentProvider, which is not exported.

It seems that the way to solve it is to open Google Play Music. If you haven't launched it in a while, it will redirect to com.google.android.music.store.ConfigContentProvider and trigger a SecurityException. It's kind of problematic but at least I can tell my users what to do. Let me know if you can come up with something better.

It might also be a good idea to file a bug.

Upvotes: 3

CommonsWare
CommonsWare

Reputation: 1007584

You do not have access to that ContentProvider. It is not exported, and that app did not pass you a Uri that you can use to access it.

Since presumably the Uri is from an app that you did not write, apparently an update to that app changed this behavior.

Upvotes: 2

Related Questions