-
Notifications
You must be signed in to change notification settings - Fork 313
Improve camera device error reporting #3410
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 1 commit
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
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
70 changes: 70 additions & 0 deletions
70
asg_client/app/src/main/java/com/mentra/asg_client/camera/model/CameraOperationError.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,70 @@ | ||
| package com.mentra.asg_client.camera.model; | ||
|
|
||
| import android.hardware.camera2.CameraDevice; | ||
| import androidx.annotation.NonNull; | ||
|
|
||
| /** Structured camera failure carried from Camera2 callbacks to SDK responses. */ | ||
| public final class CameraOperationError { | ||
| public static final String CAMERA_CAPTURE_FAILED = "CAMERA_CAPTURE_FAILED"; | ||
| public static final String CAMERA_WARM_UP_FAILED = "camera_warm_up_failed"; | ||
|
|
||
| private final String code; | ||
| private final String message; | ||
|
|
||
| public CameraOperationError(@NonNull String code, @NonNull String message) { | ||
| this.code = code; | ||
| this.message = message; | ||
| } | ||
|
|
||
| @NonNull | ||
| public String code() { | ||
| return code; | ||
| } | ||
|
|
||
| @NonNull | ||
| public String message() { | ||
| return message; | ||
| } | ||
|
|
||
| public static CameraOperationError captureFailed(@NonNull String message) { | ||
| return new CameraOperationError(CAMERA_CAPTURE_FAILED, message); | ||
| } | ||
|
|
||
| public static CameraOperationError warmUpFailed(@NonNull String message) { | ||
| return new CameraOperationError(CAMERA_WARM_UP_FAILED, message); | ||
| } | ||
|
|
||
| public static CameraOperationError cameraBusy() { | ||
| return new CameraOperationError( | ||
| "camera_busy", "Camera is busy with another operation. Wait and try again."); | ||
| } | ||
|
|
||
| public static CameraOperationError fromCameraDeviceError(int error) { | ||
| switch (error) { | ||
| case CameraDevice.StateCallback.ERROR_CAMERA_IN_USE: | ||
| return new CameraOperationError( | ||
| "CAMERA_IN_USE", "Camera is already in use. Wait and try again."); | ||
| case CameraDevice.StateCallback.ERROR_MAX_CAMERAS_IN_USE: | ||
| return new CameraOperationError( | ||
| "MAX_CAMERAS_IN_USE", | ||
| "Another camera operation is active. Wait and try again."); | ||
| case CameraDevice.StateCallback.ERROR_CAMERA_DISABLED: | ||
| return new CameraOperationError( | ||
| "CAMERA_DISABLED", "Camera access is disabled by the system."); | ||
| case CameraDevice.StateCallback.ERROR_CAMERA_DEVICE: | ||
| return new CameraOperationError( | ||
| "CAMERA_DEVICE_ERROR", | ||
| "Camera hardware was not ready. Wait a few seconds and try again."); | ||
| case CameraDevice.StateCallback.ERROR_CAMERA_SERVICE: | ||
| return new CameraOperationError( | ||
| "CAMERA_SERVICE_ERROR", | ||
| "Camera service failed. Restart the glasses if the problem continues."); | ||
| default: | ||
| return new CameraOperationError( | ||
| "CAMERA_DEVICE_ERROR", | ||
| "Camera failed with an unknown device error (Android code " | ||
| + error | ||
| + "). Try again."); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
For callers that still implement the previously documented string callback, this new typed overload is abstract, so an existing anonymous class passed to
takePictureWithCallback/enqueuePhotoRequestwith onlyonPhotoCaptured(...)andonPhotoError(String)now fails to compile despite the added default string overload. If the string callback is meant to remain backward-compatible, make the typed overload default/delegate to the string path or otherwise keep the old abstract contract so existing camera integrations are not forced to change.Useful? React with 👍 / 👎.