-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera] fix RECORD_AUDIO permission on Android when there is no permission #10424
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
Changes from all commits
752c5df
61a6b51
a615897
481ab0f
c897f93
3ab8b9f
6d556c1
25d2bd0
70c849f
e7c94e3
62841e3
98c5dd9
be11da6
a99cb3c
7d7f52e
caa960b
27f6339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
|
|
@@ -52,7 +53,6 @@ public void withAudioEnabled_doesNotEnableAudioWhenRequestedAndPermissionNotGran | |
| final PigeonApiPendingRecording api = | ||
| new TestProxyApiRegistrar().getPigeonApiPendingRecording(); | ||
| final PendingRecording instance = mock(PendingRecording.class); | ||
| final PendingRecording newInstance = mock(PendingRecording.class); | ||
|
|
||
| try (MockedStatic<ContextCompat> mockedContextCompat = | ||
| Mockito.mockStatic(ContextCompat.class)) { | ||
|
|
@@ -63,10 +63,32 @@ public void withAudioEnabled_doesNotEnableAudioWhenRequestedAndPermissionNotGran | |
| any(Context.class), eq(Manifest.permission.RECORD_AUDIO))) | ||
| .thenAnswer((Answer<Integer>) invocation -> PackageManager.PERMISSION_DENIED); | ||
|
|
||
| when(instance.withAudioEnabled(true)).thenReturn(newInstance); | ||
| when(instance.withAudioEnabled(false)).thenReturn(instance); | ||
|
|
||
| assertEquals(api.withAudioEnabled(instance, false), newInstance); | ||
| verify(instance).withAudioEnabled(true); | ||
| assertEquals(api.withAudioEnabled(instance, false), instance); | ||
| verify(instance, never()).withAudioEnabled(false); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void withAudioEnabled_doesNotEnableAudioWhenNotRequestedAndPermissionNotGranted() { | ||
| final PigeonApiPendingRecording api = | ||
| new TestProxyApiRegistrar().getPigeonApiPendingRecording(); | ||
| final PendingRecording instance = mock(PendingRecording.class); | ||
|
|
||
| try (MockedStatic<ContextCompat> mockedContextCompat = | ||
| Mockito.mockStatic(ContextCompat.class)) { | ||
| mockedContextCompat | ||
| .when( | ||
| () -> | ||
| ContextCompat.checkSelfPermission( | ||
| any(Context.class), eq(Manifest.permission.RECORD_AUDIO))) | ||
| .thenAnswer((Answer<Integer>) invocation -> PackageManager.PERMISSION_DENIED); | ||
|
|
||
| when(instance.withAudioEnabled(true)).thenReturn(instance); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make a separate test with these changes? This (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 i might be missing something. i'm falling to see the issue. could you help?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the original test was testing an invalid assumption. withAudioEnabled_doesNotEnableAudioWhenRequestedAndPermissionNotGranted is testing when audio IS requested with permission denied.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe so.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
|
||
| assertEquals(api.withAudioEnabled(instance, true), instance); | ||
| verify(instance, never()).withAudioEnabled(true); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.