• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.connecteddevice;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 import android.util.FeatureFlagUtils;
22 
23 import com.android.settings.core.FeatureFlags;
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settings.core.TogglePreferenceController;
26 
27 /** Handles a toggle for a setting to turn on Bluetooth while driving. * */
28 public class BluetoothOnWhileDrivingPreferenceController extends TogglePreferenceController
29         implements PreferenceControllerMixin {
30     static final String KEY_BLUETOOTH_ON_DRIVING = "bluetooth_on_while_driving";
31 
BluetoothOnWhileDrivingPreferenceController(Context context)32     public BluetoothOnWhileDrivingPreferenceController(Context context) {
33         super(context, KEY_BLUETOOTH_ON_DRIVING);
34     }
35 
36     @Override
getAvailabilityStatus()37     public int getAvailabilityStatus() {
38         if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.BLUETOOTH_WHILE_DRIVING)) {
39             return AVAILABLE;
40         }
41         return CONDITIONALLY_UNAVAILABLE;
42     }
43 
44     @Override
isChecked()45     public boolean isChecked() {
46         return Settings.Secure.getInt(
47                         mContext.getContentResolver(),
48                         Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING,
49                         0)
50                 != 0;
51     }
52 
53     @Override
setChecked(boolean isChecked)54     public boolean setChecked(boolean isChecked) {
55         final int value = isChecked ? 1 : 0;
56         return Settings.Secure.putInt(
57                 mContext.getContentResolver(), Settings.Secure.BLUETOOTH_ON_WHILE_DRIVING, value);
58     }
59 }
60