Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class CachedBluetoothDeviceManager { mBtManager = localBtManager; mHearingAidDeviceManager = new HearingAidDeviceManager(context, localBtManager, mCachedDevices); mCsipDeviceManager = new CsipDeviceManager(localBtManager, mCachedDevices); mCsipDeviceManager = new CsipDeviceManager(context, localBtManager, mCachedDevices); } public synchronized Collection<CachedBluetoothDevice> getCachedDevicesCopy() { Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/CsipDeviceManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,10 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; import android.os.Build; import android.os.ParcelUuid; import android.os.UserManager; import android.util.Log; import androidx.annotation.ChecksSdkIntAtLeast; Loading @@ -45,9 +47,11 @@ public class CsipDeviceManager { private final LocalBluetoothManager mBtManager; private final List<CachedBluetoothDevice> mCachedDevices; private final Context mContext; CsipDeviceManager(LocalBluetoothManager localBtManager, CsipDeviceManager(Context context, LocalBluetoothManager localBtManager, List<CachedBluetoothDevice> cachedDevices) { mContext = context; mBtManager = localBtManager; mCachedDevices = cachedDevices; } Loading Loading @@ -379,8 +383,12 @@ public class CsipDeviceManager { preferredMainDevice.refresh(); hasChanged = true; } if (isWorkProfile()) { log("addMemberDevicesIntoMainDevice: skip sync source for work profile"); } else { syncAudioSharingSourceIfNeeded(preferredMainDevice); } } if (hasChanged) { log("addMemberDevicesIntoMainDevice: After changed, CachedBluetoothDevice list: " + mCachedDevices); Loading @@ -388,6 +396,11 @@ public class CsipDeviceManager { return hasChanged; } private boolean isWorkProfile() { UserManager userManager = mContext.getSystemService(UserManager.class); return userManager != null && userManager.isManagedProfile(); } private void syncAudioSharingSourceIfNeeded(CachedBluetoothDevice mainDevice) { boolean isAudioSharingEnabled = BluetoothUtils.isAudioSharingEnabled(); if (isAudioSharingEnabled) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CsipDeviceManagerTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.os.Looper; import android.os.Parcel; import android.os.UserManager; import android.platform.test.flag.junit.SetFlagsRule; import com.android.settingslib.flags.Flags; Loading Loading @@ -104,6 +105,8 @@ public class CsipDeviceManagerTest { private LocalBluetoothLeBroadcast mBroadcast; @Mock private LocalBluetoothLeBroadcastAssistant mAssistant; @Mock private UserManager mUserManager; private ShadowBluetoothAdapter mShadowBluetoothAdapter; private CachedBluetoothDevice mCachedDevice1; Loading @@ -128,7 +131,7 @@ public class CsipDeviceManagerTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mContext = spy(RuntimeEnvironment.application); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter.setEnabled(true); mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported( Loading Loading @@ -355,6 +358,37 @@ public class CsipDeviceManagerTest { any(BluetoothLeBroadcastMetadata.class), anyBoolean()); } @Test public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_workProfile_doNothing() { // Condition: The preferredDevice is main and there is another main device in top list // Expected Result: return true and there is the preferredDevice in top list CachedBluetoothDevice preferredDevice = mCachedDevice1; mCachedDevice1.getMemberDevice().clear(); mCachedDevices.clear(); mCachedDevices.add(preferredDevice); mCachedDevices.add(mCachedDevice2); mCachedDevices.add(mCachedDevice3); mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); when(mBroadcast.isEnabled(null)).thenReturn(true); BluetoothLeBroadcastMetadata metadata = Mockito.mock(BluetoothLeBroadcastMetadata.class); when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(metadata); BluetoothLeBroadcastReceiveState state = Mockito.mock( BluetoothLeBroadcastReceiveState.class); when(state.getBisSyncState()).thenReturn(ImmutableList.of(1L)); when(mAssistant.getAllSources(mDevice2)).thenReturn(ImmutableList.of(state)); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); when(mUserManager.isManagedProfile()).thenReturn(true); assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice)) .isTrue(); assertThat(mCachedDevices.contains(preferredDevice)).isTrue(); assertThat(mCachedDevices.contains(mCachedDevice2)).isFalse(); assertThat(mCachedDevices.contains(mCachedDevice3)).isTrue(); assertThat(preferredDevice.getMemberDevice()).contains(mCachedDevice2); verify(mAssistant, never()).addSource(mDevice1, metadata, /* isGroupOp= */ false); } @Test public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_syncSource() { // Condition: The preferredDevice is main and there is another main device in top list Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class CachedBluetoothDeviceManager { mBtManager = localBtManager; mHearingAidDeviceManager = new HearingAidDeviceManager(context, localBtManager, mCachedDevices); mCsipDeviceManager = new CsipDeviceManager(localBtManager, mCachedDevices); mCsipDeviceManager = new CsipDeviceManager(context, localBtManager, mCachedDevices); } public synchronized Collection<CachedBluetoothDevice> getCachedDevicesCopy() { Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/CsipDeviceManager.java +15 −2 Original line number Diff line number Diff line Loading @@ -21,8 +21,10 @@ import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothLeBroadcastMetadata; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.content.Context; import android.os.Build; import android.os.ParcelUuid; import android.os.UserManager; import android.util.Log; import androidx.annotation.ChecksSdkIntAtLeast; Loading @@ -45,9 +47,11 @@ public class CsipDeviceManager { private final LocalBluetoothManager mBtManager; private final List<CachedBluetoothDevice> mCachedDevices; private final Context mContext; CsipDeviceManager(LocalBluetoothManager localBtManager, CsipDeviceManager(Context context, LocalBluetoothManager localBtManager, List<CachedBluetoothDevice> cachedDevices) { mContext = context; mBtManager = localBtManager; mCachedDevices = cachedDevices; } Loading Loading @@ -379,8 +383,12 @@ public class CsipDeviceManager { preferredMainDevice.refresh(); hasChanged = true; } if (isWorkProfile()) { log("addMemberDevicesIntoMainDevice: skip sync source for work profile"); } else { syncAudioSharingSourceIfNeeded(preferredMainDevice); } } if (hasChanged) { log("addMemberDevicesIntoMainDevice: After changed, CachedBluetoothDevice list: " + mCachedDevices); Loading @@ -388,6 +396,11 @@ public class CsipDeviceManager { return hasChanged; } private boolean isWorkProfile() { UserManager userManager = mContext.getSystemService(UserManager.class); return userManager != null && userManager.isManagedProfile(); } private void syncAudioSharingSourceIfNeeded(CachedBluetoothDevice mainDevice) { boolean isAudioSharingEnabled = BluetoothUtils.isAudioSharingEnabled(); if (isAudioSharingEnabled) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/CsipDeviceManagerTest.java +35 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothStatusCodes; import android.content.Context; import android.os.Looper; import android.os.Parcel; import android.os.UserManager; import android.platform.test.flag.junit.SetFlagsRule; import com.android.settingslib.flags.Flags; Loading Loading @@ -104,6 +105,8 @@ public class CsipDeviceManagerTest { private LocalBluetoothLeBroadcast mBroadcast; @Mock private LocalBluetoothLeBroadcastAssistant mAssistant; @Mock private UserManager mUserManager; private ShadowBluetoothAdapter mShadowBluetoothAdapter; private CachedBluetoothDevice mCachedDevice1; Loading @@ -128,7 +131,7 @@ public class CsipDeviceManagerTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; mContext = spy(RuntimeEnvironment.application); mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); mShadowBluetoothAdapter.setEnabled(true); mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported( Loading Loading @@ -355,6 +358,37 @@ public class CsipDeviceManagerTest { any(BluetoothLeBroadcastMetadata.class), anyBoolean()); } @Test public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_workProfile_doNothing() { // Condition: The preferredDevice is main and there is another main device in top list // Expected Result: return true and there is the preferredDevice in top list CachedBluetoothDevice preferredDevice = mCachedDevice1; mCachedDevice1.getMemberDevice().clear(); mCachedDevices.clear(); mCachedDevices.add(preferredDevice); mCachedDevices.add(mCachedDevice2); mCachedDevices.add(mCachedDevice3); mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); when(mBroadcast.isEnabled(null)).thenReturn(true); BluetoothLeBroadcastMetadata metadata = Mockito.mock(BluetoothLeBroadcastMetadata.class); when(mBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(metadata); BluetoothLeBroadcastReceiveState state = Mockito.mock( BluetoothLeBroadcastReceiveState.class); when(state.getBisSyncState()).thenReturn(ImmutableList.of(1L)); when(mAssistant.getAllSources(mDevice2)).thenReturn(ImmutableList.of(state)); when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager); when(mUserManager.isManagedProfile()).thenReturn(true); assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice)) .isTrue(); assertThat(mCachedDevices.contains(preferredDevice)).isTrue(); assertThat(mCachedDevices.contains(mCachedDevice2)).isFalse(); assertThat(mCachedDevices.contains(mCachedDevice3)).isTrue(); assertThat(preferredDevice.getMemberDevice()).contains(mCachedDevice2); verify(mAssistant, never()).addSource(mDevice1, metadata, /* isGroupOp= */ false); } @Test public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_syncSource() { // Condition: The preferredDevice is main and there is another main device in top list Loading