blob: 136ddad5fcf9c54c7430e53e0854f1b7e7ec6776 [file] [log] [blame]
jeffreyhuangff1e0e12017-10-06 10:24:35 -07001/*
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
17package com.android.settings.development;
18
19import android.content.Context;
20import android.os.SystemProperties;
Fan Zhangde117042018-09-04 13:52:15 -070021import android.text.TextUtils;
22
Aurimas Liutikas03fcde32018-04-17 11:22:43 -070023import androidx.annotation.VisibleForTesting;
24import androidx.preference.ListPreference;
25import androidx.preference.Preference;
jeffreyhuangff1e0e12017-10-06 10:24:35 -070026
27import com.android.settings.R;
28import com.android.settings.core.PreferenceControllerMixin;
29import com.android.settingslib.development.DeveloperOptionsPreferenceController;
30
Doris Ling4fbf04c2018-03-01 10:33:14 -080031public class BluetoothAvrcpVersionPreferenceController extends DeveloperOptionsPreferenceController
32 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin {
jeffreyhuangff1e0e12017-10-06 10:24:35 -070033
34 private static final String BLUETOOTH_SELECT_AVRCP_VERSION_KEY =
35 "bluetooth_select_avrcp_version";
36
37 @VisibleForTesting
38 static final String BLUETOOTH_AVRCP_VERSION_PROPERTY = "persist.bluetooth.avrcpversion";
39
40 private final String[] mListValues;
41 private final String[] mListSummaries;
jeffreyhuangff1e0e12017-10-06 10:24:35 -070042
43 public BluetoothAvrcpVersionPreferenceController(Context context) {
44 super(context);
45
46 mListValues = context.getResources().getStringArray(R.array.bluetooth_avrcp_version_values);
47 mListSummaries = context.getResources().getStringArray(R.array.bluetooth_avrcp_versions);
48 }
49
50 @Override
51 public String getPreferenceKey() {
52 return BLUETOOTH_SELECT_AVRCP_VERSION_KEY;
53 }
54
55 @Override
jeffreyhuangff1e0e12017-10-06 10:24:35 -070056 public boolean onPreferenceChange(Preference preference, Object newValue) {
57 SystemProperties.set(BLUETOOTH_AVRCP_VERSION_PROPERTY, newValue.toString());
58 updateState(mPreference);
59 return true;
60 }
61
62 @Override
63 public void updateState(Preference preference) {
Doris Ling4fbf04c2018-03-01 10:33:14 -080064 final ListPreference listPreference = (ListPreference) preference;
jeffreyhuangff1e0e12017-10-06 10:24:35 -070065 final String currentValue = SystemProperties.get(BLUETOOTH_AVRCP_VERSION_PROPERTY);
66 int index = 0; // Defaults to AVRCP 1.4
67 for (int i = 0; i < mListValues.length; i++) {
68 if (TextUtils.equals(currentValue, mListValues[i])) {
69 index = i;
70 break;
71 }
72 }
Doris Ling4fbf04c2018-03-01 10:33:14 -080073 listPreference.setValue(mListValues[index]);
74 listPreference.setSummary(mListSummaries[index]);
jeffreyhuangff1e0e12017-10-06 10:24:35 -070075 }
76}