aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-09-01 16:28:48 -0700
committerScott Jackson <daneren2005@gmail.com>2016-09-01 16:28:48 -0700
commitd3cd581edd08ba9811aa4f87362ea81a02fe11db (patch)
tree434ca996c0bb21ec3005ecea064e5bdcf81cb2da /app/src/main
parentd8c5a9f8b4b58489e113c637d358ba64df899a42 (diff)
downloaddsub-d3cd581edd08ba9811aa4f87362ea81a02fe11db.tar.gz
dsub-d3cd581edd08ba9811aa4f87362ea81a02fe11db.tar.bz2
dsub-d3cd581edd08ba9811aa4f87362ea81a02fe11db.zip
Fixes #732: Add support for runtime permissions
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml4
-rw-r--r--app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java25
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/Util.java12
-rw-r--r--app/src/main/res/values/strings.xml2
5 files changed, 37 insertions, 8 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 999fb150..65305cbd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -8,11 +8,11 @@
android:label="Tests" />
<uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.RECORD_AUDIO"/>
+ <uses-permission android:name="android.permission.RECORD_AUDIO" android:maxSdkVersion="22"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
diff --git a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
index ab846ba0..d987f403 100644
--- a/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/app/src/main/java/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -32,12 +32,15 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.design.widget.NavigationView;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
@@ -81,6 +84,8 @@ import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.view.UpdateView;
import github.daneren2005.dsub.util.UserUtil;
+import static android.Manifest.*;
+
public class SubsonicActivity extends AppCompatActivity implements OnItemSelectedListener {
private static final String TAG = SubsonicActivity.class.getSimpleName();
private static ImageLoader IMAGE_LOADER;
@@ -89,6 +94,7 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
protected static boolean actionbarColored;
private static final int MENU_GROUP_SERVER = 10;
private static final int MENU_ITEM_SERVER_BASE = 100;
+ private static final int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
private final List<Runnable> afterServiceAvailable = new ArrayList<>();
private boolean drawerIdle = true;
@@ -165,6 +171,25 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
};
Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
}
+
+ if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this, new String[]{ permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
+ switch (requestCode) {
+ case PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
+ // If request is cancelled, the result arrays are empty.
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+
+ } else {
+ Util.toast(this, R.string.permission_external_storage_failed);
+ finish();
+ }
+ }
+ }
}
@Override
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index f8272356..726840b2 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -155,6 +155,8 @@ public class DownloadServiceLifecycleSupport {
// Pause temporarily on incoming phone calls.
phoneStateListener = new MyPhoneStateListener();
+
+ // Android 6.0 removes requirement for android.Manifest.permission.READ_PHONE_STATE;
TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/Util.java b/app/src/main/java/github/daneren2005/dsub/util/Util.java
index fc7292f6..759c6799 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/Util.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/Util.java
@@ -1198,22 +1198,22 @@ public final class Util {
showDialog(context, android.R.drawable.ic_dialog_info, title, message, linkify);
}
- private static void showDialog(Context context, int icon, int titleId, int messageId) {
+ public static void showDialog(Context context, int icon, int titleId, int messageId) {
showDialog(context, icon, titleId, messageId, true);
}
- private static void showDialog(Context context, int icon, int titleId, String message) {
+ public static void showDialog(Context context, int icon, int titleId, String message) {
showDialog(context, icon, titleId, message, true);
}
- private static void showDialog(Context context, int icon, String title, String message) {
+ public static void showDialog(Context context, int icon, String title, String message) {
showDialog(context, icon, title, message, true);
}
- private static void showDialog(Context context, int icon, int titleId, int messageId, boolean linkify) {
+ public static void showDialog(Context context, int icon, int titleId, int messageId, boolean linkify) {
showDialog(context, icon, context.getResources().getString(titleId), context.getResources().getString(messageId), linkify);
}
- private static void showDialog(Context context, int icon, int titleId, String message, boolean linkify) {
+ public static void showDialog(Context context, int icon, int titleId, String message, boolean linkify) {
showDialog(context, icon, context.getResources().getString(titleId), message, linkify);
}
- private static void showDialog(Context context, int icon, String title, String message, boolean linkify) {
+ public static void showDialog(Context context, int icon, String title, String message, boolean linkify) {
SpannableString ss = new SpannableString(message);
if(linkify) {
Linkify.addLinks(ss, Linkify.ALL);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b987bad6..92d0bb8a 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -648,6 +648,8 @@
<string name="details.expiration">Expiration</string>
<string name="details.played_count">Played Count</string>
+ <string name="permission.external_storage.failed">DSub cannot function without the ability to write to storage</string>
+
<plurals name="select_album_n_songs">
<item quantity="zero">No songs</item>
<item quantity="one">One song</item>