Methods Summary |
---|
public void | cleanup()Cleans up scan clients. Should be called when bluetooth is down.
mLeScanClients.clear();
|
public void | flushPendingScanResults(ScanCallback callback)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}.
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
if (callback == null) {
throw new IllegalArgumentException("callback cannot be null!");
}
synchronized (mLeScanClients) {
BleScanCallbackWrapper wrapper = mLeScanClients.get(callback);
if (wrapper == null) {
return;
}
wrapper.flushPendingBatchResults();
}
|
private boolean | isSettingsConfigAllowedForScan(ScanSettings settings)
if (mBluetoothAdapter.isOffloadedFilteringSupported()) {
return true;
}
final int callbackType = settings.getCallbackType();
// Only support regular scan if no offloaded filter support.
if (callbackType == ScanSettings.CALLBACK_TYPE_ALL_MATCHES
&& settings.getReportDelayMillis() == 0) {
return true;
}
return false;
|
private void | postCallbackError(ScanCallback callback, int errorCode)
mHandler.post(new Runnable() {
@Override
public void run() {
callback.onScanFailed(errorCode);
}
});
|
public void | startScan(ScanCallback callback)Start Bluetooth LE scan with default parameters and no filters. The scan results will be
delivered through {@code callback}.
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
if (callback == null) {
throw new IllegalArgumentException("callback is null");
}
startScan(null, new ScanSettings.Builder().build(), callback);
|
public void | startScan(java.util.List filters, ScanSettings settings, ScanCallback callback)Start Bluetooth LE scan. The scan results will be delivered through {@code callback}.
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
startScan(filters, settings, callback, null);
|
private void | startScan(java.util.List filters, ScanSettings settings, ScanCallback callback, java.util.List resultStorages)
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
if (settings == null || callback == null) {
throw new IllegalArgumentException("settings or callback is null");
}
synchronized (mLeScanClients) {
if (mLeScanClients.containsKey(callback)) {
postCallbackError(callback, ScanCallback.SCAN_FAILED_ALREADY_STARTED);
return;
}
IBluetoothGatt gatt;
try {
gatt = mBluetoothManager.getBluetoothGatt();
} catch (RemoteException e) {
gatt = null;
}
if (gatt == null) {
postCallbackError(callback, ScanCallback.SCAN_FAILED_INTERNAL_ERROR);
return;
}
if (!isSettingsConfigAllowedForScan(settings)) {
postCallbackError(callback,
ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED);
return;
}
BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters,
settings, callback, resultStorages);
wrapper.startRegisteration();
}
|
public void | startTruncatedScan(java.util.List truncatedFilters, ScanSettings settings, ScanCallback callback)Start truncated scan.
int filterSize = truncatedFilters.size();
List<ScanFilter> scanFilters = new ArrayList<ScanFilter>(filterSize);
List<List<ResultStorageDescriptor>> scanStorages =
new ArrayList<List<ResultStorageDescriptor>>(filterSize);
for (TruncatedFilter filter : truncatedFilters) {
scanFilters.add(filter.getFilter());
scanStorages.add(filter.getStorageDescriptors());
}
startScan(scanFilters, settings, callback, scanStorages);
|
public void | stopScan(ScanCallback callback)Stops an ongoing Bluetooth LE scan.
Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} permission.
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
synchronized (mLeScanClients) {
BleScanCallbackWrapper wrapper = mLeScanClients.remove(callback);
if (wrapper == null) {
if (DBG) Log.d(TAG, "could not find callback wrapper");
return;
}
wrapper.stopLeScan();
}
|