2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.development;
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;
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.development.DeveloperOptionsPreferenceController;
29 public class BluetoothInbandRingingPreferenceController extends DeveloperOptionsPreferenceController
30 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
32 private static final String BLUETOOTH_DISABLE_INBAND_RINGING_KEY =
33 "bluetooth_disable_inband_ringing";
35 static final String BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY =
36 "persist.bluetooth.disableinbandringing";
38 public BluetoothInbandRingingPreferenceController(Context context) {
43 public boolean isAvailable() {
44 return isInbandRingingSupported();
48 public String getPreferenceKey() {
49 return BLUETOOTH_DISABLE_INBAND_RINGING_KEY;
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");
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);
68 protected void onDeveloperOptionsSwitchDisabled() {
69 super.onDeveloperOptionsSwitchDisabled();
70 ((SwitchPreference) mPreference).setChecked(false);
71 SystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, "false");
75 boolean isInbandRingingSupported() {
76 return BluetoothHeadset.isInbandRingingSupported(mContext);