Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +25 −9 Original line number Diff line number Diff line Loading @@ -58,10 +58,12 @@ import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HeadsetProfile; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; 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.flags.Flags; import com.android.settingslib.utils.ThreadUtils; import java.util.Locale; Loading @@ -83,6 +85,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro @Nullable private final CachedBluetoothDeviceManager mDeviceManager; @Nullable private final BluetoothEventManager mEventManager; @Nullable private final LocalBluetoothProfileManager mProfileManager; @Nullable private final LocalBluetoothLeBroadcast mBroadcast; @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant; private final Executor mExecutor; private final MetricsFeatureProvider mMetricsFeatureProvider; Loading Loading @@ -190,6 +193,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro mEventManager = mBtManager == null ? null : mBtManager.getEventManager(); mDeviceManager = mBtManager == null ? null : mBtManager.getCachedDeviceManager(); mProfileManager = mBtManager == null ? null : mBtManager.getProfileManager(); mBroadcast = mProfileManager == null ? null : mProfileManager.getLeAudioBroadcastProfile(); mAssistant = mProfileManager == null ? null Loading Loading @@ -334,23 +338,32 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro @NonNull CachedBluetoothDevice cachedDevice, @ConnectionState int state, int bluetoothProfile) { if (mDialogHandler == null || mAssistant == null || mFragment == null) { if (mDialogHandler == null || mBroadcast == null || mAssistant == null || mFragment == null) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, not init correctly"); return; } if (Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice() && mBroadcast.isEnabled( null)) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, in broadcast"); // Device connected in broadcast will be handled in sysui via settingslib return; } if (!isMediaDevice(cachedDevice)) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, not a media device"); return; } // Close related dialogs if the BT remote device is disconnected. if (state == BluetoothAdapter.STATE_DISCONNECTED) { boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice); if (isLeAudioSupported && bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT) { Log.d(TAG, "closeOpeningDialogsForLeaDevice"); mDialogHandler.closeOpeningDialogsForLeaDevice(cachedDevice); return; } if (!isLeAudioSupported && !cachedDevice.isConnected()) { Log.d(TAG, "closeOpeningDialogsForNonLeaDevice"); mDialogHandler.closeOpeningDialogsForNonLeaDevice(cachedDevice); return; } Loading @@ -362,6 +375,13 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro handleOnProfileStateChanged(cachedDevice, bluetoothProfile); } @Override public void onBluetoothStateChanged(@AdapterState int bluetoothState) { if (bluetoothState == BluetoothAdapter.STATE_OFF && mDialogHandler != null) { mDialogHandler.closeOpeningDialogsOtherThan(""); } } @Override public void onAudioModeChanged() { mIsAudioModeOngoingCall.set(isAudioModeOngoingCall(mContext)); Loading Loading @@ -421,7 +441,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro private void handleOnProfileStateChanged( @NonNull CachedBluetoothDevice cachedDevice, int bluetoothProfile) { boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice); // For eligible (LE audio) remote device, we only check its connected LE audio assistant // profile. if (isLeAudioSupported Loading @@ -441,12 +461,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + " non le audio device"); return; } if (DEBUG) { Log.d( TAG, "Start handling onProfileConnectionStateChanged for " Log.d(TAG, "Start handling onProfileConnectionStateChanged for " + cachedDevice.getDevice().getAnonymizedAddress()); } // Check nullability to pass NullAway check if (mDialogHandler != null) { mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ false); Loading tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java +102 −21 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import android.util.Pair; Loading Loading @@ -201,8 +203,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStart_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStart(mLifecycleOwner); verify(mEventManager, never()).registerCallback(any(BluetoothCallback.class)); verify(mDialogHandler, never()).registerCallbacks(any(Executor.class)); Loading @@ -214,8 +216,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStart_flagOn_registerCallbacks() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStart(mLifecycleOwner); verify(mEventManager).registerCallback(any(BluetoothCallback.class)); verify(mDialogHandler).registerCallbacks(any(Executor.class)); Loading @@ -227,8 +229,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStop_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStop(mLifecycleOwner); verify(mEventManager, never()).unregisterCallback(any(BluetoothCallback.class)); verify(mDialogHandler, never()).unregisterCallbacks(); Loading @@ -238,8 +240,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStop_flagOn_unregisterCallbacks() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStop(mLifecycleOwner); verify(mEventManager).unregisterCallback(any(BluetoothCallback.class)); verify(mDialogHandler).unregisterCallbacks(); Loading @@ -249,16 +251,16 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void displayPreference_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater, never()).forceUpdate(); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void displayPreference_flagOn_updateDeviceList() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater).setPrefContext(mContext); Loading @@ -271,14 +273,14 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void getAvailabilityStatus_flagOff_returnUnSupported() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void getAvailabilityStatus_flagOn_returnSupported() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE); } Loading Loading @@ -314,6 +316,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_leaDeviceDisconnected_closeOpeningDialogsForIt() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT disconnected. when(mDevice.isConnected()).thenReturn(true); Loading @@ -326,6 +329,21 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mDialogHandler).closeOpeningDialogsForLeaDevice(mCachedDevice); } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_leaDeviceDisconnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT disconnected. when(mDevice.isConnected()).thenReturn(true); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_DISCONNECTED, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); verifyNoInteractions(mDialogHandler); } @Test public void onProfileConnectionStateChanged_assistantProfileConnecting_doNothing() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting Loading Loading @@ -361,6 +379,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_assistantProfileConnected_handle() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connected when(mDevice.isConnected()).thenReturn(true); Loading @@ -374,6 +393,22 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_assistantProfileConnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connected when(mDevice.isConnected()).thenReturn(true); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); verifyNoInteractions(mDialogHandler); } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaDeviceDisconnected_closeOpeningDialogsForIt() { // Test when non-LEA device totally disconnected Loading @@ -386,6 +421,21 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mDialogHandler).closeOpeningDialogsForNonLeaDevice(mCachedDevice); } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaDeviceDisconnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when non-LEA device totally disconnected when(mLeAudioProfile.isEnabled(mDevice)).thenReturn(false); doReturn(ImmutableList.of(mA2dpProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile, mA2dpProfile)).when(mCachedDevice).getProfiles(); when(mCachedDevice.isConnected()).thenReturn(false); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_DISCONNECTED, BluetoothProfile.A2DP); verifyNoInteractions(mDialogHandler); } @Test public void onProfileConnectionStateChanged_nonLeaNotFirstProfileConnected_doNothing() { // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting Loading @@ -402,6 +452,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaFirstProfileConnected_handle() { // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting when(mDevice.isConnected()).thenReturn(true); Loading @@ -417,8 +468,26 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaFirstProfileConnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting when(mDevice.isConnected()).thenReturn(true); when(mHeadsetProfile.getConnectionStatus(mDevice)) .thenReturn(BluetoothAdapter.STATE_DISCONNECTED); doReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile)) .when(mCachedDevice) .getUiAccessibleProfiles(); doReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.A2DP); verifyNoInteractions(mDialogHandler); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_noDevice_doNothing() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Intent intent = new Intent(); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, new Bundle()); doReturn(intent).when(mActivity).getIntent(); Loading @@ -430,8 +499,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_profileNotReady_doNothing() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); when(mBroadcast.isProfileReady()).thenReturn(false); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Loading @@ -447,8 +516,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_intentHandled_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -465,8 +534,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_disconnectedDevice_connect() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -479,8 +548,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_connectedDevice_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -494,8 +563,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_onServiceConnected_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading Loading @@ -570,10 +639,10 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API}) @DisableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX) public void testInCallState_showCallStateTitleAndSetActiveOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API); Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); Loading @@ -596,10 +665,10 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX}) public void testInCallState_enableHysteresisFix_setAndSaveActiveOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API); Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); Loading @@ -619,8 +688,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void testInNormalState_showNormalStateTitleAndDoNothingOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); mAudioManager.setMode(AudioManager.MODE_NORMAL); Loading @@ -636,6 +705,18 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mCachedDevice, never()).setActive(); } @Test public void onBluetoothStateChanged_stateOff_closeAllOpeningDialogs() { mController.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); verify(mDialogHandler).closeOpeningDialogsOtherThan(""); } @Test public void onBluetoothStateChanged_stateOn_doNothing() { mController.onBluetoothStateChanged(BluetoothAdapter.STATE_ON); verify(mDialogHandler, never()).closeOpeningDialogsOtherThan(""); } @NonNull private BluetoothDevicePreference createBluetoothDevicePreference() { Drawable drawable = mock(Drawable.class); Loading Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceController.java +25 −9 Original line number Diff line number Diff line Loading @@ -58,10 +58,12 @@ import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HeadsetProfile; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast; 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.flags.Flags; import com.android.settingslib.utils.ThreadUtils; import java.util.Locale; Loading @@ -83,6 +85,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro @Nullable private final CachedBluetoothDeviceManager mDeviceManager; @Nullable private final BluetoothEventManager mEventManager; @Nullable private final LocalBluetoothProfileManager mProfileManager; @Nullable private final LocalBluetoothLeBroadcast mBroadcast; @Nullable private final LocalBluetoothLeBroadcastAssistant mAssistant; private final Executor mExecutor; private final MetricsFeatureProvider mMetricsFeatureProvider; Loading Loading @@ -190,6 +193,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro mEventManager = mBtManager == null ? null : mBtManager.getEventManager(); mDeviceManager = mBtManager == null ? null : mBtManager.getCachedDeviceManager(); mProfileManager = mBtManager == null ? null : mBtManager.getProfileManager(); mBroadcast = mProfileManager == null ? null : mProfileManager.getLeAudioBroadcastProfile(); mAssistant = mProfileManager == null ? null Loading Loading @@ -334,23 +338,32 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro @NonNull CachedBluetoothDevice cachedDevice, @ConnectionState int state, int bluetoothProfile) { if (mDialogHandler == null || mAssistant == null || mFragment == null) { if (mDialogHandler == null || mBroadcast == null || mAssistant == null || mFragment == null) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, not init correctly"); return; } if (Flags.promoteAudioSharingForSecondAutoConnectedLeaDevice() && mBroadcast.isEnabled( null)) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, in broadcast"); // Device connected in broadcast will be handled in sysui via settingslib return; } if (!isMediaDevice(cachedDevice)) { Log.d(TAG, "Ignore onProfileConnectionStateChanged, not a media device"); return; } // Close related dialogs if the BT remote device is disconnected. if (state == BluetoothAdapter.STATE_DISCONNECTED) { boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice); if (isLeAudioSupported && bluetoothProfile == BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT) { Log.d(TAG, "closeOpeningDialogsForLeaDevice"); mDialogHandler.closeOpeningDialogsForLeaDevice(cachedDevice); return; } if (!isLeAudioSupported && !cachedDevice.isConnected()) { Log.d(TAG, "closeOpeningDialogsForNonLeaDevice"); mDialogHandler.closeOpeningDialogsForNonLeaDevice(cachedDevice); return; } Loading @@ -362,6 +375,13 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro handleOnProfileStateChanged(cachedDevice, bluetoothProfile); } @Override public void onBluetoothStateChanged(@AdapterState int bluetoothState) { if (bluetoothState == BluetoothAdapter.STATE_OFF && mDialogHandler != null) { mDialogHandler.closeOpeningDialogsOtherThan(""); } } @Override public void onAudioModeChanged() { mIsAudioModeOngoingCall.set(isAudioModeOngoingCall(mContext)); Loading Loading @@ -421,7 +441,7 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro private void handleOnProfileStateChanged( @NonNull CachedBluetoothDevice cachedDevice, int bluetoothProfile) { boolean isLeAudioSupported = AudioSharingUtils.isLeAudioSupported(cachedDevice); boolean isLeAudioSupported = BluetoothUtils.isLeAudioSupported(cachedDevice); // For eligible (LE audio) remote device, we only check its connected LE audio assistant // profile. if (isLeAudioSupported Loading @@ -441,12 +461,8 @@ public class AudioSharingDevicePreferenceController extends BasePreferenceContro + " non le audio device"); return; } if (DEBUG) { Log.d( TAG, "Start handling onProfileConnectionStateChanged for " Log.d(TAG, "Start handling onProfileConnectionStateChanged for " + cachedDevice.getDevice().getAnonymizedAddress()); } // Check nullability to pass NullAway check if (mDialogHandler != null) { mDialogHandler.handleDeviceConnected(cachedDevice, /* userTriggered= */ false); Loading
tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDevicePreferenceControllerTest.java +102 −21 Original line number Diff line number Diff line Loading @@ -51,6 +51,8 @@ import android.graphics.drawable.Drawable; import android.media.AudioManager; import android.os.Bundle; import android.os.Looper; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import android.util.Pair; Loading Loading @@ -201,8 +203,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStart_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStart(mLifecycleOwner); verify(mEventManager, never()).registerCallback(any(BluetoothCallback.class)); verify(mDialogHandler, never()).registerCallbacks(any(Executor.class)); Loading @@ -214,8 +216,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStart_flagOn_registerCallbacks() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStart(mLifecycleOwner); verify(mEventManager).registerCallback(any(BluetoothCallback.class)); verify(mDialogHandler).registerCallbacks(any(Executor.class)); Loading @@ -227,8 +229,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStop_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStop(mLifecycleOwner); verify(mEventManager, never()).unregisterCallback(any(BluetoothCallback.class)); verify(mDialogHandler, never()).unregisterCallbacks(); Loading @@ -238,8 +240,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void onStop_flagOn_unregisterCallbacks() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.onStop(mLifecycleOwner); verify(mEventManager).unregisterCallback(any(BluetoothCallback.class)); verify(mDialogHandler).unregisterCallbacks(); Loading @@ -249,16 +251,16 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void displayPreference_flagOff_doNothing() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater, never()).forceUpdate(); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void displayPreference_flagOn_updateDeviceList() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); assertThat(mPreferenceGroup.isVisible()).isFalse(); verify(mBluetoothDeviceUpdater).setPrefContext(mContext); Loading @@ -271,14 +273,14 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void getAvailabilityStatus_flagOff_returnUnSupported() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void getAvailabilityStatus_flagOn_returnSupported() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE); } Loading Loading @@ -314,6 +316,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_leaDeviceDisconnected_closeOpeningDialogsForIt() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT disconnected. when(mDevice.isConnected()).thenReturn(true); Loading @@ -326,6 +329,21 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mDialogHandler).closeOpeningDialogsForLeaDevice(mCachedDevice); } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_leaDeviceDisconnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT disconnected. when(mDevice.isConnected()).thenReturn(true); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_DISCONNECTED, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); verifyNoInteractions(mDialogHandler); } @Test public void onProfileConnectionStateChanged_assistantProfileConnecting_doNothing() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting Loading Loading @@ -361,6 +379,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_assistantProfileConnected_handle() { // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connected when(mDevice.isConnected()).thenReturn(true); Loading @@ -374,6 +393,22 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_assistantProfileConnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when LEA device LE_AUDIO_BROADCAST_ASSISTANT connected when(mDevice.isConnected()).thenReturn(true); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); verifyNoInteractions(mDialogHandler); } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaDeviceDisconnected_closeOpeningDialogsForIt() { // Test when non-LEA device totally disconnected Loading @@ -386,6 +421,21 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mDialogHandler).closeOpeningDialogsForNonLeaDevice(mCachedDevice); } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaDeviceDisconnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when non-LEA device totally disconnected when(mLeAudioProfile.isEnabled(mDevice)).thenReturn(false); doReturn(ImmutableList.of(mA2dpProfile)).when(mCachedDevice).getUiAccessibleProfiles(); doReturn(ImmutableList.of(mLeAudioProfile, mA2dpProfile)).when(mCachedDevice).getProfiles(); when(mCachedDevice.isConnected()).thenReturn(false); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_DISCONNECTED, BluetoothProfile.A2DP); verifyNoInteractions(mDialogHandler); } @Test public void onProfileConnectionStateChanged_nonLeaNotFirstProfileConnected_doNothing() { // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting Loading @@ -402,6 +452,7 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @DisableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaFirstProfileConnected_handle() { // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting when(mDevice.isConnected()).thenReturn(true); Loading @@ -417,8 +468,26 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_PROMOTE_AUDIO_SHARING_FOR_SECOND_AUTO_CONNECTED_LEA_DEVICE) public void onProfileConnectionStateChanged_nonLeaFirstProfileConnected_broadcastOn_doNothing() { when(mBroadcast.isEnabled(null)).thenReturn(true); // Test when non-LEA device LE_AUDIO_BROADCAST_ASSISTANT connecting when(mDevice.isConnected()).thenReturn(true); when(mHeadsetProfile.getConnectionStatus(mDevice)) .thenReturn(BluetoothAdapter.STATE_DISCONNECTED); doReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile)) .when(mCachedDevice) .getUiAccessibleProfiles(); doReturn(ImmutableList.of(mA2dpProfile, mHeadsetProfile)).when(mCachedDevice).getProfiles(); mController.onProfileConnectionStateChanged( mCachedDevice, BluetoothAdapter.STATE_CONNECTED, BluetoothProfile.A2DP); verifyNoInteractions(mDialogHandler); } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_noDevice_doNothing() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Intent intent = new Intent(); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, new Bundle()); doReturn(intent).when(mActivity).getIntent(); Loading @@ -430,8 +499,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_profileNotReady_doNothing() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); when(mBroadcast.isProfileReady()).thenReturn(false); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Loading @@ -447,8 +516,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_intentHandled_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -465,8 +534,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_disconnectedDevice_connect() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -479,8 +548,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_connectedDevice_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading @@ -494,8 +563,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void handleDeviceClickFromIntent_onServiceConnected_handle() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); Bundle arg = new Bundle(); arg.putParcelable(EXTRA_BLUETOOTH_DEVICE, mDevice); Intent intent = new Intent(); Loading Loading @@ -570,10 +639,10 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API}) @DisableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX) public void testInCallState_showCallStateTitleAndSetActiveOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API); Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); Loading @@ -596,10 +665,10 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API, Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX}) public void testInCallState_enableHysteresisFix_setAndSaveActiveOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_ADOPT_PRIMARY_GROUP_MANAGEMENT_API); Settings.Secure.putInt(mContext.getContentResolver(), BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); Loading @@ -619,8 +688,8 @@ public class AudioSharingDevicePreferenceControllerTest { } @Test @EnableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING) public void testInNormalState_showNormalStateTitleAndDoNothingOnDeviceClick() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mController.displayPreference(mScreen); mAudioManager.setMode(AudioManager.MODE_NORMAL); Loading @@ -636,6 +705,18 @@ public class AudioSharingDevicePreferenceControllerTest { verify(mCachedDevice, never()).setActive(); } @Test public void onBluetoothStateChanged_stateOff_closeAllOpeningDialogs() { mController.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); verify(mDialogHandler).closeOpeningDialogsOtherThan(""); } @Test public void onBluetoothStateChanged_stateOn_doNothing() { mController.onBluetoothStateChanged(BluetoothAdapter.STATE_ON); verify(mDialogHandler, never()).closeOpeningDialogsOtherThan(""); } @NonNull private BluetoothDevicePreference createBluetoothDevicePreference() { Drawable drawable = mock(Drawable.class); Loading