Bug 1528303 - Update GVE to demonstrate how to handle media permissions correctly r=geckoview-reviewers,snorp
authorEmily Toop <etoop@mozilla.com>
Wed, 06 Mar 2019 15:41:26 +0000
changeset 520768 b4eb5531f8e7ce7993eca23add7c06fc3cbad05e
parent 520767 84f0b9acc4e9d12ceecd12e75481fd468b7c184a
child 520769 39cdd8bf9e755af92ae8ee171638dfbcb0bed38e
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)
reviewersgeckoview-reviewers, snorp
bugs1528303
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 1528303 - Update GVE to demonstrate how to handle media permissions correctly r=geckoview-reviewers,snorp Update `onMediaPermissionRequest` documentation to better reflect usage Differential Revision: https://phabricator.services.mozilla.com/D21925
mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/geckoview/GeckoSession.java
@@ -4063,16 +4063,21 @@ public class GeckoSession implements Par
             @UiThread
             void reject();
         }
 
         /**
          * Request content media permissions, including request for which video and/or
          * audio source to use.
          *
+         * Media permissions will still be requested if the associated device permissions have been
+         * denied if there are video or audio sources in that category that can still be accessed.
+         * It is the responsibility of consumers to ensure that media permission requests are not
+         * displayed in this case.
+         *
          * @param session GeckoSession instance requesting the permission.
          * @param uri The URI of the content requesting the permission.
          * @param video List of video sources, or null if not requesting video.
          * @param audio List of audio sources, or null if not requesting audio.
          * @param callback Callback interface.
          */
         @UiThread
         void onMediaPermissionRequest(@NonNull GeckoSession session, @NonNull String uri,
--- a/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
+++ b/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java
@@ -656,16 +656,30 @@ public class GeckoViewActivity extends A
 
             return res;
         }
 
         @Override
         public void onMediaPermissionRequest(final GeckoSession session, final String uri,
                                            final MediaSource[] video, final MediaSource[] audio,
                                            final MediaCallback callback) {
+            // If we don't have device permissions at this point, just automatically reject the request
+            // as we will have already have requested device permissions before getting to this point
+            // and if we've reached here and we don't have permissions then that means that the user
+            // denied them.
+            if ((audio != null
+                    && ContextCompat.checkSelfPermission(GeckoViewActivity.this,
+                        Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED)
+                || (video != null
+                    && ContextCompat.checkSelfPermission(GeckoViewActivity.this,
+                        Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)) {
+                callback.reject();
+                return;
+            }
+
             final String host = Uri.parse(uri).getAuthority();
             final String title;
             if (audio == null) {
                 title = getString(R.string.request_video, host);
             } else if (video == null) {
                 title = getString(R.string.request_audio, host);
             } else {
                 title = getString(R.string.request_media, host);