Package org.robolectric.shadows
Class ShadowCameraManager
java.lang.Object
org.robolectric.shadows.ShadowCameraManager
@Implements(value=android.hardware.camera2.CameraManager.class,
minSdk=21)
public class ShadowCameraManager
extends Object
Shadow class for
CameraManager
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Shadow class for internal class CameraManager$CameraManagerGlobal -
Field Summary
Modifier and TypeFieldDescriptionprotected static final Set<android.hardware.camera2.impl.CameraDeviceImpl>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCamera
(String cameraId, CameraCharacteristics characteristics) Adds the given cameraId and characteristics to this shadow.protected CameraCharacteristics
getCameraCharacteristics
(String cameraId) protected String[]
boolean
getTorchMode
(String cameraId) Returns what the supplied camera's torch is set to.protected CameraDevice
openCameraDeviceUserAsync
(String cameraId, CameraDevice.StateCallback callback, Handler handler) EnablesCameraManager.openCamera(String, StateCallback, Handler)
to open aCameraDevice
.protected CameraDevice
openCameraDeviceUserAsync
(String cameraId, CameraDevice.StateCallback callback, Handler handler, int uid) protected CameraDevice
openCameraDeviceUserAsync
(String cameraId, CameraDevice.StateCallback callback, Executor executor, int uid) protected CameraDevice
openCameraDeviceUserAsync
(String cameraId, CameraDevice.StateCallback callback, Executor executor, int unusedClientUid, int unusedOomScoreOffset) protected CameraDevice
openCameraDeviceUserAsync
(String cameraId, CameraDevice.StateCallback callback, Executor executor, int uid, int oomScoreOffset, boolean overrideToPortrait) protected void
registerAvailabilityCallback
(CameraManager.AvailabilityCallback callback, Handler handler) void
removeCamera
(String cameraId) Removes the given cameraId and associated characteristics from this shadow.static void
reset()
protected void
setTorchMode
(String cameraId, boolean enabled) void
Triggers a disconnect event, where any open camera will be disconnected (simulating the case where another app takes control of the camera).protected void
protected void
updateCameraCallback
(CameraDevice device, CameraDevice.StateCallback callback, Handler handler, Executor executor)
-
Field Details
-
createdCameras
-
-
Constructor Details
-
ShadowCameraManager
public ShadowCameraManager()
-
-
Method Details
-
getCameraIdList
- Throws:
CameraAccessException
-
getCameraCharacteristics
-
setTorchMode
-
openCameraDeviceUserAsync
@Implementation(minSdk=34) protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Executor executor, int uid, int oomScoreOffset, boolean overrideToPortrait) -
openCameraDeviceUserAsync
@Implementation(minSdk=31, maxSdk=33) protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Executor executor, int unusedClientUid, int unusedOomScoreOffset) -
openCameraDeviceUserAsync
@Implementation(minSdk=28, maxSdk=30) protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Executor executor, int uid) throws CameraAccessException - Throws:
CameraAccessException
-
openCameraDeviceUserAsync
@Implementation(minSdk=25, maxSdk=27) protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Handler handler, int uid) throws CameraAccessException - Throws:
CameraAccessException
-
openCameraDeviceUserAsync
@Implementation(minSdk=21, maxSdk=24) protected CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Handler handler) throws CameraAccessException EnablesCameraManager.openCamera(String, StateCallback, Handler)
to open aCameraDevice
.If the provided cameraId exists, this will always post
to the provided {@link Handler}. Unlike on real Android, this will not check if the camera has been disabled by device policy and does not attempt to connect to the camera service, so {@link CameraDevice.StateCallback#onError(CameraDevice, int)} and {@link CameraDevice.StateCallback#onDisconnected(CameraDevice)} will not be triggered by {@link CameraManager#openCamera(String, StateCallback, Handler)}.
- Throws:
CameraAccessException
-
registerAvailabilityCallback
@Implementation(minSdk=21) protected void registerAvailabilityCallback(CameraManager.AvailabilityCallback callback, Handler handler) -
unregisterAvailabilityCallback
@Implementation(minSdk=21) protected void unregisterAvailabilityCallback(CameraManager.AvailabilityCallback callback) -
addCamera
Adds the given cameraId and characteristics to this shadow.The result from
getCameraIdList()
will be in the order in which cameras were added.- Throws:
IllegalArgumentException
- if there's already an existing camera with the given id.
-
removeCamera
Removes the given cameraId and associated characteristics from this shadow.- Throws:
IllegalArgumentException
- if there is not an existing camera with the given id.
-
getTorchMode
Returns what the supplied camera's torch is set to. -
triggerDisconnect
public void triggerDisconnect()Triggers a disconnect event, where any open camera will be disconnected (simulating the case where another app takes control of the camera). -
updateCameraCallback
protected void updateCameraCallback(CameraDevice device, CameraDevice.StateCallback callback, @Nullable Handler handler, @Nullable Executor executor) -
reset
-