1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.one.v2.common;
18
19import android.hardware.camera2.CaptureRequest;
20
21import com.android.camera.one.OneCameraCharacteristics.FaceDetectMode;
22import com.android.camera.one.OneCameraCharacteristics.SupportedHardwareLevel;
23import com.google.common.base.Supplier;
24
25/**
26 * Select a control mode based on the HdrSettings and face detection modes.
27 */
28public class ControlModeSelector implements Supplier<Integer> {
29    private final Supplier<Boolean> mHdrSetting;
30    private final Supplier<FaceDetectMode> mFaceDetectMode;
31    private final SupportedHardwareLevel mSupportedHardwareLevel;
32
33    public ControlModeSelector(
34          Supplier<Boolean> hdrSetting,
35          Supplier<FaceDetectMode> faceDetectMode,
36          SupportedHardwareLevel supportedHardwareLevel) {
37        mHdrSetting = hdrSetting;
38        mFaceDetectMode = faceDetectMode;
39        mSupportedHardwareLevel = supportedHardwareLevel;
40    }
41
42    @Override
43    public Integer get() {
44        if (mSupportedHardwareLevel == SupportedHardwareLevel.LEGACY) {
45            if (mHdrSetting.get()) {
46                return CaptureRequest.CONTROL_MODE_USE_SCENE_MODE;
47            }
48        }
49
50        if (mFaceDetectMode.get() == FaceDetectMode.FULL ||
51              mFaceDetectMode.get() == FaceDetectMode.SIMPLE) {
52            return CaptureRequest.CONTROL_MODE_USE_SCENE_MODE;
53        }
54
55        return CaptureRequest.CONTROL_MODE_AUTO;
56    }
57}
58