summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authord34d <clark@cyngn.com>2016-01-08 14:47:45 -0800
committerd34d <clark@cyngn.com>2016-01-08 15:00:50 -0800
commitbf494dfad68db9a53d3ae1210a9bc9acf147b258 (patch)
tree8d56c1df1b86d08ca57445a83826e4843b333236 /src
parentffd1eaea0b78df32f0bf7d4e4c691dd3dd57290e (diff)
downloadpackages_apps_ThemeChooser-bf494dfad68db9a53d3ae1210a9bc9acf147b258.zip
packages_apps_ThemeChooser-bf494dfad68db9a53d3ae1210a9bc9acf147b258.tar.gz
packages_apps_ThemeChooser-bf494dfad68db9a53d3ae1210a9bc9acf147b258.tar.bz2
Request READ_EXTERNAL_STORAGE permission
This bumps the target SDK up to 23 and gracefully handles getting the required permissions from the user. Change-Id: I66e0d8f4e6f28039811636e3684b2eb7c2bba336 TICKET: CYNGNOS-1565
Diffstat (limited to 'src')
-rw-r--r--src/com/cyngn/theme/chooser/ThemeFragment.java77
1 files changed, 71 insertions, 6 deletions
diff --git a/src/com/cyngn/theme/chooser/ThemeFragment.java b/src/com/cyngn/theme/chooser/ThemeFragment.java
index 641651b..45a469a 100644
--- a/src/com/cyngn/theme/chooser/ThemeFragment.java
+++ b/src/com/cyngn/theme/chooser/ThemeFragment.java
@@ -3,6 +3,7 @@
*/
package com.cyngn.theme.chooser;
+import android.Manifest;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.IntEvaluator;
@@ -73,6 +74,7 @@ import android.widget.ProgressBar;
import android.widget.Space;
import android.widget.TextView;
+import android.widget.Toast;
import com.android.internal.widget.LockPatternUtils;
import com.cyngn.theme.chooser.ComponentSelector.OnItemClickedListener;
import com.cyngn.theme.util.AudioUtils;
@@ -103,6 +105,8 @@ import java.util.List;
import java.util.Map;
import java.util.zip.ZipFile;
+import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
+import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.provider.ThemesContract.ThemesColumns.MODIFIES_ALARMS;
import static android.provider.ThemesContract.ThemesColumns.MODIFIES_BOOT_ANIM;
import static android.provider.ThemesContract.ThemesColumns.MODIFIES_LAUNCHER;
@@ -190,6 +194,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
private static final String LLS_PROVIDER_NAME =
"com.cyngn.lockscreen.live.LockScreenProviderService";
+ private static final int PERMISSION_REQUEST = 100;
+
protected static ComponentName[] sIconComponents;
protected static TypefaceHelperCache sTypefaceHelperCache;
@@ -305,6 +311,8 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
protected boolean mIsLegacyTheme;
+ private Runnable mAfterPermissionGrantedRunnable;
+
private static final int mThemeVersion = ThemeVersion.getVersion();
protected enum CustomizeResetAction {
@@ -565,6 +573,31 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
}
@Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
+ int[] grantResults) {
+ if (requestCode == PERMISSION_REQUEST) {
+ int N = permissions.length;
+ for (int i = 0; i < N; i++) {
+ if (READ_EXTERNAL_STORAGE.equals(permissions[i])) {
+ if (grantResults[i] == PERMISSION_GRANTED) {
+ // Run the runnable now that we have been granted permission
+ if (mAfterPermissionGrantedRunnable != null) {
+ mAfterPermissionGrantedRunnable.run();
+ mAfterPermissionGrantedRunnable = null;
+ }
+ } else {
+ // inform the user that they will be unable to pick an image because
+ // we were not granted permission to do so
+ Toast.makeText(getActivity(),
+ R.string.read_external_permission_denied_message,
+ Toast.LENGTH_LONG).show();
+ }
+ }
+ }
+ }
+ }
+
+ @Override
public void onProgress(int progress) {
mProgress.setProgress(progress);
}
@@ -1993,9 +2026,25 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
setCardTitle(mWallpaperCard, WALLPAPER_NONE,
getString(R.string.wallpaper_label));
} else if (ComponentSelector.EXTERNAL_WALLPAPER.equals(pkgName)) {
- getChooserActivity().pickExternalWallpaper();
- setCardTitle(mWallpaperCard, WALLPAPER_NONE,
- getString(R.string.wallpaper_label));
+ // Check if we have READ_EXTERNAL_STORAGE permission and if not request it,
+ // otherwise let the user pick an image
+ if (getActivity().checkSelfPermission(
+ READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
+ mAfterPermissionGrantedRunnable = new Runnable() {
+ @Override
+ public void run() {
+ getChooserActivity().pickExternalWallpaper();
+ setCardTitle(mWallpaperCard, WALLPAPER_NONE,
+ getString(R.string.wallpaper_label));
+ }
+ };
+ requestPermissions(new String[] {READ_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST);
+ } else {
+ getChooserActivity().pickExternalWallpaper();
+ setCardTitle(mWallpaperCard, WALLPAPER_NONE,
+ getString(R.string.wallpaper_label));
+ }
} else {
loaderId = LOADER_ID_WALLPAPER;
}
@@ -2008,9 +2057,25 @@ public class ThemeFragment extends Fragment implements LoaderManager.LoaderCallb
setCardTitle(mLockScreenCard, WALLPAPER_NONE,
getString(R.string.lockscreen_label));
} else if (ComponentSelector.EXTERNAL_WALLPAPER.equals(pkgName)) {
- getChooserActivity().pickExternalLockscreen();
- setCardTitle(mLockScreenCard, WALLPAPER_NONE,
- getString(R.string.lockscreen_label));
+ // Check if we have READ_EXTERNAL_STORAGE permission and if not request it,
+ // otherwise let the user pick an image
+ if (getActivity().checkSelfPermission(
+ READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) {
+ mAfterPermissionGrantedRunnable = new Runnable() {
+ @Override
+ public void run() {
+ getChooserActivity().pickExternalLockscreen();
+ setCardTitle(mLockScreenCard, WALLPAPER_NONE,
+ getString(R.string.lockscreen_label));
+ }
+ };
+ requestPermissions(new String[] {READ_EXTERNAL_STORAGE},
+ PERMISSION_REQUEST);
+ } else {
+ getChooserActivity().pickExternalLockscreen();
+ setCardTitle(mLockScreenCard, WALLPAPER_NONE,
+ getString(R.string.lockscreen_label));
+ }
} else {
if (MODIFIES_LIVE_LOCK_SCREEN.equals(component)) {
loaderId = LOADER_ID_LIVE_LOCK_SCREEN;