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.BluetoothCodecConfig; 20 import android.content.Context; 21 22 import com.android.settings.R; 23 import com.android.settingslib.core.lifecycle.Lifecycle; 24 25 public class BluetoothAudioQualityPreferenceController extends 26 AbstractBluetoothA2dpPreferenceController { 27 28 private static final int DEFAULT_INDEX = 3; 29 private static final String BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY = 30 "bluetooth_select_a2dp_ldac_playback_quality"; 31 BluetoothAudioQualityPreferenceController(Context context, Lifecycle lifecycle, BluetoothA2dpConfigStore store)32 public BluetoothAudioQualityPreferenceController(Context context, Lifecycle lifecycle, 33 BluetoothA2dpConfigStore store) { 34 super(context, lifecycle, store); 35 } 36 37 @Override getPreferenceKey()38 public String getPreferenceKey() { 39 return BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY; 40 } 41 42 @Override getListValues()43 protected String[] getListValues() { 44 return mContext.getResources().getStringArray( 45 R.array.bluetooth_a2dp_codec_ldac_playback_quality_values); 46 } 47 48 @Override getListSummaries()49 protected String[] getListSummaries() { 50 return mContext.getResources().getStringArray( 51 R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries); 52 } 53 54 @Override getDefaultIndex()55 protected int getDefaultIndex() { 56 return DEFAULT_INDEX; 57 } 58 59 @Override writeConfigurationValues(Object newValue)60 protected void writeConfigurationValues(Object newValue) { 61 final int index = mPreference.findIndexOfValue(newValue.toString()); 62 int codecSpecific1Value = 0; // default 63 switch (index) { 64 case 0: 65 case 1: 66 case 2: 67 case 3: 68 codecSpecific1Value = 1000 + index; 69 break; 70 default: 71 break; 72 } 73 mBluetoothA2dpConfigStore.setCodecSpecific1Value(codecSpecific1Value); 74 } 75 76 @Override getCurrentA2dpSettingIndex(BluetoothCodecConfig config)77 protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) { 78 // The actual values are 0, 1, 2 - those are extracted 79 // as mod-10 remainders of a larger value. 80 // The reason is because within BluetoothCodecConfig we cannot use 81 // a codec-specific value of zero. 82 int index = (int) config.getCodecSpecific1(); 83 if (index > 0) { 84 index %= 10; 85 } else { 86 index = DEFAULT_INDEX; 87 } 88 switch (index) { 89 case 0: 90 case 1: 91 case 2: 92 case 3: 93 break; 94 default: 95 index = DEFAULT_INDEX; 96 break; 97 } 98 return index; 99 } 100 } 101