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

Commit 6293d2a1 authored by SongFerng Wang's avatar SongFerng Wang Committed by Automerger Merge Worker
Browse files

Merge "The UI only shows the active LE device" into tm-d1-dev am: dc72a4a1 am: 0018589f

parents 257d3e0c 0018589f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
        }

        boolean isFilterMatched = false;
        if (isDeviceConnected(cachedDevice)) {
        if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
            if (DBG) {
                Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
            }
@@ -74,6 +74,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
            // It would show in Available Devices group.
            if (cachedDevice.isConnectedHearingAidDevice()
                    || cachedDevice.isConnectedLeAudioDevice()) {
                Log.d(TAG, "isFilterMatched() device : " +
                        cachedDevice.getName() + ", the profile is connected.");
                return true;
            }
            // According to the current audio profile type,
+4 −0
Original line number Diff line number Diff line
@@ -326,4 +326,8 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
            ((BluetoothDevicePreference) preference).onPreferenceAttributesChanged();
        }
    }

    protected boolean isDeviceInCachedDevicesList(CachedBluetoothDevice cachedDevice){
        return mLocalManager.getCachedDeviceManager().getCachedDevicesCopy().contains(cachedDevice);
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
        }

        boolean isFilterMatched = false;
        if (isDeviceConnected(cachedDevice)) {
        if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
            if (DBG) {
                Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
            }
+2 −1
Original line number Diff line number Diff line
@@ -106,7 +106,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
                    + cachedDevice.isConnected());
        }
        return device.getBondState() == BluetoothDevice.BOND_BONDED
                && (mDisplayConnected || !device.isConnected());
                && (mDisplayConnected || (!device.isConnected() && isDeviceInCachedDevicesList(
                cachedDevice)));
    }

    @Override
+30 −4
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        mShadowCachedBluetoothDeviceManager = Shadow.extract(
                Utils.getLocalBtManager(mContext).getCachedDeviceManager());
        mCachedDevices = new ArrayList<>();
        mCachedDevices.add(mCachedBluetoothDevice);
        mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
        Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");

@@ -109,7 +110,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        when(mBluetoothDeviceUpdater.
                isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
        mCachedDevices.add(mCachedBluetoothDevice);

        mBluetoothDeviceUpdater.onAudioModeChanged();

@@ -122,7 +122,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        when(mBluetoothDeviceUpdater.
                isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
        mCachedDevices.add(mCachedBluetoothDevice);

        mBluetoothDeviceUpdater.onAudioModeChanged();

@@ -135,7 +134,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        when(mBluetoothDeviceUpdater.
                isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
        mCachedDevices.add(mCachedBluetoothDevice);

        mBluetoothDeviceUpdater.onAudioModeChanged();

@@ -148,7 +146,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        when(mBluetoothDeviceUpdater.
                isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
        mCachedDevices.add(mCachedBluetoothDevice);

        mBluetoothDeviceUpdater.onAudioModeChanged();

@@ -260,6 +257,35 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
        verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
    }

    @Test
    public void
            onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovePreference() {
        mAudioManager.setMode(AudioManager.MODE_NORMAL);
        when(mBluetoothDeviceUpdater
                .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
        mCachedDevices.clear();

        mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
                BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);

        verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
    }

    @Test
    public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
        mAudioManager.setMode(AudioManager.MODE_IN_CALL);
        when(mBluetoothDeviceUpdater
                .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
        when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
        mCachedDevices.clear();

        mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
                BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);

        verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
    }

    @Test
    public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
        mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
Loading