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

Commit 69c7e2ec authored by Sal Savage's avatar Sal Savage
Browse files

Drop codec configuration changes for disconnected devices

Currently, if a device associated with a config changed event isn't
null, we look for it in the state machine map. If the device is
disconnected, the state machine has been cleaned up and returns a null
instead. We use the null state machine, which gives us an NPE.

For now, we can drop the configuration changed event for the null
device so we can avoid a crash that would have otherwise logically
dropped the event anyways.

Tag: #stability
Bug: 324073867
Flag: EXEMPT, null check to avoid a crash + test coverage
Test: atest A2dpSinkServiceTest#testOnAudioConfigChanged_withUnknownDevice_eventDropped
Change-Id: I8531ae5697404a214254be13109d9ec290903fbb
parent a0541c03
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -636,6 +636,13 @@ public class A2dpSinkService extends ProfileService {
            return;
        }
        A2dpSinkStateMachine stateMachine = getStateMachineForDevice(device);
        if (stateMachine == null) {
            Log.w(
                    TAG,
                    "Received audio config changed event for an unconnected device, device="
                            + device);
            return;
        }
        stateMachine.onStackEvent(event);
    }

+20 −0
Original line number Diff line number Diff line
@@ -295,6 +295,26 @@ public class A2dpSinkServiceTest {
        assertThat(config).isEqualTo(expected);
    }

    /** Make sure we ignore audio configuration changes for disconnected/unknown devices */
    @Test
    public void testOnAudioConfigChanged_withNullDevice_eventDropped() {
        StackEvent audioConfigChanged =
                StackEvent.audioConfigChanged(null, TEST_SAMPLE_RATE, TEST_CHANNEL_COUNT);
        mService.messageFromNative(audioConfigChanged);
        assertThat(mService.getAudioConfig(null)).isNull();
    }

    /** Make sure we ignore audio configuration changes for disconnected/unknown devices */
    @Test
    public void testOnAudioConfigChanged_withUnknownDevice_eventDropped() {
        assertThat(mService.getConnectionState(mDevice1))
                .isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
        StackEvent audioConfigChanged =
                StackEvent.audioConfigChanged(mDevice1, TEST_SAMPLE_RATE, TEST_CHANNEL_COUNT);
        mService.messageFromNative(audioConfigChanged);
        assertThat(mService.getAudioConfig(mDevice1)).isNull();
    }

    /**
     * Getting an audio config for a device that hasn't received one yet should return null
     */