2 * Copyright (C) 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.development;
19 import android.content.Context;
20 import android.os.SystemProperties;
21 import android.support.v14.preference.SwitchPreference;
22 import android.support.v7.preference.Preference;
23 import android.text.TextUtils;
25 import com.android.internal.annotations.VisibleForTesting;
26 import com.android.settings.R;
27 import com.android.settings.core.PreferenceControllerMixin;
28 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30 public class LogicalCameraDefaultPreferenceController extends DeveloperOptionsPreferenceController
31 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
33 private static final String KEY_LOGICAL_CAMERA_DEFAULT_SWITCH = "logical_camera_default_switch";
35 static final String BUILD_TYPE = "ro.build.type";
37 static final String PROPERTY_LOGICAL_CAMERA_DEFAULT = "persist.camera.logical.default";
39 static final int ENABLED = 1;
41 static final int DISABLED = 0;
43 static final String USERDEBUG_BUILD = "userdebug";
45 static final String ENG_BUILD = "eng";
47 static final String USER_BUILD = "user";
49 public LogicalCameraDefaultPreferenceController(Context context) {
54 public boolean isAvailable() {
55 return mContext.getResources().getBoolean(R.bool.config_show_logical_camera_default);
59 public String getPreferenceKey() {
60 return KEY_LOGICAL_CAMERA_DEFAULT_SWITCH;
64 public boolean onPreferenceChange(Preference preference, Object newValue) {
65 final boolean isEnabled = (Boolean) newValue;
66 String value = Integer.toString(isEnabled ? ENABLED : DISABLED);
67 SystemProperties.set(PROPERTY_LOGICAL_CAMERA_DEFAULT, value);
72 public void updateState(Preference preference) {
73 final boolean enabled = isLogicalCameraDefault();
74 ((SwitchPreference) mPreference).setChecked(enabled);
78 protected void onDeveloperOptionsSwitchDisabled() {
79 super.onDeveloperOptionsSwitchDisabled();
80 SystemProperties.set(PROPERTY_LOGICAL_CAMERA_DEFAULT, Integer.toString(DISABLED));
81 ((SwitchPreference) mPreference).setChecked(false);
84 private boolean isLogicalCameraDefault() {
85 final String prop = SystemProperties.get(PROPERTY_LOGICAL_CAMERA_DEFAULT,
86 Integer.toString(DISABLED));
87 return TextUtils.equals(Integer.toString(ENABLED), prop);