diff options
author | Prerepa Viswanadham <dham@google.com> | 2014-07-08 16:33:34 -0700 |
---|---|---|
committer | Prerepa Viswanadham <dham@google.com> | 2014-07-08 23:34:49 +0000 |
commit | 8e5270fdf5639461d67e9a898a85520abac6053d (patch) | |
tree | c3bba7d420094455ec5ae9da82d017c0f0a9adc3 /core/java/android/bluetooth/le | |
parent | 521e86f4d77c02405dfc919c7c473ff2cbe17d05 (diff) | |
download | frameworks_base-8e5270fdf5639461d67e9a898a85520abac6053d.zip frameworks_base-8e5270fdf5639461d67e9a898a85520abac6053d.tar.gz frameworks_base-8e5270fdf5639461d67e9a898a85520abac6053d.tar.bz2 |
Tie in BLE hw capabilities with api invocation and support.
Change-Id: Ic1f0b3f156cf2fdde8f04b5c4384e4fd3d79623a
Diffstat (limited to 'core/java/android/bluetooth/le')
4 files changed, 39 insertions, 0 deletions
diff --git a/core/java/android/bluetooth/le/AdvertiseCallback.java b/core/java/android/bluetooth/le/AdvertiseCallback.java index 59f8cdc..1d26ef9 100644 --- a/core/java/android/bluetooth/le/AdvertiseCallback.java +++ b/core/java/android/bluetooth/le/AdvertiseCallback.java @@ -58,6 +58,12 @@ public abstract class AdvertiseCallback { public static final int ADVERTISE_FAILED_GATT_SERVICE_FAILURE = 6; /** + * Operation fails as this feature is not supported + */ + public static final int ADVERTISE_FAILED_FEATURE_UNSUPPORTED = 7; + + + /** * Callback when advertising operation succeeds. * * @param settingsInEffect The actual settings used for advertising, which may be different from diff --git a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java index a83d875..6b21ce2 100644 --- a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java +++ b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java @@ -51,6 +51,7 @@ public final class BluetoothLeAdvertiser { private final IBluetoothManager mBluetoothManager; private final Handler mHandler; + private BluetoothAdapter mBluetoothAdapter; private final Map<AdvertiseCallback, AdvertiseCallbackWrapper> mLeAdvertisers = new HashMap<AdvertiseCallback, AdvertiseCallbackWrapper>(); @@ -62,6 +63,7 @@ public final class BluetoothLeAdvertiser { */ public BluetoothLeAdvertiser(IBluetoothManager bluetoothManager) { mBluetoothManager = bluetoothManager; + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(Looper.getMainLooper()); } @@ -112,6 +114,10 @@ public final class BluetoothLeAdvertiser { postCallbackFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_CONTROLLER_FAILURE); return; } + if (!mBluetoothAdapter.isMultipleAdvertisementSupported()) { + postCallbackFailure(callback, AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED); + return; + } AdvertiseCallbackWrapper wrapper = new AdvertiseCallbackWrapper(callback, advertiseData, scanResponse, settings, gatt); UUID uuid = UUID.randomUUID(); diff --git a/core/java/android/bluetooth/le/BluetoothLeScanner.java b/core/java/android/bluetooth/le/BluetoothLeScanner.java index 44aa117..863282a 100644 --- a/core/java/android/bluetooth/le/BluetoothLeScanner.java +++ b/core/java/android/bluetooth/le/BluetoothLeScanner.java @@ -54,6 +54,7 @@ public final class BluetoothLeScanner { private final IBluetoothManager mBluetoothManager; private final Handler mHandler; + private BluetoothAdapter mBluetoothAdapter; private final Map<ScanCallback, BleScanCallbackWrapper> mLeScanClients; /** @@ -61,6 +62,7 @@ public final class BluetoothLeScanner { */ public BluetoothLeScanner(IBluetoothManager bluetoothManager) { mBluetoothManager = bluetoothManager; + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); mHandler = new Handler(Looper.getMainLooper()); mLeScanClients = new HashMap<ScanCallback, BleScanCallbackWrapper>(); } @@ -95,6 +97,11 @@ public final class BluetoothLeScanner { postCallbackError(callback, ScanCallback.SCAN_FAILED_GATT_SERVICE_FAILURE); return; } + if (!isSettingsConfigAllowedForScan(settings)) { + postCallbackError(callback, + ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED); + return; + } BleScanCallbackWrapper wrapper = new BleScanCallbackWrapper(gatt, filters, settings, callback); try { @@ -424,4 +431,19 @@ 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; + } } diff --git a/core/java/android/bluetooth/le/ScanCallback.java b/core/java/android/bluetooth/le/ScanCallback.java index 50ebf50..f5d7a9a 100644 --- a/core/java/android/bluetooth/le/ScanCallback.java +++ b/core/java/android/bluetooth/le/ScanCallback.java @@ -41,6 +41,11 @@ public abstract class ScanCallback { public static final int SCAN_FAILED_CONTROLLER_FAILURE = 4; /** + * Fails to start power optimized scan as this feature is not supported. + */ + public static final int SCAN_FAILED_FEATURE_UNSUPPORTED = 5; + + /** * Callback when a BLE advertisement is found. * * @param result A Bluetooth LE scan result. |