1 /*
2  * Copyright (C) 2020 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 
17 package com.android.settings.gestures;
18 
19 import android.content.Context;
20 import android.content.pm.PackageManager;
21 import android.provider.Settings;
22 import android.text.TextUtils;
23 
24 import com.android.internal.annotations.VisibleForTesting;
25 
26 public class DeviceControlsPreferenceController extends GesturePreferenceController {
27     private static final String PREF_KEY_VIDEO = "device_controls_video";
28 
29     @VisibleForTesting
30     protected static final String ENABLED_SETTING = Settings.Secure.CONTROLS_ENABLED;
31 
32     @VisibleForTesting
33     protected static final String TOGGLE_KEY = "gesture_device_controls_switch";
34 
DeviceControlsPreferenceController(Context context, String key)35     public DeviceControlsPreferenceController(Context context, String key) {
36         super(context, key);
37     }
38 
39     @Override
getAvailabilityStatus()40     public int getAvailabilityStatus() {
41         boolean available = mContext.getPackageManager().hasSystemFeature(
42                 PackageManager.FEATURE_CONTROLS);
43         return available ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
44     }
45 
46     @Override
setChecked(boolean isChecked)47     public boolean setChecked(boolean isChecked) {
48         return Settings.Secure.putInt(mContext.getContentResolver(), ENABLED_SETTING,
49                 isChecked ? 1 : 0);
50     }
51 
52     @Override
getVideoPrefKey()53     protected String getVideoPrefKey() {
54         return PREF_KEY_VIDEO;
55     }
56 
57     @Override
isSliceable()58     public boolean isSliceable() {
59         return TextUtils.equals(getPreferenceKey(), TOGGLE_KEY);
60     }
61 
62     @Override
isPublicSlice()63     public boolean isPublicSlice() {
64         return true;
65     }
66 
67     @Override
isChecked()68     public boolean isChecked() {
69         int enabled = Settings.Secure.getInt(mContext.getContentResolver(), ENABLED_SETTING, 1);
70         return enabled == 1;
71     }
72 }
73