Bug 1507531 - FilePicker will request WRITE_EXTERNAL_STORAGE; r=JanH
authorPetru Lingurar <petru.lingurar@softvision.ro>
Fri, 22 Feb 2019 15:43:13 +0000
changeset 518921 7ae76ec6dad573ca4313bc1f117f88e1f5be3935
parent 518920 9ff4aa05d88146da01176e4d3ec5a1ab9739a7e2
child 518922 758cf7b85e44892add9477895caa84448dc0cff5
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJanH
bugs1507531
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1507531 - FilePicker will request WRITE_EXTERNAL_STORAGE; r=JanH "Prior to Android 8.0 (API level 26), if an app requested a permission at runtime and the permission was granted, the system would also incorrectly grant the app the rest of the permissions that belonged to the same permission group, and that were registered in the manifest. For apps targeting Android 8.0, this behavior has been corrected. The app is granted only the permissions it has explicitly requested. However, once the user grants a permission to the app, all subsequent requests for permissions in that permission group are automatically granted." https://developer.android.com/about/versions/oreo/android-8.0-changes#rmp Our FilePicker can delegate other applications to record media files (photo/audio/video) which are then to be sent to websites. They must be saved locally before the upload, scenario that wasn't possible anymore on Oreo+ because of the change in how Android handles runtime permissions. As a way to get around this one could grant the "Storage" permission from System Settings which would grant the app both READ and WRITE access. But for actually being prepared to handle all situations our FilePicker must ask for the WRITE_EXTERNAL_STORAGE permission at runtime. Differential Revision: https://phabricator.services.mozilla.com/D20821
mobile/android/base/java/org/mozilla/gecko/FilePicker.java
--- a/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
@@ -109,23 +109,23 @@ public class FilePicker implements Bundl
                         }, tabId);
                     }
                 });
         }
     }
 
     private static String[] getPermissionsForMimeType(final String mimeType) {
         if (mimeType.startsWith("audio/")) {
-            return new String[] { Manifest.permission.READ_EXTERNAL_STORAGE };
+            return new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE };
         } else if (mimeType.startsWith("image/")) {
-            return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
+            return new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE };
         } else if (mimeType.startsWith("video/")) {
-            return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
+            return new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE };
         }
-        return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE };
+        return new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE };
     }
 
     private static boolean hasPermissionsForMimeType(final String mimeType, final String[] availPermissions) {
         return Arrays.asList(availPermissions)
                 .containsAll(Arrays.asList(getPermissionsForMimeType(mimeType)));
     }
 
     private void addActivities(Intent intent, HashMap<String, Intent> intents, HashMap<String, Intent> filters) {