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
Nested Classes Modifier and Type Class Description static class
ShadowCameraManager.ShadowCameraManagerGlobal
Shadow class for internal class CameraManager$CameraManagerGlobal -
Field Summary
Fields Modifier and Type Field Description protected static Set<android.hardware.camera2.impl.CameraDeviceImpl>
createdCameras
-
Constructor Summary
Constructors Constructor Description ShadowCameraManager()
-
Method Summary
Modifier and Type Method Description void
addCamera(String cameraId, CameraCharacteristics characteristics)
Adds the given cameraId and characteristics to this shadow.protected CameraCharacteristics
getCameraCharacteristics(String cameraId)
protected String[]
getCameraIdList()
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
triggerDisconnect()
Triggers a disconnect event, where any open camera will be disconnected (simulating the case where another app takes control of the camera).protected void
unregisterAvailabilityCallback(CameraManager.AvailabilityCallback callback)
protected void
updateCameraCallback(CameraDevice device, CameraDevice.StateCallback callback, Handler handler, Executor executor)
-
Field Details
-
Constructor Details
-
ShadowCameraManager
public ShadowCameraManager()
-
-
Method Details
-
getCameraIdList
- Throws:
CameraAccessException
-
getCameraCharacteristics
-
setTorchMode
-
openCameraDeviceUserAsync
@Implementation(minSdk=10000) 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 CameraAccessExceptionEnablesCameraManager.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
-