jenkins-bot has submitted this change and it was merged.
Change subject: 6.0 runtime permission for save image from gallery
......................................................................
6.0 runtime permission for save image from gallery
Added runtime permission checks before trying to write to
external storage in gallery.
Note this patch does not address the share a fact functionality since
it doesn't currently work, see T116120.
The runtime checks are used once target SDK level is set to 23.
I'll let a later patch change this value, once we're done with all the
permission checks and the backup check.
Bug: T113750
Change-Id: I356a736a0d84c99e05e0a6ae1784f99c1c59779e
---
M app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
3 files changed, 47 insertions(+), 1 deletion(-)
Approvals:
Sniedzielski: Looks good to me, approved
Mholloway: Looks good to me, but someone else must approve
Dbrant: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git
a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
index 99cfc95..f76c27c 100644
--- a/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
+++ b/app/src/main/java/org/wikipedia/page/gallery/GalleryItemFragment.java
@@ -5,8 +5,11 @@
import org.wikipedia.WikipediaApp;
import org.wikipedia.concurrency.SaneAsyncTask;
import org.wikipedia.util.FeedbackUtil;
+import org.wikipedia.util.PermissionUtil;
import org.wikipedia.util.ShareUtils;
+import android.Manifest;
+import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
@@ -14,7 +17,9 @@
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
+import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
+import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@@ -38,6 +43,7 @@
public static final String ARG_PAGETITLE = "pageTitle";
public static final String ARG_MEDIATITLE = "imageTitle";
public static final String ARG_MIMETYPE = "mimeType";
+ private static final int WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST = 44;
private WikipediaApp app;
private GalleryActivity parentActivity;
@@ -169,7 +175,7 @@
}
return true;
case R.id.menu_gallery_save:
- saveImageToMediaStore();
+ checkPermissionsToSaveImage();
return true;
case R.id.menu_gallery_share:
shareImage();
@@ -420,6 +426,43 @@
}
/**
+ * Checks runtime permissions first. If allowed it then proceeds with
saving the image
+ * to the MediaStore.
+ */
+ private void checkPermissionsToSaveImage() {
+ if (ContextCompat.checkSelfPermission(getActivity(),
+ Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
+
requestWriteStorageRuntimePermissions(WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST);
+ } else {
+ saveImageToMediaStore();
+ }
+ }
+
+ private void requestWriteStorageRuntimePermissions(int requestCode) {
+ requestPermissions(new
String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, requestCode);
+ // once permission is granted/denied it will continue with
onRequestPermissionsResult
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode,
+ @NonNull String[] permissions,
+ @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case WRITE_EXTERNAL_STORAGE_PERMISSION_REQUEST:
+ if (PermissionUtil.isPermitted(grantResults)) {
+ saveImageToMediaStore();
+ } else {
+ Log.e(TAG, "Write permission was denied by user");
+ FeedbackUtil.showMessage(getActivity(),
+
R.string.gallery_save_image_write_permission_rationale);
+ }
+ break;
+ default:
+ throw new RuntimeException("unexpected permission request code
" + requestCode);
+ }
+ }
+
+ /**
* Save the current image to the MediaStore of the local device ("Photos"
/ "Gallery" / etc).
*/
private void saveImageToMediaStore() {
diff --git a/app/src/main/res/values-qq/strings.xml
b/app/src/main/res/values-qq/strings.xml
index 7bb1278..018fbd1 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -334,6 +334,7 @@
<string name="gallery_image_saved_notification_title">Message shown when an
image is saved to the device.</string>
<string name="gallery_image_saved_notification_text">Message inviting the
user to touch the notification to view the saved image.</string>
<string name="gallery_error_video_failed">Error message displayed when a
video fails to be played on the device.</string>
+ <string name="gallery_save_image_write_permission_rationale">Message shown
to explain that an extra write permission is needed to save an image.</string>
<string name="err_cannot_save_file">Error message when we detect that a file
cannot be written to storage.</string>
<string name="snippet_share_intro">Intro text included as part of the shared
text snippet, aka Tweet-a-fact. Please do not translate the \"@Wikipedia\" in
the message and preserve the spaces around it, as it refers specifically to
Wikipedia\'s Twitter account. This message has two parameters. Please keep the
parameters exactly as in the original English message.
* %1$s is the title of the page the text snippet is from.
diff --git a/app/src/main/res/values/strings.xml
b/app/src/main/res/values/strings.xml
index a238bcd..3024157 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -263,6 +263,7 @@
<string name="gallery_image_saved_notification_title">Image saved.</string>
<string name="gallery_image_saved_notification_text">Touch to
view.</string>
<string name="gallery_error_video_failed">Could not play the
video.</string>
+ <string name="gallery_save_image_write_permission_rationale">Permission to
write to storage on your device is required for saving images. Please try
again, and grant the requested permission.</string>
<string name="err_cannot_save_file">Cannot save file</string>
<string name="snippet_share_intro">\"%1$s\" on @Wikipedia: %2$s</string>
<string name="expand_refs">Tap to expand</string>
@@ -301,4 +302,5 @@
<string name="crash_report_relaunch">Start over</string>
<string name="crash_report_quit">Quit</string>
<!-- /Crash reporter -->
+
</resources>
--
To view, visit https://gerrit.wikimedia.org/r/247770
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I356a736a0d84c99e05e0a6ae1784f99c1c59779e
Gerrit-PatchSet: 7
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits