From eb70f05168dcf3a07d8716c772db3a3c3c3a59f8 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Wed, 3 Jun 2015 22:59:49 +0200 Subject: [PATCH] CB-9115 android: Grant Lollipop permission req This patch overrides onPermissionRequest so that getUserMedia can be used inside the browser. Since a hybrid app has to request permissions anyways via AndroidManifest.xml, I think it is unnecessary to have any further configuration for onPermissionRequest. Anything that the app is allowed to do should be possible from the JS side. Hence all requests are granted. This enables getUserMedia (and WebRTC) on Android Lollipop, without resorting to crosswalk. The docs say that request.grant has to be called from the UI thread, but don't explicitly spell out whether onPermissionRequest is called from the UI thread. I think that this is so, the WebChromeClient of course makes its calls from the UI thread unless otherwise noted. So there is no need to post a runnable to the UI thread. This closes 178 https://github.com/apache/cordova-android/pull/178 --- .../org/apache/cordova/engine/SystemWebChromeClient.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index 7b6c883e..3b5866c3 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -18,6 +18,7 @@ */ package org.apache.cordova.engine; +import java.util.Arrays; import android.annotation.TargetApi; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -36,6 +37,7 @@ import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebStorage; import android.webkit.WebView; +import android.webkit.PermissionRequest; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; @@ -266,6 +268,13 @@ public class SystemWebChromeClient extends WebChromeClient { return true; } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + @Override + public void onPermissionRequest(final PermissionRequest request) { + Log.d(LOG_TAG, "onPermissionRequest: " + Arrays.toString(request.getResources())); + request.grant(request.getResources()); + } + public void destroyLastDialog(){ dialogsHelper.destroyLastDialog(); }