Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +19 −19 Original line number Diff line number Diff line Loading @@ -230,30 +230,30 @@ public class BluetoothEventManager { @VisibleForTesting void dispatchActiveDeviceChanged( @Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) { @Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) { CachedBluetoothDevice targetDevice = activeDevice; for (CachedBluetoothDevice cachedDevice : mDeviceManager.getCachedDevicesCopy()) { Set<CachedBluetoothDevice> memberSet = cachedDevice.getMemberDevice(); boolean isActive = Objects.equals(cachedDevice, activeDevice); if (!isActive && !memberSet.isEmpty()) { for (CachedBluetoothDevice memberCachedDevice : memberSet) { isActive = Objects.equals(memberCachedDevice, activeDevice); if (isActive) { // should report isActive from main device or it will cause trouble to other callers. CachedBluetoothDevice subDevice = cachedDevice.getSubDevice(); CachedBluetoothDevice finalTargetDevice = targetDevice; if (targetDevice != null && ((subDevice != null && subDevice.equals(targetDevice)) || cachedDevice.getMemberDevice().stream().anyMatch( memberDevice -> memberDevice.equals(finalTargetDevice)))) { Log.d(TAG, "The active device is the member device " + activeDevice.getDevice().getAnonymizedAddress() + ". change activeDevice as main device " "The active device is the sub/member device " + targetDevice.getDevice().getAnonymizedAddress() + ". change targetDevice as main device " + cachedDevice.getDevice().getAnonymizedAddress()); activeDevice = cachedDevice; break; } targetDevice = cachedDevice; } } cachedDevice.onActiveDeviceChanged(isActive, bluetoothProfile); boolean isActiveDevice = cachedDevice.equals(targetDevice); cachedDevice.onActiveDeviceChanged(isActiveDevice, bluetoothProfile); mDeviceManager.onActiveDeviceChanged(cachedDevice); } for (BluetoothCallback callback : mCallbacks) { callback.onActiveDeviceChanged(activeDevice, bluetoothProfile); callback.onActiveDeviceChanged(targetDevice, bluetoothProfile); } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -411,6 +411,21 @@ public class BluetoothEventManagerTest { BluetoothProfile.HEARING_AID); } @Test public void dispatchActiveDeviceChanged_activeFromSubDevice_mainCachedDeviceActive() { CachedBluetoothDevice subDevice = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice3); mCachedDevice1.setSubDevice(subDevice); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( Collections.singletonList(mCachedDevice1)); mCachedDevice1.onProfileStateChanged(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); mBluetoothEventManager.dispatchActiveDeviceChanged(subDevice, BluetoothProfile.HEARING_AID); assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).isTrue(); } @Test public void showUnbondMessage_reasonAuthTimeout_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); Loading Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java +19 −19 Original line number Diff line number Diff line Loading @@ -230,30 +230,30 @@ public class BluetoothEventManager { @VisibleForTesting void dispatchActiveDeviceChanged( @Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) { @Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) { CachedBluetoothDevice targetDevice = activeDevice; for (CachedBluetoothDevice cachedDevice : mDeviceManager.getCachedDevicesCopy()) { Set<CachedBluetoothDevice> memberSet = cachedDevice.getMemberDevice(); boolean isActive = Objects.equals(cachedDevice, activeDevice); if (!isActive && !memberSet.isEmpty()) { for (CachedBluetoothDevice memberCachedDevice : memberSet) { isActive = Objects.equals(memberCachedDevice, activeDevice); if (isActive) { // should report isActive from main device or it will cause trouble to other callers. CachedBluetoothDevice subDevice = cachedDevice.getSubDevice(); CachedBluetoothDevice finalTargetDevice = targetDevice; if (targetDevice != null && ((subDevice != null && subDevice.equals(targetDevice)) || cachedDevice.getMemberDevice().stream().anyMatch( memberDevice -> memberDevice.equals(finalTargetDevice)))) { Log.d(TAG, "The active device is the member device " + activeDevice.getDevice().getAnonymizedAddress() + ". change activeDevice as main device " "The active device is the sub/member device " + targetDevice.getDevice().getAnonymizedAddress() + ". change targetDevice as main device " + cachedDevice.getDevice().getAnonymizedAddress()); activeDevice = cachedDevice; break; } targetDevice = cachedDevice; } } cachedDevice.onActiveDeviceChanged(isActive, bluetoothProfile); boolean isActiveDevice = cachedDevice.equals(targetDevice); cachedDevice.onActiveDeviceChanged(isActiveDevice, bluetoothProfile); mDeviceManager.onActiveDeviceChanged(cachedDevice); } for (BluetoothCallback callback : mCallbacks) { callback.onActiveDeviceChanged(activeDevice, bluetoothProfile); callback.onActiveDeviceChanged(targetDevice, bluetoothProfile); } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothEventManagerTest.java +15 −0 Original line number Diff line number Diff line Loading @@ -411,6 +411,21 @@ public class BluetoothEventManagerTest { BluetoothProfile.HEARING_AID); } @Test public void dispatchActiveDeviceChanged_activeFromSubDevice_mainCachedDeviceActive() { CachedBluetoothDevice subDevice = new CachedBluetoothDevice(mContext, mLocalProfileManager, mDevice3); mCachedDevice1.setSubDevice(subDevice); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( Collections.singletonList(mCachedDevice1)); mCachedDevice1.onProfileStateChanged(mHearingAidProfile, BluetoothProfile.STATE_CONNECTED); assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).isFalse(); mBluetoothEventManager.dispatchActiveDeviceChanged(subDevice, BluetoothProfile.HEARING_AID); assertThat(mCachedDevice1.isActiveDevice(BluetoothProfile.HEARING_AID)).isTrue(); } @Test public void showUnbondMessage_reasonAuthTimeout_showCorrectedErrorCode() { mIntent = new Intent(BluetoothDevice.ACTION_BOND_STATE_CHANGED); Loading