fix(android): onPermissionRequest duplicate (#2002)
This commit is contained in:
parent
4e07183a2d
commit
bba5907906
|
@ -1148,46 +1148,6 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Fix WebRTC permission request error.
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@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);
|
||||
} else if(requestedResources[i].equals(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) {
|
||||
permissions.add(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID);
|
||||
}
|
||||
// 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);
|
||||
} else if (permissions.get(i).equals(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) {
|
||||
grantedPermissions.add(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -1223,6 +1183,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
androidPermission = Manifest.permission.RECORD_AUDIO;
|
||||
} else if (requestedResource.equals(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
|
||||
androidPermission = Manifest.permission.CAMERA;
|
||||
} else if(requestedResource.equals(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) {
|
||||
androidPermission = PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID;
|
||||
}
|
||||
// TODO: RESOURCE_MIDI_SYSEX, RESOURCE_PROTECTED_MEDIA_ID.
|
||||
|
||||
|
@ -1349,6 +1311,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
|||
}
|
||||
shouldAnswerToPermissionRequest = true;
|
||||
}
|
||||
|
||||
if (permission.equals(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID)) {
|
||||
if (granted && grantedPermissions != null) {
|
||||
grantedPermissions.add(PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID);
|
||||
}
|
||||
shouldAnswerToPermissionRequest = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAnswerToPermissionRequest
|
||||
|
|
Loading…
Reference in New Issue