Loading src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +4 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.utils.ThreadUtils; /** Controller to maintain available media Bluetooth devices */ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater Loading Loading @@ -135,7 +136,9 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater @Override public boolean onPreferenceClick(Preference preference) { mMetricsFeatureProvider.logClickedPreference(preference, mMetricsCategory); mDevicePreferenceCallback.onDeviceClick(preference); var unused = ThreadUtils.postOnBackgroundThread( () -> mDevicePreferenceCallback.onDeviceClick(preference)); return true; } Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +3 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.utils.ThreadUtils; import java.util.Locale; import java.util.concurrent.Executor; Loading Loading @@ -287,7 +288,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro if (AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (!mIntentHandled.get()) { Log.d(TAG, "displayPreference: profile ready, handleDeviceClickFromIntent"); handleDeviceClickFromIntent(); var unused = ThreadUtils.postOnBackgroundThread(() -> handleDeviceClickFromIntent()); mIntentHandled.set(true); } } Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java +19 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.bluetooth.BluetoothLeBroadcast; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.util.Log; import android.util.Pair; Loading Loading @@ -64,6 +65,7 @@ public class AudioSharingDialogHandler { @Nullable private final CachedBluetoothDeviceManager mDeviceManager; @Nullable private final LocalBluetoothLeBroadcast mBroadcast; @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant; @Nullable private final AudioManager mAudioManager; private final MetricsFeatureProvider mMetricsFeatureProvider; private boolean mIsStoppingBroadcast = false; Loading Loading @@ -157,6 +159,7 @@ public class AudioSharingDialogHandler { mLocalBtManager != null ? mLocalBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile() : null; mAudioManager = context.getSystemService(AudioManager.class); mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); } Loading @@ -178,6 +181,22 @@ public class AudioSharingDialogHandler { public void handleDeviceConnected( @NonNull CachedBluetoothDevice cachedDevice, boolean userTriggered) { String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress(); if (mAudioManager != null) { int audioMode = mAudioManager.getMode(); if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { Log.d(TAG, "Skip handleDeviceConnected, audio mode = " + audioMode); // TODO: add metric for this case if (userTriggered) { // If this method is called with user triggered, e.g. manual click on the // "Connected devices" page, we need call setActive for the device, since user // intend to switch active device for the call. cachedDevice.setActive(); } return; } } boolean isBroadcasting = isBroadcasting(); boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); if (!isLeAudioSupported) { Loading tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -113,6 +114,7 @@ public class AudioSharingDialogHandlerTest { @Mock private CachedBluetoothDeviceManager mCacheManager; @Mock private LocalBluetoothLeBroadcast mBroadcast; @Mock private LocalBluetoothLeBroadcastAssistant mAssistant; @Mock private AudioManager mAudioManager; @Mock private CachedBluetoothDevice mCachedDevice1; @Mock private CachedBluetoothDevice mCachedDevice2; @Mock private CachedBluetoothDevice mCachedDevice3; Loading Loading @@ -152,6 +154,8 @@ public class AudioSharingDialogHandlerTest { when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager); when(mLocalBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mLocalBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager); when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mState.getBisSyncState()).thenReturn(bisSyncState); Loading Loading @@ -187,6 +191,18 @@ public class AudioSharingDialogHandlerTest { ShadowBluetoothUtils.reset(); } @Test public void handleUserTriggeredDeviceConnected_inCall_setActive() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL); setUpBroadcast(true); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1); when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredNonLeaDeviceConnected_noSharing_setActive() { setUpBroadcast(false); Loading Loading @@ -403,6 +419,18 @@ public class AudioSharingDialogHandlerTest { verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false); } @Test public void handleDeviceConnected_inCall_doNothing() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL); setUpBroadcast(true); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); verify(mCachedDevice2, never()).setActive(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); } @Test public void handleNonLeaDeviceConnected_noSharing_doNothing() { setUpBroadcast(false); Loading Loading
src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +4 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.settings.connecteddevice.DevicePreferenceCallback; import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.utils.ThreadUtils; /** Controller to maintain available media Bluetooth devices */ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater Loading Loading @@ -135,7 +136,9 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater @Override public boolean onPreferenceClick(Preference preference) { mMetricsFeatureProvider.logClickedPreference(preference, mMetricsCategory); mDevicePreferenceCallback.onDeviceClick(preference); var unused = ThreadUtils.postOnBackgroundThread( () -> mDevicePreferenceCallback.onDeviceClick(preference)); return true; } Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +3 −1 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.utils.ThreadUtils; import java.util.Locale; import java.util.concurrent.Executor; Loading Loading @@ -287,7 +288,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro if (AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { if (!mIntentHandled.get()) { Log.d(TAG, "displayPreference: profile ready, handleDeviceClickFromIntent"); handleDeviceClickFromIntent(); var unused = ThreadUtils.postOnBackgroundThread(() -> handleDeviceClickFromIntent()); mIntentHandled.set(true); } } Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java +19 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.bluetooth.BluetoothLeBroadcast; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.util.Log; import android.util.Pair; Loading Loading @@ -64,6 +65,7 @@ public class AudioSharingDialogHandler { @Nullable private final CachedBluetoothDeviceManager mDeviceManager; @Nullable private final LocalBluetoothLeBroadcast mBroadcast; @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant; @Nullable private final AudioManager mAudioManager; private final MetricsFeatureProvider mMetricsFeatureProvider; private boolean mIsStoppingBroadcast = false; Loading Loading @@ -157,6 +159,7 @@ public class AudioSharingDialogHandler { mLocalBtManager != null ? mLocalBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile() : null; mAudioManager = context.getSystemService(AudioManager.class); mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); } Loading @@ -178,6 +181,22 @@ public class AudioSharingDialogHandler { public void handleDeviceConnected( @NonNull CachedBluetoothDevice cachedDevice, boolean userTriggered) { String anonymizedAddress = cachedDevice.getDevice().getAnonymizedAddress(); if (mAudioManager != null) { int audioMode = mAudioManager.getMode(); if (audioMode == AudioManager.MODE_RINGTONE || audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) { Log.d(TAG, "Skip handleDeviceConnected, audio mode = " + audioMode); // TODO: add metric for this case if (userTriggered) { // If this method is called with user triggered, e.g. manual click on the // "Connected devices" page, we need call setActive for the device, since user // intend to switch active device for the call. cachedDevice.setActive(); } return; } } boolean isBroadcasting = isBroadcasting(); boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); if (!isLeAudioSupported) { Loading
tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java +28 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothLeBroadcastReceiveState; import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -113,6 +114,7 @@ public class AudioSharingDialogHandlerTest { @Mock private CachedBluetoothDeviceManager mCacheManager; @Mock private LocalBluetoothLeBroadcast mBroadcast; @Mock private LocalBluetoothLeBroadcastAssistant mAssistant; @Mock private AudioManager mAudioManager; @Mock private CachedBluetoothDevice mCachedDevice1; @Mock private CachedBluetoothDevice mCachedDevice2; @Mock private CachedBluetoothDevice mCachedDevice3; Loading Loading @@ -152,6 +154,8 @@ public class AudioSharingDialogHandlerTest { when(mLocalBtManager.getProfileManager()).thenReturn(mLocalBtProfileManager); when(mLocalBtProfileManager.getLeAudioBroadcastProfile()).thenReturn(mBroadcast); when(mLocalBtProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn(mAssistant); when(mContext.getSystemService(AudioManager.class)).thenReturn(mAudioManager); when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_NORMAL); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mState.getBisSyncState()).thenReturn(bisSyncState); Loading Loading @@ -187,6 +191,18 @@ public class AudioSharingDialogHandlerTest { ShadowBluetoothUtils.reset(); } @Test public void handleUserTriggeredDeviceConnected_inCall_setActive() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL); setUpBroadcast(true); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1); when(mAssistant.getAllConnectedDevices()).thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredNonLeaDeviceConnected_noSharing_setActive() { setUpBroadcast(false); Loading Loading @@ -403,6 +419,18 @@ public class AudioSharingDialogHandlerTest { verify(mAssistant).addSource(mDevice1, mMetadata, /* isGroupOp= */ false); } @Test public void handleDeviceConnected_inCall_doNothing() { when(mAudioManager.getMode()).thenReturn(AudioManager.MODE_IN_CALL); setUpBroadcast(true); when(mAssistant.getAllConnectedDevices()).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice2, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); verify(mCachedDevice2, never()).setActive(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); } @Test public void handleNonLeaDeviceConnected_noSharing_doNothing() { setUpBroadcast(false); Loading