use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.
the class LegacyCameraDevice method submitRequestList.
/**
* Submit a burst of capture requests.
*
* @param requestList a list of capture requests to execute.
* @param repeating {@code true} if this burst is repeating.
* @return the submission info, including the new request id, and the last frame number, which
* contains either the frame number of the last frame that will be returned for this request,
* or the frame number of the last frame that will be returned for the current repeating
* request if this burst is set to be repeating.
*/
public SubmitInfo submitRequestList(CaptureRequest[] requestList, boolean repeating) {
if (requestList == null || requestList.length == 0) {
Log.e(TAG, "submitRequestList - Empty/null requests are not allowed");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Empty/null requests are not allowed");
}
List<Long> surfaceIds;
try {
surfaceIds = (mConfiguredSurfaces == null) ? new ArrayList<Long>() : getSurfaceIds(mConfiguredSurfaces);
} catch (BufferQueueAbandonedException e) {
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - configured surface is abandoned.");
}
// Make sure that there all requests have at least 1 surface; all surfaces are non-null
for (CaptureRequest request : requestList) {
if (request.getTargets().isEmpty()) {
Log.e(TAG, "submitRequestList - " + "Each request must have at least one Surface target");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - " + "Each request must have at least one Surface target");
}
for (Surface surface : request.getTargets()) {
if (surface == null) {
Log.e(TAG, "submitRequestList - Null Surface targets are not allowed");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - Null Surface targets are not allowed");
} else if (mConfiguredSurfaces == null) {
Log.e(TAG, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
throw new ServiceSpecificException(INVALID_OPERATION, "submitRequestList - must configure " + " device with valid surfaces before submitting requests");
} else if (!containsSurfaceId(surface, surfaceIds)) {
Log.e(TAG, "submitRequestList - cannot use a surface that wasn't configured");
throw new ServiceSpecificException(BAD_VALUE, "submitRequestList - cannot use a surface that wasn't configured");
}
}
}
// TODO: further validation of request here
mIdle.close();
return mRequestThreadManager.submitCaptureRequests(requestList, repeating);
}
use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.
the class CameraManager method openCameraDeviceUserAsync.
/**
* Helper for opening a connection to a camera with the given ID.
*
* @param cameraId The unique identifier of the camera device to open
* @param callback The callback for the camera. Must not be null.
* @param handler The handler to invoke the callback on. Must not be null.
* @param uid The UID of the application actually opening the camera.
* Must be USE_CALLING_UID unless the caller is a service
* that is trusted to open the device on behalf of an
* application and to forward the real UID.
*
* @throws CameraAccessException if the camera is disabled by device policy,
* too many camera devices are already open, or the cameraId does not match
* any currently available camera device.
*
* @throws SecurityException if the application does not have permission to
* access the camera
* @throws IllegalArgumentException if callback or handler is null.
* @return A handle to the newly-created camera device.
*
* @see #getCameraIdList
* @see android.app.admin.DevicePolicyManager#setCameraDisabled
*/
private CameraDevice openCameraDeviceUserAsync(String cameraId, CameraDevice.StateCallback callback, Handler handler, final int uid) throws CameraAccessException {
CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
CameraDevice device = null;
synchronized (mLock) {
ICameraDeviceUser cameraUser = null;
android.hardware.camera2.impl.CameraDeviceImpl deviceImpl = new android.hardware.camera2.impl.CameraDeviceImpl(cameraId, callback, handler, characteristics);
ICameraDeviceCallbacks callbacks = deviceImpl.getCallbacks();
int id;
try {
id = Integer.parseInt(cameraId);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Expected cameraId to be numeric, but it was: " + cameraId);
}
try {
if (supportsCamera2ApiLocked(cameraId)) {
// Use cameraservice's cameradeviceclient implementation for HAL3.2+ devices
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
if (cameraService == null) {
throw new ServiceSpecificException(ICameraService.ERROR_DISCONNECTED, "Camera service is currently unavailable");
}
cameraUser = cameraService.connectDevice(callbacks, id, mContext.getOpPackageName(), uid);
} else {
// Use legacy camera implementation for HAL1 devices
Log.i(TAG, "Using legacy camera HAL.");
cameraUser = CameraDeviceUserShim.connectBinderShim(callbacks, id);
}
} catch (ServiceSpecificException e) {
if (e.errorCode == ICameraService.ERROR_DEPRECATED_HAL) {
throw new AssertionError("Should've gone down the shim path");
} else if (e.errorCode == ICameraService.ERROR_CAMERA_IN_USE || e.errorCode == ICameraService.ERROR_MAX_CAMERAS_IN_USE || e.errorCode == ICameraService.ERROR_DISABLED || e.errorCode == ICameraService.ERROR_DISCONNECTED || e.errorCode == ICameraService.ERROR_INVALID_OPERATION) {
// Received one of the known connection errors
// The remote camera device cannot be connected to, so
// set the local camera to the startup error state
deviceImpl.setRemoteFailure(e);
if (e.errorCode == ICameraService.ERROR_DISABLED || e.errorCode == ICameraService.ERROR_DISCONNECTED || e.errorCode == ICameraService.ERROR_CAMERA_IN_USE) {
// Per API docs, these failures call onError and throw
throwAsPublicException(e);
}
} else {
// Unexpected failure - rethrow
throwAsPublicException(e);
}
} catch (RemoteException e) {
// Camera service died - act as if it's a CAMERA_DISCONNECTED case
ServiceSpecificException sse = new ServiceSpecificException(ICameraService.ERROR_DISCONNECTED, "Camera service is currently unavailable");
deviceImpl.setRemoteFailure(sse);
throwAsPublicException(sse);
}
// TODO: factor out callback to be non-nested, then move setter to constructor
// For now, calling setRemoteDevice will fire initial
// onOpened/onUnconfigured callbacks.
// This function call may post onDisconnected and throw CAMERA_DISCONNECTED if
// cameraUser dies during setup.
deviceImpl.setRemoteDevice(cameraUser);
device = deviceImpl;
}
return device;
}
use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.
the class CameraManager method getCameraCharacteristics.
/**
* <p>Query the capabilities of a camera device. These capabilities are
* immutable for a given camera.</p>
*
* @param cameraId The id of the camera device to query
* @return The properties of the given camera
*
* @throws IllegalArgumentException if the cameraId does not match any
* known camera device.
* @throws CameraAccessException if the camera device has been disconnected.
*
* @see #getCameraIdList
* @see android.app.admin.DevicePolicyManager#setCameraDisabled
*/
@NonNull
public CameraCharacteristics getCameraCharacteristics(@NonNull String cameraId) throws CameraAccessException {
CameraCharacteristics characteristics = null;
synchronized (mLock) {
if (!getOrCreateDeviceIdListLocked().contains(cameraId)) {
throw new IllegalArgumentException(String.format("Camera id %s does not match any" + " currently connected camera device", cameraId));
}
int id = Integer.parseInt(cameraId);
/*
* Get the camera characteristics from the camera service directly if it supports it,
* otherwise get them from the legacy shim instead.
*/
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
if (cameraService == null) {
throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable");
}
try {
if (!supportsCamera2ApiLocked(cameraId)) {
// Legacy backwards compatibility path; build static info from the camera
// parameters
String parameters = cameraService.getLegacyParameters(id);
CameraInfo info = cameraService.getCameraInfo(id);
characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info);
} else {
// Normal path: Get the camera characteristics directly from the camera service
CameraMetadataNative info = cameraService.getCameraCharacteristics(id);
characteristics = new CameraCharacteristics(info);
}
} catch (ServiceSpecificException e) {
throwAsPublicException(e);
} catch (RemoteException e) {
// Camera service died - act as if the camera was disconnected
throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service is currently unavailable", e);
}
}
return characteristics;
}
use of android.os.ServiceSpecificException in project android_frameworks_base by crdroidandroid.
the class CameraDeviceUserShim method connectBinderShim.
public static CameraDeviceUserShim connectBinderShim(ICameraDeviceCallbacks callbacks, int cameraId) {
if (DEBUG) {
Log.d(TAG, "Opening shim Camera device");
}
/*
* Put the camera open on a separate thread with its own looper; otherwise
* if the main thread is used then the callbacks might never get delivered
* (e.g. in CTS which run its own default looper only after tests)
*/
CameraLooper init = new CameraLooper(cameraId);
CameraCallbackThread threadCallbacks = new CameraCallbackThread(callbacks);
// TODO: Make this async instead of blocking
int initErrors = init.waitForOpen(OPEN_CAMERA_TIMEOUT_MS);
Camera legacyCamera = init.getCamera();
// Check errors old HAL initialization
LegacyExceptionUtils.throwOnServiceError(initErrors);
// Disable shutter sounds (this will work unconditionally) for api2 clients
legacyCamera.disableShutterSound();
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(cameraId, info);
Camera.Parameters legacyParameters = null;
try {
legacyParameters = legacyCamera.getParameters();
} catch (RuntimeException e) {
throw new ServiceSpecificException(ICameraService.ERROR_INVALID_OPERATION, "Unable to get initial parameters: " + e.getMessage());
}
CameraCharacteristics characteristics = LegacyMetadataMapper.createCharacteristics(legacyParameters, info);
LegacyCameraDevice device = new LegacyCameraDevice(cameraId, legacyCamera, characteristics, threadCallbacks);
return new CameraDeviceUserShim(cameraId, device, characteristics, init, threadCallbacks);
}
use of android.os.ServiceSpecificException in project android_frameworks_base by crdroidandroid.
the class CameraBinderTest method testAddRemoveListeners.
/**
* <pre>
* adb shell am instrument \
* -e class 'com.android.mediaframeworktest.integration.CameraBinderTest#testAddRemoveListeners' \
* -w com.android.mediaframeworktest/.MediaFrameworkIntegrationTestRunner
* </pre>
*/
@SmallTest
public void testAddRemoveListeners() throws Exception {
for (int cameraId = 0; cameraId < mUtils.getGuessedNumCameras(); ++cameraId) {
ICameraServiceListener listener = new DummyCameraServiceListener();
try {
mUtils.getCameraService().removeListener(listener);
fail("Listener was removed before added");
} catch (ServiceSpecificException e) {
assertEquals("Listener was removed before added", e.errorCode, ICameraService.ERROR_ILLEGAL_ARGUMENT);
}
mUtils.getCameraService().addListener(listener);
try {
mUtils.getCameraService().addListener(listener);
fail("Listener was wrongly added again");
} catch (ServiceSpecificException e) {
assertEquals("Listener was wrongly added again", e.errorCode, ICameraService.ERROR_ALREADY_EXISTS);
}
mUtils.getCameraService().removeListener(listener);
try {
mUtils.getCameraService().removeListener(listener);
fail("Listener was wrongly removed twice");
} catch (ServiceSpecificException e) {
assertEquals("Listener was wrongly removed twice", e.errorCode, ICameraService.ERROR_ILLEGAL_ARGUMENT);
}
}
}
Aggregations