Search in sources :

Example 1 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_frameworks_base by ResurrectionRemix.

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 2 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_frameworks_base by ResurrectionRemix.

the class CameraUtils method isLegacyHAL.

/**
     * Returns {@code true} if this device only supports {@code LEGACY} mode operation in the
     * Camera2 API for the given camera ID.
     *
     * @param context {@link Context} to access the {@link CameraManager} in.
     * @param cameraId the ID of the camera device to check.
     * @return {@code true} if this device only supports {@code LEGACY} mode.
     */
public static boolean isLegacyHAL(Context context, int cameraId) throws Exception {
    CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(Integer.toString(cameraId));
    return characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL) == CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager)

Example 3 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_frameworks_base by ResurrectionRemix.

the class GlobalActions method getTorchToggleAction.

private Action getTorchToggleAction() {
    return new SinglePressAction(com.android.internal.R.drawable.ic_lock_torch, R.string.global_action_torch) {

        public void onPress() {
            try {
                CameraManager cameraManager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
                for (final String cameraId : cameraManager.getCameraIdList()) {
                    CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
                    int orient = characteristics.get(CameraCharacteristics.LENS_FACING);
                    if (orient == CameraCharacteristics.LENS_FACING_BACK) {
                        cameraManager.setTorchMode(cameraId, !mTorchEnabled);
                        mTorchEnabled = !mTorchEnabled;
                    }
                }
            } catch (CameraAccessException e) {
            }
        }

        public boolean showDuringKeyguard() {
            return true;
        }

        public boolean showBeforeProvisioning() {
            return false;
        }
    };
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager) Paint(android.graphics.Paint)

Example 4 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_frameworks_base by ResurrectionRemix.

the class PhoneWindowManager method getCameraId.

private String getCameraId() throws CameraAccessException {
    String[] ids = mCameraManager.getCameraIdList();
    int length = ids.length;
    for (int i = 0; i < length; i += 1) {
        String id = ids[i];
        CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
        Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
        Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
        if (flashAvailable != null && flashAvailable && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
            return id;
        }
    }
    return null;
}
Also used : CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) MutableBoolean(android.util.MutableBoolean)

Example 5 with CameraCharacteristics

use of android.hardware.camera2.CameraCharacteristics in project android_frameworks_base by ResurrectionRemix.

the class LegacyMetadataMapper method createCharacteristics.

/**
     * Create characteristics for a legacy device by mapping the {@code parameters}
     * and {@code info}
     *
     * @param parameters A string parseable by {@link Camera.Parameters#unflatten}
     * @param info Camera info with camera facing direction and angle of orientation
     * @return static camera characteristics for a camera device
     *
     * @throws NullPointerException if any of the args were {@code null}
     */
public static CameraCharacteristics createCharacteristics(String parameters, android.hardware.CameraInfo info) {
    checkNotNull(parameters, "parameters must not be null");
    checkNotNull(info, "info must not be null");
    checkNotNull(info.info, "info.info must not be null");
    CameraMetadataNative m = new CameraMetadataNative();
    mapCharacteristicsFromInfo(m, info.info);
    Camera.Parameters params = Camera.getEmptyParameters();
    params.unflatten(parameters);
    mapCharacteristicsFromParameters(m, params);
    if (DEBUG) {
        Log.v(TAG, "createCharacteristics metadata:");
        Log.v(TAG, "--------------------------------------------------- (start)");
        m.dumpToLog();
        Log.v(TAG, "--------------------------------------------------- (end)");
    }
    return new CameraCharacteristics(m);
}
Also used : Parameters(android.hardware.Camera.Parameters) CameraMetadataNative(android.hardware.camera2.impl.CameraMetadataNative) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) Camera(android.hardware.Camera)

Aggregations

CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)100 CameraAccessException (android.hardware.camera2.CameraAccessException)40 Size (android.util.Size)37 CameraManager (android.hardware.camera2.CameraManager)35 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)28 Camera (android.hardware.Camera)25 Rect (android.graphics.Rect)20 CameraMetadataNative (android.hardware.camera2.impl.CameraMetadataNative)20 CaptureRequest (android.hardware.camera2.CaptureRequest)18 Parameters (android.hardware.Camera.Parameters)15 ArrayList (java.util.ArrayList)13 ZoomData (android.hardware.camera2.legacy.ParameterUtils.ZoomData)10 MeteringRectangle (android.hardware.camera2.params.MeteringRectangle)10 ServiceSpecificException (android.os.ServiceSpecificException)10 Range (android.util.Range)10 Point (android.graphics.Point)8 NonNull (android.annotation.NonNull)6 Activity (android.app.Activity)5 CameraInfo (android.hardware.Camera.CameraInfo)5 CameraInfo (android.hardware.CameraInfo)5