Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "Fix User Level READ_EXTERNAL_STORAGE Permission"
Browse files Browse the repository at this point in the history
  • Loading branch information
Treehugger Robot authored and Gerrit Code Review committed Jan 27, 2017
2 parents 879edc6 + f9e434b commit a6dc51c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
12 changes: 8 additions & 4 deletions AndroidManifest.xml
Expand Up @@ -24,6 +24,7 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

Expand All @@ -32,14 +33,15 @@
android:taskAffinity="android.task.music"
android:allowTaskReparenting="true"
android:usesCleartextTraffic="true">

<meta-data
android:name="android.app.default_searchable"
android:value="com.android.music.QueryBrowserActivity"
/>
android:value="com.android.music.QueryBrowserActivity"/>

<!-- The main activity -->
<activity android:name="com.android.music.MusicBrowserActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:exported="true"
>
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.MUSIC_PLAYER" />
Expand All @@ -48,12 +50,14 @@
<category android:name="android.intent.category.APP_MUSIC" />
</intent-filter>
</activity>

<receiver android:name="com.android.music.MediaButtonIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
</intent-filter>
</receiver>

<!-- This is the "current music playing" panel, which has special
launch behavior. We clear its task affinity, so it will not
be associated with the main media task and if launched
Expand Down
29 changes: 28 additions & 1 deletion src/com/android/music/MusicBrowserActivity.java
Expand Up @@ -16,18 +16,20 @@

package com.android.music;

import android.Manifest.permission;
import android.content.pm.PackageManager;
import com.android.music.MusicUtils.ServiceToken;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;

public class MusicBrowserActivity extends Activity implements MusicUtils.Defs {
private ServiceToken mToken;
private static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 42;

public MusicBrowserActivity() {}

Expand All @@ -37,6 +39,16 @@ public MusicBrowserActivity() {}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE},
MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
initApp();
}

public void initApp() {
int activeTab = MusicUtils.getIntPref(this, "activetab", R.id.artisttab);
if (activeTab != R.id.artisttab && activeTab != R.id.albumtab && activeTab != R.id.songtab
&& activeTab != R.id.playlisttab) {
Expand Down Expand Up @@ -76,4 +88,19 @@ public void onServiceConnected(ComponentName classname, IBinder obj) {

public void onServiceDisconnected(ComponentName classname) {}
};

@Override
public void onRequestPermissionsResult(
int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: {
if (grantResults.length == 0
|| grantResults[0] != PackageManager.PERMISSION_GRANTED) {
finish();
return;
}
initApp();
}
}
}
}

0 comments on commit a6dc51c

Please sign in to comment.