erisu commented on code in PR #1895:
URL: https://github.com/apache/cordova-android/pull/1895#discussion_r2944353229


##########
framework/src/org/apache/cordova/engine/SystemWebChromeClient.java:
##########
@@ -59,6 +66,12 @@ Licensed to the Apache Software Foundation (ASF) under one
  */
 public class SystemWebChromeClient extends WebChromeClient {
 
+    private interface PermissionListener {
+        void onPermissionSelect(Boolean isGranted);
+    }
+
+    private ActivityResultLauncher permissionLauncher;

Review Comment:
   There were a couple of warnings in Android Studio:
   
   > Raw use of parameterized class 'ActivityResultLauncher' 
   
   and
   
   > Field 'permissionLauncher' may be 'final' 
   
   Would it be safe to use the following?
   
   ```suggestion
       private final ActivityResultLauncher<String[]> permissionLauncher;
   ```



##########
framework/src/org/apache/cordova/engine/SystemWebChromeClient.java:
##########
@@ -325,7 +347,27 @@ private Uri createUriForFile(Context context, File 
tempFile) throws IOException
     @Override
     public void onPermissionRequest(final PermissionRequest request) {
         LOG.d(LOG_TAG, "onPermissionRequest: " + 
Arrays.toString(request.getResources()));
-        request.grant(request.getResources());
+        List<String> permissionList = new ArrayList<>();
+        if 
(Arrays.asList(request.getResources()).contains("android.webkit.resource.VIDEO_CAPTURE"))
 {
+            permissionList.add(Manifest.permission.CAMERA);
+        }
+        if 
(Arrays.asList(request.getResources()).contains("android.webkit.resource.AUDIO_CAPTURE"))
 {
+            permissionList.add(Manifest.permission.MODIFY_AUDIO_SETTINGS);
+            permissionList.add(Manifest.permission.RECORD_AUDIO);
+        }
+        if (!permissionList.isEmpty()) {
+            String[] permissions = permissionList.toArray(new String[0]);
+            permissionListener = (isGranted) -> {
+                if (isGranted) {
+                    request.grant(request.getResources());
+                } else {
+                    request.deny();
+                }
+            };
+            permissionLauncher.launch(permissions);

Review Comment:
   The following warning appears when `permissionLauncher` is declared as 
`ActivityResultLauncher` instead of `ActivityResultLauncher<String[]>`.
   
   > Unchecked call to 'launch(I)' as a member of raw type 
'androidx.activity.result.ActivityResultLauncher'



##########
framework/src/org/apache/cordova/engine/SystemWebChromeClient.java:
##########
@@ -45,6 +48,10 @@ Licensed to the Apache Software Foundation (ASF) under one
 import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
+
+import androidx.activity.result.ActivityResultCallback;

Review Comment:
   Can you confirm if this import is needed?
   
   I don't see it used anywhere within code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to