summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcretin45 <cretin45@gmail.com>2016-05-05 19:52:55 (GMT)
committerEd Carrigan <cretin45@gmail.com>2016-05-05 20:00:26 (GMT)
commit019b74b566d0589ada06a3ea6b6b11be829c106a (patch)
treede649ccdaa2f0d79f545ff4fd0d56236cc27aa29
parent70b1937340c2c48acfd74def2d92f072e939b4c4 (diff)
downloadandroid_packages_apps_Trebuchet-019b74b566d0589ada06a3ea6b6b11be829c106a.zip
android_packages_apps_Trebuchet-019b74b566d0589ada06a3ea6b6b11be829c106a.tar.gz
android_packages_apps_Trebuchet-019b74b566d0589ada06a3ea6b6b11be829c106a.tar.bz2
Trebuchet: Add runtime storage perm check for wallpaper picker
Issue-id: FEIJ-441 Change-Id: Iac9a2c249de595568f68313335d337410928d19e (cherry picked from commit 71e092266117e0d7d57f9a78fb9b52552acc9cda)
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java42
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java2
-rw-r--r--res/values/cm_strings.xml2
3 files changed, 45 insertions, 1 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 4aa51db..1efe301 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -16,6 +16,7 @@
package com.android.launcher3;
+import android.Manifest;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
@@ -23,6 +24,7 @@ import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -58,6 +60,8 @@ import java.util.WeakHashMap;
public class WallpaperCropActivity extends BaseActivity implements Handler.Callback {
private static final String LOGTAG = "Launcher3.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;
@@ -90,6 +94,34 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
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();
+ }
+ }
+ }
+ }
+ }
+
+ private void load() {
mLoaderThread = new HandlerThread("wallpaper_loader");
mLoaderThread.start();
mLoaderHandler = new Handler(mLoaderThread.getLooper(), this);
@@ -451,6 +483,16 @@ 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/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index 5985850..abf2026 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -721,7 +721,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
public void onStop() {
super.onStop();
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
- if (mWallpaperStrip.getAlpha() < 1f) {
+ if (mWallpaperStrip != null && mWallpaperStrip.getAlpha() < 1f) {
mWallpaperStrip.setAlpha(1f);
mWallpaperStrip.setVisibility(View.VISIBLE);
}
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 1c6aaf8..36a2f25 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -77,4 +77,6 @@
<!-- App not available toast text -->
<string name="app_not_available">App not available</string>
+
+ <string name="storage_permission_denied">Can\'t access storage</string>
</resources>