public class BlockingStateCallback extends CameraDevice.StateCallback
Provides wait calls that block until the next unobserved state of the requested type arrives. Unobserved states are states that have occurred since the last wait, or that will be received from the camera device in the future.
Pass-through all StateCallback changes to the proxy.
CameraDevice.StateCallback.ErrorCode
Modifier and Type | Field and Description |
---|---|
static int |
STATE_CLOSED
Device is closed
|
static int |
STATE_DISCONNECTED
Device is disconnected
|
static int |
STATE_ERROR
Device has encountered a fatal error
|
static int |
STATE_OPENED
Device is in the first-opened state (transitory)
|
static int |
STATE_UNINITIALIZED
Device has not reported any state yet
|
ERROR_CAMERA_DEVICE, ERROR_CAMERA_DISABLED, ERROR_CAMERA_IN_USE, ERROR_CAMERA_SERVICE, ERROR_MAX_CAMERAS_IN_USE
Constructor and Description |
---|
BlockingStateCallback() |
BlockingStateCallback(CameraDevice.StateCallback listener) |
Modifier and Type | Method and Description |
---|---|
static void |
appendStates(StringBuilder s,
Collection<Integer> states)
Append all states to string
|
void |
onClosed(CameraDevice camera)
The method called when a camera device has been closed with
CameraDevice.close() . |
void |
onDisconnected(CameraDevice camera)
The method called when a camera device is no longer available for
use.
|
void |
onError(CameraDevice camera,
int error)
The method called when a camera device has encountered a serious error.
|
void |
onOpened(CameraDevice camera)
The method called when a camera device has finished opening.
|
static String |
stateToString(int state)
Convert state integer to a String
|
int |
waitForAnyOfStates(Collection<Integer> states,
long timeout)
Wait until the one of the desired states is observed, checking all
state transitions since the last state that was waited on.
|
void |
waitForState(int state,
long timeout)
Wait until the desired state is observed, checking all state
transitions since the last state that was waited on.
|
public static final int STATE_UNINITIALIZED
public static final int STATE_OPENED
public static final int STATE_CLOSED
public static final int STATE_DISCONNECTED
public static final int STATE_ERROR
public BlockingStateCallback()
public BlockingStateCallback(CameraDevice.StateCallback listener)
public void onOpened(CameraDevice camera)
CameraDevice.StateCallback
At this point, the camera device is ready to use, and
CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
can be called to set up the first capture
session.
onOpened
in class CameraDevice.StateCallback
camera
- the camera device that has become openedpublic void onDisconnected(CameraDevice camera)
CameraDevice.StateCallback
This callback may be called instead of CameraDevice.StateCallback.onOpened(android.hardware.camera2.CameraDevice)
if opening the camera fails.
Any attempt to call methods on this CameraDevice will throw a
CameraAccessException
. The disconnection could be due to a
change in security policy or permissions; the physical disconnection
of a removable camera device; or the camera being needed for a
higher-priority camera API client.
There may still be capture callbacks that are invoked after this method is called, or new image buffers that are delivered to active outputs.
The default implementation logs a notice to the system log about the disconnection.
You should clean up the camera with CameraDevice.close()
after
this happens, as it is not recoverable until the camera can be opened
again. For most use cases, this will be when the camera again becomes
available
.
onDisconnected
in class CameraDevice.StateCallback
camera
- the device that has been disconnectedpublic void onError(CameraDevice camera, int error)
CameraDevice.StateCallback
This callback may be called instead of CameraDevice.StateCallback.onOpened(android.hardware.camera2.CameraDevice)
if opening the camera fails.
This indicates a failure of the camera device or camera service in
some way. Any attempt to call methods on this CameraDevice in the
future will throw a CameraAccessException
with the
CAMERA_ERROR
reason.
There may still be capture completion or camera stream callbacks that will be called after this error is received.
You should clean up the camera with CameraDevice.close()
after
this happens. Further attempts at recovery are error-code specific.
onError
in class CameraDevice.StateCallback
camera
- The device reporting the errorerror
- The error code, one of the
StateCallback.ERROR_*
values.CameraDevice.StateCallback.ERROR_CAMERA_IN_USE
,
CameraDevice.StateCallback.ERROR_MAX_CAMERAS_IN_USE
,
CameraDevice.StateCallback.ERROR_CAMERA_DISABLED
,
CameraDevice.StateCallback.ERROR_CAMERA_DEVICE
,
CameraDevice.StateCallback.ERROR_CAMERA_SERVICE
public void onClosed(CameraDevice camera)
CameraDevice.StateCallback
CameraDevice.close()
.
Any attempt to call methods on this CameraDevice in the
future will throw a IllegalStateException
.
The default implementation of this method does nothing.
onClosed
in class CameraDevice.StateCallback
camera
- the camera device that has become closedpublic void waitForState(int state, long timeout)
Note: Only one waiter allowed at a time!
state
- state to observe a transition totimeout
- how long to wait in millisecondsTimeoutRuntimeException
- if the desired state is not observed before timeout.public int waitForAnyOfStates(Collection<Integer> states, long timeout)
Note: Only one waiter allowed at a time!
states
- Set of desired states to observe a transition to.timeout
- how long to wait in millisecondsTimeoutRuntimeException
- if none of the states is observed before timeout.public static String stateToString(int state)
public static void appendStates(StringBuilder s, Collection<Integer> states)