Loading packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaManager.java +18 −17 Original line number Diff line number Diff line Loading @@ -126,10 +126,13 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall return; } final List<Long> devicesHiSyncIds = new ArrayList<>(); final List<BluetoothDevice> devices = hapProfile.getConnectableDevices(); for (BluetoothDevice device : devices) { // Only add master HearingAid device, ignore sub if (mCachedBluetoothDeviceManager.isSubDevice(device)) { Log.w(TAG, "Sub hearingAid device: " + device.getName()); continue; } final CachedBluetoothDevice cachedDevice = mCachedBluetoothDeviceManager.findDevice(device); Loading @@ -142,13 +145,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall + ", is connected : " + cachedDevice.isConnected() + ", is preferred : " + hapProfile.isPreferred(device)); final long hiSyncId = hapProfile.getHiSyncId(device); // device with same hiSyncId should not be shown in the UI. // So do not add it into connectedDevices. if (!devicesHiSyncIds.contains(hiSyncId) && hapProfile.isPreferred(device) if (hapProfile.isPreferred(device) && BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) { devicesHiSyncIds.add(hiSyncId); addMediaDevice(cachedDevice); } } Loading Loading @@ -284,9 +282,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall + activeDevice + ", profile : " + bluetoothProfile); if (BluetoothProfile.HEARING_AID == bluetoothProfile) { if (activeDevice != null) { dispatchConnectedDeviceChanged(MediaDeviceUtils.getId(activeDevice)); } dispatchConnectedDeviceChanged(activeDevice == null ? PhoneMediaDevice.ID : MediaDeviceUtils.getId(activeDevice)); } else if (BluetoothProfile.A2DP == bluetoothProfile) { // When active device change to Hearing Aid, // BluetoothEventManager also send onActiveDeviceChanged() to notify that active device Loading @@ -304,12 +301,16 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall private MediaDevice findActiveHearingAidDevice() { final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile(); if (hearingAidProfile != null) { if (hearingAidProfile == null) { Log.e(TAG, "findActiveHearingAidDevice: hearingAidProfile == null"); return null; } final List<BluetoothDevice> activeDevices = hearingAidProfile.getActiveDevices(); for (BluetoothDevice btDevice : activeDevices) { if (btDevice != null) { return findMediaDevice(MediaDeviceUtils.getId(btDevice)); } final MediaDevice mediaDevice = findMediaDevice(Long.toString(hearingAidProfile.getHiSyncId(btDevice))); if (mediaDevice != null) { return mediaDevice; } } return null; Loading packages/SettingsLib/src/com/android/settingslib/media/MediaDeviceUtils.java +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ public class MediaDeviceUtils { * @return CachedBluetoothDevice address */ public static String getId(CachedBluetoothDevice cachedDevice) { if (cachedDevice.isHearingAidDevice()) { return Long.toString(cachedDevice.getHiSyncId()); } return cachedDevice.getAddress(); } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaManagerTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -428,20 +428,21 @@ public class BluetoothMediaManagerTest { @Test public void onActiveDeviceChanged_hearingAidDeviceIsActive_returnHearingAidDeviceId() { final Long hiSyncId = Integer.toUnsignedLong(12345); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final List<BluetoothDevice> devices = new ArrayList<>(); devices.add(bluetoothDevice); final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class); mMediaManager.mMediaDevices.add(bluetoothMediaDevice); when(bluetoothDevice.getAddress()).thenReturn(TEST_ADDRESS); when(mHapProfile.getHiSyncId(bluetoothDevice)).thenReturn(hiSyncId); when(mHapProfile.getActiveDevices()).thenReturn(devices); when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS); when(bluetoothMediaDevice.getId()).thenReturn(Long.toString(hiSyncId)); mMediaManager.registerCallback(mCallback); mMediaManager.onActiveDeviceChanged(null, BluetoothProfile.A2DP); verify(mCallback).onConnectedDeviceChanged(TEST_ADDRESS); verify(mCallback).onConnectedDeviceChanged(Long.toString(hiSyncId)); } @Test Loading Loading
packages/SettingsLib/src/com/android/settingslib/media/BluetoothMediaManager.java +18 −17 Original line number Diff line number Diff line Loading @@ -126,10 +126,13 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall return; } final List<Long> devicesHiSyncIds = new ArrayList<>(); final List<BluetoothDevice> devices = hapProfile.getConnectableDevices(); for (BluetoothDevice device : devices) { // Only add master HearingAid device, ignore sub if (mCachedBluetoothDeviceManager.isSubDevice(device)) { Log.w(TAG, "Sub hearingAid device: " + device.getName()); continue; } final CachedBluetoothDevice cachedDevice = mCachedBluetoothDeviceManager.findDevice(device); Loading @@ -142,13 +145,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall + ", is connected : " + cachedDevice.isConnected() + ", is preferred : " + hapProfile.isPreferred(device)); final long hiSyncId = hapProfile.getHiSyncId(device); // device with same hiSyncId should not be shown in the UI. // So do not add it into connectedDevices. if (!devicesHiSyncIds.contains(hiSyncId) && hapProfile.isPreferred(device) if (hapProfile.isPreferred(device) && BluetoothDevice.BOND_BONDED == cachedDevice.getBondState()) { devicesHiSyncIds.add(hiSyncId); addMediaDevice(cachedDevice); } } Loading Loading @@ -284,9 +282,8 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall + activeDevice + ", profile : " + bluetoothProfile); if (BluetoothProfile.HEARING_AID == bluetoothProfile) { if (activeDevice != null) { dispatchConnectedDeviceChanged(MediaDeviceUtils.getId(activeDevice)); } dispatchConnectedDeviceChanged(activeDevice == null ? PhoneMediaDevice.ID : MediaDeviceUtils.getId(activeDevice)); } else if (BluetoothProfile.A2DP == bluetoothProfile) { // When active device change to Hearing Aid, // BluetoothEventManager also send onActiveDeviceChanged() to notify that active device Loading @@ -304,12 +301,16 @@ public class BluetoothMediaManager extends MediaManager implements BluetoothCall private MediaDevice findActiveHearingAidDevice() { final HearingAidProfile hearingAidProfile = mProfileManager.getHearingAidProfile(); if (hearingAidProfile != null) { if (hearingAidProfile == null) { Log.e(TAG, "findActiveHearingAidDevice: hearingAidProfile == null"); return null; } final List<BluetoothDevice> activeDevices = hearingAidProfile.getActiveDevices(); for (BluetoothDevice btDevice : activeDevices) { if (btDevice != null) { return findMediaDevice(MediaDeviceUtils.getId(btDevice)); } final MediaDevice mediaDevice = findMediaDevice(Long.toString(hearingAidProfile.getHiSyncId(btDevice))); if (mediaDevice != null) { return mediaDevice; } } return null; Loading
packages/SettingsLib/src/com/android/settingslib/media/MediaDeviceUtils.java +3 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,9 @@ public class MediaDeviceUtils { * @return CachedBluetoothDevice address */ public static String getId(CachedBluetoothDevice cachedDevice) { if (cachedDevice.isHearingAidDevice()) { return Long.toString(cachedDevice.getHiSyncId()); } return cachedDevice.getAddress(); } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/BluetoothMediaManagerTest.java +4 −3 Original line number Diff line number Diff line Loading @@ -428,20 +428,21 @@ public class BluetoothMediaManagerTest { @Test public void onActiveDeviceChanged_hearingAidDeviceIsActive_returnHearingAidDeviceId() { final Long hiSyncId = Integer.toUnsignedLong(12345); final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); final List<BluetoothDevice> devices = new ArrayList<>(); devices.add(bluetoothDevice); final BluetoothMediaDevice bluetoothMediaDevice = mock(BluetoothMediaDevice.class); mMediaManager.mMediaDevices.add(bluetoothMediaDevice); when(bluetoothDevice.getAddress()).thenReturn(TEST_ADDRESS); when(mHapProfile.getHiSyncId(bluetoothDevice)).thenReturn(hiSyncId); when(mHapProfile.getActiveDevices()).thenReturn(devices); when(bluetoothMediaDevice.getId()).thenReturn(TEST_ADDRESS); when(bluetoothMediaDevice.getId()).thenReturn(Long.toString(hiSyncId)); mMediaManager.registerCallback(mCallback); mMediaManager.onActiveDeviceChanged(null, BluetoothProfile.A2DP); verify(mCallback).onConnectedDeviceChanged(TEST_ADDRESS); verify(mCallback).onConnectedDeviceChanged(Long.toString(hiSyncId)); } @Test Loading