From 3ca9ef8edca0c7c608c9735316035392a3ab10d2 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Thu, 18 Jan 2024 06:56:36 +0000 Subject: [PATCH] New hearing device pairing page: check gatt status Checks the gatt status in `onConnectionStateChange()` and `onServiceDiscovered()` callbacks. Disconnects and removes the gatt from the `mConnectingGattList` if the gatt status is not success in these callbacks. Bug: 307890347 Test: manual test Change-Id: Iab09f13b2ff3d33e5c4d6a8710736307c26b17e7 --- .../HearingDevicePairingFragment.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/accessibility/HearingDevicePairingFragment.java b/src/com/android/settings/accessibility/HearingDevicePairingFragment.java index 78f5b4c1b6e..e9ea71a0330 100644 --- a/src/com/android/settings/accessibility/HearingDevicePairingFragment.java +++ b/src/com/android/settings/accessibility/HearingDevicePairingFragment.java @@ -17,6 +17,7 @@ package com.android.settings.accessibility; import static android.app.Activity.RESULT_OK; +import static android.bluetooth.BluetoothGatt.GATT_SUCCESS; import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH; import android.app.settings.SettingsEnums; @@ -461,24 +462,33 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im Log.d(TAG, "onConnectionStateChange, status: " + status + ", newState: " + newState + ", device: " + cachedDevice); } - if (newState == BluetoothProfile.STATE_CONNECTED) { + if (status == GATT_SUCCESS + && newState == BluetoothProfile.STATE_CONNECTED) { gatt.discoverServices(); + } else { + gatt.disconnect(); + mConnectingGattList.remove(gatt); } } @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); - boolean isCompatible = gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) - != null - || gatt.getService(BluetoothUuid.HAS.getUuid()) != null; if (DEBUG) { - Log.d(TAG, - "onServicesDiscovered, compatible with Android: " + isCompatible - + ", device: " + cachedDevice); + Log.d(TAG, "onServicesDiscovered, status: " + status + ", device: " + + cachedDevice); } - if (isCompatible) { - addDevice(cachedDevice); + if (status == GATT_SUCCESS) { + if (gatt.getService(BluetoothUuid.HEARING_AID.getUuid()) != null + || gatt.getService(BluetoothUuid.HAS.getUuid()) != null) { + if (DEBUG) { + Log.d(TAG, "compatible with Android, device: " + cachedDevice); + } + addDevice(cachedDevice); + } + } else { + gatt.disconnect(); + mConnectingGattList.remove(gatt); } } });