Loading packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ import java.util.concurrent.Executors; public class InfoMediaManager extends MediaManager { private static final String TAG = "InfoMediaManager"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @VisibleForTesting final RouterManagerCallback mMediaRouterCallback = new RouterManagerCallback(); @VisibleForTesting Loading packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +18 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR; import android.app.Notification; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.RoutingSessionInfo; import android.text.TextUtils; Loading Loading @@ -409,7 +408,8 @@ public class LocalMediaManager implements BluetoothCallback { synchronized (mMediaDevicesLock) { for (MediaDevice device : mMediaDevices) { if (device instanceof BluetoothMediaDevice) { if (isActiveDevice(((BluetoothMediaDevice) device).getCachedDevice())) { if (isActiveDevice(((BluetoothMediaDevice) device).getCachedDevice()) && device.isConnected()) { return device; } } else if (device instanceof PhoneMediaDevice) { Loading @@ -422,8 +422,22 @@ public class LocalMediaManager implements BluetoothCallback { } private boolean isActiveDevice(CachedBluetoothDevice device) { return device.isActiveDevice(BluetoothProfile.A2DP) || device.isActiveDevice(BluetoothProfile.HEARING_AID); boolean isActiveDeviceA2dp = false; boolean isActiveDeviceHearingAid = false; final A2dpProfile a2dpProfile = mLocalBluetoothManager.getProfileManager().getA2dpProfile(); if (a2dpProfile != null) { isActiveDeviceA2dp = device.getDevice().equals(a2dpProfile.getActiveDevice()); } if (!isActiveDeviceA2dp) { final HearingAidProfile hearingAidProfile = mLocalBluetoothManager.getProfileManager() .getHearingAidProfile(); if (hearingAidProfile != null) { isActiveDeviceHearingAid = hearingAidProfile.getActiveDevices().contains(device.getDevice()); } } return isActiveDeviceA2dp || isActiveDeviceHearingAid; } private Collection<DeviceCallback> getCallbacks() { Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -578,6 +578,9 @@ public class LocalMediaManagerTest { when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); Loading Loading @@ -734,11 +737,19 @@ public class LocalMediaManagerTest { final PhoneMediaDevice phoneDevice = mock(PhoneMediaDevice.class); final CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class); final BluetoothDevice bluetoothDevice1 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice2); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getCachedDevice()).thenReturn(cachedDevice1); when(device2.getCachedDevice()).thenReturn(cachedDevice2); when(cachedDevice1.getDevice()).thenReturn(bluetoothDevice1); when(cachedDevice2.getDevice()).thenReturn(bluetoothDevice2); when(cachedDevice1.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(cachedDevice2.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(true); when(device1.isConnected()).thenReturn(true); when(device2.isConnected()).thenReturn(true); mLocalMediaManager.mMediaDevices.add(device1); mLocalMediaManager.mMediaDevices.add(phoneDevice); Loading @@ -754,11 +765,19 @@ public class LocalMediaManagerTest { final PhoneMediaDevice phoneDevice = mock(PhoneMediaDevice.class); final CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class); final BluetoothDevice bluetoothDevice1 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); when(mA2dpProfile.getActiveDevice()).thenReturn(null); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getCachedDevice()).thenReturn(cachedDevice1); when(device2.getCachedDevice()).thenReturn(cachedDevice2); when(cachedDevice1.getDevice()).thenReturn(bluetoothDevice1); when(cachedDevice2.getDevice()).thenReturn(bluetoothDevice2); when(cachedDevice1.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(cachedDevice2.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(device1.isConnected()).thenReturn(true); when(device2.isConnected()).thenReturn(true); mLocalMediaManager.mMediaDevices.add(device1); mLocalMediaManager.mMediaDevices.add(phoneDevice); Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/InfoMediaManager.java +1 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ import java.util.concurrent.Executors; public class InfoMediaManager extends MediaManager { private static final String TAG = "InfoMediaManager"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @VisibleForTesting final RouterManagerCallback mMediaRouterCallback = new RouterManagerCallback(); @VisibleForTesting Loading
packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +18 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR; import android.app.Notification; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; import android.media.RoutingSessionInfo; import android.text.TextUtils; Loading Loading @@ -409,7 +408,8 @@ public class LocalMediaManager implements BluetoothCallback { synchronized (mMediaDevicesLock) { for (MediaDevice device : mMediaDevices) { if (device instanceof BluetoothMediaDevice) { if (isActiveDevice(((BluetoothMediaDevice) device).getCachedDevice())) { if (isActiveDevice(((BluetoothMediaDevice) device).getCachedDevice()) && device.isConnected()) { return device; } } else if (device instanceof PhoneMediaDevice) { Loading @@ -422,8 +422,22 @@ public class LocalMediaManager implements BluetoothCallback { } private boolean isActiveDevice(CachedBluetoothDevice device) { return device.isActiveDevice(BluetoothProfile.A2DP) || device.isActiveDevice(BluetoothProfile.HEARING_AID); boolean isActiveDeviceA2dp = false; boolean isActiveDeviceHearingAid = false; final A2dpProfile a2dpProfile = mLocalBluetoothManager.getProfileManager().getA2dpProfile(); if (a2dpProfile != null) { isActiveDeviceA2dp = device.getDevice().equals(a2dpProfile.getActiveDevice()); } if (!isActiveDeviceA2dp) { final HearingAidProfile hearingAidProfile = mLocalBluetoothManager.getProfileManager() .getHearingAidProfile(); if (hearingAidProfile != null) { isActiveDeviceHearingAid = hearingAidProfile.getActiveDevices().contains(device.getDevice()); } } return isActiveDeviceA2dp || isActiveDeviceHearingAid; } private Collection<DeviceCallback> getCallbacks() { Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -578,6 +578,9 @@ public class LocalMediaManagerTest { when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); Loading Loading @@ -734,11 +737,19 @@ public class LocalMediaManagerTest { final PhoneMediaDevice phoneDevice = mock(PhoneMediaDevice.class); final CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class); final BluetoothDevice bluetoothDevice1 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice2); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getCachedDevice()).thenReturn(cachedDevice1); when(device2.getCachedDevice()).thenReturn(cachedDevice2); when(cachedDevice1.getDevice()).thenReturn(bluetoothDevice1); when(cachedDevice2.getDevice()).thenReturn(bluetoothDevice2); when(cachedDevice1.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(cachedDevice2.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(true); when(device1.isConnected()).thenReturn(true); when(device2.isConnected()).thenReturn(true); mLocalMediaManager.mMediaDevices.add(device1); mLocalMediaManager.mMediaDevices.add(phoneDevice); Loading @@ -754,11 +765,19 @@ public class LocalMediaManagerTest { final PhoneMediaDevice phoneDevice = mock(PhoneMediaDevice.class); final CachedBluetoothDevice cachedDevice1 = mock(CachedBluetoothDevice.class); final CachedBluetoothDevice cachedDevice2 = mock(CachedBluetoothDevice.class); final BluetoothDevice bluetoothDevice1 = mock(BluetoothDevice.class); final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); when(mA2dpProfile.getActiveDevice()).thenReturn(null); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getCachedDevice()).thenReturn(cachedDevice1); when(device2.getCachedDevice()).thenReturn(cachedDevice2); when(cachedDevice1.getDevice()).thenReturn(bluetoothDevice1); when(cachedDevice2.getDevice()).thenReturn(bluetoothDevice2); when(cachedDevice1.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(cachedDevice2.isActiveDevice(BluetoothProfile.A2DP)).thenReturn(false); when(device1.isConnected()).thenReturn(true); when(device2.isConnected()).thenReturn(true); mLocalMediaManager.mMediaDevices.add(device1); mLocalMediaManager.mMediaDevices.add(phoneDevice); Loading