Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2eefac52 authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "Revert "[Audiosharing] Sync temp bond state when CSIP grouping"" into main

parents 48a11073 06769e8b
Loading
Loading
Loading
Loading
+8 −26
Original line number Diff line number Diff line
@@ -30,13 +30,11 @@ import android.util.Log;
import androidx.annotation.ChecksSdkIntAtLeast;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.flags.Flags;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

@@ -387,7 +385,7 @@ public class CsipDeviceManager {
                preferredMainDevice.refresh();
                hasChanged = true;
            }
            syncAudioSharingStatusIfNeeded(preferredMainDevice);
            syncAudioSharingSourceIfNeeded(preferredMainDevice);
        }
        if (hasChanged) {
            log("addMemberDevicesIntoMainDevice: After changed, CachedBluetoothDevice list: "
@@ -401,16 +399,13 @@ public class CsipDeviceManager {
        return userManager != null && userManager.isManagedProfile();
    }

    private void syncAudioSharingStatusIfNeeded(CachedBluetoothDevice mainDevice) {
    private void syncAudioSharingSourceIfNeeded(CachedBluetoothDevice mainDevice) {
        boolean isAudioSharingEnabled = BluetoothUtils.isAudioSharingUIAvailable(mContext);
        if (isAudioSharingEnabled && mainDevice != null) {
        if (isAudioSharingEnabled) {
            if (isWorkProfile()) {
                log("addMemberDevicesIntoMainDevice: skip sync audio sharing status, work profile");
                log("addMemberDevicesIntoMainDevice: skip sync source for work profile");
                return;
            }
            Set<CachedBluetoothDevice> deviceSet = new HashSet<>();
            deviceSet.add(mainDevice);
            deviceSet.addAll(mainDevice.getMemberDevice());
            boolean hasBroadcastSource = BluetoothUtils.isBroadcasting(mBtManager)
                    && BluetoothUtils.hasConnectedBroadcastSource(
                    mainDevice, mBtManager);
@@ -424,6 +419,9 @@ public class CsipDeviceManager {
                if (metadata != null && assistant != null) {
                    log("addMemberDevicesIntoMainDevice: sync audio sharing source after "
                            + "combining the top level devices.");
                    Set<CachedBluetoothDevice> deviceSet = new HashSet<>();
                    deviceSet.add(mainDevice);
                    deviceSet.addAll(mainDevice.getMemberDevice());
                    Set<BluetoothDevice> sinksToSync = deviceSet.stream()
                            .map(CachedBluetoothDevice::getDevice)
                            .filter(device ->
@@ -437,24 +435,8 @@ public class CsipDeviceManager {
                    }
                }
            }
            if (Flags.enableTemporaryBondDevicesUi()) {
                log("addMemberDevicesIntoMainDevice: sync temp bond metadata for audio sharing "
                        + "sinks after combining the top level devices.");
                Set<BluetoothDevice> sinksToSync = deviceSet.stream()
                        .map(CachedBluetoothDevice::getDevice).filter(Objects::nonNull).collect(
                                Collectors.toSet());
                if (sinksToSync.stream().anyMatch(BluetoothUtils::isTemporaryBondDevice)) {
                    for (BluetoothDevice device : sinksToSync) {
                        if (!BluetoothUtils.isTemporaryBondDevice(device)) {
                            log("addMemberDevicesIntoMainDevice: sync temp bond metadata for "
                                    + device.getAnonymizedAddress());
                            BluetoothUtils.setTemporaryBondMetadata(device);
                        }
                    }
                }
            }
        } else {
            log("addMemberDevicesIntoMainDevice: skip sync audio sharing status, flag disabled");
            log("addMemberDevicesIntoMainDevice: skip sync source, flag disabled");
        }
    }

+7 −30
Original line number Diff line number Diff line
@@ -40,8 +40,6 @@ import android.content.Context;
import android.os.Looper;
import android.os.Parcel;
import android.os.UserManager;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import com.android.settingslib.flags.Flags;
@@ -76,9 +74,6 @@ public class CsipDeviceManagerTest {
    private final static String DEVICE_ADDRESS_1 = "AA:BB:CC:DD:EE:11";
    private final static String DEVICE_ADDRESS_2 = "AA:BB:CC:DD:EE:22";
    private final static String DEVICE_ADDRESS_3 = "AA:BB:CC:DD:EE:33";
    private static final int METADATA_FAST_PAIR_CUSTOMIZED_FIELDS = 25;
    private static final String TEMP_BOND_METADATA =
            "<TEMP_BOND_TYPE>le_audio_sharing</TEMP_BOND_TYPE>";
    private final static int GROUP1 = 1;
    private final BluetoothClass DEVICE_CLASS_1 =
            createBtClass(BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES);
@@ -342,7 +337,6 @@ public class CsipDeviceManagerTest {
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_returnTrue() {
        // 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
@@ -352,6 +346,7 @@ public class CsipDeviceManagerTest {
        mCachedDevices.add(preferredDevice);
        mCachedDevices.add(mCachedDevice2);
        mCachedDevices.add(mCachedDevice3);
        mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);

        assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice))
                .isTrue();
@@ -364,7 +359,6 @@ public class CsipDeviceManagerTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI})
    public void
            addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_workProfile_doNothing() {
        // Condition: The preferredDevice is main and there is another main device in top list
@@ -375,6 +369,7 @@ public class CsipDeviceManagerTest {
        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);
@@ -382,8 +377,6 @@ public class CsipDeviceManagerTest {
                BluetoothLeBroadcastReceiveState.class);
        when(state.getBisSyncState()).thenReturn(ImmutableList.of(1L));
        when(mAssistant.getAllSources(mDevice2)).thenReturn(ImmutableList.of(state));
        when(mDevice2.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn(TEMP_BOND_METADATA.getBytes());
        when(mContext.getSystemService(UserManager.class)).thenReturn(mUserManager);
        when(mUserManager.isManagedProfile()).thenReturn(true);

@@ -394,13 +387,10 @@ public class CsipDeviceManagerTest {
        assertThat(mCachedDevices.contains(mCachedDevice3)).isTrue();
        assertThat(preferredDevice.getMemberDevice()).contains(mCachedDevice2);
        verify(mAssistant, never()).addSource(mDevice1, metadata, /* isGroupOp= */ false);
        verify(mDevice1, never()).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI})
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_syncState() {
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMainAndTwoMain_syncSource() {
        // 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;
@@ -409,6 +399,7 @@ public class CsipDeviceManagerTest {
        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);
@@ -416,8 +407,6 @@ public class CsipDeviceManagerTest {
                BluetoothLeBroadcastReceiveState.class);
        when(state.getBisSyncState()).thenReturn(ImmutableList.of(1L));
        when(mAssistant.getAllSources(mDevice2)).thenReturn(ImmutableList.of(state));
        when(mDevice2.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn(TEMP_BOND_METADATA.getBytes());

        assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice))
                .isTrue();
@@ -426,8 +415,6 @@ public class CsipDeviceManagerTest {
        assertThat(mCachedDevices.contains(mCachedDevice3)).isTrue();
        assertThat(preferredDevice.getMemberDevice()).contains(mCachedDevice2);
        verify(mAssistant).addSource(mDevice1, metadata, /* isGroupOp= */ false);
        verify(mDevice1).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
    }

    @Test
@@ -449,13 +436,13 @@ public class CsipDeviceManagerTest {
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI})
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMemberAndTwoMain_returnTrue() {
        // Condition: The preferredDevice is member and there are two main device in top list
        // Expected Result: return true and there is the preferredDevice in top list
        CachedBluetoothDevice preferredDevice = mCachedDevice2;
        BluetoothDevice expectedMainBluetoothDevice = preferredDevice.getDevice();
        mCachedDevice3.setGroupId(GROUP1);
        mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING);
        when(mBroadcast.isEnabled(null)).thenReturn(false);

        assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice))
@@ -470,20 +457,16 @@ public class CsipDeviceManagerTest {
        assertThat(mCachedDevice1.getDevice()).isEqualTo(expectedMainBluetoothDevice);
        verify(mAssistant, never()).addSource(any(BluetoothDevice.class),
                any(BluetoothLeBroadcastMetadata.class), anyBoolean());
        verify(mDevice2, never()).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
        verify(mDevice3, never()).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_LE_AUDIO_SHARING, Flags.FLAG_ENABLE_TEMPORARY_BOND_DEVICES_UI})
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMemberAndTwoMain_syncState() {
    public void addMemberDevicesIntoMainDevice_preferredDeviceIsMemberAndTwoMain_syncSource() {
        // Condition: The preferredDevice is member and there are two main device in top list
        // Expected Result: return true and there is the preferredDevice in top list
        CachedBluetoothDevice preferredDevice = mCachedDevice2;
        BluetoothDevice expectedMainBluetoothDevice = preferredDevice.getDevice();
        mCachedDevice3.setGroupId(GROUP1);
        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);
@@ -491,8 +474,6 @@ public class CsipDeviceManagerTest {
                BluetoothLeBroadcastReceiveState.class);
        when(state.getBisSyncState()).thenReturn(ImmutableList.of(1L));
        when(mAssistant.getAllSources(mDevice1)).thenReturn(ImmutableList.of(state));
        when(mDevice1.getMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS))
                .thenReturn(TEMP_BOND_METADATA.getBytes());

        assertThat(mCsipDeviceManager.addMemberDevicesIntoMainDevice(GROUP1, preferredDevice))
                .isTrue();
@@ -507,10 +488,6 @@ public class CsipDeviceManagerTest {
        assertThat(mCachedDevice1.getDevice()).isEqualTo(expectedMainBluetoothDevice);
        verify(mAssistant).addSource(mDevice2, metadata, /* isGroupOp= */ false);
        verify(mAssistant).addSource(mDevice3, metadata, /* isGroupOp= */ false);
        verify(mDevice2).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
        verify(mDevice3).setMetadata(METADATA_FAST_PAIR_CUSTOMIZED_FIELDS,
                TEMP_BOND_METADATA.getBytes());
    }

    @Test