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

Commit f5cc663a authored by Chris Antol's avatar Chris Antol Committed by Cherrypicker Worker
Browse files

Fix NPE in AudioSwitchPreferenceController

Test: Unit Test to verify nullness
Bug: 338892614
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:7ac80f0a0a69e99ec3603e9157cd5a2b20509e85)
Merged-In: Ic97d1a6269a6d98ffd15a9b512f6ae24ff1c5b5e
Change-Id: Ic97d1a6269a6d98ffd15a9b512f6ae24ff1c5b5e
parent b9a0722d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -242,6 +242,10 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
            return connectedDevices;
        }
        final List<BluetoothDevice> devices = leAudioProfile.getConnectedDevices();
        if (devices == null) {
          Log.d(TAG, "No connected LeAudioProfile devices");
          return connectedDevices;
        }
        for (BluetoothDevice device : devices) {
            if (device.isConnected() && isDeviceInCachedList(device)) {
                connectedDevices.add(device);
+9 −0
Original line number Diff line number Diff line
@@ -516,6 +516,15 @@ public class AudioOutputSwitchPreferenceControllerTest {
        assertThat(mEmptyDevices).containsExactly(connectedBtLeAduioDevice1);
    }

    @Test
    public void getConnectedLeAudioDevices_nullConnectedDevices_returnEmptyList() {
      when(mLeAudioProfile.getConnectedDevices()).thenReturn(null);

      List<BluetoothDevice> connectedDevices = mController.getConnectedLeAudioDevices();

      assertThat(connectedDevices.isEmpty()).isTrue();
    }

    @Test
    public void findActiveLeAudioDevice_noActiveDevice_returnNull() {
        mLeAudioActiveDevices.clear();