Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f036938c authored by Christine Hallstrom's avatar Christine Hallstrom Committed by William Escande
Browse files

Unregister GATT client if closed before registration completes

If BluetoothGatt#close is called before onClientRegistered, ensure
unregisterClient is called once mClientIf is set and clientConnect is
not called in this scenario.

Test: atest BumbleBluetoothTests
Test: atest GattClientTest#directConnectGattAfterClose from aosp/2755825
Bug: 295587623
Change-Id: Ie949f0ac9fe6130b6d09793642835e2ef38e5bc9
parent 68d769dd
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -229,14 +229,24 @@ public final class BluetoothGatt implements BluetoothProfile {
                        Log.d(TAG, "onClientRegistered() - status=" + status
                                + " clientIf=" + clientIf);
                    }
                    if (VDBG) {
                    mClientIf = clientIf;
                    synchronized (mStateLock) {
                        if (mConnState == CONN_STATE_CLOSED) {
                            if (DBG) {
                                Log.d(
                                        TAG,
                                        "Client registration completed after closed,"
                                                + " unregistering");
                            }
                            unregisterApp();
                            return;
                        }
                        if (VDBG) {
                            if (mConnState != CONN_STATE_CONNECTING) {
                                Log.e(TAG, "Bad connection state: " + mConnState);
                            }
                        }
                    }
                    mClientIf = clientIf;
                    if (status != GATT_SUCCESS) {
                        runOrQueueCallback(new Runnable() {
                            @Override
@@ -1006,8 +1016,8 @@ public final class BluetoothGatt implements BluetoothProfile {
    @RequiresBluetoothConnectPermission
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    private void unregisterApp() {
        if (DBG) Log.d(TAG, "unregisterApp() - mClientIf=" + mClientIf);
        if (mService == null || mClientIf == 0) return;
        if (DBG) Log.d(TAG, "unregisterApp() - mClientIf=" + mClientIf);

        try {
            mCallback = null;