use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by crdroidandroid.
the class CameraManager method getOrCreateDeviceIdListLocked.
/**
* Return or create the list of currently connected camera devices.
*
* <p>In case of errors connecting to the camera service, will return an empty list.</p>
*/
private ArrayList<String> getOrCreateDeviceIdListLocked() throws CameraAccessException {
if (mDeviceIdList == null) {
int numCameras = 0;
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
ArrayList<String> deviceIdList = new ArrayList<>();
// If no camera service, then no devices
if (cameraService == null) {
return deviceIdList;
}
try {
numCameras = cameraService.getNumberOfCameras(CAMERA_TYPE_ALL);
/* Force to exposing only two cameras
* if the package name falls in this bucket
*/
boolean exposeAuxCamera = true;
String packageName = ActivityThread.currentOpPackageName();
String packageList = SystemProperties.get("camera.auxdisable.packagelist");
if (packageList.length() > 0) {
TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
splitter.setString(packageList);
for (String str : splitter) {
if (packageName.equals(str)) {
exposeAuxCamera = false;
break;
}
}
}
if (exposeAuxCamera == false && (numCameras > 2)) {
numCameras = 2;
}
} catch (ServiceSpecificException e) {
throwAsPublicException(e);
} catch (RemoteException e) {
// camera service just died - if no camera service, then no devices
return deviceIdList;
}
for (int i = 0; i < numCameras; ++i) {
// Non-removable cameras use integers starting at 0 for their
// identifiers
boolean isDeviceSupported = false;
try {
CameraMetadataNative info = cameraService.getCameraCharacteristics(i);
if (!info.isEmpty()) {
isDeviceSupported = true;
} else {
throw new AssertionError("Expected to get non-empty characteristics");
}
} catch (ServiceSpecificException e) {
// propagate exception onward
if (e.errorCode != ICameraService.ERROR_DISCONNECTED || e.errorCode != ICameraService.ERROR_ILLEGAL_ARGUMENT) {
throwAsPublicException(e);
}
} catch (RemoteException e) {
// Camera service died - no devices to list
deviceIdList.clear();
return deviceIdList;
}
if (isDeviceSupported) {
deviceIdList.add(String.valueOf(i));
} else {
Log.w(TAG, "Error querying camera device " + i + " for listing.");
}
}
mDeviceIdList = deviceIdList;
}
return mDeviceIdList;
}
use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by crdroidandroid.
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.hardware.camera2.CameraAccessException in project android_frameworks_base by crdroidandroid.
the class CameraUtilsUncheckedThrowTest method testUncheckedThrow.
@SmallTest
public void testUncheckedThrow() {
try {
UncheckedThrow.throwAnyException(new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED));
Assert.fail("unreachable");
fakeNeverThrowsCameraAccess();
} catch (CameraAccessException e) {
}
}
use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by crdroidandroid.
the class Camera2Focuser method cancelAutoFocus.
/**
* Cancel ongoing auto focus, unlock the auto-focus if it was locked, and
* resume to passive continuous auto focus.
*
* @throws CameraAccessException
*/
public synchronized void cancelAutoFocus() throws CameraAccessException {
mSuccess = false;
mLocked = false;
// reset the AF regions:
setAfRegions(null);
// Create request builders, the af regions are automatically updated.
mRepeatingBuilder = createRequestBuilder();
CaptureRequest.Builder requestBuilder = createRequestBuilder();
mAutoFocus.setPassiveAutoFocus(/*picture*/
true, mRepeatingBuilder);
mAutoFocus.unlockAutoFocus(mRepeatingBuilder, requestBuilder);
CaptureCallback listener = createCaptureListener();
mSession.setRepeatingRequest(mRepeatingBuilder.build(), listener, mHandler);
mSession.capture(requestBuilder.build(), listener, mHandler);
}
use of android.hardware.camera2.CameraAccessException in project android_frameworks_base by AOSPA.
the class CameraDeviceImpl method createReprocessableCaptureSession.
@Override
public void createReprocessableCaptureSession(InputConfiguration inputConfig, List<Surface> outputs, CameraCaptureSession.StateCallback callback, Handler handler) throws CameraAccessException {
if (DEBUG) {
Log.d(TAG, "createReprocessableCaptureSession");
}
if (inputConfig == null) {
throw new IllegalArgumentException("inputConfig cannot be null when creating a " + "reprocessable capture session");
}
List<OutputConfiguration> outConfigurations = new ArrayList<>(outputs.size());
for (Surface surface : outputs) {
outConfigurations.add(new OutputConfiguration(surface));
}
createCaptureSessionInternal(inputConfig, outConfigurations, callback, handler, /*isConstrainedHighSpeed*/
false);
}
Aggregations