forked from react-native-webview/react-native-webview
-
Notifications
You must be signed in to change notification settings - Fork 6
fix(android): honor media capture deny policy #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "@phantom/react-native-webview": patch | ||
| --- | ||
|
|
||
| Honor `mediaCapturePermissionGrantType="deny"` on Android by rejecting camera | ||
| and microphone resources before the existing permission flow can display a | ||
| prompt. Other permission resources and grant-type values retain their current | ||
| behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
android/src/main/java/com/reactnativecommunity/webview/RNCMediaCapturePermission.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.reactnativecommunity.webview; | ||
|
|
||
| import android.webkit.PermissionRequest; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| final class RNCMediaCapturePermission { | ||
| private static final String GRANT_TYPE_DENY = "deny"; | ||
|
|
||
| private RNCMediaCapturePermission() {} | ||
|
|
||
| static String[] filterRequestedResources(String grantType, String[] resources) { | ||
| if (!GRANT_TYPE_DENY.equals(grantType)) { | ||
| return resources; | ||
| } | ||
|
|
||
| List<String> filteredResources = new ArrayList<>(resources.length); | ||
| for (String resource : resources) { | ||
| if (!isMediaCaptureResource(resource)) { | ||
| filteredResources.add(resource); | ||
| } | ||
| } | ||
| return filteredResources.toArray(new String[0]); | ||
| } | ||
|
|
||
| private static boolean isMediaCaptureResource(String resource) { | ||
| return PermissionRequest.RESOURCE_AUDIO_CAPTURE.equals(resource) | ||
| || PermissionRequest.RESOURCE_VIDEO_CAPTURE.equals(resource); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
android/src/test/java/com/reactnativecommunity/webview/RNCMediaCapturePermissionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.reactnativecommunity.webview; | ||
|
|
||
| import static org.junit.Assert.assertArrayEquals; | ||
| import static org.junit.Assert.assertSame; | ||
|
|
||
| import android.webkit.PermissionRequest; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| public class RNCMediaCapturePermissionTest { | ||
| @Test | ||
| public void denyRemovesCameraAndMicrophoneResources() { | ||
| String[] resources = { | ||
| PermissionRequest.RESOURCE_VIDEO_CAPTURE, | ||
| PermissionRequest.RESOURCE_AUDIO_CAPTURE, | ||
| }; | ||
|
|
||
| assertArrayEquals( | ||
| new String[0], | ||
| RNCMediaCapturePermission.filterRequestedResources("deny", resources) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void denyPreservesUnrelatedResources() { | ||
| String[] resources = { | ||
| PermissionRequest.RESOURCE_VIDEO_CAPTURE, | ||
| PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID, | ||
| }; | ||
|
|
||
| assertArrayEquals( | ||
| new String[] { PermissionRequest.RESOURCE_PROTECTED_MEDIA_ID }, | ||
| RNCMediaCapturePermission.filterRequestedResources("deny", resources) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| public void otherPoliciesPreserveExistingBehavior() { | ||
| String[] resources = { PermissionRequest.RESOURCE_VIDEO_CAPTURE }; | ||
|
|
||
| assertSame( | ||
| resources, | ||
| RNCMediaCapturePermission.filterRequestedResources("prompt", resources) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.