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

Commit 531382fe authored by hughchen's avatar hughchen
Browse files

Use removeActiveDevice() when set phone as active device

- Use removeActiveDevice() to set phone as active device instead of use
  setActiveDevice().
- Add test case

Bug: 150111193
Test: manually
Change-Id: Icfe6a50ba3fc807daf3445cfdd852787dc26e3c1
parent 227ae85d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -164,7 +164,9 @@ public class A2dpProfile implements LocalBluetoothProfile {
        if (mBluetoothAdapter == null) {
            return false;
        }
        return mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_AUDIO);
        return device == null
                ? mBluetoothAdapter.removeActiveDevice(ACTIVE_DEVICE_AUDIO)
                : mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_AUDIO);
    }

    public BluetoothDevice getActiveDevice() {
+4 −1
Original line number Diff line number Diff line
@@ -125,7 +125,10 @@ public class HeadsetProfile implements LocalBluetoothProfile {
        if (mBluetoothAdapter == null) {
            return false;
        }
        return mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_PHONE_CALL);

        return device == null
                ? mBluetoothAdapter.removeActiveDevice(ACTIVE_DEVICE_PHONE_CALL)
                : mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_PHONE_CALL);
    }

    public BluetoothDevice getActiveDevice() {
+3 −1
Original line number Diff line number Diff line
@@ -162,7 +162,9 @@ public class HearingAidProfile implements LocalBluetoothProfile {
        if (mBluetoothAdapter == null) {
            return false;
        }
        return mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_ALL);
        return device == null
                ? mBluetoothAdapter.removeActiveDevice(ACTIVE_DEVICE_ALL)
                : mBluetoothAdapter.setActiveDevice(device, ACTIVE_DEVICE_ALL);
    }

    public List<BluetoothDevice> getActiveDevices() {
+6 −0
Original line number Diff line number Diff line
@@ -203,4 +203,10 @@ public class A2dpProfileTest {
        assertThat(mProfile.getHighQualityAudioOptionLabel(mDevice)).isEqualTo(
                String.format(KNOWN_CODEC_LABEL, config.getCodecName()));
    }

    @Test
    public void setActiveDevice_returnTrue() {
        assertThat(mProfile.setActiveDevice(null)).isTrue();
        assertThat(mProfile.setActiveDevice(mDevice)).isTrue();
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -75,4 +75,10 @@ public class HeadsetProfileTest {
        assertThat(mProfile.getAudioState(mBluetoothDevice)).
                isEqualTo(BluetoothHeadset.STATE_AUDIO_CONNECTED);
    }

    @Test
    public void setActiveDevice_returnTrue() {
        assertThat(mProfile.setActiveDevice(null)).isTrue();
        assertThat(mProfile.setActiveDevice(mBluetoothDevice)).isTrue();
    }
}
Loading