BlockingCameraManager.javaAPI DocAndroid 5.1 API11865Thu Mar 12 22:22:48 GMT


public class BlockingCameraManager extends Object
Expose {@link CameraManager} functionality with blocking functions.

Safe to use at the same time as the regular CameraManager, so this does not duplicate any functionality that is already blocking.

Be careful when using this from UI thread! This function will typically block for about 500ms when successful, and as long as {@value #OPEN_TIME_OUT}ms when timing out.

Fields Summary
private static final String
private static final boolean
private static final int
private final android.hardware.camera2.CameraManager
Constructors Summary
public BlockingCameraManager(android.hardware.camera2.CameraManager manager)
Create a new blocking camera manager.

manager CameraManager returned by {@code Context.getSystemService(Context.CAMERA_SERVICE)}

        if (manager == null) {
            throw new IllegalArgumentException("manager must not be null");
        mManager = manager;
Methods Summary
private static voidassertEquals(java.lang.Object a, java.lang.Object b)

        if (!Objects.equals(a, b)) {
            throw new AssertionError("Expected " + a + ", but got " + b);
public android.hardware.camera2.CameraDeviceopenCamera(java.lang.String cameraId, CameraDevice.StateCallback listener, android.os.Handler handler)
Open the camera, blocking it until it succeeds or fails.

Note that the Handler provided must not be null. Furthermore, if there is a handler, its Looper must not be the current thread's Looper. Otherwise we'd never receive the callbacks from the CameraDevice since this function would prevent them from being processed.

Throws {@link CameraAccessException} for the same reason {@link CameraManager#openCamera} does.

Throws {@link BlockingOpenException} when the open fails asynchronously (due to {@link CameraDevice.StateCallback#onDisconnected(CameraDevice)} or ({@link CameraDevice.StateCallback#onError(CameraDevice)}.

Throws {@link TimeoutRuntimeException} if opening times out. This is usually highly unrecoverable, and all future calls to opening that camera will fail since the service will think it's busy. This class will do its best to clean up eventually.

cameraId Id of the camera
listener Listener to the camera. onOpened, onDisconnected, onError need not be implemented.
handler Handler which to run the listener on. Must not be null.
IllegalArgumentException If the handler is null, or if the handler's looper is current.
CameraAccessException If open fails immediately.
BlockingOpenException If open fails after blocking for some amount of time.
TimeoutRuntimeException If opening times out. Typically unrecoverable.

        if (handler == null) {
            throw new IllegalArgumentException("handler must not be null");
        } else if (handler.getLooper() == Looper.myLooper()) {
            throw new IllegalArgumentException("handler's looper must not be the current looper");

        return (new OpenListener(mManager, cameraId, listener, handler)).blockUntilOpen();