Skip to content

Commit

Permalink
[camera_android] Mark description in sendCameraErrorEvent as `@No…
Browse files Browse the repository at this point in the history
…nNull` (#7877)

`sendCameraErrorEvent` is package-visible and only called in
`Camera.java` and `CameraTest.java`. This should be test- and
version-exempt, as it is essentially just an annotation change.

Fixes flutter/flutter#156729

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] page, which explains my
responsibilities.
- [x] I read and followed the [relevant style guides] and ran the
auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages
repo does use `dart format`.)
- [ ] I signed the [CLA].
- [x] The title of the PR starts with the name of the package surrounded
by square brackets, e.g. `[shared_preferences]`
- [x] I [linked to at least one issue that this PR fixes] in the
description above.
- [x] I updated `pubspec.yaml` with an appropriate new version according
to the [pub versioning philosophy], or this PR is [exempt from version
changes].
- [x] I updated `CHANGELOG.md` to add a description of the change,
[following repository CHANGELOG style], or this PR is [exempt from
CHANGELOG changes].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]:
https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[CLA]: https://cla.developers.google.com/
[Discord]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[pub versioning philosophy]: https://dart.dev/tools/pub/versioning
[exempt from version changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version
[following repository CHANGELOG style]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[exempt from CHANGELOG changes]:
https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog
[test-exempt]:
https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
  • Loading branch information
yaakovschectman authored Oct 17, 2024
1 parent 6a4b660 commit f12eda7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,14 @@ public void onOpened(@NonNull CameraDevice device) {
cameraFeatures.getFocusPoint().checkIsSupported());
}
} catch (Exception e) {
String message =
(e.getMessage() == null)
? (e.getClass().getName() + " occurred while opening camera.")
: e.getMessage();
if (BuildConfig.DEBUG) {
Log.i(TAG, "open | onOpened error: " + e.getMessage());
Log.i(TAG, "open | onOpened error: " + message);
}
dartMessenger.sendCameraErrorEvent(e.getMessage());
dartMessenger.sendCameraErrorEvent(message);
close();
}
}
Expand Down Expand Up @@ -792,7 +796,11 @@ private void lockAutoFocus() {
try {
captureSession.capture(previewRequestBuilder.build(), null, backgroundHandler);
} catch (CameraAccessException e) {
dartMessenger.sendCameraErrorEvent(e.getMessage());
String message =
(e.getMessage() == null)
? "CameraAccessException occurred while locking autofocus."
: e.getMessage();
dartMessenger.sendCameraErrorEvent(message);
}
}

Expand All @@ -815,7 +823,11 @@ void unlockAutoFocus() {

captureSession.capture(previewRequestBuilder.build(), null, backgroundHandler);
} catch (CameraAccessException e) {
dartMessenger.sendCameraErrorEvent(e.getMessage());
String message =
(e.getMessage() == null)
? "CameraAccessException occurred while unlocking autofocus."
: e.getMessage();
dartMessenger.sendCameraErrorEvent(message);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,14 @@ void sendCameraClosingEvent() {
handler.post(() -> eventApi.closed(new NoOpVoidResult()));
}

// TODO(schectman): Make `description` non-null, see
// https://github.com/flutter/flutter/issues/156729
/**
* Sends a message to the Flutter client informing that an error occurred while interacting with
* the camera.
*
* @param description contains details regarding the error that occurred.
*/
void sendCameraErrorEvent(@Nullable String description) {
String errorMessage = (description == null) ? "" : description;
handler.post(() -> eventApi.error(errorMessage, new NoOpVoidResult()));
void sendCameraErrorEvent(@NonNull String description) {
handler.post(() -> eventApi.error(description, new NoOpVoidResult()));
}

/**
Expand Down

0 comments on commit f12eda7

Please sign in to comment.