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

Commit 304cb88e authored by Poompatai Puntitpong's avatar Poompatai Puntitpong Committed by Automerger Merge Worker
Browse files

Merge "Align call-related broadcasts of LE Audio and Hearing Aid with Headset...

Merge "Align call-related broadcasts of LE Audio and Hearing Aid with Headset for multi-user scenarios" into main am: cdf04e40

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/3235653



Change-Id: I339e3518348d5f393d31936615e7a401ecc9f72a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a7e815ca cdf04e40
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.UserHandle;
import android.sysprop.BluetoothProperties;
import android.util.Log;

@@ -662,7 +663,7 @@ public class HearingAidService extends ProfileService {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent, BLUETOOTH_CONNECT);
        sendBroadcastAsUser(intent, UserHandle.ALL, BLUETOOTH_CONNECT);
    }

    /* Notifications of audio device disconnection events. */
+6 −2
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.Looper;
import android.os.Message;
import android.os.UserHandle;
import android.util.Log;

import com.android.bluetooth.Utils;
@@ -556,8 +557,11 @@ final class HearingAidStateMachine extends StateMachine {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        mService.sendBroadcast(
                intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
        mService.sendBroadcastAsUser(
                intent,
                UserHandle.ALL,
                BLUETOOTH_CONNECT,
                Utils.getTempBroadcastOptions().toBundle());
    }

    private static String messageWhatToString(int what) {
+8 −3
Original line number Diff line number Diff line
@@ -1831,7 +1831,11 @@ public class LeAudioService extends ProfileService {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcast(intent, BLUETOOTH_CONNECT, Utils.getTempBroadcastOptions().toBundle());
        sendBroadcastAsUser(
                intent,
                UserHandle.ALL,
                BLUETOOTH_CONNECT,
                Utils.getTempBroadcastOptions().toBundle());
    }

    void sentActiveDeviceChangeIntent(BluetoothDevice device) {
@@ -1840,7 +1844,8 @@ public class LeAudioService extends ProfileService {
        intent.addFlags(
                Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
                        | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
        sendBroadcastWithMultiplePermissions(
        createContextAsUser(UserHandle.ALL, /* flags= */ 0)
                .sendBroadcastWithMultiplePermissions(
                        intent, new String[] {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED});
    }

+8 −2
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.media.AudioManager;
import android.media.BluetoothProfileConnectionInfo;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.UserHandle;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.filters.MediumTest;
@@ -166,7 +167,11 @@ public class HearingAidServiceTest {
    @SafeVarargs
    private void verifyIntentSent(Matcher<Intent>... matchers) {
        mInOrder.verify(mContext, timeout(TIMEOUT.toMillis() * 2))
                .sendBroadcast(MockitoHamcrest.argThat(AllOf.allOf(matchers)), any(), any());
                .sendBroadcastAsUser(
                        MockitoHamcrest.argThat(AllOf.allOf(matchers)),
                        eq(UserHandle.ALL),
                        any(),
                        any());
    }

    private void verifyConnectionStateIntent(BluetoothDevice device, int newState, int prevState) {
@@ -1253,9 +1258,10 @@ public class HearingAidServiceTest {
        mService.messageFromNative(stackEvent);
        // Verify the connection state broadcast
        mInOrder.verify(mContext, times(0))
                .sendBroadcast(
                .sendBroadcastAsUser(
                        MockitoHamcrest.argThat(
                                hasAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED)),
                        eq(UserHandle.ALL),
                        any(),
                        any());
    }
+33 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;
import android.os.UserHandle;

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;
@@ -118,7 +119,8 @@ public class HearingAidStateMachineTest {

        // Verify that no connection state broadcast is executed
        verify(mHearingAidService, after(TIMEOUT_MS).never())
                .sendBroadcast(any(Intent.class), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        any(Intent.class), eq(UserHandle.ALL), anyString(), any(Bundle.class));
        // Check that we are in Disconnected state
        Assert.assertThat(
                mHearingAidStateMachine.getCurrentState(),
@@ -140,7 +142,11 @@ public class HearingAidStateMachineTest {
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument1 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(TIMEOUT_MS).times(1))
                .sendBroadcast(intentArgument1.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument1.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        Assert.assertEquals(
                BluetoothProfile.STATE_CONNECTING,
                intentArgument1.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
@@ -161,7 +167,11 @@ public class HearingAidStateMachineTest {
        // - two calls to broadcastConnectionState(): Disconnected -> Conecting -> Connected
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(TIMEOUT_MS).times(2))
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument2.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        // Check that we are in Connected state
        Assert.assertThat(
                mHearingAidStateMachine.getCurrentState(),
@@ -186,7 +196,11 @@ public class HearingAidStateMachineTest {
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument1 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(TIMEOUT_MS).times(1))
                .sendBroadcast(intentArgument1.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument1.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        Assert.assertEquals(
                BluetoothProfile.STATE_CONNECTING,
                intentArgument1.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
@@ -199,7 +213,11 @@ public class HearingAidStateMachineTest {
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(HearingAidStateMachine.sConnectTimeoutMs * 2L).times(2))
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument2.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        Assert.assertEquals(
                BluetoothProfile.STATE_DISCONNECTED,
                intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
@@ -233,7 +251,11 @@ public class HearingAidStateMachineTest {
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument1 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(TIMEOUT_MS).times(1))
                .sendBroadcast(intentArgument1.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument1.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        Assert.assertEquals(
                BluetoothProfile.STATE_CONNECTING,
                intentArgument1.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1));
@@ -246,7 +268,11 @@ public class HearingAidStateMachineTest {
        // Verify that one connection state broadcast is executed
        ArgumentCaptor<Intent> intentArgument2 = ArgumentCaptor.forClass(Intent.class);
        verify(mHearingAidService, timeout(HearingAidStateMachine.sConnectTimeoutMs * 2L).times(2))
                .sendBroadcast(intentArgument2.capture(), anyString(), any(Bundle.class));
                .sendBroadcastAsUser(
                        intentArgument2.capture(),
                        eq(UserHandle.ALL),
                        anyString(),
                        any(Bundle.class));
        Assert.assertEquals(
                BluetoothProfile.STATE_DISCONNECTED,
                intentArgument2.getValue().getIntExtra(BluetoothProfile.EXTRA_STATE, -1));