Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +1 −11 Original line number Diff line number Diff line Loading @@ -823,18 +823,8 @@ public class BluetoothUtils { Log.d(TAG, "Skip check hasConnectedBroadcastSourceForBtDevice due to arg is null"); return false; } if (isAudioSharingHysteresisModeFixAvailable(localBtManager.getContext())) { return hasActiveLocalBroadcastSourceForBtDevice(device, localBtManager); } LocalBluetoothLeBroadcastAssistant assistant = localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (device == null || assistant == null) { Log.d(TAG, "Skip check hasConnectedBroadcastSourceForBtDevice due to arg is null"); return false; } List<BluetoothLeBroadcastReceiveState> sourceList = assistant.getAllSources(device); return !sourceList.isEmpty() && sourceList.stream().anyMatch(BluetoothUtils::isConnected); } /** * Check if {@link BluetoothDevice} has a active local broadcast source. Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +1 −33 Original line number Diff line number Diff line Loading @@ -24,13 +24,10 @@ import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssista import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.STREAMING; import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.getLocalSourceStateWithSelectedChannel; import static java.util.stream.Collectors.toList; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeAudioContentMetadata; import android.bluetooth.BluetoothLeBroadcast; Loading Loading @@ -144,7 +141,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { private final Context mContext; private final CachedBluetoothDeviceManager mDeviceManager; private final LocalBluetoothProfileManager mProfileManager; private final boolean mHysteresisModeFixAvailable; private final boolean mIsWorkProfile; private BluetoothLeBroadcast mServiceBroadcast; private BluetoothLeBroadcastAssistant mServiceBroadcastAssistant; Loading Loading @@ -444,7 +440,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { var sourceState = sourceStateAndSelectedChannel.first; var selectedChannel = sourceStateAndSelectedChannel.second; if (sourceState == STREAMING || sourceState == DECRYPTION_FAILED || (mHysteresisModeFixAvailable && sourceState == PAUSED) || sourceState == PAUSED || (Flags.audioStreamPlayPauseByModifySource() && sourceState == PAUSED_BY_RECEIVER)) { List<BluetoothLeAudioContentMetadata> subgroupMetadata = Loading Loading @@ -492,9 +488,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { BluetoothAdapter.getDefaultAdapter() .getProfileProxy( context, mServiceListener, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); mHysteresisModeFixAvailable = BluetoothUtils.isAudioSharingHysteresisModeFixAvailable( context); mIsWorkProfile = isWorkProfile(mContext); } Loading Loading @@ -1200,31 +1193,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { } } @Nullable private CachedBluetoothDevice getMainDevice(@Nullable List<BluetoothDevice> devices) { if (devices == null || devices.isEmpty()) return null; List<CachedBluetoothDevice> cachedDevices = devices.stream() .map(device -> mDeviceManager.findDevice(device)) .filter(Objects::nonNull) .collect(toList()); for (CachedBluetoothDevice cachedDevice : cachedDevices) { if (!cachedDevice.getMemberDevice().isEmpty()) { return cachedDevice; } } CachedBluetoothDevice mainDevice = cachedDevices.isEmpty() ? null : cachedDevices.get(0); return mainDevice; } private int getUserPreferredPrimaryGroupId() { // TODO: use real key name in SettingsProvider return Settings.Secure.getInt( mContentResolver, BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); } private void notifyBroadcastStateChange(@BroadcastState int state) { String packageName = mContext.getPackageName(); if (!packageName.equals(SETTINGS_PKG) && !packageName.equals(SYSUI_PKG)) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +5 −135 Original line number Diff line number Diff line Loading @@ -774,111 +774,7 @@ public class BluetoothUtilsTest { } @Test public void testHasConnectedBroadcastSource_leadDeviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); when(memberCachedDevice.getDevice()).thenReturn(memberDevice); Set<CachedBluetoothDevice> memberCachedDevices = new HashSet<>(); memberCachedDevices.add(memberCachedDevice); when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(memberCachedDevices); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); when(mAssistant.getAllSources(memberDevice)).thenReturn(Collections.emptyList()); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSource_memberDeviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); when(memberCachedDevice.getDevice()).thenReturn(memberDevice); Set<CachedBluetoothDevice> memberCachedDevices = new HashSet<>(); memberCachedDevices.add(memberCachedDevice); when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(memberCachedDevices); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(memberDevice)).thenReturn(sourceList); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(Collections.emptyList()); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSource_deviceNotConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); List<Long> bisSyncState = new ArrayList<>(); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isFalse(); } @Test public void testHasConnectedBroadcastSourceForBtDevice_deviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSourceForBtDevice( mBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSourceForBtDevice_deviceNotConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); List<Long> bisSyncState = new ArrayList<>(); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSourceForBtDevice( mBluetoothDevice, mLocalBluetoothManager)) .isFalse(); } @Test public void hasConnectedBroadcastSource_hysteresisFix_leadDeviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_leadDeviceHasActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); Loading @@ -903,8 +799,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSource_hysteresisFix_memberDeviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_memberDeviceHasActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); Loading @@ -928,8 +823,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSource_hysteresisFix_deviceNoActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_deviceNoActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBroadcast.getLatestBroadcastId()).thenReturn(UNKNOWN_VALUE_PLACEHOLDER); Loading @@ -945,8 +839,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSourceForBtDevice_hysteresisFix_deviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSourceForBtDevice_deviceHasActiveLocalSource() { when(mBroadcast.getLatestBroadcastId()).thenReturn(TEST_BROADCAST_ID); when(mLeBroadcastReceiveState.getBroadcastId()).thenReturn(TEST_BROADCAST_ID); Loading @@ -961,8 +854,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSourceForBtDevice_hysteresisFix_deviceNoActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSourceForBtDevice_deviceNoActiveLocalSource() { when(mBroadcast.getLatestBroadcastId()).thenReturn(TEST_BROADCAST_ID); when(mLeBroadcastReceiveState.getBroadcastId()).thenReturn(UNKNOWN_VALUE_PLACEHOLDER); Loading Loading @@ -1454,36 +1346,14 @@ public class BluetoothUtilsTest { @Test public void isAudioSharingHysteresisModeFixAvailable_mainAndPreviewFlagOff_returnsFalse() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isFalse(); } @Test public void isAudioSharingHysteresisModeFixAvailable_hysteresisFixFlagOff_returnsFalse() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isFalse(); } @Test public void isAudioSharingHysteresisModeFixAvailable_previewFlagOn_returnsTrue() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); Settings.Global.putInt(mContext.getContentResolver(), BluetoothUtils.DEVELOPER_OPTION_PREVIEW_KEY, 1); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isTrue(); } @Test public void isAudioSharingHysteresisModeFixAvailable_mainAndPreviewFlagOn_returnsTrue() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isTrue(); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +1 −11 Original line number Diff line number Diff line Loading @@ -823,18 +823,8 @@ public class BluetoothUtils { Log.d(TAG, "Skip check hasConnectedBroadcastSourceForBtDevice due to arg is null"); return false; } if (isAudioSharingHysteresisModeFixAvailable(localBtManager.getContext())) { return hasActiveLocalBroadcastSourceForBtDevice(device, localBtManager); } LocalBluetoothLeBroadcastAssistant assistant = localBtManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); if (device == null || assistant == null) { Log.d(TAG, "Skip check hasConnectedBroadcastSourceForBtDevice due to arg is null"); return false; } List<BluetoothLeBroadcastReceiveState> sourceList = assistant.getAllSources(device); return !sourceList.isEmpty() && sourceList.stream().anyMatch(BluetoothUtils::isConnected); } /** * Check if {@link BluetoothDevice} has a active local broadcast source. Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/LocalBluetoothLeBroadcast.java +1 −33 Original line number Diff line number Diff line Loading @@ -24,13 +24,10 @@ import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssista import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.LocalBluetoothLeBroadcastSourceState.STREAMING; import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant.getLocalSourceStateWithSelectedChannel; import static java.util.stream.Collectors.toList; import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothCsipSetCoordinator; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeAudioContentMetadata; import android.bluetooth.BluetoothLeBroadcast; Loading Loading @@ -144,7 +141,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { private final Context mContext; private final CachedBluetoothDeviceManager mDeviceManager; private final LocalBluetoothProfileManager mProfileManager; private final boolean mHysteresisModeFixAvailable; private final boolean mIsWorkProfile; private BluetoothLeBroadcast mServiceBroadcast; private BluetoothLeBroadcastAssistant mServiceBroadcastAssistant; Loading Loading @@ -444,7 +440,7 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { var sourceState = sourceStateAndSelectedChannel.first; var selectedChannel = sourceStateAndSelectedChannel.second; if (sourceState == STREAMING || sourceState == DECRYPTION_FAILED || (mHysteresisModeFixAvailable && sourceState == PAUSED) || sourceState == PAUSED || (Flags.audioStreamPlayPauseByModifySource() && sourceState == PAUSED_BY_RECEIVER)) { List<BluetoothLeAudioContentMetadata> subgroupMetadata = Loading Loading @@ -492,9 +488,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { BluetoothAdapter.getDefaultAdapter() .getProfileProxy( context, mServiceListener, BluetoothProfile.LE_AUDIO_BROADCAST_ASSISTANT); mHysteresisModeFixAvailable = BluetoothUtils.isAudioSharingHysteresisModeFixAvailable( context); mIsWorkProfile = isWorkProfile(mContext); } Loading Loading @@ -1200,31 +1193,6 @@ public class LocalBluetoothLeBroadcast implements LocalBluetoothProfile { } } @Nullable private CachedBluetoothDevice getMainDevice(@Nullable List<BluetoothDevice> devices) { if (devices == null || devices.isEmpty()) return null; List<CachedBluetoothDevice> cachedDevices = devices.stream() .map(device -> mDeviceManager.findDevice(device)) .filter(Objects::nonNull) .collect(toList()); for (CachedBluetoothDevice cachedDevice : cachedDevices) { if (!cachedDevice.getMemberDevice().isEmpty()) { return cachedDevice; } } CachedBluetoothDevice mainDevice = cachedDevices.isEmpty() ? null : cachedDevices.get(0); return mainDevice; } private int getUserPreferredPrimaryGroupId() { // TODO: use real key name in SettingsProvider return Settings.Secure.getInt( mContentResolver, BLUETOOTH_LE_BROADCAST_PRIMARY_DEVICE_GROUP_ID, BluetoothCsipSetCoordinator.GROUP_ID_INVALID); } private void notifyBroadcastStateChange(@BroadcastState int state) { String packageName = mContext.getPackageName(); if (!packageName.equals(SETTINGS_PKG) && !packageName.equals(SYSUI_PKG)) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +5 −135 Original line number Diff line number Diff line Loading @@ -774,111 +774,7 @@ public class BluetoothUtilsTest { } @Test public void testHasConnectedBroadcastSource_leadDeviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); when(memberCachedDevice.getDevice()).thenReturn(memberDevice); Set<CachedBluetoothDevice> memberCachedDevices = new HashSet<>(); memberCachedDevices.add(memberCachedDevice); when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(memberCachedDevices); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); when(mAssistant.getAllSources(memberDevice)).thenReturn(Collections.emptyList()); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSource_memberDeviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); when(memberCachedDevice.getDevice()).thenReturn(memberDevice); Set<CachedBluetoothDevice> memberCachedDevices = new HashSet<>(); memberCachedDevices.add(memberCachedDevice); when(mCachedBluetoothDevice.getMemberDevice()).thenReturn(memberCachedDevices); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(memberDevice)).thenReturn(sourceList); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(Collections.emptyList()); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSource_deviceNotConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); List<Long> bisSyncState = new ArrayList<>(); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSource( mCachedBluetoothDevice, mLocalBluetoothManager)) .isFalse(); } @Test public void testHasConnectedBroadcastSourceForBtDevice_deviceConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); List<Long> bisSyncState = new ArrayList<>(); bisSyncState.add(1L); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSourceForBtDevice( mBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @Test public void testHasConnectedBroadcastSourceForBtDevice_deviceNotConnectedToBroadcastSource() { mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); List<Long> bisSyncState = new ArrayList<>(); when(mLeBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mLeBroadcastReceiveState); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( BluetoothUtils.hasConnectedBroadcastSourceForBtDevice( mBluetoothDevice, mLocalBluetoothManager)) .isFalse(); } @Test public void hasConnectedBroadcastSource_hysteresisFix_leadDeviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_leadDeviceHasActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); Loading @@ -903,8 +799,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSource_hysteresisFix_memberDeviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_memberDeviceHasActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); CachedBluetoothDevice memberCachedDevice = mock(CachedBluetoothDevice.class); BluetoothDevice memberDevice = mock(BluetoothDevice.class); Loading @@ -928,8 +823,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSource_hysteresisFix_deviceNoActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSource_deviceNoActiveLocalSource() { when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); when(mBroadcast.getLatestBroadcastId()).thenReturn(UNKNOWN_VALUE_PLACEHOLDER); Loading @@ -945,8 +839,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSourceForBtDevice_hysteresisFix_deviceHasActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSourceForBtDevice_deviceHasActiveLocalSource() { when(mBroadcast.getLatestBroadcastId()).thenReturn(TEST_BROADCAST_ID); when(mLeBroadcastReceiveState.getBroadcastId()).thenReturn(TEST_BROADCAST_ID); Loading @@ -961,8 +854,7 @@ public class BluetoothUtilsTest { } @Test public void hasConnectedBroadcastSourceForBtDevice_hysteresisFix_deviceNoActiveLocalSource() { mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); public void hasConnectedBroadcastSourceForBtDevice_deviceNoActiveLocalSource() { when(mBroadcast.getLatestBroadcastId()).thenReturn(TEST_BROADCAST_ID); when(mLeBroadcastReceiveState.getBroadcastId()).thenReturn(UNKNOWN_VALUE_PLACEHOLDER); Loading Loading @@ -1454,36 +1346,14 @@ public class BluetoothUtilsTest { @Test public void isAudioSharingHysteresisModeFixAvailable_mainAndPreviewFlagOff_returnsFalse() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isFalse(); } @Test public void isAudioSharingHysteresisModeFixAvailable_hysteresisFixFlagOff_returnsFalse() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isFalse(); } @Test public void isAudioSharingHysteresisModeFixAvailable_previewFlagOn_returnsTrue() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); Settings.Global.putInt(mContext.getContentResolver(), BluetoothUtils.DEVELOPER_OPTION_PREVIEW_KEY, 1); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isTrue(); } @Test public void isAudioSharingHysteresisModeFixAvailable_mainAndPreviewFlagOn_returnsTrue() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); mSetFlagsRule.enableFlags(Flags.FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX); mSetFlagsRule.disableFlags(Flags.FLAG_AUDIO_SHARING_DEVELOPER_OPTION); assertThat(BluetoothUtils.isAudioSharingHysteresisModeFixAvailable(mContext)).isTrue(); Loading