summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/le/BluetoothLeScanner.java
diff options
context:
space:
mode:
authorWei Wang <weiwa@google.com>2014-07-09 14:03:42 -0700
committerAndre Eisenbach <eisenbach@google.com>2014-07-11 11:06:10 -0700
commit7faed2f183c09307b398c22e1b92ac52f1d93a7e (patch)
treea1b965074345becdbbd7474cc50662a7cd9d8e97 /framework/java/android/bluetooth/le/BluetoothLeScanner.java
parent0649e964a14ffea79689a81fdcb5546ee6ad4553 (diff)
Unhide Bluetooth batch APIs. Deprecate BluetoothAdpater scan APIs. (1/2)
Change-Id: Ib0c4ea6c8372a15473269660355fb5ccf4284457
Diffstat (limited to 'framework/java/android/bluetooth/le/BluetoothLeScanner.java')
-rw-r--r--framework/java/android/bluetooth/le/BluetoothLeScanner.java72
1 files changed, 37 insertions, 35 deletions
diff --git a/framework/java/android/bluetooth/le/BluetoothLeScanner.java b/framework/java/android/bluetooth/le/BluetoothLeScanner.java
index d5a4728a0f..7e87edc127 100644
--- a/framework/java/android/bluetooth/le/BluetoothLeScanner.java
+++ b/framework/java/android/bluetooth/le/BluetoothLeScanner.java
@@ -36,14 +36,14 @@ import java.util.UUID;
/**
* This class provides methods to perform scan related operations for Bluetooth LE devices. An
- * application can scan for a particular type of BLE devices using {@link ScanFilter}. It can also
- * request different types of callbacks for delivering the result.
+ * application can scan for a particular type of Bluetotoh LE devices using {@link ScanFilter}.
+ * It can also request different types of callbacks for delivering the result.
* <p>
* Use {@link BluetoothAdapter#getBluetoothLeScanner()} to get an instance of
* {@link BluetoothLeScanner}.
* <p>
- * Note most of the scan methods here require {@link android.Manifest.permission#BLUETOOTH_ADMIN}
- * permission.
+ * <b>Note:</b> Most of the scan methods here require
+ * {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @see ScanFilter
*/
@@ -58,6 +58,8 @@ public final class BluetoothLeScanner {
private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients;
/**
+ * Use {@link BluetoothAdapter#getBluetoothLeScanner()} instead.
+ * @param bluetoothManager BluetoothManager that conducts overall Bluetooth Management
* @hide
*/
public BluetoothLeScanner(IBluetoothManager bluetoothManager) {
@@ -68,13 +70,29 @@ public final class BluetoothLeScanner {
}
/**
+ * Start Bluetooth LE scan with default parameters and no filters.
+ * The scan results will be delivered through {@code callback}.
+ * <p>
+ * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
+ *
+ * @param callback Callback used to deliver scan results.
+ * @throws IllegalArgumentException If {@code callback} is null.
+ */
+ public void startScan(final ScanCallback callback) {
+ if (callback == null) {
+ throw new IllegalArgumentException("callback is null");
+ }
+ this.startScan(null, new ScanSettings.Builder().build(), callback);
+ }
+
+ /**
* Start Bluetooth LE scan. The scan results will be delivered through {@code callback}.
* <p>
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
*
* @param filters {@link ScanFilter}s for finding exact BLE devices.
- * @param settings Settings for ble scan.
- * @param callback Callback when scan results are delivered.
+ * @param settings Settings for the scan.
+ * @param callback Callback used to deliver scan results.
* @throws IllegalArgumentException If {@code settings} or {@code callback} is null.
*/
public void startScan(List<ScanFilter> filters, ScanSettings settings,
@@ -94,7 +112,7 @@ public final class BluetoothLeScanner {
gatt = null;
}
if (gatt == null) {
- postCallbackError(callback, ScanCallback.SCAN_FAILED_GATT_SERVICE_FAILURE);
+ postCallbackError(callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR);
return;
}
if (!isSettingsConfigAllowedForScan(settings)) {
@@ -116,7 +134,7 @@ public final class BluetoothLeScanner {
}
} catch (RemoteException e) {
Log.e(TAG, "GATT service exception when starting scan", e);
- postCallbackError(callback, ScanCallback.SCAN_FAILED_GATT_SERVICE_FAILURE);
+ postCallbackError(callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR);
}
}
}
@@ -139,24 +157,12 @@ public final class BluetoothLeScanner {
}
/**
- * Returns available storage size for batch scan results. It's recommended not to use batch scan
- * if available storage size is small (less than 1k bytes, for instance).
- *
- * @hide TODO: unhide when batching is supported in stack.
- */
- public int getAvailableBatchStorageSizeBytes() {
- throw new UnsupportedOperationException("not impelemented");
- }
-
- /**
* Flush pending batch scan results stored in Bluetooth controller. This will return Bluetooth
* LE scan results batched on bluetooth controller. Returns immediately, batch scan results data
* will be delivered through the {@code callback}.
*
* @param callback Callback of the Bluetooth LE Scan, it has to be the same instance as the one
* used to start scan.
- *
- * @hide
*/
public void flushPendingScanResults(ScanCallback callback) {
if (callback == null) {
@@ -302,7 +308,7 @@ public final class BluetoothLeScanner {
handler.post(new Runnable() {
@Override
public void run() {
- mScanCallback.onAdvertisementUpdate(result);
+ mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, result);
}
});
@@ -435,9 +441,9 @@ public final class BluetoothLeScanner {
ScanResult result = new ScanResult(device, advData, rssi,
scanNanos);
if (onFound) {
- mScanCallback.onAdvertisementFound(result);
+ mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_FIRST_MATCH, result);
} else {
- mScanCallback.onAdvertisementLost(result);
+ mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_MATCH_LOST, result);
}
}
}
@@ -452,17 +458,13 @@ public final class BluetoothLeScanner {
}
private boolean isSettingsConfigAllowedForScan(ScanSettings settings) {
- boolean ret = true;
- int callbackType;
-
- callbackType = settings.getCallbackType();
- if (((callbackType == ScanSettings.CALLBACK_TYPE_ON_LOST) ||
- (callbackType == ScanSettings.CALLBACK_TYPE_ON_FOUND) ||
- (callbackType == ScanSettings.CALLBACK_TYPE_ON_UPDATE &&
- settings.getReportDelayNanos() > 0) &&
- (!mBluetoothAdapter.isOffloadedFilteringSupported()))) {
- ret = false;
- }
- return ret;
+ final int callbackType = settings.getCallbackType();
+ if (( callbackType != ScanSettings.CALLBACK_TYPE_ALL_MATCHES
+ || (callbackType == ScanSettings.CALLBACK_TYPE_ALL_MATCHES
+ && settings.getReportDelaySeconds() > 0))
+ && !mBluetoothAdapter.isOffloadedFilteringSupported()) {
+ return false;
+ }
+ return true;
}
}