aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Birg <roman@cyngn.com>2016-01-11 19:16:36 (GMT)
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-01-14 22:55:49 (GMT)
commit6a4f804228c5ce93ccc48a2e2725d32d83a5bd8c (patch)
treea25aa1067c2da6078f6b9006df85daf47baedcd4
parent1304d693154c2dff936003fee76aa82abde82814 (diff)
downloadandroid_packages_wallpapers_PhotoPhase-6a4f804228c5ce93ccc48a2e2725d32d83a5bd8c.zip
android_packages_wallpapers_PhotoPhase-6a4f804228c5ce93ccc48a2e2725d32d83a5bd8c.tar.gz
android_packages_wallpapers_PhotoPhase-6a4f804228c5ce93ccc48a2e2725d32d83a5bd8c.tar.bz2
PhotoPhase: ask for runtime permissions
Ref: CYNGNOS-1555 Change-Id: I7cc351fca1085ec29823b12d3959b83142eac4cb Signed-off-by: Roman Birg <roman@cyngn.com>
-rw-r--r--AndroidManifest.xml10
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java10
-rw-r--r--src/org/cyanogenmod/wallpapers/photophase/RequestPermissionsActivity.java55
4 files changed, 77 insertions, 1 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 7070495..42f7eec 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -22,7 +22,7 @@
<original-package android:name="org.cyanogenmod.wallpapers.photophase" />
- <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="19" />
+ <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
<uses-feature android:name="android.software.live_wallpaper" android:required="true" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
@@ -52,6 +52,14 @@
<meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper" />
</service>
+ <activity android:name=".RequestPermissionsActivity"
+ android:exported="false"
+ android:theme="@style/android:Theme.Translucent.NoTitleBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
<activity
android:name=".PhotoPhaseActivity"
android:exported="true"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b26417a..d06e721 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -26,6 +26,9 @@
<!-- No images message -->
<string name="no_pictures_oops_msg">No pictures found</string>
+ <!-- runtime permission warning -->
+ <string name="runtime_permission_warning">The application can not run without permission to read the external storage.</string>
+
<!-- Menus -->
<string name="mnu_ok" translatable="false">@android:string/ok</string>
<string name="mnu_restore">Restore</string>
diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
index ecb0872..2c53709 100644
--- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
+++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java
@@ -19,6 +19,7 @@ package org.cyanogenmod.wallpapers.photophase;
import android.app.ActivityManager;
import android.app.WallpaperManager;
import android.content.Context;
+import android.content.Intent;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
@@ -94,10 +95,19 @@ public class PhotoPhaseWallpaper
*/
@Override
public Engine onCreateEngine() {
+ checkPermission();
mEngine = new PhotoPhaseWallpaperEngine(this);
return mEngine;
}
+ private void checkPermission() {
+ if (!RequestPermissionsActivity.hasRequestedPermissions(this)) {
+ startActivity(new Intent(Intent.ACTION_MAIN)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .setClass(this, RequestPermissionsActivity.class));
+ }
+ }
+
/**
* A wallpaper engine implementation using GLES.
*/
diff --git a/src/org/cyanogenmod/wallpapers/photophase/RequestPermissionsActivity.java b/src/org/cyanogenmod/wallpapers/photophase/RequestPermissionsActivity.java
new file mode 100644
index 0000000..5999d10
--- /dev/null
+++ b/src/org/cyanogenmod/wallpapers/photophase/RequestPermissionsActivity.java
@@ -0,0 +1,55 @@
+package org.cyanogenmod.wallpapers.photophase;
+
+import android.Manifest;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.widget.Toast;
+
+public class RequestPermissionsActivity extends Activity {
+
+ public static final int REQUEST_STORAGE_PERMISSION = 1;
+
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ if (!hasRequestedPermissions(this)) {
+ requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
+ REQUEST_STORAGE_PERMISSION);
+ } else {
+ setResult(Activity.RESULT_OK);
+ finish();
+ }
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case REQUEST_STORAGE_PERMISSION: {
+ // If request is cancelled, the result arrays are empty.
+ if (grantResults.length > 0
+ && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ setResult(Activity.RESULT_OK);
+ } else {
+ Toast.makeText(this, R.string.runtime_permission_warning, Toast.LENGTH_SHORT)
+ .show();
+ setResult(Activity.RESULT_CANCELED);
+ }
+ finish();
+ return;
+ }
+ }
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+
+ public static boolean hasRequestedPermissions(Context context) {
+ return context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) ==
+ PackageManager.PERMISSION_GRANTED;
+ }
+
+}