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

Commit cead26c3 authored by Wei Wang's avatar Wei Wang Committed by android-build-merger
Browse files

Properly handle registration timeout in BLE. am: 02bc0086 am: cde5d3db

am: faf357e8

* commit 'faf357e8':
  Properly handle registration timeout in BLE.

Change-Id: I9b9a7ef6167ae397ebf943bc61e854e4b887140d
parents b9751ddd faf357e8
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -237,8 +237,8 @@ public final class BluetoothLeAdvertiser {
        private final IBluetoothGatt mBluetoothGatt;

        // mClientIf 0: not registered
        // -1: scan stopped
        // >0: registered and scan started
        // -1: advertise stopped or registration timeout
        // >0: registered and advertising started
        private int mClientIf;
        private boolean mIsAdvertising = false;

@@ -268,6 +268,10 @@ public final class BluetoothLeAdvertiser {
                if (mClientIf > 0 && mIsAdvertising) {
                    mLeAdvertisers.put(mAdvertiseCallback, this);
                } else if (mClientIf <= 0) {

                    // Registration timeout, reset mClientIf to -1 so no subsequent operations can
                    // proceed.
                    if (mClientIf == 0) mClientIf = -1;
                    // Post internal error if registration failed.
                    postStartFailure(mAdvertiseCallback,
                            AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
@@ -308,10 +312,15 @@ public final class BluetoothLeAdvertiser {
            Log.d(TAG, "onClientRegistered() - status=" + status + " clientIf=" + clientIf);
            synchronized (this) {
                if (status == BluetoothGatt.GATT_SUCCESS) {
                    mClientIf = clientIf;
                    try {
                        if (mClientIf == -1) {
                            // Registration succeeds after timeout, unregister client.
                            mBluetoothGatt.unregisterClient(clientIf);
                        } else {
                            mClientIf = clientIf;
                            mBluetoothGatt.startMultiAdvertising(mClientIf, mAdvertisement,
                                    mScanResponse, mSettings);
                        }
                        return;
                    } catch (RemoteException e) {
                        Log.e(TAG, "failed to start advertising", e);
+14 −11
Original line number Diff line number Diff line
@@ -278,7 +278,7 @@ public final class BluetoothLeScanner {
        private List<List<ResultStorageDescriptor>> mResultStorages;

        // mLeHandle 0: not registered
        // -1: scan stopped
        // -1: scan stopped or registration failed
        // > 0: registered and scan started
        private int mClientIf;

@@ -310,6 +310,9 @@ public final class BluetoothLeScanner {
                if (mClientIf > 0) {
                    mLeScanClients.put(mScanCallback, this);
                } else {
                    // Registration timed out or got exception, reset clientIf to -1 so no
                    // subsequent operations can proceed.
                    if (mClientIf == 0) mClientIf = -1;
                    postCallbackError(mScanCallback,
                            ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED);
                }
@@ -352,19 +355,19 @@ public final class BluetoothLeScanner {
        @Override
        public void onClientRegistered(int status, int clientIf) {
            Log.d(TAG, "onClientRegistered() - status=" + status +
                    " clientIf=" + clientIf);
                    " clientIf=" + clientIf + " mClientIf=" + mClientIf);
            synchronized (this) {
                if (mClientIf == -1) {
                    if (DBG) Log.d(TAG, "onClientRegistered LE scan canceled");
                }

                if (status == BluetoothGatt.GATT_SUCCESS) {
                    mClientIf = clientIf;
                    try {
                        if (mClientIf == -1) {
                            // Registration succeeds after timeout, unregister client.
                            mBluetoothGatt.unregisterClient(clientIf);
                        } else {
                            mClientIf = clientIf;
                            mBluetoothGatt.startScan(mClientIf, false, mSettings, mFilters,
                                    mWorkSource, mResultStorages,
                                    ActivityThread.currentOpPackageName());

                        }
                    } catch (RemoteException e) {
                        Log.e(TAG, "fail to start le scan: " + e);
                        mClientIf = -1;