Unable to set Bluetooth configuration at the first time
- initial configuration value - add test case Bug: 147634692 Test: make -j50 RunSettingsRoboTests Change-Id: If55036d358d664bcbcb816a38f18019c62976d38
This commit is contained in:
@@ -54,7 +54,7 @@ public class BluetoothA2dpConfigStore {
|
|||||||
mChannelMode = channelMode;
|
mChannelMode = channelMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCodecSpecific1Value(int codecSpecific1Value) {
|
public void setCodecSpecific1Value(long codecSpecific1Value) {
|
||||||
mCodecSpecific1Value = codecSpecific1Value;
|
mCodecSpecific1Value = codecSpecific1Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,9 +53,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
|
|||||||
protected static final int[] CHANNEL_MODES = {BluetoothCodecConfig.CHANNEL_MODE_STEREO,
|
protected static final int[] CHANNEL_MODES = {BluetoothCodecConfig.CHANNEL_MODE_STEREO,
|
||||||
BluetoothCodecConfig.CHANNEL_MODE_MONO};
|
BluetoothCodecConfig.CHANNEL_MODE_MONO};
|
||||||
|
|
||||||
|
protected final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
||||||
|
|
||||||
public AbstractBluetoothDialogPreferenceController(Context context, Lifecycle lifecycle,
|
public AbstractBluetoothDialogPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
BluetoothA2dpConfigStore store) {
|
BluetoothA2dpConfigStore store) {
|
||||||
super(context, lifecycle, store);
|
super(context, lifecycle, store);
|
||||||
|
mBluetoothA2dpConfigStore = store;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,6 +95,25 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
|
|||||||
return getCurrentIndexByConfig(codecConfig);
|
return getCurrentIndexByConfig(codecConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBluetoothServiceConnected(BluetoothA2dp bluetoothA2dp) {
|
||||||
|
super.onBluetoothServiceConnected(bluetoothA2dp);
|
||||||
|
initConfigStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initConfigStore() {
|
||||||
|
final BluetoothCodecConfig config = getCurrentCodecConfig();
|
||||||
|
if (config == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mBluetoothA2dpConfigStore.setCodecType(config.getCodecType());
|
||||||
|
mBluetoothA2dpConfigStore.setSampleRate(config.getSampleRate());
|
||||||
|
mBluetoothA2dpConfigStore.setBitsPerSample(config.getBitsPerSample());
|
||||||
|
mBluetoothA2dpConfigStore.setChannelMode(config.getChannelMode());
|
||||||
|
mBluetoothA2dpConfigStore.setCodecPriority(config.getCodecPriority());
|
||||||
|
mBluetoothA2dpConfigStore.setCodecSpecific1Value(config.getCodecSpecific1());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the new value to the {@link BluetoothA2dpConfigStore}.
|
* Updates the new value to the {@link BluetoothA2dpConfigStore}.
|
||||||
*
|
*
|
||||||
@@ -174,7 +196,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
|
|||||||
*
|
*
|
||||||
* @param enabled Is {@code true} when the setting is enabled.
|
* @param enabled Is {@code true} when the setting is enabled.
|
||||||
*/
|
*/
|
||||||
public void onHDAudioEnabled(boolean enabled) {};
|
public void onHDAudioEnabled(boolean enabled) {}
|
||||||
|
|
||||||
static int getHighestCodec(BluetoothCodecConfig[] configs) {
|
static int getHighestCodec(BluetoothCodecConfig[] configs) {
|
||||||
if (configs == null) {
|
if (configs == null) {
|
||||||
|
@@ -33,13 +33,11 @@ public abstract class AbstractBluetoothPreferenceController extends
|
|||||||
DeveloperOptionsPreferenceController implements BluetoothServiceConnectionListener,
|
DeveloperOptionsPreferenceController implements BluetoothServiceConnectionListener,
|
||||||
LifecycleObserver, OnDestroy {
|
LifecycleObserver, OnDestroy {
|
||||||
|
|
||||||
protected final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
|
|
||||||
protected volatile BluetoothA2dp mBluetoothA2dp;
|
protected volatile BluetoothA2dp mBluetoothA2dp;
|
||||||
|
|
||||||
public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle,
|
public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
BluetoothA2dpConfigStore store) {
|
BluetoothA2dpConfigStore store) {
|
||||||
super(context);
|
super(context);
|
||||||
mBluetoothA2dpConfigStore = store;
|
|
||||||
if (lifecycle != null) {
|
if (lifecycle != null) {
|
||||||
lifecycle.addObserver(this);
|
lifecycle.addObserver(this);
|
||||||
}
|
}
|
||||||
|
@@ -57,7 +57,7 @@ public class BluetoothQualityDialogPreferenceController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeConfigurationValues(final int index) {
|
protected void writeConfigurationValues(final int index) {
|
||||||
int codecSpecific1Value = 0; // default
|
long codecSpecific1Value = 0; // default
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0:
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
|
@@ -102,6 +102,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onIndexUpdated_checkFlow() {
|
public void onIndexUpdated_checkFlow() {
|
||||||
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
|
||||||
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
|
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
mController.onIndexUpdated(mCurrentConfig);
|
mController.onIndexUpdated(mCurrentConfig);
|
||||||
@@ -138,27 +140,27 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCurrentCodecConfig_verifyConfig() {
|
public void getCurrentCodecConfig_verifyConfig() {
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
|
||||||
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC);
|
assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSelectableConfigs_verifyConfig() {
|
public void getSelectableConfigs_verifyConfig() {
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
||||||
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
|
assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSelectableByCodecType_verifyConfig() {
|
public void getSelectableByCodecType_verifyConfig() {
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
||||||
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC))
|
assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC))
|
||||||
.isEqualTo(mCodecConfigAAC);
|
.isEqualTo(mCodecConfigAAC);
|
||||||
@@ -166,14 +168,29 @@ public class AbstractBluetoothDialogPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSelectableByCodecType_unavailable() {
|
public void getSelectableByCodecType_unavailable() {
|
||||||
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
|
||||||
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
||||||
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
assertThat(mController.getSelectableByCodecType(
|
assertThat(mController.getSelectableByCodecType(
|
||||||
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX)).isNull();
|
BluetoothCodecConfig.SOURCE_CODEC_TYPE_APTX)).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onBluetoothServiceConnected_verifyBluetoothA2dpConfigStore() {
|
||||||
|
mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
|
||||||
|
when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
|
||||||
|
mController.onBluetoothServiceConnected(mBluetoothA2dp);
|
||||||
|
|
||||||
|
verify(mBluetoothA2dpConfigStore).setCodecType(mCodecConfigAAC.getCodecType());
|
||||||
|
verify(mBluetoothA2dpConfigStore).setSampleRate(mCodecConfigAAC.getSampleRate());
|
||||||
|
verify(mBluetoothA2dpConfigStore).setBitsPerSample(mCodecConfigAAC.getBitsPerSample());
|
||||||
|
verify(mBluetoothA2dpConfigStore).setChannelMode(mCodecConfigAAC.getChannelMode());
|
||||||
|
verify(mBluetoothA2dpConfigStore).setCodecPriority(mCodecConfigAAC.getCodecPriority());
|
||||||
|
verify(mBluetoothA2dpConfigStore).setCodecSpecific1Value(
|
||||||
|
mCodecConfigAAC.getCodecSpecific1());
|
||||||
|
}
|
||||||
|
|
||||||
private static class AbstractBluetoothDialogPreferenceControllerImpl extends
|
private static class AbstractBluetoothDialogPreferenceControllerImpl extends
|
||||||
AbstractBluetoothDialogPreferenceController {
|
AbstractBluetoothDialogPreferenceController {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user