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

Commit 6657bd97 authored by Henri Chataing's avatar Henri Chataing
Browse files

Generate CONNECTION_STATE_CHANGED intent when A2dpService is stopped

Generate the intent as if connections were disconnected
locally or remotely.

Bug: 360034472
Bug: 277573958
Bug: 277846618
Test: atest BluetoothInstrumentationTests
Flag: com.android.bluetooth.a2dp_broadcast_connection_state_when_turned_off
Change-Id: I40b09e72e879fc702fb06028fa765c0db6af663a
parent 1835706c
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
@@ -125,9 +126,16 @@ final class A2dpStateMachine extends StateMachine {

    public void doQuit() {
        log("doQuit for device " + mDevice);
        if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()
                && mConnectionState != BluetoothProfile.STATE_DISCONNECTED
                && mLastConnectionState != -1) {
            // Broadcast CONNECTION_STATE_CHANGED when A2dpService is turned off while
            // the device is connected
            broadcastConnectionState(BluetoothProfile.STATE_DISCONNECTED, mConnectionState);
        }
        if (mIsPlaying) {
            // Stop if auido is still playing
            log("doQuit: stopped playing " + mDevice);
            // Broadcast AUDIO_STATE_CHANGED when A2dpService is turned off while
            // the device is playing
            mIsPlaying = false;
            broadcastAudioState(BluetoothA2dp.STATE_NOT_PLAYING, BluetoothA2dp.STATE_PLAYING);
        }
+12 −1
Original line number Diff line number Diff line
@@ -104,7 +104,9 @@ public class A2dpServiceTest {

    @Parameters(name = "{0}")
    public static List<FlagsParameterization> getParams() {
        return FlagsParameterization.allCombinationsOf(Flags.FLAG_A2DP_SERVICE_LOOPER);
        return FlagsParameterization.allCombinationsOf(
                Flags.FLAG_A2DP_SERVICE_LOOPER,
                Flags.FLAG_A2DP_BROADCAST_CONNECTION_STATE_WHEN_TURNED_OFF);
    }

    public A2dpServiceTest(FlagsParameterization flags) {
@@ -198,6 +200,15 @@ public class A2dpServiceTest {
        mA2dpService.stop();
        dispatchAtLeastOneMessage();

        if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) {
            // Verify that the intent CONNECTION_STATE_CHANGED is generated
            // for the existing connections.
            verifyConnectionStateIntent(
                    sTestDevice,
                    BluetoothProfile.STATE_DISCONNECTED,
                    BluetoothProfile.STATE_CONNECTED);
        }

        // Verify that setActiveDevice(null) was called during shutdown
        verify(mMockNativeInterface).setActiveDevice(null);
        mA2dpService.start();