Fix 1836138: Crash (permissions) when sharing from Email/Gmail --> Gallery --> Anywhere Else
diff --git a/src/com/android/camera/MenuHelper.java b/src/com/android/camera/MenuHelper.java
index f631b69..6c0c58d 100644
--- a/src/com/android/camera/MenuHelper.java
+++ b/src/com/android/camera/MenuHelper.java
@@ -140,12 +140,29 @@
}
// This is a hack before we find a solution to pass a permission to other
- // applications. See bug #1735149.
- // Checks if the URI starts with "content://mms".
- public static boolean isMMSUri(Uri uri) {
- return (uri != null) &&
- uri.getScheme().equals("content") &&
- uri.getAuthority().equals("mms");
+ // applications. See bug #1735149, #1836138.
+ // Checks if the URI is on our whitelist:
+ // content://media/... (MediaProvider)
+ // file:///sdcard/... (Browser download)
+ public static boolean isWhiteListUri(Uri uri) {
+ if (uri == null) return false;
+
+ String scheme = uri.getScheme();
+ String authority = uri.getAuthority();
+
+ if (scheme.equals("content") && authority.equals("media")) {
+ return true;
+ }
+
+ if (scheme.equals("file")) {
+ List<String> p = uri.getPathSegments();
+
+ if (p.size() >= 1 && p.get(0).equals("sdcard")) {
+ return true;
+ }
+ }
+
+ return false;
}
public static void enableShareMenuItem(Menu menu, boolean enabled) {
diff --git a/src/com/android/camera/ReviewImage.java b/src/com/android/camera/ReviewImage.java
index e755187..5ea4196 100644
--- a/src/com/android/camera/ReviewImage.java
+++ b/src/com/android/camera/ReviewImage.java
@@ -398,7 +398,7 @@
}
Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
- MenuHelper.enableShareMenuItem(menu, !MenuHelper.isMMSUri(uri));
+ MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));
return true;
}
@@ -934,7 +934,7 @@
break;
case R.id.btn_share: {
IImage image = mAllImages.getImageAt(mCurrentPosition);
- if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
+ if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);
diff --git a/src/com/android/camera/ViewImage.java b/src/com/android/camera/ViewImage.java
index 3c63ae2..0e66576 100644
--- a/src/com/android/camera/ViewImage.java
+++ b/src/com/android/camera/ViewImage.java
@@ -434,7 +434,7 @@
}
Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
- MenuHelper.enableShareMenuItem(menu, !MenuHelper.isMMSUri(uri));
+ MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));
return true;
}
@@ -581,13 +581,11 @@
return;
}
- // We don't show action icons for MMS uri because we don't have
- // delete and share action icons for MMS. It is obvious that we don't
- // need the "delete" action, but for the share part, although we get
- // read permission (for the image) from the MMS application, we cannot
- // pass the permission to other activities due to the current framework
- // design.
- if (MenuHelper.isMMSUri(uri)) {
+ // We only show action icons for URIs that we know we can share and
+ // delete. Although we get read permission (for the images) from
+ // applications like MMS, we cannot pass the permission to other
+ // activities due to the current framework design.
+ if (!MenuHelper.isWhiteListUri(uri)) {
mShowActionIcons = false;
}
@@ -998,7 +996,7 @@
break;
case R.id.share: {
IImage image = mAllImages.getImageAt(mCurrentPosition);
- if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
+ if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
return;
}
startShareMediaActivity(image);