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