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
This commit is contained in:
Volker Braun 2015-06-03 22:59:49 +02:00 committed by Joe Bowser
parent 505db38232
commit eb70f05168

View File

@ -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();
}