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.emergency;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.VisibleForTesting;
22 
23 import com.android.settings.R;
24 import com.android.settings.core.TogglePreferenceController;
25 import com.android.settingslib.emergencynumber.EmergencyNumberUtils;
26 
27 /**
28  * Preference controller for emergency sos gesture setting
29  */
30 public class EmergencyGestureSoundPreferenceController extends TogglePreferenceController {
31 
32     @VisibleForTesting
33     EmergencyNumberUtils mEmergencyNumberUtils;
34 
EmergencyGestureSoundPreferenceController(Context context, String key)35     public EmergencyGestureSoundPreferenceController(Context context, String key) {
36         super(context, key);
37         mEmergencyNumberUtils = new EmergencyNumberUtils(context);
38     }
39 
isGestureAvailable(Context context)40     private static boolean isGestureAvailable(Context context) {
41         return context.getResources()
42                 .getBoolean(R.bool.config_show_emergency_gesture_settings);
43     }
44 
45     @Override
getAvailabilityStatus()46     public int getAvailabilityStatus() {
47         return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
48     }
49 
50     @Override
isSliceable()51     public boolean isSliceable() {
52         return false;
53     }
54 
55     @Override
getSliceHighlightMenuRes()56     public int getSliceHighlightMenuRes() {
57         // not needed since it's not sliceable
58         return NO_RES;
59     }
60 
61     @Override
isChecked()62     public boolean isChecked() {
63         return mEmergencyNumberUtils.getEmergencyGestureSoundEnabled();
64     }
65 
66     @Override
setChecked(boolean isChecked)67     public boolean setChecked(boolean isChecked) {
68         mEmergencyNumberUtils.setEmergencySoundEnabled(isChecked);
69         return true;
70     }
71 }
72