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

Commit 260c6b6a authored by Angela Wang's avatar Angela Wang
Browse files

Rename CachedBluetoothDevice.getConnectableProfiles()

The original method name implied that the returned profiles were guaranteed to be connectable. However, it actually filters profiles based on user can access the profile in the UI and initiate the connection. Change the method name to getUiAccessibleProfiles() aligns the name with the actual behavior.

Flag: EXEMPT simple renaming
Bug: 356530795
Test: m
Change-Id: Ic9b771a4d68ac8c96ec4fa58d42302b02fedc7ca
parent 33600e82
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -1026,21 +1026,29 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice>
        return mDevice.getBluetoothClass();
    }

    /**
     * Returns a list of {@link LocalBluetoothProfile} supported by the device.
     */
    public List<LocalBluetoothProfile> getProfiles() {
        return new ArrayList<>(mProfiles);
    }

    public List<LocalBluetoothProfile> getConnectableProfiles() {
        List<LocalBluetoothProfile> connectableProfiles =
                new ArrayList<LocalBluetoothProfile>();
    /**
     * Returns a list of {@link LocalBluetoothProfile} that are user-accessible from UI to
     * initiate a connection.
     *
     * Note: Use {@link #getProfiles()} to retrieve all supported profiles on the device.
     */
    public List<LocalBluetoothProfile> getUiAccessibleProfiles() {
        List<LocalBluetoothProfile> accessibleProfiles = new ArrayList<>();
        synchronized (mProfileLock) {
            for (LocalBluetoothProfile profile : mProfiles) {
                if (profile.accessProfileEnabled()) {
                    connectableProfiles.add(profile);
                    accessibleProfiles.add(profile);
                }
            }
        }
        return connectableProfiles;
        return accessibleProfiles;
    }

    public List<LocalBluetoothProfile> getRemovedProfiles() {
+2 −2
Original line number Diff line number Diff line
@@ -261,9 +261,9 @@ public class CsipDeviceManager {
        }

        CachedBluetoothDevice dualModeDevice = groupDevicesList.stream()
                .filter(cachedDevice -> cachedDevice.getConnectableProfiles().stream()
                .filter(cachedDevice -> cachedDevice.getUiAccessibleProfiles().stream()
                        .anyMatch(profile -> profile instanceof LeAudioProfile))
                .filter(cachedDevice -> cachedDevice.getConnectableProfiles().stream()
                .filter(cachedDevice -> cachedDevice.getUiAccessibleProfiles().stream()
                        .anyMatch(profile -> profile instanceof A2dpProfile
                                || profile instanceof HeadsetProfile))
                .findFirst().orElse(null);
+1 −1
Original line number Diff line number Diff line
@@ -634,7 +634,7 @@ public class LocalMediaManager implements BluetoothCallback {
        }

        private boolean isMediaDevice(CachedBluetoothDevice device) {
            for (LocalBluetoothProfile profile : device.getConnectableProfiles()) {
            for (LocalBluetoothProfile profile : device.getUiAccessibleProfiles()) {
                if (profile instanceof A2dpProfile || profile instanceof HearingAidProfile ||
                        profile instanceof LeAudioProfile) {
                    return true;
+4 −4
Original line number Diff line number Diff line
@@ -145,18 +145,18 @@ public class CsipDeviceManagerTest {
        profiles.add(mHfpProfile);
        profiles.add(mA2dpProfile);
        profiles.add(mLeAudioProfile);
        when(mCachedDevice1.getConnectableProfiles()).thenReturn(profiles);
        when(mCachedDevice1.getUiAccessibleProfiles()).thenReturn(profiles);
        when(mCachedDevice1.isConnected()).thenReturn(true);

        profiles.clear();
        profiles.add(mLeAudioProfile);
        when(mCachedDevice2.getConnectableProfiles()).thenReturn(profiles);
        when(mCachedDevice2.getUiAccessibleProfiles()).thenReturn(profiles);
        when(mCachedDevice2.isConnected()).thenReturn(true);

        profiles.clear();
        profiles.add(mHfpProfile);
        profiles.add(mA2dpProfile);
        when(mCachedDevice3.getConnectableProfiles()).thenReturn(profiles);
        when(mCachedDevice3.getUiAccessibleProfiles()).thenReturn(profiles);
        when(mCachedDevice3.isConnected()).thenReturn(true);
    }

@@ -253,7 +253,7 @@ public class CsipDeviceManagerTest {
        when(mDevice2.isConnected()).thenReturn(false);
        List<LocalBluetoothProfile> profiles = new ArrayList<LocalBluetoothProfile>();
        profiles.add(mLeAudioProfile);
        when(mCachedDevice1.getConnectableProfiles()).thenReturn(profiles);
        when(mCachedDevice1.getUiAccessibleProfiles()).thenReturn(profiles);
        CachedBluetoothDevice expectedDevice = mCachedDevice1;

        assertThat(
+1 −1
Original line number Diff line number Diff line
@@ -470,7 +470,7 @@ public class LocalMediaManagerTest {
        when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice);
        when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
        when(cachedDevice.isConnected()).thenReturn(false);
        when(cachedDevice.getConnectableProfiles()).thenReturn(profiles);
        when(cachedDevice.getUiAccessibleProfiles()).thenReturn(profiles);
        when(cachedDevice.getDevice()).thenReturn(bluetoothDevice);
        when(cachedDevice.getAddress()).thenReturn(TEST_ADDRESS);
        when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice);
Loading