From c16970217d8ec1242db2e0591e7a49ee1c6b6d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Fri, 19 May 2023 12:09:33 +0000 Subject: [PATCH] bt: Fix displaying late bond device name In a case when we are pairing set members the action SET_MEMBER_AVAILABLE may come before advertising information was able to arrive to Java layer and thus the information like device name was not cached and is not available for the new set member device. In this case we want to use the first set member device's name to have some name displayed to the user instead of an address. Bug: 282193044 Test: manual Tag: #feature Change-Id: I25eb50702f8c41cd5917cf9ea29eb0c3c17d2bd5 --- .../bluetooth/CachedBluetoothDeviceManager.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java index 0db88af92a568..0c1b793102bfb 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDeviceManager.java @@ -51,6 +51,7 @@ public class CachedBluetoothDeviceManager { CsipDeviceManager mCsipDeviceManager; BluetoothDevice mOngoingSetMemberPair; boolean mIsLateBonding; + int mGroupIdOfLateBonding; public CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) { mContext = context; @@ -213,6 +214,14 @@ public class CachedBluetoothDeviceManager { * @return The name, or if unavailable, the address. */ public String getName(BluetoothDevice device) { + if (isOngoingPairByCsip(device)) { + CachedBluetoothDevice firstDevice = + mCsipDeviceManager.getFirstMemberDevice(mGroupIdOfLateBonding); + if (firstDevice != null && firstDevice.getName() != null) { + return firstDevice.getName(); + } + } + CachedBluetoothDevice cachedDevice = findDevice(device); if (cachedDevice != null && cachedDevice.getName() != null) { return cachedDevice.getName(); @@ -314,6 +323,7 @@ public class CachedBluetoothDeviceManager { // To clear the SetMemberPair flag when the Bluetooth is turning off. mOngoingSetMemberPair = null; mIsLateBonding = false; + mGroupIdOfLateBonding = BluetoothCsipSetCoordinator.GROUP_ID_INVALID; } } @@ -426,6 +436,7 @@ public class CachedBluetoothDeviceManager { return false; } + Log.d(TAG, "isLateBonding: " + mIsLateBonding); return mIsLateBonding; } @@ -444,11 +455,13 @@ public class CachedBluetoothDeviceManager { Log.d(TAG, "Bond " + device.getAnonymizedAddress() + " groupId=" + groupId + " by CSIP "); mOngoingSetMemberPair = device; mIsLateBonding = checkLateBonding(groupId); + mGroupIdOfLateBonding = groupId; syncConfigFromMainDevice(device, groupId); if (!device.createBond(BluetoothDevice.TRANSPORT_LE)) { Log.d(TAG, "Bonding could not be started"); mOngoingSetMemberPair = null; mIsLateBonding = false; + mGroupIdOfLateBonding = BluetoothCsipSetCoordinator.GROUP_ID_INVALID; } } @@ -494,6 +507,7 @@ public class CachedBluetoothDeviceManager { mOngoingSetMemberPair = null; mIsLateBonding = false; + mGroupIdOfLateBonding = BluetoothCsipSetCoordinator.GROUP_ID_INVALID; if (bondState != BluetoothDevice.BOND_NONE) { if (findDevice(device) == null) { final LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();