summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2018-04-30 17:28:13 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2018-04-30 17:30:25 +0530
commitf1fa46829d10c5159a8b6c6aad97339f9734b42b (patch)
treeab4ce004c37842b05375849cf9c59deaf44d0890
parenta6e530049cfb3786cfbadf73fc9844cb7b16e4ef (diff)
SettingsActivity: Migrate permissions check to AppCompat
Pretty straightforward, I was clearly overthinking this. Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
-rw-r--r--app/src/main/java/com/wireguard/android/activity/SettingsActivity.java31
1 files changed, 11 insertions, 20 deletions
diff --git a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
index b1754b87..e48b6d88 100644
--- a/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
+++ b/app/src/main/java/com/wireguard/android/activity/SettingsActivity.java
@@ -3,6 +3,7 @@ package com.wireguard.android.activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
+import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
@@ -31,30 +32,20 @@ public class SettingsActivity extends AppCompatActivity {
private int permissionRequestCounter = 0;
public synchronized void ensurePermissions(String[] permissions, PermissionRequestCallback cb) {
- /* TODO(MSF): since when porting to AppCompat, you'll be replacing checkSelfPermission
- * and requestPermission with AppCompat.checkSelfPermission and AppCompat.requestPermission,
- * you can remove this SDK_INT block entirely here, and count on the compat lib to do
- * the right thing. */
- if (android.os.Build.VERSION.SDK_INT < 23) {
+ List<String> needPermissions = new ArrayList<>(permissions.length);
+ for (final String permission : permissions) {
+ if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED)
+ needPermissions.add(permission);
+ }
+ if (needPermissions.isEmpty()) {
int[] granted = new int[permissions.length];
Arrays.fill(granted, PackageManager.PERMISSION_GRANTED);
cb.done(permissions, granted);
- } else {
- List<String> needPermissions = new ArrayList<>(permissions.length);
- for (final String permission : permissions) {
- if (getApplicationContext().checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
- needPermissions.add(permission);
- }
- if (needPermissions.isEmpty()) {
- int[] granted = new int[permissions.length];
- Arrays.fill(granted, PackageManager.PERMISSION_GRANTED);
- cb.done(permissions, granted);
- return;
- }
- int idx = permissionRequestCounter++;
- permissionRequestCallbacks.put(idx, cb);
- requestPermissions(needPermissions.toArray(new String[needPermissions.size()]), idx);
+ return;
}
+ int idx = permissionRequestCounter++;
+ permissionRequestCallbacks.put(idx, cb);
+ ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]), idx);
}
@Override