From 3caa8ad8f090aea33203b7b76077940702b01e81 Mon Sep 17 00:00:00 2001 From: changbetty Date: Wed, 21 Dec 2022 09:17:39 +0000 Subject: [PATCH] To check the bond state when get the connection state Bug: 251973679 Test: manual test Change-Id: I1e637bf5accbc5706f9d8a6f557a4fe038dae66b --- .../settings/bluetooth/BluetoothDevicePreference.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java index d90e394d0b9..751a168beeb 100644 --- a/src/com/android/settings/bluetooth/BluetoothDevicePreference.java +++ b/src/com/android/settings/bluetooth/BluetoothDevicePreference.java @@ -190,9 +190,8 @@ public final class BluetoothDevicePreference extends GearPreference { setTitle(mCachedDevice.getName()); try { ThreadUtils.postOnBackgroundThread(() -> { - String summary = mCachedDevice.getConnectionSummary(); // Null check is done at the framework - ThreadUtils.postOnMainThread(() -> setSummary(summary)); + ThreadUtils.postOnMainThread(() -> setSummary(getConnectionSummary())); }); } catch (RejectedExecutionException e) { Log.w(TAG, "Handler thread unavailable, skipping getConnectionSummary!"); @@ -319,4 +318,12 @@ public final class BluetoothDevicePreference extends GearPreference { R.string.bluetooth_pairing_error_message); } } + + private String getConnectionSummary() { + String summary = null; + if (mCachedDevice.getBondState() != BluetoothDevice.BOND_NONE) { + summary = mCachedDevice.getConnectionSummary(); + } + return summary; + } }