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

Commit 3cc1ad87 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge "Fix GATT client leakage when scan is throttled (1/2)"

parents 91817b31 ee02e1ce
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -344,6 +344,7 @@ public final class BluetoothLeScanner {
        private List<List<ResultStorageDescriptor>> mResultStorages;

        // mLeHandle 0: not registered
        // -2: registration failed because app is scanning to frequently
        // -1: scan stopped or registration failed
        // > 0: registered and scan started
        private int mScannerId;
@@ -364,7 +365,7 @@ public final class BluetoothLeScanner {
        public void startRegistration() {
            synchronized (this) {
                // Scan stopped.
                if (mScannerId == -1) return;
                if (mScannerId == -1 || mScannerId == -2) return;
                try {
                    mBluetoothGatt.registerScanner(this, mWorkSource);
                    wait(REGISTRATION_CALLBACK_TIMEOUT_MILLIS);
@@ -378,6 +379,10 @@ public final class BluetoothLeScanner {
                    // Registration timed out or got exception, reset scannerId to -1 so no
                    // subsequent operations can proceed.
                    if (mScannerId == 0) mScannerId = -1;

                    // If scanning too frequently, don't report anything to the app.
                    if (mScannerId == -2) return;

                    postCallbackError(mScanCallback,
                            ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED);
                }
@@ -437,6 +442,9 @@ public final class BluetoothLeScanner {
                        Log.e(TAG, "fail to start le scan: " + e);
                        mScannerId = -1;
                    }
                } else if (status == ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY) {
                    // applicaiton was scanning too frequently
                    mScannerId = -2;
                } else {
                    // registration failed
                    mScannerId = -1;
+6 −0
Original line number Diff line number Diff line
@@ -51,6 +51,12 @@ public abstract class ScanCallback {
     */
    public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES = 5;

    /**
     * Fails to start scan as application tries to scan too frequently.
     * @hide
     */
    public static final int SCAN_FAILED_SCANNING_TOO_FREQUENTLY = 6;

    static final int NO_ERROR = 0;

    /**