summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Pawlowski <jpawlowski@google.com> 2016-11-04 15:25:57 -0700
committer Andre Eisenbach <eisenbach@google.com> 2016-11-11 23:28:32 +0000
commit3d83b0e90bfa0d993c8624fc3032249025d6f269 (patch)
tree534346d5eb56df12030a5a5625256dd566698270
parentb828b6bf6cbd87d344157abe4a1cb7fcf6a0423c (diff)
Bluetooth: advertising improvements
This patch removes isPeripheralModeSupported(), hidden public method which is always returning true. It also modify the BluetoothLeAdvertiser to be able to use advertising instance with instance id equal 0. Bug: 30622771 Bug: 24099160 Change-Id: Id31582621dbe56d5c3a8d4ee5cd296af66a5f026
-rw-r--r--core/java/android/bluetooth/BluetoothAdapter.java22
-rw-r--r--core/java/android/bluetooth/IBluetooth.aidl1
-rw-r--r--core/java/android/bluetooth/le/BluetoothLeAdvertiser.java30
3 files changed, 12 insertions, 41 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 11c27355c787..4271e3f99dff 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -601,10 +601,6 @@ public final class BluetoothAdapter {
*/
public BluetoothLeAdvertiser getBluetoothLeAdvertiser() {
if (!getLeAccess()) return null;
- if (!isMultipleAdvertisementSupported() && !isPeripheralModeSupported()) {
- Log.e(TAG, "Bluetooth LE advertising not supported");
- return null;
- }
synchronized(mLock) {
if (sBluetoothLeAdvertiser == null) {
sBluetoothLeAdvertiser = new BluetoothLeAdvertiser(mManagerService);
@@ -1354,24 +1350,6 @@ public final class BluetoothAdapter {
}
/**
- * Returns whether peripheral mode is supported.
- *
- * @hide
- */
- public boolean isPeripheralModeSupported() {
- if (getState() != STATE_ON) return false;
- try {
- mServiceLock.readLock().lock();
- if (mService != null) return mService.isPeripheralModeSupported();
- } catch (RemoteException e) {
- Log.e(TAG, "failed to get peripheral mode capability: ", e);
- } finally {
- mServiceLock.readLock().unlock();
- }
- return false;
- }
-
- /**
* Return true if offloaded filters are supported
*
* @return true if chipset supports on-chip filtering
diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl
index 96a1ae8b9455..7c5458b7704b 100644
--- a/core/java/android/bluetooth/IBluetooth.aidl
+++ b/core/java/android/bluetooth/IBluetooth.aidl
@@ -100,7 +100,6 @@ interface IBluetooth
boolean factoryReset();
boolean isMultiAdvertisementSupported();
- boolean isPeripheralModeSupported();
boolean isOffloadedFilteringSupported();
boolean isOffloadedScanBatchingSupported();
boolean isActivityAndEnergyReportingSupported();
diff --git a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
index 26f2dea9022f..5d276623ce1c 100644
--- a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
+++ b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java
@@ -111,12 +111,6 @@ public final class BluetoothLeAdvertiser {
if (callback == null) {
throw new IllegalArgumentException("callback cannot be null");
}
- if (!mBluetoothAdapter.isMultipleAdvertisementSupported() &&
- !mBluetoothAdapter.isPeripheralModeSupported()) {
- postStartFailure(callback,
- AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED);
- return;
- }
boolean isConnectable = settings.isConnectable();
if (totalBytes(advertiseData, isConnectable) > MAX_ADVERTISING_DATA_BYTES ||
totalBytes(scanResponse, false) > MAX_ADVERTISING_DATA_BYTES) {
@@ -236,9 +230,9 @@ public final class BluetoothLeAdvertiser {
private final AdvertiseSettings mSettings;
private final IBluetoothGatt mBluetoothGatt;
- // mAdvertiserId 0: not registered
- // -1: advertise stopped or registration timeout
- // >0: registered and advertising started
+ // mAdvertiserId -1: not registered
+ // -2: advertise stopped or registration timeout
+ // >=0: registered and advertising started
private int mAdvertiserId;
private boolean mIsAdvertising = false;
@@ -251,12 +245,12 @@ public final class BluetoothLeAdvertiser {
mScanResponse = scanResponse;
mSettings = settings;
mBluetoothGatt = bluetoothGatt;
- mAdvertiserId = 0;
+ mAdvertiserId = -1;
}
public void startRegisteration() {
synchronized (this) {
- if (mAdvertiserId == -1) return;
+ if (mAdvertiserId == -2) return;
try {
mBluetoothGatt.registerAdvertiser(this);
@@ -264,13 +258,13 @@ public final class BluetoothLeAdvertiser {
} catch (InterruptedException | RemoteException e) {
Log.e(TAG, "Failed to start registeration", e);
}
- if (mAdvertiserId > 0 && mIsAdvertising) {
+ if (mAdvertiserId >= 0 && mIsAdvertising) {
mLeAdvertisers.put(mAdvertiseCallback, this);
- } else if (mAdvertiserId <= 0) {
+ } else if (mAdvertiserId < 0) {
// Registration timeout, reset mClientIf to -1 so no subsequent operations can
// proceed.
- if (mAdvertiserId == 0) mAdvertiserId = -1;
+ if (mAdvertiserId == 0) mAdvertiserId = -2;
// Post internal error if registration failed.
postStartFailure(mAdvertiseCallback,
AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR);
@@ -278,7 +272,7 @@ public final class BluetoothLeAdvertiser {
// Unregister application if it's already registered but advertise failed.
try {
mBluetoothGatt.unregisterAdvertiser(mAdvertiserId);
- mAdvertiserId = -1;
+ mAdvertiserId = -2;
} catch (RemoteException e) {
Log.e(TAG, "remote exception when unregistering", e);
}
@@ -312,7 +306,7 @@ public final class BluetoothLeAdvertiser {
synchronized (this) {
if (status == BluetoothGatt.GATT_SUCCESS) {
try {
- if (mAdvertiserId == -1) {
+ if (mAdvertiserId == -2) {
// Registration succeeds after timeout, unregister advertiser.
mBluetoothGatt.unregisterAdvertiser(advertiserId);
} else {
@@ -326,7 +320,7 @@ public final class BluetoothLeAdvertiser {
}
}
// Registration failed.
- mAdvertiserId = -1;
+ mAdvertiserId = -2;
notifyAll();
}
}
@@ -348,7 +342,7 @@ public final class BluetoothLeAdvertiser {
// unregister advertiser for stop.
try {
mBluetoothGatt.unregisterAdvertiser(mAdvertiserId);
- mAdvertiserId = -1;
+ mAdvertiserId = -2;
mIsAdvertising = false;
mLeAdvertisers.remove(mAdvertiseCallback);
} catch (RemoteException e) {