Search in sources :

Example 11 with ServiceSpecificException

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

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);
        }
    }
}
Also used : ICameraServiceListener(android.hardware.ICameraServiceListener) ServiceSpecificException(android.os.ServiceSpecificException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with ServiceSpecificException

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

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 13 with ServiceSpecificException

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

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);
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) ArrayList(java.util.ArrayList) CaptureRequest(android.hardware.camera2.CaptureRequest) Surface(android.view.Surface)

Example 14 with ServiceSpecificException

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

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 expose only two cameras
                 * if the package name does not falls in this bucket
                 */
            boolean exposeAuxCamera = false;
            String packageName = ActivityThread.currentOpPackageName();
            String packageList = SystemProperties.get("camera.aux.packagelist");
            if (packageList.length() > 0) {
                TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
                splitter.setString(packageList);
                for (String str : splitter) {
                    if (packageName.equals(str)) {
                        exposeAuxCamera = true;
                        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 15 with ServiceSpecificException

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

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