Merge "Fix GATT client leakage when scan is throttled (1/2)" am: 3cc1ad87f0

am: d019cce887

Change-Id: I24d4dbf1344b13c558aa6974dfee6fd0e8549056
This commit is contained in:
Jakub Pawlowski
2017-08-29 08:19:50 +00:00
committed by android-build-merger
2 changed files with 15 additions and 1 deletions

View File

@@ -345,6 +345,7 @@ public final class BluetoothLeScanner {
private List<List<ResultStorageDescriptor>> mResultStorages; private List<List<ResultStorageDescriptor>> mResultStorages;
// mLeHandle 0: not registered // mLeHandle 0: not registered
// -2: registration failed because app is scanning to frequently
// -1: scan stopped or registration failed // -1: scan stopped or registration failed
// > 0: registered and scan started // > 0: registered and scan started
private int mScannerId; private int mScannerId;
@@ -365,7 +366,7 @@ public final class BluetoothLeScanner {
public void startRegistration() { public void startRegistration() {
synchronized (this) { synchronized (this) {
// Scan stopped. // Scan stopped.
if (mScannerId == -1) return; if (mScannerId == -1 || mScannerId == -2) return;
try { try {
mBluetoothGatt.registerScanner(this, mWorkSource); mBluetoothGatt.registerScanner(this, mWorkSource);
wait(REGISTRATION_CALLBACK_TIMEOUT_MILLIS); wait(REGISTRATION_CALLBACK_TIMEOUT_MILLIS);
@@ -379,6 +380,10 @@ public final class BluetoothLeScanner {
// Registration timed out or got exception, reset scannerId to -1 so no // Registration timed out or got exception, reset scannerId to -1 so no
// subsequent operations can proceed. // subsequent operations can proceed.
if (mScannerId == 0) mScannerId = -1; if (mScannerId == 0) mScannerId = -1;
// If scanning too frequently, don't report anything to the app.
if (mScannerId == -2) return;
postCallbackError(mScanCallback, postCallbackError(mScanCallback,
ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED); ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED);
} }
@@ -438,6 +443,9 @@ public final class BluetoothLeScanner {
Log.e(TAG, "fail to start le scan: " + e); Log.e(TAG, "fail to start le scan: " + e);
mScannerId = -1; mScannerId = -1;
} }
} else if (status == ScanCallback.SCAN_FAILED_SCANNING_TOO_FREQUENTLY) {
// applicaiton was scanning too frequently
mScannerId = -2;
} else { } else {
// registration failed // registration failed
mScannerId = -1; mScannerId = -1;

View File

@@ -51,6 +51,12 @@ public abstract class ScanCallback {
*/ */
public static final int SCAN_FAILED_OUT_OF_HARDWARE_RESOURCES = 5; 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; static final int NO_ERROR = 0;
/** /**