FileDocCategorySizeDatePackage
Camera2PortabilityTest.javaAPI DocAndroid 5.1 API13029Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.portability

Camera2PortabilityTest

public class Camera2PortabilityTest extends com.android.ex.camera2.utils.Camera2DeviceTester

Fields Summary
Constructors Summary
Methods Summary
private android.hardware.camera2.CameraCharacteristicsbuildFrameworkCharacteristics()

        CameraManager manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        String id = manager.getCameraIdList()[0];
        return manager.getCameraCharacteristics(id);
    
public voidcamera2CapabilitiesFocusModeFromInt()
Ensure that {@code AndroidCamera2Capabilities#.*FromInt} correctly translates from framework API 2 representations to the equivalent {@code FocusMode}s, {@code SceneMode}s, and {@code WhiteBalance}s.

        CameraCharacteristics chars = buildFrameworkCharacteristics();
        AndroidCamera2Capabilities intstr = new AndroidCamera2Capabilities(chars);

        // Focus modes
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_AUTO), FocusMode.AUTO);
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_CONTINUOUS_PICTURE),
                FocusMode.CONTINUOUS_PICTURE);
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_CONTINUOUS_VIDEO),
                FocusMode.CONTINUOUS_VIDEO);
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_EDOF), FocusMode.EXTENDED_DOF);
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_OFF), FocusMode.FIXED);
        assertEquals(intstr.focusModeFromInt(CONTROL_AF_MODE_MACRO), FocusMode.MACRO);

        // Scene modes
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_DISABLED), SceneMode.AUTO);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_ACTION), SceneMode.ACTION);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_BARCODE), SceneMode.BARCODE);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_BEACH), SceneMode.BEACH);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_CANDLELIGHT), SceneMode.CANDLELIGHT);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_FIREWORKS), SceneMode.FIREWORKS);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_LANDSCAPE), SceneMode.LANDSCAPE);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_NIGHT), SceneMode.NIGHT);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_PARTY), SceneMode.PARTY);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_PORTRAIT), SceneMode.PORTRAIT);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SNOW), SceneMode.SNOW);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SPORTS), SceneMode.SPORTS);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_STEADYPHOTO),
                SceneMode.STEADYPHOTO);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_SUNSET), SceneMode.SUNSET);
        assertEquals(intstr.sceneModeFromInt(CONTROL_SCENE_MODE_THEATRE), SceneMode.THEATRE);

        // White balances
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_AUTO), WhiteBalance.AUTO);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_CLOUDY_DAYLIGHT),
                WhiteBalance.CLOUDY_DAYLIGHT);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_DAYLIGHT), WhiteBalance.DAYLIGHT);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_FLUORESCENT),
                WhiteBalance.FLUORESCENT);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_INCANDESCENT),
                WhiteBalance.INCANDESCENT);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_SHADE), WhiteBalance.SHADE);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_TWILIGHT), WhiteBalance.TWILIGHT);
        assertEquals(intstr.whiteBalanceFromInt(CONTROL_AWB_MODE_WARM_FLUORESCENT),
                WhiteBalance.WARM_FLUORESCENT);
    
private voidcamera2SettingsCheckSingleOption(AndroidCamera2Settings setts, Key apiKey, int apiVal)

        assertEquals(apiVal, setts.getRequestSettings().get(apiKey));
    
public voidcamera2SettingsSetOptionsAndGetRequestSettings()
Ensure that {@link AndroidCamera2Settings} correctly translates its {@code FocusMode}, {@code SceneMode}, and {@code WhiteBalance} to the corresponding framework API 2 representations.

        // We're only testing the focus modes, scene modes and white balances,
        // and won't use the activeArray, previewSize, or photoSize. The
        // constructor requires the former, so pass a degenerate rectangle.
        AndroidCamera2Settings set = new AndroidCamera2Settings(
                mCamera, CameraDevice.TEMPLATE_PREVIEW, /*activeArray*/new Rect(),
                /*previewSize*/null, /*photoSize*/null);

        // Focus modes
        set.setFocusMode(FocusMode.AUTO);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_AUTO);
        set.setFocusMode(FocusMode.CONTINUOUS_PICTURE);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        set.setFocusMode(FocusMode.CONTINUOUS_VIDEO);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_CONTINUOUS_VIDEO);
        set.setFocusMode(FocusMode.EXTENDED_DOF);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_EDOF);
        set.setFocusMode(FocusMode.FIXED);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_OFF);
        set.setFocusMode(FocusMode.MACRO);
        camera2SettingsCheckSingleOption(set, CONTROL_AF_MODE, CONTROL_AF_MODE_MACRO);

        // Scene modes
        set.setSceneMode(SceneMode.AUTO);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_DISABLED);
        set.setSceneMode(SceneMode.ACTION);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_ACTION);
        set.setSceneMode(SceneMode.BARCODE);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_BARCODE);
        set.setSceneMode(SceneMode.BEACH);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_BEACH);
        set.setSceneMode(SceneMode.CANDLELIGHT);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_CANDLELIGHT);
        set.setSceneMode(SceneMode.FIREWORKS);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_FIREWORKS);
        set.setSceneMode(SceneMode.LANDSCAPE);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_LANDSCAPE);
        set.setSceneMode(SceneMode.NIGHT);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_NIGHT);
        set.setSceneMode(SceneMode.PARTY);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_PARTY);
        set.setSceneMode(SceneMode.PORTRAIT);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_PORTRAIT);
        set.setSceneMode(SceneMode.SNOW);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_SNOW);
        set.setSceneMode(SceneMode.SPORTS);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_SPORTS);
        set.setSceneMode(SceneMode.STEADYPHOTO);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_STEADYPHOTO);
        set.setSceneMode(SceneMode.SUNSET);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_SUNSET);
        set.setSceneMode(SceneMode.THEATRE);
        camera2SettingsCheckSingleOption(set, CONTROL_SCENE_MODE, CONTROL_SCENE_MODE_THEATRE);

        // White balances
        set.setWhiteBalance(WhiteBalance.AUTO);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_AUTO);
        set.setWhiteBalance(WhiteBalance.CLOUDY_DAYLIGHT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_CLOUDY_DAYLIGHT);
        set.setWhiteBalance(WhiteBalance.DAYLIGHT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_DAYLIGHT);
        set.setWhiteBalance(WhiteBalance.FLUORESCENT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_FLUORESCENT);
        set.setWhiteBalance(WhiteBalance.INCANDESCENT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_INCANDESCENT);
        set.setWhiteBalance(WhiteBalance.SHADE);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_SHADE);
        set.setWhiteBalance(WhiteBalance.TWILIGHT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_TWILIGHT);
        set.setWhiteBalance(WhiteBalance.WARM_FLUORESCENT);
        camera2SettingsCheckSingleOption(set, CONTROL_AWB_MODE, CONTROL_AWB_MODE_WARM_FLUORESCENT);
    
public voidcameraCapabilitiesStringifier()
Ensure that applying {@code Stringifier#.*FromString()} reverses {@link Stringifier#stringify} for {@link FocusMode}, {@link FlashMode}, {@link SceneMode}, and {@link WhiteBalance}.

        Stringifier strfy = new Stringifier();
        for(FocusMode val : FocusMode.values()) {
            assertEquals(val, strfy.focusModeFromString(strfy.stringify(val)));
        }
        for(FlashMode val : FlashMode.values()) {
            assertEquals(val, strfy.flashModeFromString(strfy.stringify(val)));
        }
        for(SceneMode val : SceneMode.values()) {
            assertEquals(val, strfy.sceneModeFromString(strfy.stringify(val)));
        }
        for(WhiteBalance val : WhiteBalance.values()) {
            assertEquals(val, strfy.whiteBalanceFromString(strfy.stringify(val)));
        }
    
public voidcameraCapabilitiesStringifierInvalid()
Ensure that {@code Stringifier#.*FromString()} default to the correct {@link FocusMode}, {@link FlashMode}, {@link SceneMode}, and {@link WhiteBalance} when given an unrecognized string.

        Stringifier strfy = new Stringifier();
        assertEquals(strfy.focusModeFromString("crap"), FocusMode.AUTO);
        assertEquals(strfy.flashModeFromString("crap"), FlashMode.NO_FLASH);
        assertEquals(strfy.sceneModeFromString("crap"), SceneMode.NO_SCENE_MODE);
        assertEquals(strfy.whiteBalanceFromString("crap"), WhiteBalance.AUTO);
    
public voidcameraCapabilitiesStringifierNull()
Ensure that {@code Stringifier#.*FromString()} default to the correct {@link FocusMode}, {@link FlashMode}, {@link SceneMode}, and {@link WhiteBalance} when given a {@code null}.

        Stringifier strfy = new Stringifier();
        assertEquals(strfy.focusModeFromString(null), FocusMode.AUTO);
        assertEquals(strfy.flashModeFromString(null), FlashMode.NO_FLASH);
        assertEquals(strfy.sceneModeFromString(null), SceneMode.NO_SCENE_MODE);
        assertEquals(strfy.whiteBalanceFromString(null), WhiteBalance.AUTO);