OSDN Git Service

Merge "Update the initial expanded count for apps and notifications." into pi-dev
[android-x86/packages-apps-Settings.git] / src / com / android / settings / development / BluetoothInbandRingingPreferenceController.java
1 /*
2  * Copyright (C) 2017 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.development;
18
19 import android.bluetooth.BluetoothHeadset;
20 import android.content.Context;
21 import android.os.SystemProperties;
22 import android.support.annotation.VisibleForTesting;
23 import android.support.v14.preference.SwitchPreference;
24 import android.support.v7.preference.Preference;
25
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
28
29 public class BluetoothInbandRingingPreferenceController extends DeveloperOptionsPreferenceController
30         implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
31
32     private static final String BLUETOOTH_DISABLE_INBAND_RINGING_KEY =
33             "bluetooth_disable_inband_ringing";
34     @VisibleForTesting
35     static final String BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY =
36             "persist.bluetooth.disableinbandringing";
37
38     public BluetoothInbandRingingPreferenceController(Context context) {
39         super(context);
40     }
41
42     @Override
43     public boolean isAvailable() {
44         return isInbandRingingSupported();
45     }
46
47     @Override
48     public String getPreferenceKey() {
49         return BLUETOOTH_DISABLE_INBAND_RINGING_KEY;
50     }
51
52     @Override
53     public boolean onPreferenceChange(Preference preference, Object newValue) {
54         final boolean isChecked = (Boolean) newValue;
55         SystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY,
56                 isChecked ? "true" : "false");
57         return true;
58     }
59
60     @Override
61     public void updateState(Preference preference) {
62         final boolean isEnabled = SystemProperties.getBoolean(
63                 BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, false /* default */);
64         ((SwitchPreference) mPreference).setChecked(isEnabled);
65     }
66
67     @Override
68     protected void onDeveloperOptionsSwitchDisabled() {
69         super.onDeveloperOptionsSwitchDisabled();
70         ((SwitchPreference) mPreference).setChecked(false);
71         SystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, "false");
72     }
73
74     @VisibleForTesting
75     boolean isInbandRingingSupported() {
76         return BluetoothHeadset.isInbandRingingSupported(mContext);
77     }
78 }