-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Fix for CameraAccessException that prevents image capture on certain devices running Android 7/8 #4572
[camera] Fix for CameraAccessException that prevents image capture on certain devices running Android 7/8 #4572
Conversation
6bf62d7
to
17bbff0
Compare
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Apologies if anything is incorrect/incomplete but this is my first PR. It was suggested I create one for this bug. Any help would be greatly appreciated as although the changes I've made are minimal I've never done this before. |
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.
Apologies if anything is incorrect/incomplete but this is my first PR.
Thanks for the contribution! It mostly looks good, except for the item in the checklist that you missed; please see the linked documents about testing requirements.
captureSession.stopRepeating(); | ||
captureSession.abortCaptures(); | ||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) { | ||
captureSession.stopRepeating(); |
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.
Why is this line duplicated instead of outside of the if/else?
captureSession.stopRepeating(); | ||
} else { | ||
captureSession.stopRepeating(); | ||
captureSession.abortCaptures(); |
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.
There needs to be a comment explaining why this is conditional.
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.
I can confirm that this line causes troubles on some old Huawei/Xiaomi devices.
Actually, I'm pretty sure the captureSession.abortCaptures(); can be removed completely. I was about to make a PR for this myself and stumbled upon this issue. According to the documentation it should only be called before a new session is created, however, calling .capture() does not create a new session. The .abortCaptures call also adds a significant delay between when the take picture button is pressed and when the shutter actually takes a picture (around 200ms on my Samsung S10), removing this line causes the delay of the shutter to dissappear. I have not noticed any negative side effects from removing this line completely, git blame doesn't give any reason why it exists in the first place. |
@jgoyvaerts Hi, so do you think the code can simply be I'm also noticing some issues on specific devices (Alcatel 1C, and Pixel 6 Pro so far) that don't seem to be able to capture at all ... I'm wondering if it's something related to the Captures don't seem to complete, nor do they throw an error. And following attempts to capture get caught on:
|
I'm just saying based on my tests, the .abortCaptures call
Based on these reasons, I'm inclined to believe the line can be removed, especially if you have noticed it causes issues on certain Android versions. Maybe there's an edge case we're missing why it needs to be there, but then that edge case should probably be fixed in a different way, since the happy flow of taking a picture should not have an unneccessary 150-200ms delay. |
@jgoyvaerts Ok. I will test on the three different devices I have, and potentially test on some cloud devices as well. Also I've just realised it can't be the cause of the issues on those devices I mentioned, as they are both higher versions than Android 8.0 ( If I find no problems removing it then I'm tempted to test it out in the wild although certainly not the best way to test whether it's worked or not. |
@carman247 Can you just adjust the PR so it removes the line captureSession.abortCaptures(); completely? |
@jgoyvaerts no problem, will get that updated in a moment. |
Can anyone explain why the checks are failing? Not sure what I'm doing wrong there. Also, I haven't added any new "tests" for this PR .. I'm assuming the current ones will still be fine. |
The repository keys are rotated periodically; you likely just need to merge in the latest changes from
This PR doesn't meet any of the test exemption criteria (see the link in that checkbox item), so this needs tests. See also the comment from the bot above. If having this call breaks image capture on certain devices, then there need to be a test that the call isn't being made in this flow. |
The PR has been changed to completely delete the line, since it serves no purpose AND causes issues on certain devices. I thought delete only PRs did not require tests? |
I missed that it was delete-only now; my comment was based on the previous state. That said, this should still have a test, for the reason described in the bot comment above: someone added this once, thinking it was a good idea. If someone does so again, do you want all of the currently affected devices to silently regress again? |
@mvanbeusekom You added this line in #3383; do you remember why by any chance? @carman247 Have you verified that this doesn't regress the fix in that PR? |
I took a look at this in more detail, and was not as straightforward as I thought since @blasten Please review closely, since I'm very out of practice with Java. |
@BeMacized Could you also take a look since you were in this code quite a bit? |
@stuartmorgan thanks for sorting the test! Glad you tackled it as would've taken me ages to get in done and would probably be wrong anyway 😅 |
packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java
Outdated
Show resolved
Hide resolved
packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java
Show resolved
Hide resolved
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
This pull request is not suitable for automatic merging in its current state.
|
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.
Explicitly approving the non-test parts (i.e., the parts I didn't write) for the bot.
…capture on certain devices running Android 7/8 (flutter/plugins#4572)
Fix for flutter/flutter#88775
CameraAccessException
that affects certain devices running Android 7/8Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.