summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2016-07-08 21:03:35 (GMT)
committerd34d <clark@cyngn.com>2016-07-08 21:03:35 (GMT)
commit3cd562df77bdbeb093d104b92a2a4fdc6413e536 (patch)
treee587ee01945eeed63f63c3d41dd91d25aaceca6a
parent4909ba22ef96d81adca53c44e2e6dd69786e889e (diff)
downloadandroid_packages_apps_WallpaperPicker-3cd562df77bdbeb093d104b92a2a4fdc6413e536.zip
android_packages_apps_WallpaperPicker-3cd562df77bdbeb093d104b92a2a4fdc6413e536.tar.gz
android_packages_apps_WallpaperPicker-3cd562df77bdbeb093d104b92a2a4fdc6413e536.tar.bz2
Only ask for storage perms when needed
Unless a user clicks on "My photos", there is no need to deny them access to the entire wallpaper picker when they deny storage access permissions. Change-Id: I7028f373d4da65d2e8aa3939600681c92d03dc31 TICKET: CYNGNOS-3175
-rw-r--r--src/org/cyanogenmod/wallpaperpicker/WallpaperCropActivity.java39
-rw-r--r--src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java50
2 files changed, 48 insertions, 41 deletions
diff --git a/src/org/cyanogenmod/wallpaperpicker/WallpaperCropActivity.java b/src/org/cyanogenmod/wallpaperpicker/WallpaperCropActivity.java
index 945ccac..bca08ea 100644
--- a/src/org/cyanogenmod/wallpaperpicker/WallpaperCropActivity.java
+++ b/src/org/cyanogenmod/wallpaperpicker/WallpaperCropActivity.java
@@ -60,8 +60,6 @@ import java.util.WeakHashMap;
public class WallpaperCropActivity extends BaseActivity implements Handler.Callback {
private static final String LOGTAG = "CropActivity";
- private static final int REQUEST_CODE_STORAGE_PERMISSION_CHECK = 100;
-
protected static final String WALLPAPER_WIDTH_KEY = WallpaperUtils.WALLPAPER_WIDTH_KEY;
protected static final String WALLPAPER_HEIGHT_KEY = WallpaperUtils.WALLPAPER_HEIGHT_KEY;
@@ -94,32 +92,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- if (!hasStoragePermissions()) {
- requestStoragePermissions();
- } else {
- load();
- }
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, String[] permissions,
- int[] grantResults) {
- if (requestCode == REQUEST_CODE_STORAGE_PERMISSION_CHECK) {
- for (int i = 0; i < permissions.length; i++ ) {
- final String permission = permissions[i];
- final int grantResult = grantResults[i];
- if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
- if (grantResult == PackageManager.PERMISSION_GRANTED) {
- load();
- } else {
- Toast.makeText(this, getString(R.string.storage_permission_denied),
- Toast.LENGTH_SHORT).show();
- finish();
- }
- }
- }
- }
+ load();
}
private void load() {
@@ -514,16 +487,6 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
sp, getWindowManager(), WallpaperManager.getInstance(getContext()), true);
}
- private boolean hasStoragePermissions() {
- return checkCallingOrSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) ==
- PackageManager.PERMISSION_GRANTED;
- }
-
- private void requestStoragePermissions() {
- requestPermissions(new String[] {android.Manifest.permission.READ_EXTERNAL_STORAGE},
- REQUEST_CODE_STORAGE_PERMISSION_CHECK);
- }
-
static class LoadRequest {
BitmapSource src;
boolean touchEnabled;
diff --git a/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java b/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java
index a5c1d03..9ba2515 100644
--- a/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java
+++ b/src/org/cyanogenmod/wallpaperpicker/WallpaperPickerActivity.java
@@ -104,6 +104,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
private static final String ACTION_SET_KEYGUARD_WALLPAPER =
"android.intent.action.SET_KEYGUARD_WALLPAPER";
+ private static final int REQUEST_CODE_STORAGE_PERMISSION_CHECK = 100;
+
@Thunk
View mSelectedTile;
@Thunk boolean mIgnoreNextTap;
@@ -147,9 +149,11 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
public static class PickImageInfo extends WallpaperTileInfo {
@Override
public void onClick(WallpaperPickerActivity a) {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType("image/*");
- a.startActivityForResultSafely(intent, IMAGE_PICK);
+ if (a.hasStoragePermissions()) {
+ a.startPickImageActivity();
+ } else {
+ a.requestStoragePermissions();
+ }
}
}
@@ -511,6 +515,30 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
}
}
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ int[] grantResults) {
+ if (requestCode == REQUEST_CODE_STORAGE_PERMISSION_CHECK) {
+ for (int i = 0; i < permissions.length; i++ ) {
+ final String permission = permissions[i];
+ final int grantResult = grantResults[i];
+ if (permission.equals(Manifest.permission.READ_EXTERNAL_STORAGE)) {
+ if (grantResult == PackageManager.PERMISSION_GRANTED) {
+ startPickImageActivity();
+ } else {
+ Toast.makeText(this, getString(R.string.storage_permission_denied),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+ }
+ }
+
// called by onCreate; this is subclassed to overwrite WallpaperCropActivity
protected void init() {
setContentView(R.layout.wallpaper_picker);
@@ -1378,6 +1406,22 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
Utilities.startActivityForResultSafely(getActivity(), intent, requestCode);
}
+ public void startPickImageActivity() {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.setType("image/*");
+ startActivityForResultSafely(intent, IMAGE_PICK);
+ }
+
+ public boolean hasStoragePermissions() {
+ return checkCallingOrSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) ==
+ PackageManager.PERMISSION_GRANTED;
+ }
+
+ public void requestStoragePermissions() {
+ requestPermissions(new String[] {android.Manifest.permission.READ_EXTERNAL_STORAGE},
+ REQUEST_CODE_STORAGE_PERMISSION_CHECK);
+ }
+
private static class ThemeWallpapersAdapter extends BaseAdapter implements ListAdapter {
private LayoutInflater mLayoutInflater;
private ArrayList<ThemeWallpaperInfo> mWallpapers;