OSDN Git Service

Fix 1836138: Crash (permissions) when sharing from Email/Gmail --> Gallery --> Anywhe...
authorChih-Chung Chang <chihchung@google.com>
Fri, 10 Jul 2009 10:39:49 +0000 (18:39 +0800)
committerChih-Chung Chang <chihchung@google.com>
Fri, 10 Jul 2009 15:45:29 +0000 (23:45 +0800)
src/com/android/camera/MenuHelper.java
src/com/android/camera/ReviewImage.java
src/com/android/camera/ViewImage.java

index f631b69..6c0c58d 100644 (file)
@@ -140,12 +140,29 @@ public class MenuHelper {
     }
 
     // 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) {
index e755187..5ea4196 100644 (file)
@@ -398,7 +398,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
         }
 
         Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
-        MenuHelper.enableShareMenuItem(menu, !MenuHelper.isMMSUri(uri));
+        MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));
 
         return true;
     }
@@ -934,7 +934,7 @@ public class ReviewImage extends Activity implements View.OnClickListener {
                 break;
             case R.id.btn_share: {
                 IImage image = mAllImages.getImageAt(mCurrentPosition);
-                if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
+                if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
                     return;
                 }
                 startShareMediaActivity(image);
index 3c63ae2..0e66576 100644 (file)
@@ -434,7 +434,7 @@ public class ViewImage extends Activity implements View.OnClickListener {
         }
 
         Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
-        MenuHelper.enableShareMenuItem(menu, !MenuHelper.isMMSUri(uri));
+        MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));
 
         return true;
     }
@@ -581,13 +581,11 @@ public class ViewImage extends Activity implements View.OnClickListener {
             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 @@ public class ViewImage extends Activity implements View.OnClickListener {
                 break;
             case R.id.share: {
                 IImage image = mAllImages.getImageAt(mCurrentPosition);
-                if (MenuHelper.isMMSUri(image.fullSizeImageUri())) {
+                if (!MenuHelper.isWhiteListUri(image.fullSizeImageUri())) {
                     return;
                 }
                 startShareMediaActivity(image);