Loading flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", ], } flags/telecom_bluetoothdevicemanager_flags.aconfig 0 → 100644 +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" } src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +30 −8 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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"); Loading tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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 ) { Loading Loading
flags/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -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", ], }
flags/telecom_bluetoothdevicemanager_flags.aconfig 0 → 100644 +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" }
src/com/android/server/telecom/bluetooth/BluetoothDeviceManager.java +30 −8 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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"); Loading
tests/src/com/android/server/telecom/tests/BluetoothDeviceManagerTest.java +29 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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; Loading Loading @@ -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); Loading Loading @@ -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 ) { Loading