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

Commit dbe62b94 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 11778614 from b1de336f to 24Q3-release

Change-Id: Ia2470fb51e95e2b5e763f6607cd549b59e569b7c
parents 376dad83 b1de336f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41,5 +41,6 @@ aconfig_declarations {
        "telecom_connection_service_wrapper_flags.aconfig",
        "telecom_remote_connection_service.aconfig",
        "telecom_profile_user_flags.aconfig",
        "telecom_bluetoothdevicemanager_flags.aconfig",
    ],
}
+10 −0
Original line number Diff line number Diff line
package: "com.android.server.telecom.flags"
container: "system"

# OWNER=tgunn TARGET=24Q4
flag {
  name: "postpone_register_to_leaudio"
  namespace: "telecom"
  description: "Fix for Log.wtf in the BinderProxy"
  bug: "333417369"
}
+30 −8
Original line number Diff line number Diff line
@@ -116,15 +116,14 @@ public class BluetoothDeviceManager {
                                        + mBluetoothHearingAid;
                            } else if (profile == BluetoothProfile.LE_AUDIO) {
                                mBluetoothLeAudioService = (BluetoothLeAudio) proxy;
                                logString = "Got BluetoothLeAudio: "
                                        + mBluetoothLeAudioService;
                                logString = ("Got BluetoothLeAudio: " + mBluetoothLeAudioService )
                                        + (", mLeAudioCallbackRegistered: "
                                        + mLeAudioCallbackRegistered);
                                if (!mLeAudioCallbackRegistered) {
                                    try {
                                        mBluetoothLeAudioService.registerCallback(
                                                    mExecutor, mLeAudioCallbacks);
                                        mLeAudioCallbackRegistered = true;
                                    } catch (IllegalStateException e) {
                                        logString += ", but Bluetooth is down";
                                    if (mFeatureFlags.postponeRegisterToLeaudio()) {
                                        mExecutor.execute(this::registerToLeAudio);
                                    } else {
                                        registerToLeAudio();
                                    }
                                }
                            } else {
@@ -139,6 +138,29 @@ public class BluetoothDeviceManager {
                    }
                }

                private void registerToLeAudio() {
                    synchronized (mLock) {
                        String logString = "Register to leAudio";

                        if (mLeAudioCallbackRegistered) {
                            logString +=  ", but already registered";
                            Log.i(BluetoothDeviceManager.this, logString);
                            mLocalLog.log(logString);
                            return;
                        }
                        try {
                            mLeAudioCallbackRegistered = true;
                            mBluetoothLeAudioService.registerCallback(
                                            mExecutor, mLeAudioCallbacks);
                        } catch (IllegalStateException e) {
                            mLeAudioCallbackRegistered = false;
                            logString += ", but failed: " + e;
                        }
                        Log.i(BluetoothDeviceManager.this, logString);
                        mLocalLog.log(logString);
                    }
                }

                @Override
                public void onServiceDisconnected(int profile) {
                    Log.startSession("BPSL.oSD");
+29 −0
Original line number Diff line number Diff line
@@ -60,9 +60,11 @@ import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import static org.mockito.Mockito.reset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;

@RunWith(JUnit4.class)
public class BluetoothDeviceManagerTest extends TelecomTestCase {
@@ -75,6 +77,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
    @Mock BluetoothLeAudio mBluetoothLeAudio;
    @Mock AudioManager mockAudioManager;
    @Mock AudioDeviceInfo mSpeakerInfo;
    @Mock Executor mExecutor;

    BluetoothDeviceManager mBluetoothDeviceManager;
    BluetoothProfile.ServiceListener serviceListenerUnderTest;
@@ -114,6 +117,7 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        mCommunicationDeviceTracker.setBluetoothRouteManager(mRouteManager);

        mockAudioManager = mContext.getSystemService(AudioManager.class);
        mExecutor = mContext.getMainExecutor();

        ArgumentCaptor<BluetoothProfile.ServiceListener> serviceCaptor =
                ArgumentCaptor.forClass(BluetoothProfile.ServiceListener.class);
@@ -750,6 +754,31 @@ public class BluetoothDeviceManagerTest extends TelecomTestCase {
        assertTrue(mBluetoothDeviceManager.isInbandRingingEnabled());
    }

    @SmallTest
    @Test
    public void testRegisterLeAudioCallbackNoPostpone() {
        reset(mBluetoothLeAudio);
        when(mFeatureFlags.postponeRegisterToLeaudio()).thenReturn(false);
        serviceListenerUnderTest.onServiceConnected(BluetoothProfile.LE_AUDIO,
                        (BluetoothProfile) mBluetoothLeAudio);
        // Second time on purpose
        serviceListenerUnderTest.onServiceConnected(BluetoothProfile.LE_AUDIO,
                        (BluetoothProfile) mBluetoothLeAudio);
        verify(mExecutor, times(0)).execute(any());
        verify(mBluetoothLeAudio, times(1)).registerCallback(any(Executor.class),
                        any(BluetoothLeAudio.Callback.class));
    }

    @SmallTest
    @Test
    public void testRegisterLeAudioCallbackWithPostpone() {
        reset(mBluetoothLeAudio);
        when(mFeatureFlags.postponeRegisterToLeaudio()).thenReturn(true);
        serviceListenerUnderTest.onServiceConnected(BluetoothProfile.LE_AUDIO,
                        (BluetoothProfile) mBluetoothLeAudio);
        verify(mExecutor, times(1)).execute(any());
    }

    private void assertClearHearingAidOrLeCommunicationDevice(
            boolean flagEnabled, int device_type
    ) {