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; 21 import android.text.TextUtils; 22 23 import androidx.annotation.VisibleForTesting; 24 import androidx.preference.ListPreference; 25 import androidx.preference.Preference; 26 27 import com.android.settings.R; 28 import com.android.settings.core.PreferenceControllerMixin; 29 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 30 31 public class BluetoothAvrcpVersionPreferenceController extends DeveloperOptionsPreferenceController 32 implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 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; 42 BluetoothAvrcpVersionPreferenceController(Context context)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 getPreferenceKey()51 public String getPreferenceKey() { 52 return BLUETOOTH_SELECT_AVRCP_VERSION_KEY; 53 } 54 55 @Override onPreferenceChange(Preference preference, Object newValue)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 updateState(Preference preference)63 public void updateState(Preference preference) { 64 final ListPreference listPreference = (ListPreference) preference; 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 } 73 listPreference.setValue(mListValues[index]); 74 listPreference.setSummary(mListSummaries[index]); 75 } 76 } 77