-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Improving handling when camera permissions are not granted. #2848
Conversation
The intent here is to catch the exception and pass it to dart code, no need to raise it afterwards. An additional complication here is that CameraAccessException does extend from RuntimeException.
@bparrishMines any concerns? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for the contribution! I changed the CHANGELOG
exception to be more specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change does still need a test. It should be possible to revoke camera permissions for a test and then verify you don't see the cast exception when opening the camera. Some code we already have for controlling camera permissions on Android: https://github.com/flutter/plugins/blob/master/packages/camera/example/test_driver/camera_e2e_test.dart
Thanks for taking a look! I'm not quite sure how to create a test here, can you help me with these two things?
|
@bparrishMines do you have any advice? |
@cyanglaz Do you know of a way to properly test this? It looks like we grant permissions before running the test and revoke permissions at the end. I don't think the |
@bparrishMines I'm not sure either. Maybe we can use a flutter driver test instead of e2e to test this? |
@dnfield Dan, do you have an idea how to create a test? |
@bparrishMines any guidance on how to progress here? |
@bparrishMines any suggestion on how to resolve the situation? I still would love to add a test, I'm just not sure how to write it. |
I don't believe we currently have a good way to test this, but the code looks good and this needs to be fixed. Merging |
Description
If camera permissions are not granted, the plugin currently throws an exception in Java:
That's because the code attempts to cast a
CameraAccessException
to aRuntimeException
. I think that part of the code is executed unintentionally: what's desired at this point is to fully handle the exception in Java and pass it to dart, i.e. don't throw it again.Related Issues
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?