feat(Android): webrtc permission request - conflicts fixed (#719)
* fix(Android): WebRTC permission request (#231) * fix(Android): Avoid unintentionally granting requests for new permissions (#231) * ContextCompat import migrated to androidx new artifact * RNCWebViewManager.java original format restored
This commit is contained in:
parent
86bfb68676
commit
bb79ae80ee
|
@ -5,12 +5,15 @@ import android.annotation.TargetApi;
|
|||
import android.app.DownloadManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.Manifest;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
|
@ -22,6 +25,7 @@ import android.webkit.CookieManager;
|
|||
import android.webkit.DownloadListener;
|
||||
import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.PermissionRequest;
|
||||
import android.webkit.URLUtil;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
|
@ -65,6 +69,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -763,6 +768,41 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Fix WebRTC permission request error.
|
||||
@Override
|
||||
public void onPermissionRequest(final PermissionRequest request) {
|
||||
String[] requestedResources = request.getResources();
|
||||
ArrayList<String> permissions = new ArrayList<>();
|
||||
ArrayList<String> grantedPermissions = new ArrayList<String>();
|
||||
for (int i = 0; i < requestedResources.length; i++) {
|
||||
if (requestedResources[i].equals(PermissionRequest.RESOURCE_AUDIO_CAPTURE)) {
|
||||
permissions.add(Manifest.permission.RECORD_AUDIO);
|
||||
} else if (requestedResources[i].equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
|
||||
permissions.add(Manifest.permission.CAMERA);
|
||||
}
|
||||
// TODO: RESOURCE_MIDI_SYSEX, RESOURCE_PROTECTED_MEDIA_ID.
|
||||
}
|
||||
|
||||
for (int i = 0; i < permissions.size(); i++) {
|
||||
if (ContextCompat.checkSelfPermission(mReactContext, permissions.get(i)) != PackageManager.PERMISSION_GRANTED) {
|
||||
continue;
|
||||
}
|
||||
if (permissions.get(i).equals(Manifest.permission.RECORD_AUDIO)) {
|
||||
grantedPermissions.add(PermissionRequest.RESOURCE_AUDIO_CAPTURE);
|
||||
} else if (permissions.get(i).equals(Manifest.permission.CAMERA)) {
|
||||
grantedPermissions.add(PermissionRequest.RESOURCE_VIDEO_CAPTURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (grantedPermissions.isEmpty()) {
|
||||
request.deny();
|
||||
} else {
|
||||
String[] grantedPermissionsArray = new String[grantedPermissions.size()];
|
||||
grantedPermissionsArray = grantedPermissions.toArray(grantedPermissionsArray);
|
||||
request.grant(grantedPermissionsArray);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(WebView webView, int newProgress) {
|
||||
super.onProgressChanged(webView, newProgress);
|
||||
|
@ -1010,4 +1050,4 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue