Bug 1410975 - Support recording audio via supported app from the file picker. r=nechen
authorJan Henning <jh+bugzilla@buttercookie.de>
Mon, 23 Oct 2017 21:10:50 +0200
changeset 387952 d5ba7b6469c7bcc3af9cd6ecef1587ae5a7d6b4b
parent 387951 cd2147b5bc3d7fe3fa403eefe815cf43b357eb35
child 387953 30e69377c285c4f37a35234a5948105199f7913b
push id32739
push useracraciun@mozilla.com
push dateWed, 25 Oct 2017 09:29:21 +0000
treeherdermozilla-central@252a8528c5ab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnechen
bugs1410975
milestone58.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 1410975 - Support recording audio via supported app from the file picker. r=nechen Unlike capturing images/videos, the Android permission for recording audio is apparently only required if we want to record the audio ourselves, but not if we're merely calling out to some other app via MediaStore.Audio.Media.RECORD_SOUND_ACTION. Therefore we can drop that permission request for now. MozReview-Commit-ID: 35vtm8Y78hh
mobile/android/base/java/org/mozilla/gecko/FilePicker.java
mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
@@ -108,23 +108,23 @@ public class FilePicker implements Bundl
                         }, tabId);
                     }
                 });
         }
     }
 
     private static String[] getPermissionsForMimeType(final String mimeType) {
         if (mimeType.startsWith("audio/")) {
-            return new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE };
+            return new String[] { Manifest.permission.READ_EXTERNAL_STORAGE };
         } else if (mimeType.startsWith("image/")) {
             return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_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.RECORD_AUDIO, Manifest.permission.READ_EXTERNAL_STORAGE };
+        return new String[] { Manifest.permission.CAMERA, Manifest.permission.READ_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) {
@@ -155,19 +155,25 @@ public class FilePicker implements Bundl
         Intent baseIntent;
         // A HashMap of Activities the base intent will show in the chooser. This is used
         // to filter activities from other intents so that we don't show duplicates.
         HashMap<String, Intent> baseIntents = new HashMap<String, Intent>();
         // A list of other activities to show in the picker (and the intents to launch them).
         HashMap<String, Intent> intents = new HashMap<String, Intent> ();
 
         if (mimeType.startsWith("audio/")) {
-            // For audio the only intent is the mimetype
             baseIntent = getIntent(mimeType);
             addActivities(baseIntent, baseIntents, null);
+
+            if (mimeType.equals("audio/*") &&
+                    hasPermissionsForMimeType(mimeType, availPermissions)) {
+                // We also add a capture intent
+                Intent intent = IntentHelper.getAudioCaptureIntent();
+                addActivities(intent, intents, baseIntents);
+            }
         } else if (mimeType.startsWith("image/")) {
             baseIntent = getIntent(mimeType);
             addActivities(baseIntent, baseIntents, null);
 
             if (mimeType.equals("image/*") &&
                     hasPermissionsForMimeType(mimeType, availPermissions)) {
                 // We also add a capture intent
                 Intent intent = IntentHelper.getImageCaptureIntent(
@@ -185,16 +191,20 @@ public class FilePicker implements Bundl
                 Intent intent = IntentHelper.getVideoCaptureIntent();
                 addActivities(intent, intents, baseIntents);
             }
         } else {
             baseIntent = getIntent("*/*");
             addActivities(baseIntent, baseIntents, null);
 
             Intent intent;
+            if (hasPermissionsForMimeType("audio/*", availPermissions)) {
+                intent = IntentHelper.getAudioCaptureIntent();
+                addActivities(intent, intents, baseIntents);
+            }
             if (hasPermissionsForMimeType("image/*", availPermissions)) {
                 intent = IntentHelper.getImageCaptureIntent(
                         new File(Environment.getExternalStorageDirectory(),
                                 fileHandler.generateImageName()));
                 addActivities(intent, intents, baseIntents);
             }
             if (hasPermissionsForMimeType("video/*", availPermissions)) {
                 intent = IntentHelper.getVideoCaptureIntent();
--- a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
@@ -234,16 +234,20 @@ public final class IntentHelper implemen
         intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
         intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         intent.putExtra(BrowserContract.SKIP_TAB_QUEUE_FLAG, true);
         intent.putExtra(INTENT_EXTRA_TAB_ID, tab.getId());
         intent.putExtra(INTENT_EXTRA_SESSION_UUID, GeckoApplication.getSessionUUID());
         return intent;
     }
 
+    public static Intent getAudioCaptureIntent() {
+        return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
+    }
+
     public static Intent getImageCaptureIntent(final File destinationFile) {
         final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
         intent.putExtra(MediaStore.EXTRA_OUTPUT,
                 Uri.fromFile(destinationFile));
         return intent;
     }
 
     public static Intent getVideoCaptureIntent() {