Search in sources :

Example 6 with ServiceSpecificException

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

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

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

the class CameraDeviceUserShim method createDefaultRequest.

@Override
public CameraMetadataNative createDefaultRequest(int templateId) {
    if (DEBUG) {
        Log.d(TAG, "createDefaultRequest called.");
    }
    if (mLegacyDevice.isClosed()) {
        String err = "Cannot create default request, device has been closed.";
        Log.e(TAG, err);
        throw new ServiceSpecificException(ICameraService.ERROR_DISCONNECTED, err);
    }
    CameraMetadataNative template;
    try {
        template = LegacyMetadataMapper.createRequestTemplate(mCameraCharacteristics, templateId);
    } catch (IllegalArgumentException e) {
        String err = "createDefaultRequest - invalid templateId specified";
        Log.e(TAG, err);
        throw new ServiceSpecificException(ICameraService.ERROR_ILLEGAL_ARGUMENT, err);
    }
    return template;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative)

Example 8 with ServiceSpecificException

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

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)

Example 9 with ServiceSpecificException

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

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;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService)

Example 10 with ServiceSpecificException

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

the class NetworkManagementService method closeSocketsForFirewallChainLocked.

private void closeSocketsForFirewallChainLocked(int chain, String chainName) {
    // UID ranges to close sockets on.
    UidRange[] ranges;
    // UID ranges whose sockets we won't touch.
    int[] exemptUids;
    final SparseIntArray rules = getUidFirewallRules(chain);
    int numUids = 0;
    if (getFirewallType(chain) == FIREWALL_TYPE_WHITELIST) {
        // Close all sockets on all non-system UIDs...
        ranges = new UidRange[] { // specify their ranges here.
        new UidRange(Process.FIRST_APPLICATION_UID, Integer.MAX_VALUE) };
        // ... except for the UIDs that have allow rules.
        exemptUids = new int[rules.size()];
        for (int i = 0; i < exemptUids.length; i++) {
            if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_ALLOW) {
                exemptUids[numUids] = rules.keyAt(i);
                numUids++;
            }
        }
        // fix setFirewallEnabled to grab mQuotaLock and clear rules.
        if (numUids != exemptUids.length) {
            exemptUids = Arrays.copyOf(exemptUids, numUids);
        }
    } else {
        // Close sockets for every UID that has a deny rule...
        ranges = new UidRange[rules.size()];
        for (int i = 0; i < ranges.length; i++) {
            if (rules.valueAt(i) == NetworkPolicyManager.FIREWALL_RULE_DENY) {
                int uid = rules.keyAt(i);
                ranges[numUids] = new UidRange(uid, uid);
                numUids++;
            }
        }
        // As above; usually numUids == ranges.length, but not always.
        if (numUids != ranges.length) {
            ranges = Arrays.copyOf(ranges, numUids);
        }
        // ... with no exceptions.
        exemptUids = new int[0];
    }
    try {
        mNetdService.socketDestroy(ranges, exemptUids);
    } catch (RemoteException | ServiceSpecificException e) {
        Slog.e(TAG, "Error closing sockets after enabling chain " + chainName + ": " + e);
    }
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) UidRange(android.net.UidRange) SparseIntArray(android.util.SparseIntArray) 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