Merge changes I145c2e25,I4abe87dd,I86575d17,I90a0e583
* changes: Introduce BluetoothAudioQualityPreferenceCtrl Introduce BluetoothAudioChannelModePreferenceCtrl Introduce BluetoothAudioBitsPerSamplePrefCtrl Introduce BluetoothAudioCodecPreferenceController
This commit is contained in:
committed by
Android (Google) Code Review
commit
db60997f2a
@@ -40,17 +40,15 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
||||
static final int STREAMING_LABEL_ID = R.string.bluetooth_select_a2dp_codec_streaming_label;
|
||||
|
||||
protected final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||
protected final Object mBluetoothA2dpLock;
|
||||
protected BluetoothA2dp mBluetoothA2dp;
|
||||
protected ListPreference mPreference;
|
||||
private final String[] mListValues;
|
||||
private final String[] mListSummaries;
|
||||
private ListPreference mPreference;
|
||||
|
||||
public AbstractBluetoothA2dpPreferenceController(Context context, Lifecycle lifecycle,
|
||||
Object bluetoothA2dpLock, BluetoothA2dpConfigStore store) {
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context);
|
||||
|
||||
mBluetoothA2dpLock = bluetoothA2dpLock;
|
||||
mBluetoothA2dpConfigStore = store;
|
||||
mListValues = getListValues();
|
||||
mListSummaries = getListSummaries();
|
||||
@@ -80,7 +78,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
||||
writeConfigurationValues(newValue);
|
||||
|
||||
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
|
||||
synchronized (mBluetoothA2dpLock) {
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
if (mBluetoothA2dp != null) {
|
||||
setCodecConfigPreference(codecConfig);
|
||||
}
|
||||
@@ -106,7 +104,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
||||
}
|
||||
|
||||
BluetoothCodecConfig codecConfig;
|
||||
synchronized (mBluetoothA2dpLock) {
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
codecConfig = getCodecConfig();
|
||||
}
|
||||
|
||||
@@ -168,7 +166,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
||||
protected abstract String[] getListSummaries();
|
||||
|
||||
/**
|
||||
* Updates the new value to the {@link BluetoothA2dpConfigStore}.
|
||||
* Updates the new value to the {@link BluetoothA2dpConfigStore} and the {@link BluetoothA2dp}.
|
||||
*
|
||||
* @param newValue the new setting value
|
||||
*/
|
||||
@@ -197,18 +195,4 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
||||
|
||||
return mBluetoothA2dp.getCodecStatus().getCodecConfig();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BluetoothCodecConfig createCodecConfig(int codecTypeValue, int codecPriorityValue,
|
||||
int sampleRateValue, int bitsPerSampleValue,
|
||||
int channelModeValue, long codecSpecific1Value,
|
||||
long codecSpecific2Value, long codecSpecific3Value,
|
||||
long codecSpecific4Value) {
|
||||
return new BluetoothCodecConfig(codecTypeValue, codecPriorityValue,
|
||||
sampleRateValue, bitsPerSampleValue,
|
||||
channelModeValue, codecSpecific1Value,
|
||||
codecSpecific2Value, codecSpecific3Value,
|
||||
codecSpecific4Value);
|
||||
}
|
||||
|
||||
}
|
||||
|
25
src/com/android/settings/development/BluetoothA2dpLock.java
Normal file
25
src/com/android/settings/development/BluetoothA2dpLock.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothA2dp;
|
||||
|
||||
/**
|
||||
* Utility class to provide synchronization locks for {@link BluetoothA2dp}
|
||||
*/
|
||||
public class BluetoothA2dpLock {
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class BluetoothAudioBitsPerSamplePreferenceController extends
|
||||
AbstractBluetoothA2dpPreferenceController {
|
||||
|
||||
private static final int DEFAULT_INDEX = 0;
|
||||
private static final String BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY =
|
||||
"bluetooth_select_a2dp_bits_per_sample";
|
||||
|
||||
public BluetoothAudioBitsPerSamplePreferenceController(Context context, Lifecycle lifecycle,
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return BLUETOOTH_SELECT_A2DP_BITS_PER_SAMPLE_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListValues() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_bits_per_sample_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListSummaries() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_bits_per_sample_summaries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultIndex() {
|
||||
return DEFAULT_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeConfigurationValues(Object newValue) {
|
||||
final int index = mPreference.findIndexOfValue(newValue.toString());
|
||||
int bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_NONE; // default
|
||||
switch (index) {
|
||||
case 0:
|
||||
// Reset to default
|
||||
break;
|
||||
case 1:
|
||||
bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_16;
|
||||
break;
|
||||
case 2:
|
||||
bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_24;
|
||||
break;
|
||||
case 3:
|
||||
bitsPerSampleValue = BluetoothCodecConfig.BITS_PER_SAMPLE_32;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mBluetoothA2dpConfigStore.setBitsPerSample(bitsPerSampleValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
|
||||
final int bitsPerSample = config.getBitsPerSample();
|
||||
int index = DEFAULT_INDEX;
|
||||
switch (bitsPerSample) {
|
||||
case BluetoothCodecConfig.BITS_PER_SAMPLE_16:
|
||||
index = 1;
|
||||
break;
|
||||
case BluetoothCodecConfig.BITS_PER_SAMPLE_24:
|
||||
index = 2;
|
||||
break;
|
||||
case BluetoothCodecConfig.BITS_PER_SAMPLE_32:
|
||||
index = 3;
|
||||
break;
|
||||
case BluetoothCodecConfig.BITS_PER_SAMPLE_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class BluetoothAudioChannelModePreferenceController extends
|
||||
AbstractBluetoothA2dpPreferenceController {
|
||||
|
||||
private static final int DEFAULT_INDEX = 0;
|
||||
private static final String BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY =
|
||||
"bluetooth_select_a2dp_channel_mode";
|
||||
|
||||
public BluetoothAudioChannelModePreferenceController(Context context, Lifecycle lifecycle,
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return BLUETOOTH_SELECT_A2DP_CHANNEL_MODE_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListValues() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_channel_mode_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListSummaries() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_channel_mode_summaries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultIndex() {
|
||||
return DEFAULT_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeConfigurationValues(Object newValue) {
|
||||
final int index = mPreference.findIndexOfValue(newValue.toString());
|
||||
int channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_NONE; // default
|
||||
switch (index) {
|
||||
case 0:
|
||||
// Reset to default
|
||||
break;
|
||||
case 1:
|
||||
channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_MONO;
|
||||
break;
|
||||
case 2:
|
||||
channelModeValue = BluetoothCodecConfig.CHANNEL_MODE_STEREO;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mBluetoothA2dpConfigStore.setChannelMode(channelModeValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
|
||||
final int channelMode = config.getChannelMode();
|
||||
int index = DEFAULT_INDEX;
|
||||
switch (channelMode) {
|
||||
case BluetoothCodecConfig.CHANNEL_MODE_MONO:
|
||||
index = 1;
|
||||
break;
|
||||
case BluetoothCodecConfig.CHANNEL_MODE_STEREO:
|
||||
index = 2;
|
||||
break;
|
||||
case BluetoothCodecConfig.CHANNEL_MODE_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class BluetoothAudioCodecPreferenceController extends
|
||||
AbstractBluetoothA2dpPreferenceController {
|
||||
|
||||
private static final int DEFAULT_INDEX = 0;
|
||||
private static final String BLUETOOTH_SELECT_A2DP_CODEC_KEY = "bluetooth_select_a2dp_codec";
|
||||
|
||||
public BluetoothAudioCodecPreferenceController(Context context, Lifecycle lifecycle,
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return BLUETOOTH_SELECT_A2DP_CODEC_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListValues() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListSummaries() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_summaries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultIndex() {
|
||||
return DEFAULT_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeConfigurationValues(Object newValue) {
|
||||
final int index = mPreference.findIndexOfValue(newValue.toString());
|
||||
int codecTypeValue = BluetoothCodecConfig.SAMPLE_RATE_NONE; // default
|
||||
int codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT;
|
||||
switch (index) {
|
||||
case 0:
|
||||
// Reset the priority of the current codec to default
|
||||
final String oldValue = mPreference.getValue();
|
||||
switch (mPreference.findIndexOfValue(oldValue)) {
|
||||
case 0:
|
||||
break; // No current codec
|
||||
case 1:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
|
||||
break;
|
||||
case 2:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
|
||||
break;
|
||||
case 3:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
|
||||
break;
|
||||
case 4:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
|
||||
break;
|
||||
case 5:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC;
|
||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||
break;
|
||||
case 2:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC;
|
||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||
break;
|
||||
case 3:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX;
|
||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||
break;
|
||||
case 4:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD;
|
||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||
break;
|
||||
case 5:
|
||||
codecTypeValue = BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC;
|
||||
codecPriorityValue = BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST;
|
||||
break;
|
||||
case 6:
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
if (mBluetoothA2dp != null) {
|
||||
mBluetoothA2dp.enableOptionalCodecs();
|
||||
}
|
||||
}
|
||||
return;
|
||||
case 7:
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
if (mBluetoothA2dp != null) {
|
||||
mBluetoothA2dp.disableOptionalCodecs();
|
||||
}
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mBluetoothA2dpConfigStore.setCodecType(codecTypeValue);
|
||||
mBluetoothA2dpConfigStore.setCodecPriority(codecPriorityValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
|
||||
final int codecType = config.getCodecType();
|
||||
int index = DEFAULT_INDEX;
|
||||
switch (codecType) {
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_SBC:
|
||||
index = 1;
|
||||
break;
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC:
|
||||
index = 2;
|
||||
break;
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX:
|
||||
index = 3;
|
||||
break;
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX_HD:
|
||||
index = 4;
|
||||
break;
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_LDAC:
|
||||
index = 5;
|
||||
break;
|
||||
case BluetoothCodecConfig.SOURCE_CODEC_TYPE_INVALID:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class BluetoothAudioQualityPreferenceController extends
|
||||
AbstractBluetoothA2dpPreferenceController {
|
||||
|
||||
private static final int DEFAULT_INDEX = 3;
|
||||
private static final String BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY =
|
||||
"bluetooth_select_a2dp_ldac_playback_quality";
|
||||
|
||||
public BluetoothAudioQualityPreferenceController(Context context, Lifecycle lifecycle,
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return BLUETOOTH_SELECT_A2DP_LDAC_PLAYBACK_QUALITY_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListValues() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_ldac_playback_quality_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListSummaries() {
|
||||
return mContext.getResources().getStringArray(
|
||||
R.array.bluetooth_a2dp_codec_ldac_playback_quality_summaries);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultIndex() {
|
||||
return DEFAULT_INDEX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeConfigurationValues(Object newValue) {
|
||||
final int index = mPreference.findIndexOfValue(newValue.toString());
|
||||
int codecSpecific1Value = 0; // default
|
||||
switch (index) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
codecSpecific1Value = 1000 + index;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mBluetoothA2dpConfigStore.setCodecSpecific1Value(codecSpecific1Value);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getCurrentA2dpSettingIndex(BluetoothCodecConfig config) {
|
||||
// The actual values are 0, 1, 2 - those are extracted
|
||||
// as mod-10 remainders of a larger value.
|
||||
// The reason is because within BluetoothCodecConfig we cannot use
|
||||
// a codec-specific value of zero.
|
||||
int index = (int) config.getCodecSpecific1();
|
||||
if (index > 0) {
|
||||
index %= 10;
|
||||
} else {
|
||||
index = DEFAULT_INDEX;
|
||||
}
|
||||
switch (index) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
index = DEFAULT_INDEX;
|
||||
break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -18,8 +18,6 @@ package com.android.settings.development;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -31,11 +29,9 @@ public class BluetoothAudioSampleRatePreferenceController extends
|
||||
private static final String BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY =
|
||||
"bluetooth_select_a2dp_sample_rate";
|
||||
|
||||
private ListPreference mPreference;
|
||||
|
||||
public BluetoothAudioSampleRatePreferenceController(Context context, Lifecycle lifecycle,
|
||||
Object bluetoothA2dpLock, BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, bluetoothA2dpLock, store);
|
||||
BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,13 +39,6 @@ public class BluetoothAudioSampleRatePreferenceController extends
|
||||
return BLUETOOTH_SELECT_A2DP_SAMPLE_RATE_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getListValues() {
|
||||
return mContext.getResources().getStringArray(
|
||||
|
@@ -60,7 +60,8 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
|
||||
private static final String TAG = "DevSettingsDashboard";
|
||||
|
||||
private final Object mBluetoothA2dpLock = new Object();
|
||||
private final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore =
|
||||
new BluetoothA2dpConfigStore();
|
||||
|
||||
private boolean mIsAvailable = true;
|
||||
private SwitchBar mSwitchBar;
|
||||
@@ -104,7 +105,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
@Override
|
||||
public void onServiceConnected(int profile,
|
||||
BluetoothProfile proxy) {
|
||||
synchronized (mBluetoothA2dpLock) {
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
mBluetoothA2dp = (BluetoothA2dp) proxy;
|
||||
}
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
@@ -117,7 +118,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(int profile) {
|
||||
synchronized (mBluetoothA2dpLock) {
|
||||
synchronized (mBluetoothA2dpConfigStore) {
|
||||
mBluetoothA2dp = null;
|
||||
}
|
||||
for (AbstractPreferenceController controller : mPreferenceControllers) {
|
||||
@@ -295,7 +296,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
||||
mPreferenceControllers = buildPreferenceControllers(context, getActivity(), getLifecycle(),
|
||||
this /* devOptionsDashboardFragment */, mBluetoothA2dpLock,
|
||||
this /* devOptionsDashboardFragment */,
|
||||
new BluetoothA2dpConfigStore());
|
||||
return mPreferenceControllers;
|
||||
}
|
||||
@@ -349,7 +350,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Activity activity, Lifecycle lifecycle, DevelopmentSettingsDashboardFragment fragment,
|
||||
Object bluetoothA2dpLock, BluetoothA2dpConfigStore bluetoothA2dpConfigStore) {
|
||||
BluetoothA2dpConfigStore bluetoothA2dpConfigStore) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new BugReportPreferenceControllerV2(context));
|
||||
controllers.add(new LocalBackupPasswordPreferenceController(context));
|
||||
@@ -391,13 +392,16 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
controllers.add(new BluetoothAbsoluteVolumePreferenceController(context));
|
||||
controllers.add(new BluetoothInbandRingingPreferenceController(context));
|
||||
controllers.add(new BluetoothAvrcpVersionPreferenceController(context));
|
||||
//controllers.add(new BluetoothAudioCodecPreferenceController(context, lifecycle,
|
||||
// bluetoothA2dpLock, bluetoothA2dpConfigStore));
|
||||
controllers.add(new BluetoothAudioCodecPreferenceController(context, lifecycle,
|
||||
bluetoothA2dpConfigStore));
|
||||
controllers.add(new BluetoothAudioSampleRatePreferenceController(context, lifecycle,
|
||||
bluetoothA2dpLock, bluetoothA2dpConfigStore));
|
||||
// bluetooth audio bits per sample
|
||||
// bluetooth audio channel mode
|
||||
// bluetooth audio ldac codec: playback quality
|
||||
bluetoothA2dpConfigStore));
|
||||
controllers.add(new BluetoothAudioBitsPerSamplePreferenceController(context, lifecycle,
|
||||
bluetoothA2dpConfigStore));
|
||||
controllers.add(new BluetoothAudioChannelModePreferenceController(context, lifecycle,
|
||||
bluetoothA2dpConfigStore));
|
||||
controllers.add(new BluetoothAudioQualityPreferenceController(context, lifecycle,
|
||||
bluetoothA2dpConfigStore));
|
||||
controllers.add(new ShowTapsPreferenceController(context));
|
||||
controllers.add(new PointerLocationPreferenceController(context));
|
||||
controllers.add(new ShowSurfaceUpdatesPreferenceController(context));
|
||||
@@ -463,7 +467,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
|
||||
context) {
|
||||
return buildPreferenceControllers(context, null /* activity */,
|
||||
null /* lifecycle */, null /* devOptionsDashboardFragment */,
|
||||
null /* bluetoothA2dpLock */, null /* bluetoothA2dpConfigStore */);
|
||||
null /* bluetoothA2dpConfigStore */);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -24,11 +24,31 @@ public class BluetoothCodecConfig {
|
||||
public static final int SAMPLE_RATE_NONE = 0;
|
||||
public static final int SAMPLE_RATE_48000 = 0x1 << 1;
|
||||
public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
|
||||
public static final int SOURCE_CODEC_TYPE_AAC = 1;
|
||||
public static final int CODEC_PRIORITY_DEFAULT = 0;
|
||||
public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
|
||||
public static final int BITS_PER_SAMPLE_NONE = 0;
|
||||
public static final int CHANNEL_MODE_NONE = 0;
|
||||
public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
|
||||
public static final int CHANNEL_MODE_STEREO = 0x1 << 1;
|
||||
|
||||
public int getSampleRate() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getCodecType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getBitsPerSample() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getChannelMode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getCodecSpecific1() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mLifecycle = new Lifecycle();
|
||||
mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
|
||||
new Object(), mBluetoothA2dpConfigStore));
|
||||
mBluetoothA2dpConfigStore));
|
||||
doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig();
|
||||
doNothing().when(mController).setCodecConfigPreference(any());
|
||||
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig);
|
||||
@@ -138,8 +138,8 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
|
||||
AbstractBluetoothA2dpPreferenceController {
|
||||
|
||||
public AbstractBluetoothA2dpPreferenceControllerImpl(Context context,
|
||||
Lifecycle lifecycle, Object bluetoothA2dpLock, BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, bluetoothA2dpLock, store);
|
||||
Lifecycle lifecycle, BluetoothA2dpConfigStore store) {
|
||||
super(context, lifecycle, store);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothAudioBitsPerSamplePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private BluetoothCodecConfig mBluetoothCodecConfig;
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||
|
||||
/**
|
||||
* 0: Use System Selection (Default)
|
||||
* 1: 16 bits/sample
|
||||
* 2: 24 bits/sample
|
||||
* 3: 32 bits/sample
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private Context mContext;
|
||||
private BluetoothAudioBitsPerSamplePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new BluetoothAudioBitsPerSamplePreferenceController(mContext,
|
||||
new Lifecycle(), mBluetoothA2dpConfigStore));
|
||||
mListValues = mController.getListValues();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_option2_shouldWriteOption2ToSharedStore() {
|
||||
when(mPreference.findIndexOfValue(mListValues[2])).thenReturn(2);
|
||||
mController.writeConfigurationValues(mListValues[2]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setBitsPerSample(BluetoothCodecConfig.BITS_PER_SAMPLE_24);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_default_shouldSetDefault() {
|
||||
when(mPreference.findIndexOfValue(mListValues[0])).thenReturn(0);
|
||||
mController.writeConfigurationValues(mListValues[0]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setBitsPerSample(
|
||||
BluetoothCodecConfig.BITS_PER_SAMPLE_NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_option2_shouldReturnSecondIndex() {
|
||||
when(mBluetoothCodecConfig.getBitsPerSample()).thenReturn(
|
||||
BluetoothCodecConfig.BITS_PER_SAMPLE_24);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_unknownOption_shouldReturnDefault() {
|
||||
when(mBluetoothCodecConfig.getCodecType()).thenReturn(1381391835);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothAudioChannelModePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private BluetoothCodecConfig mBluetoothCodecConfig;
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||
|
||||
/**
|
||||
* 0: Use System Selection (Default)
|
||||
* 1: Mono
|
||||
* 2: Stereo
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private Context mContext;
|
||||
private BluetoothAudioChannelModePreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new BluetoothAudioChannelModePreferenceController(mContext,
|
||||
new Lifecycle(), mBluetoothA2dpConfigStore));
|
||||
mListValues = mController.getListValues();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_option2_shouldWriteOption2ToSharedStore() {
|
||||
when(mPreference.findIndexOfValue(mListValues[2])).thenReturn(2);
|
||||
mController.writeConfigurationValues(mListValues[2]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setChannelMode(BluetoothCodecConfig.CHANNEL_MODE_STEREO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_default_shouldSetDefault() {
|
||||
when(mPreference.findIndexOfValue(mListValues[0])).thenReturn(0);
|
||||
mController.writeConfigurationValues(mListValues[0]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setChannelMode(
|
||||
BluetoothCodecConfig.CHANNEL_MODE_NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_option2_shouldReturnSecondIndex() {
|
||||
when(mBluetoothCodecConfig.getChannelMode()).thenReturn(
|
||||
BluetoothCodecConfig.CHANNEL_MODE_STEREO);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_unknownOption_shouldReturnDefault() {
|
||||
when(mBluetoothCodecConfig.getCodecType()).thenReturn(1381391835);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothAudioCodecPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private BluetoothCodecConfig mBluetoothCodecConfig;
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||
|
||||
/**
|
||||
* 0: Use System Selection (Default)
|
||||
* 1: SBC
|
||||
* 2: AAC
|
||||
* 3: Qualcomm aptX audio
|
||||
* 4: Qualcomm aptX HD audio
|
||||
* 5: LDAC
|
||||
* 6: Enable Optional Codecs
|
||||
* 7: Disable Optional Codecs
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private Context mContext;
|
||||
private BluetoothAudioCodecPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new BluetoothAudioCodecPreferenceController(mContext, new Lifecycle(),
|
||||
mBluetoothA2dpConfigStore));
|
||||
mListValues = mController.getListValues();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_option2_shouldWriteOption2ToSharedStore() {
|
||||
when(mPreference.findIndexOfValue(mListValues[2])).thenReturn(2);
|
||||
mController.writeConfigurationValues(mListValues[2]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC);
|
||||
verify(mBluetoothA2dpConfigStore).setCodecPriority(
|
||||
BluetoothCodecConfig.CODEC_PRIORITY_HIGHEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_default_shouldSetDefaultPriority() {
|
||||
when(mPreference.findIndexOfValue(mListValues[0])).thenReturn(0);
|
||||
mController.writeConfigurationValues(mListValues[0]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setCodecPriority(
|
||||
BluetoothCodecConfig.CODEC_PRIORITY_DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_option2_shouldReturnSecondIndex() {
|
||||
when(mBluetoothCodecConfig.getCodecType()).thenReturn(
|
||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_unknownOption_shouldReturnDefault() {
|
||||
when(mBluetoothCodecConfig.getCodecType()).thenReturn(1381391835);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothCodecConfig;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class BluetoothAudioQualityPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private BluetoothCodecConfig mBluetoothCodecConfig;
|
||||
@Mock
|
||||
private ListPreference mPreference;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||
|
||||
/**
|
||||
* 0: Optimized for Audio Quality (990kbps/909kbps)
|
||||
* 1: Balanced Audio And Connection Quality (660kbps/606kbps)
|
||||
* 2: Stereo
|
||||
*/
|
||||
private String[] mListValues;
|
||||
private Context mContext;
|
||||
private BluetoothAudioQualityPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new BluetoothAudioQualityPreferenceController(mContext,
|
||||
new Lifecycle(), mBluetoothA2dpConfigStore));
|
||||
mListValues = mController.getListValues();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_option3_shouldWrite1003ToSharedStore() {
|
||||
when(mPreference.findIndexOfValue(mListValues[3])).thenReturn(3);
|
||||
mController.writeConfigurationValues(mListValues[3]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setCodecSpecific1Value(1003);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeConfigurationValues_default_shouldSetDefault() {
|
||||
when(mPreference.findIndexOfValue(mListValues[0])).thenReturn(0);
|
||||
mController.writeConfigurationValues(mListValues[0]);
|
||||
|
||||
verify(mBluetoothA2dpConfigStore).setCodecSpecific1Value(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_option2_shouldReturnSecondIndex() {
|
||||
when(mBluetoothCodecConfig.getCodecSpecific1()).thenReturn(Long.valueOf(2));
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getCurrentA2dpSettingIndex_unknownOption_shouldReturnDefault() {
|
||||
when(mBluetoothCodecConfig.getCodecType()).thenReturn(1381391835);
|
||||
|
||||
final int index = mController.getCurrentA2dpSettingIndex(mBluetoothCodecConfig);
|
||||
|
||||
assertThat(index).isEqualTo(3);
|
||||
}
|
||||
}
|
@@ -70,7 +70,7 @@ public class BluetoothAudioSampleRatePreferenceControllerTest {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mLifecycle = new Lifecycle();
|
||||
mController = spy(new BluetoothAudioSampleRatePreferenceController(mContext, mLifecycle,
|
||||
new Object(), mBluetoothA2dpConfigStore));
|
||||
mBluetoothA2dpConfigStore));
|
||||
mListValues = mController.getListValues();
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
|
Reference in New Issue
Block a user