diff options
author | Jakub Pawlowski <jpawlowski@google.com> | 2017-08-28 04:12:49 -0700 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2017-08-29 17:26:23 +0000 |
commit | 7ec636e0b36715c0c8007c969811b20743e8d49c (patch) | |
tree | 3a814bfe14d0a801de963737b0f5596172a3e4bd /framework/java/android/bluetooth/le/BluetoothLeScanner.java | |
parent | 74d849c8f21dc6df8a3accab74573f43c7e566e3 (diff) |
Fix GATT client leakage when scan is throttled (1/2)
Currently, scan throttling happens after client is registered, but
before the scan is started. This might lead to scan client being leaked.
This patch fixed that by moving check before client registration.
Bug: 64887233
Test: manual
Change-Id: I22ae624a0c51110cb69679f796926e3b2b36d0ac
Merged-In: I22ae624a0c51110cb69679f796926e3b2b36d0ac
(cherry picked from commit 01ea3736138c612f04ccee60adf68a5b0e2d5b7d)
Diffstat (limited to 'framework/java/android/bluetooth/le/BluetoothLeScanner.java')
-rw-r--r-- | framework/java/android/bluetooth/le/BluetoothLeScanner.java | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/framework/java/android/bluetooth/le/BluetoothLeScanner.java b/framework/java/android/bluetooth/le/BluetoothLeScanner.java index e3bc78e5a2..9e9c8fe71b 100644 --- a/framework/java/android/bluetooth/le/BluetoothLeScanner.java +++ b/framework/java/android/bluetooth/le/BluetoothLeScanner.java @@ -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; |