Search in sources :

Example 6 with CameraManager

use of android.hardware.camera2.CameraManager in project android_frameworks_base by DirtyUnicorns.

the class DuUtils method deviceSupportsFlashLight.

public static boolean deviceSupportsFlashLight(Context context) {
    CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
    try {
        String[] ids = cameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics c = cameraManager.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 true;
            }
        }
    } catch (CameraAccessException e) {
    // Ignore
    }
    return false;
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) CameraManager(android.hardware.camera2.CameraManager)

Example 7 with CameraManager

use of android.hardware.camera2.CameraManager in project android_frameworks_base by DirtyUnicorns.

the class CameraTestUtils method getSupportedSizeForFormat.

/**
     * Get the available output sizes for the user-defined {@code format}.
     *
     * <p>Note that implementation-defined/hidden formats are not supported.</p>
     */
public static Size[] getSupportedSizeForFormat(int format, String cameraId, CameraManager cameraManager) throws CameraAccessException {
    CameraCharacteristics properties = cameraManager.getCameraCharacteristics(cameraId);
    assertNotNull("Can't get camera characteristics!", properties);
    if (VERBOSE) {
        Log.v(TAG, "get camera characteristics for camera: " + cameraId);
    }
    StreamConfigurationMap configMap = properties.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] availableSizes = configMap.getOutputSizes(format);
    assertArrayNotEmpty(availableSizes, "availableSizes should not be empty for format: " + format);
    Size[] highResAvailableSizes = configMap.getHighResolutionOutputSizes(format);
    if (highResAvailableSizes != null && highResAvailableSizes.length > 0) {
        Size[] allSizes = new Size[availableSizes.length + highResAvailableSizes.length];
        System.arraycopy(availableSizes, 0, allSizes, 0, availableSizes.length);
        System.arraycopy(highResAvailableSizes, 0, allSizes, availableSizes.length, highResAvailableSizes.length);
        availableSizes = allSizes;
    }
    if (VERBOSE)
        Log.v(TAG, "Supported sizes are: " + Arrays.deepToString(availableSizes));
    return availableSizes;
}
Also used : Size(android.util.Size) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 8 with CameraManager

use of android.hardware.camera2.CameraManager in project android_frameworks_base by DirtyUnicorns.

the class CameraTestUtils method getSupportedSizeForClass.

/**
     * Get the available output sizes for the given class.
     *
     */
public static Size[] getSupportedSizeForClass(Class klass, String cameraId, CameraManager cameraManager) throws CameraAccessException {
    CameraCharacteristics properties = cameraManager.getCameraCharacteristics(cameraId);
    assertNotNull("Can't get camera characteristics!", properties);
    if (VERBOSE) {
        Log.v(TAG, "get camera characteristics for camera: " + cameraId);
    }
    StreamConfigurationMap configMap = properties.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    Size[] availableSizes = configMap.getOutputSizes(klass);
    assertArrayNotEmpty(availableSizes, "availableSizes should not be empty for class: " + klass);
    Size[] highResAvailableSizes = configMap.getHighResolutionOutputSizes(ImageFormat.PRIVATE);
    if (highResAvailableSizes != null && highResAvailableSizes.length > 0) {
        Size[] allSizes = new Size[availableSizes.length + highResAvailableSizes.length];
        System.arraycopy(availableSizes, 0, allSizes, 0, availableSizes.length);
        System.arraycopy(highResAvailableSizes, 0, allSizes, availableSizes.length, highResAvailableSizes.length);
        availableSizes = allSizes;
    }
    if (VERBOSE)
        Log.v(TAG, "Supported sizes are: " + Arrays.deepToString(availableSizes));
    return availableSizes;
}
Also used : Size(android.util.Size) CameraCharacteristics(android.hardware.camera2.CameraCharacteristics) StreamConfigurationMap(android.hardware.camera2.params.StreamConfigurationMap)

Example 9 with CameraManager

use of android.hardware.camera2.CameraManager in project android_frameworks_base by DirtyUnicorns.

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 10 with CameraManager

use of android.hardware.camera2.CameraManager in project android_frameworks_base by AOSPA.

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)

Aggregations

CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)22 CameraManager (android.hardware.camera2.CameraManager)12 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)11 Size (android.util.Size)11 CameraAccessException (android.hardware.camera2.CameraAccessException)8 IOException (java.io.IOException)3 Activity (android.app.Activity)2 ActivityManagerInternal (android.app.ActivityManagerInternal)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 Resources (android.content.res.Resources)2 Point (android.graphics.Point)2 InputManagerInternal (android.hardware.input.InputManagerInternal)2 Message (android.os.Message)2 PowerManagerInternal (android.os.PowerManagerInternal)2 RemoteException (android.os.RemoteException)2 DreamManagerInternal (android.service.dreams.DreamManagerInternal)2 RecognizerIntent (android.speech.RecognizerIntent)2 WindowManagerInternal (android.view.WindowManagerInternal)2