| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 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.content.Context; |
| 20 | import android.os.SystemProperties; |
| Fan Zhang | de11704 | 2018-09-04 13:52:15 -0700 | [diff] [blame^] | 21 | import android.text.TextUtils; |
| 22 | |
| Aurimas Liutikas | 03fcde3 | 2018-04-17 11:22:43 -0700 | [diff] [blame] | 23 | import androidx.annotation.VisibleForTesting; |
| 24 | import androidx.preference.ListPreference; |
| 25 | import androidx.preference.Preference; |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 26 | |
| 27 | import com.android.settings.R; |
| 28 | import com.android.settings.core.PreferenceControllerMixin; |
| 29 | import com.android.settingslib.development.DeveloperOptionsPreferenceController; |
| 30 | |
| Doris Ling | 4fbf04c | 2018-03-01 10:33:14 -0800 | [diff] [blame] | 31 | public class BluetoothAvrcpVersionPreferenceController extends DeveloperOptionsPreferenceController |
| 32 | implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 33 | |
| 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; |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 42 | |
| 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 |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 56 | 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 Ling | 4fbf04c | 2018-03-01 10:33:14 -0800 | [diff] [blame] | 64 | final ListPreference listPreference = (ListPreference) preference; |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 65 | 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 Ling | 4fbf04c | 2018-03-01 10:33:14 -0800 | [diff] [blame] | 73 | listPreference.setValue(mListValues[index]); |
| 74 | listPreference.setSummary(mListSummaries[index]); |
| jeffreyhuang | ff1e0e1 | 2017-10-06 10:24:35 -0700 | [diff] [blame] | 75 | } |
| 76 | } |