Search in sources :

Example 56 with ServiceSpecificException

use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.

the class CameraDeviceBinderTest method testSubmitBadRequest.

@SmallTest
public void testSubmitBadRequest() throws Exception {
    CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
    false);
    CaptureRequest request1 = builder.build();
    try {
        SubmitInfo requestInfo = mCameraUser.submitRequest(request1, /* streaming */
        false);
        fail("Exception expected");
    } catch (ServiceSpecificException e) {
        assertEquals("Expected submitRequest to throw ServiceSpecificException with BAD_VALUE " + "since we had 0 surface targets set.", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
    builder.addTarget(mSurface);
    CaptureRequest request2 = builder.build();
    try {
        SubmitInfo requestInfo = mCameraUser.submitRequest(request2, /* streaming */
        false);
        fail("Exception expected");
    } catch (ServiceSpecificException e) {
        assertEquals("Expected submitRequest to throw ILLEGAL_ARGUMENT " + "ServiceSpecificException since the target wasn't registered with createStream.", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 57 with ServiceSpecificException

use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.

the class CameraDeviceBinderTest method testWaitUntilIdle.

@SmallTest
public void testWaitUntilIdle() throws Exception {
    CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
    true);
    SubmitInfo requestInfoStreaming = submitCameraRequest(builder.build(), /* streaming */
    true);
    // Test Bad case first: waitUntilIdle when there is active repeating request
    try {
        mCameraUser.waitUntilIdle();
    } catch (ServiceSpecificException e) {
        assertEquals("waitUntilIdle is invalid operation when there is active repeating request", ICameraService.ERROR_INVALID_OPERATION, e.errorCode);
    }
    // Test good case, waitUntilIdle when there is no active repeating request
    long lastFrameNumber = mCameraUser.cancelRequest(requestInfoStreaming.getRequestId());
    mCameraUser.waitUntilIdle();
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 58 with ServiceSpecificException

use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.

the class CameraDeviceBinderTest method testSubmitStreamingRequest.

@SmallTest
public void testSubmitStreamingRequest() throws Exception {
    CaptureRequest.Builder builder = createDefaultBuilder(/* needStream */
    true);
    CaptureRequest request = builder.build();
    // Submit valid request once (non-streaming), and another time
    // (streaming)
    SubmitInfo requestInfo1 = submitCameraRequest(request, /* streaming */
    false);
    SubmitInfo requestInfoStreaming = submitCameraRequest(request, /* streaming */
    true);
    assertNotSame("Request IDs should be unique for multiple requests", requestInfo1.getRequestId(), requestInfoStreaming.getRequestId());
    try {
        long lastFrameNumber = mCameraUser.cancelRequest(-1);
        fail("Expected exception");
    } catch (ServiceSpecificException e) {
        assertEquals("Invalid request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
    try {
        long lastFrameNumber = mCameraUser.cancelRequest(requestInfo1.getRequestId());
        fail("Expected exception");
    } catch (ServiceSpecificException e) {
        assertEquals("Non-streaming request IDs should not be cancellable", ICameraService.ERROR_ILLEGAL_ARGUMENT, e.errorCode);
    }
    long lastFrameNumber = mCameraUser.cancelRequest(requestInfoStreaming.getRequestId());
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) SubmitInfo(android.hardware.camera2.utils.SubmitInfo) CaptureRequest(android.hardware.camera2.CaptureRequest) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 59 with ServiceSpecificException

use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.

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 exposing only two cameras
                 * if the package name does not 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;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) ArrayList(java.util.ArrayList) TextUtils(android.text.TextUtils) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService)

Example 60 with ServiceSpecificException

use of android.os.ServiceSpecificException in project android_frameworks_base by ResurrectionRemix.

the class CameraManager method throwAsPublicException.

/**
     * Convert ServiceSpecificExceptions and Binder RemoteExceptions from camera binder interfaces
     * into the correct public exceptions.
     *
     * @hide
     */
public static void throwAsPublicException(Throwable t) throws CameraAccessException {
    if (t instanceof ServiceSpecificException) {
        ServiceSpecificException e = (ServiceSpecificException) t;
        int reason = CameraAccessException.CAMERA_ERROR;
        switch(e.errorCode) {
            case ICameraService.ERROR_DISCONNECTED:
                reason = CameraAccessException.CAMERA_DISCONNECTED;
                break;
            case ICameraService.ERROR_DISABLED:
                reason = CameraAccessException.CAMERA_DISABLED;
                break;
            case ICameraService.ERROR_CAMERA_IN_USE:
                reason = CameraAccessException.CAMERA_IN_USE;
                break;
            case ICameraService.ERROR_MAX_CAMERAS_IN_USE:
                reason = CameraAccessException.MAX_CAMERAS_IN_USE;
                break;
            case ICameraService.ERROR_DEPRECATED_HAL:
                reason = CameraAccessException.CAMERA_DEPRECATED_HAL;
                break;
            case ICameraService.ERROR_ILLEGAL_ARGUMENT:
            case ICameraService.ERROR_ALREADY_EXISTS:
                throw new IllegalArgumentException(e.getMessage(), e);
            case ICameraService.ERROR_PERMISSION_DENIED:
                throw new SecurityException(e.getMessage(), e);
            case ICameraService.ERROR_TIMED_OUT:
            case ICameraService.ERROR_INVALID_OPERATION:
            default:
                reason = CameraAccessException.CAMERA_ERROR;
        }
        throw new CameraAccessException(reason, e.getMessage(), e);
    } else if (t instanceof DeadObjectException) {
        throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED, "Camera service has died unexpectedly", t);
    } else if (t instanceof RemoteException) {
        throw new UnsupportedOperationException("An unknown RemoteException was thrown" + " which should never happen.", t);
    } else if (t instanceof RuntimeException) {
        RuntimeException e = (RuntimeException) t;
        throw e;
    }
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) DeadObjectException(android.os.DeadObjectException) RemoteException(android.os.RemoteException)

Aggregations

ServiceSpecificException (android.os.ServiceSpecificException)66 RemoteException (android.os.RemoteException)26 SmallTest (android.test.suitebuilder.annotation.SmallTest)25 CaptureRequest (android.hardware.camera2.CaptureRequest)20 ICameraService (android.hardware.ICameraService)15 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)15 SubmitInfo (android.hardware.camera2.utils.SubmitInfo)15 Surface (android.view.Surface)10 ArrayList (java.util.ArrayList)10 NonNull (android.annotation.NonNull)5 SurfaceTexture (android.graphics.SurfaceTexture)5 Camera (android.hardware.Camera)5 CameraInfo (android.hardware.Camera.CameraInfo)5 CameraInfo (android.hardware.CameraInfo)5 ICameraServiceListener (android.hardware.ICameraServiceListener)5 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)5 OutputConfiguration (android.hardware.camera2.params.OutputConfiguration)5 UidRange (android.net.UidRange)5 DeadObjectException (android.os.DeadObjectException)5 SparseIntArray (android.util.SparseIntArray)5