• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.car.developeroptions.display;
15 
16 import static android.provider.Settings.System.ADAPTIVE_SLEEP;
17 
18 import android.content.Context;
19 import android.provider.Settings;
20 
21 import com.android.car.developeroptions.R;
22 import com.android.car.developeroptions.core.TogglePreferenceController;
23 
24 
25 public class AdaptiveSleepPreferenceController extends TogglePreferenceController {
26 
27     private final String SYSTEM_KEY = ADAPTIVE_SLEEP;
28     private final int DEFAULT_VALUE = 0;
29 
AdaptiveSleepPreferenceController(Context context, String key)30     public AdaptiveSleepPreferenceController(Context context, String key) {
31         super(context, key);
32     }
33 
34     @Override
isChecked()35     public boolean isChecked() {
36         return Settings.System.getInt(mContext.getContentResolver(),
37                 SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
38     }
39 
40     @Override
setChecked(boolean isChecked)41     public boolean setChecked(boolean isChecked) {
42         Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
43                 isChecked ? 1 : DEFAULT_VALUE);
44         return true;
45     }
46 
47     @Override
48     @AvailabilityStatus
getAvailabilityStatus()49     public int getAvailabilityStatus() {
50         return mContext.getResources().getBoolean(
51                 com.android.internal.R.bool.config_adaptive_sleep_available)
52                 ? AVAILABLE
53                 : UNSUPPORTED_ON_DEVICE;
54     }
55 
56     @Override
isSliceable()57     public boolean isSliceable() {
58         return true;
59     }
60 
61     @Override
getSummary()62     public CharSequence getSummary() {
63         return mContext.getText(isChecked()
64                 ? R.string.adaptive_sleep_summary_on
65                 : R.string.adaptive_sleep_summary_off);
66     }
67 }
68