Loading packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +14 −1 Original line number Original line Diff line number Diff line Loading @@ -27,10 +27,13 @@ import android.util.Log; import androidx.annotation.IntDef; import androidx.annotation.IntDef; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading Loading @@ -430,7 +433,8 @@ public class LocalMediaManager implements BluetoothCallback { cachedDeviceManager.findDevice(device); cachedDeviceManager.findDevice(device); if (cachedDevice != null) { if (cachedDevice != null) { if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED && !cachedDevice.isConnected()) { && !cachedDevice.isConnected() && isA2dpOrHearingAidDevice(cachedDevice)) { deviceCount++; deviceCount++; cachedBluetoothDeviceList.add(cachedDevice); cachedBluetoothDeviceList.add(cachedDevice); if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) { if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) { Loading @@ -454,6 +458,15 @@ public class LocalMediaManager implements BluetoothCallback { return new ArrayList<>(mDisconnectedMediaDevices); 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 @Override public void onDeviceRemoved(MediaDevice device) { public void onDeviceRemoved(MediaDevice device) { if (mMediaDevices.contains(device)) { if (mMediaDevices.contains(device)) { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; Loading Loading @@ -560,6 +561,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); 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 List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); Loading @@ -571,6 +576,7 @@ public class LocalMediaManagerTest { when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); Loading Loading @@ -634,6 +640,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); 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 List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); Loading Loading @@ -662,6 +672,7 @@ public class LocalMediaManagerTest { when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +14 −1 Original line number Original line Diff line number Diff line Loading @@ -27,10 +27,13 @@ import android.util.Log; import androidx.annotation.IntDef; import androidx.annotation.IntDef; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting; import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.BluetoothCallback; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import java.lang.annotation.Retention; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy; Loading Loading @@ -430,7 +433,8 @@ public class LocalMediaManager implements BluetoothCallback { cachedDeviceManager.findDevice(device); cachedDeviceManager.findDevice(device); if (cachedDevice != null) { if (cachedDevice != null) { if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED && !cachedDevice.isConnected()) { && !cachedDevice.isConnected() && isA2dpOrHearingAidDevice(cachedDevice)) { deviceCount++; deviceCount++; cachedBluetoothDeviceList.add(cachedDevice); cachedBluetoothDeviceList.add(cachedDevice); if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) { if (deviceCount >= MAX_DISCONNECTED_DEVICE_NUM) { Loading @@ -454,6 +458,15 @@ public class LocalMediaManager implements BluetoothCallback { return new ArrayList<>(mDisconnectedMediaDevices); 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 @Override public void onDeviceRemoved(MediaDevice device) { public void onDeviceRemoved(MediaDevice device) { if (mMediaDevices.contains(device)) { if (mMediaDevices.contains(device)) { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +11 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; import com.android.settingslib.testutils.shadow.ShadowBluetoothAdapter; Loading Loading @@ -560,6 +561,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); 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 List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); Loading @@ -571,6 +576,7 @@ public class LocalMediaManagerTest { when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); Loading Loading @@ -634,6 +640,10 @@ public class LocalMediaManagerTest { mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(device3); mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); 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 List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); Loading Loading @@ -662,6 +672,7 @@ public class LocalMediaManagerTest { when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); Loading