Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26d39236 authored by tim peng's avatar tim peng Committed by Android (Google) Code Review
Browse files

Merge "Unable to set Bluetooth configuration at the first time"

parents 846f7394 9a8ec96e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ public class BluetoothA2dpConfigStore {
        mChannelMode = channelMode;
    }

    public void setCodecSpecific1Value(int codecSpecific1Value) {
    public void setCodecSpecific1Value(long codecSpecific1Value) {
        mCodecSpecific1Value = codecSpecific1Value;
    }

+23 −1
Original line number Diff line number Diff line
@@ -53,9 +53,12 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
    protected static final int[] CHANNEL_MODES = {BluetoothCodecConfig.CHANNEL_MODE_STEREO,
            BluetoothCodecConfig.CHANNEL_MODE_MONO};

    protected final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;

    public AbstractBluetoothDialogPreferenceController(Context context, Lifecycle lifecycle,
                                                       BluetoothA2dpConfigStore store) {
        super(context, lifecycle, store);
        mBluetoothA2dpConfigStore = store;
    }

    @Override
@@ -92,6 +95,25 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
        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}.
     *
@@ -174,7 +196,7 @@ public abstract class AbstractBluetoothDialogPreferenceController extends
     *
     * @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) {
        if (configs == null) {
+0 −2
Original line number Diff line number Diff line
@@ -33,13 +33,11 @@ public abstract class AbstractBluetoothPreferenceController extends
        DeveloperOptionsPreferenceController implements BluetoothServiceConnectionListener,
        LifecycleObserver, OnDestroy {

    protected final BluetoothA2dpConfigStore mBluetoothA2dpConfigStore;
    protected volatile BluetoothA2dp mBluetoothA2dp;

    public AbstractBluetoothPreferenceController(Context context, Lifecycle lifecycle,
                                                 BluetoothA2dpConfigStore store) {
        super(context);
        mBluetoothA2dpConfigStore = store;
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ public class BluetoothQualityDialogPreferenceController extends

    @Override
    protected void writeConfigurationValues(final int index) {
        int codecSpecific1Value = 0; // default
        long codecSpecific1Value = 0; // default
        switch (index) {
            case 0:
            case 1:
+21 −4
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ public class AbstractBluetoothDialogPreferenceControllerTest {

    @Test
    public void onIndexUpdated_checkFlow() {
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
        when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
        when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mCodecConfigAAC);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mController.onIndexUpdated(mCurrentConfig);
@@ -138,27 +140,27 @@ public class AbstractBluetoothDialogPreferenceControllerTest {

    @Test
    public void getCurrentCodecConfig_verifyConfig() {
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, null);
        when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        assertThat(mController.getCurrentCodecConfig()).isEqualTo(mCodecConfigAAC);
    }

    @Test
    public void getSelectableConfigs_verifyConfig() {
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        assertThat(mController.getSelectableConfigs(null)).isEqualTo(mCodecConfigs);
    }

    @Test
    public void getSelectableByCodecType_verifyConfig() {
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        assertThat(mController.getSelectableByCodecType(BluetoothCodecConfig.SOURCE_CODEC_TYPE_AAC))
                .isEqualTo(mCodecConfigAAC);
@@ -166,14 +168,29 @@ public class AbstractBluetoothDialogPreferenceControllerTest {

    @Test
    public void getSelectableByCodecType_unavailable() {
        mController.onBluetoothServiceConnected(mBluetoothA2dp);
        mCodecStatus = new BluetoothCodecStatus(mCodecConfigAAC, null, mCodecConfigs);
        when(mBluetoothA2dp.getCodecStatus(null)).thenReturn(mCodecStatus);
        mController.onBluetoothServiceConnected(mBluetoothA2dp);

        assertThat(mController.getSelectableByCodecType(
                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
            AbstractBluetoothDialogPreferenceController {