diff options
| author | 2020-05-06 15:08:29 +0800 | |
|---|---|---|
| committer | 2020-05-06 15:08:29 +0800 | |
| commit | 81efaa51ef0bbd505aa30da3efb5c04ce89cfb54 (patch) | |
| tree | 13d4d0fd073dc987424ae3a9e4d53a8bf0eb2613 | |
| parent | 0cbca1a253a8972991321ba268d19f6357c71963 (diff) | |
Filter out non-a2dp or non-hearing Aid bluetooth device
- This CL before, disconnect group will show all disconnected
device which will confuse user because output switcher only
support a2dp or hearing aid device to transfer.
This CL will filter out non-a2dp and non-hearing aid bluetooth
device in disconnected group.
- Add test case
Bug: 154962266
Test: make -j42 RunSettingsLibRoboTests
Change-Id: Ifa927970b19a7cf7b32fcbe2093b285c718ba94f
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java | 15 | ||||
| -rw-r--r-- | packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java | 11 |
2 files changed, 25 insertions, 1 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java index 31ea5b40d756..887a49b95279 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java @@ -27,10 +27,13 @@ import android.util.Log; import androidx.annotation.IntDef; import com.android.internal.annotations.VisibleForTesting; +import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; +import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; +import com.android.settingslib.bluetooth.LocalBluetoothProfile; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -430,7 +433,8 @@ public class LocalMediaManager implements BluetoothCallback { cachedDeviceManager.findDevice(device); if (cachedDevice != null) { if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED - && !cachedDevice.isConnected()) { + && !cachedDevice.isConnected() + && isA2dpOrHearingAidDevice(cachedDevice)) { deviceCount++; cachedBluetoothDeviceList.add(cachedDevice); if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) { @@ -454,6 +458,15 @@ public class LocalMediaManager implements BluetoothCallback { return new ArrayList<>(mDisconnectedMediaDevices); } + private boolean isA2dpOrHearingAidDevice(CachedBluetoothDevice device) { + for (LocalBluetoothProfile profile : device.getConnectableProfiles()) { + if (profile instanceof A2dpProfile || profile instanceof HearingAidProfile) { + return true; + } + } + return false; + } + @Override public void onDeviceRemoved(MediaDevice device) { if (mMediaDevices.contains(device)) { diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java index 77316e91bae2..365a16c50b99 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java @@ -41,6 +41,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; +import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; @@ -560,6 +561,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); + final List<LocalBluetoothProfile> profiles = new ArrayList<>(); + final A2dpProfile a2dpProfile = mock(A2dpProfile.class); + profiles.add(a2dpProfile); + final List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); @@ -571,6 +576,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(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); @@ -634,6 +640,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); + final List<LocalBluetoothProfile> profiles = new ArrayList<>(); + final A2dpProfile a2dpProfile = mock(A2dpProfile.class); + profiles.add(a2dpProfile); + final List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); @@ -662,6 +672,7 @@ public class LocalMediaManagerTest { when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); + when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); |