Search in sources :

Example 36 with ServiceSpecificException

use of android.os.ServiceSpecificException in project platform_frameworks_base by android.

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

use of android.os.ServiceSpecificException in project platform_frameworks_base by android.

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;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

Example 38 with ServiceSpecificException

use of android.os.ServiceSpecificException in project platform_frameworks_base by android.

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);
        } 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) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService)

Example 39 with ServiceSpecificException

use of android.os.ServiceSpecificException in project platform_frameworks_base by android.

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)

Example 40 with ServiceSpecificException

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

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;
}
Also used : ServiceSpecificException(android.os.ServiceSpecificException) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) RemoteException(android.os.RemoteException) ICameraService(android.hardware.ICameraService) CameraInfo(android.hardware.CameraInfo) NonNull(android.annotation.NonNull)

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