diff options
Diffstat (limited to 'core/java')
4 files changed, 54 insertions, 42 deletions
diff --git a/core/java/android/bluetooth/IBluetoothGatt.aidl b/core/java/android/bluetooth/IBluetoothGatt.aidl index 29f29e7dba4e..c281c7f7b0f8 100644 --- a/core/java/android/bluetooth/IBluetoothGatt.aidl +++ b/core/java/android/bluetooth/IBluetoothGatt.aidl @@ -52,10 +52,10 @@ interface IBluetoothGatt { void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData, in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters, - in AdvertiseData periodicData, in IAdvertisingSetCallback callback); + in AdvertiseData periodicData, in int timeout, in IAdvertisingSetCallback callback); void stopAdvertisingSet(in IAdvertisingSetCallback callback); - void enableAdverisingSet(in int advertiserId, in boolean enable); + void enableAdverisingSet(in int advertiserId, in boolean enable, in int timeout); void setAdvertisingData(in int advertiserId, in AdvertiseData data); void setScanResponseData(in int advertiserId, in AdvertiseData data); void setAdvertisingParameters(in int advertiserId, in AdvertisingSetParameters parameters); diff --git a/core/java/android/bluetooth/le/AdvertisingSet.java b/core/java/android/bluetooth/le/AdvertisingSet.java index 1524022b1f0f..5524a2bdae18 100644 --- a/core/java/android/bluetooth/le/AdvertisingSet.java +++ b/core/java/android/bluetooth/le/AdvertisingSet.java @@ -63,9 +63,9 @@ public final class AdvertisingSet { * Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN} * */ - public void enableAdvertising(boolean enable) { + public void enableAdvertising(boolean enable, int timeout) { try { - gatt.enableAdverisingSet(this.advertiserId, enable); + gatt.enableAdverisingSet(this.advertiserId, enable, timeout); } catch (RemoteException e) { Log.e(TAG, "remote exception - ", e); } diff --git a/core/java/android/bluetooth/le/AdvertisingSetParameters.java b/core/java/android/bluetooth/le/AdvertisingSetParameters.java index 453dd70a589c..59fef8d1d1ea 100644 --- a/core/java/android/bluetooth/le/AdvertisingSetParameters.java +++ b/core/java/android/bluetooth/le/AdvertisingSetParameters.java @@ -118,13 +118,11 @@ public final class AdvertisingSetParameters implements Parcelable { private final boolean connectable; private final int interval; private final int txPowerLevel; - private final int timeoutMillis; private AdvertisingSetParameters(boolean connectable, boolean isLegacy, boolean isAnonymous, boolean includeTxPower, int primaryPhy, int secondaryPhy, - int interval, int txPowerLevel, - int timeoutMillis) { + int interval, int txPowerLevel) { this.connectable = connectable; this.isLegacy = isLegacy; this.isAnonymous = isAnonymous; @@ -133,7 +131,6 @@ public final class AdvertisingSetParameters implements Parcelable { this.secondaryPhy = secondaryPhy; this.interval = interval; this.txPowerLevel = txPowerLevel; - this.timeoutMillis = timeoutMillis; } private AdvertisingSetParameters(Parcel in) { @@ -145,7 +142,6 @@ public final class AdvertisingSetParameters implements Parcelable { secondaryPhy = in.readInt(); interval = in.readInt(); txPowerLevel = in.readInt(); - timeoutMillis = in.readInt(); } /** @@ -188,11 +184,6 @@ public final class AdvertisingSetParameters implements Parcelable { */ public int getTxPowerLevel() { return txPowerLevel; } - /** - * Returns the advertising time limit in milliseconds. - */ - public int getTimeout() { return timeoutMillis; } - @Override public String toString() { return "AdvertisingSetParameters [connectable=" + connectable @@ -202,8 +193,7 @@ public final class AdvertisingSetParameters implements Parcelable { + ", primaryPhy=" + primaryPhy + ", secondaryPhy=" + secondaryPhy + ", interval=" + interval - + ", txPowerLevel=" + txPowerLevel - + ", timeoutMillis=" + timeoutMillis + "]"; + + ", txPowerLevel=" + txPowerLevel + "]"; } @Override @@ -221,7 +211,6 @@ public final class AdvertisingSetParameters implements Parcelable { dest.writeInt(secondaryPhy); dest.writeInt(interval); dest.writeInt(txPowerLevel); - dest.writeInt(timeoutMillis); } public static final Parcelable.Creator<AdvertisingSetParameters> CREATOR = @@ -250,7 +239,6 @@ public final class AdvertisingSetParameters implements Parcelable { private int secondaryPhy = PHY_LE_1M; private int interval = INTERVAL_LOW; private int txPowerLevel = TX_POWER_MEDIUM; - private int timeoutMillis = 0; /** * Set whether the advertisement type should be connectable or @@ -380,30 +368,12 @@ public final class AdvertisingSetParameters implements Parcelable { } /** - * Limit advertising to a given amount of time. - * @param timeoutMillis Advertising time limit. May not exceed 180000 - * milliseconds. A value of 0 will disable the time limit. - * @throws IllegalArgumentException If the provided timeout is over 180000 - * ms. - */ - public Builder setTimeout(int timeoutMillis) { - if (timeoutMillis < 0 || timeoutMillis > LIMITED_ADVERTISING_MAX_MILLIS) { - throw new IllegalArgumentException("timeoutMillis invalid (must be 0-" + - LIMITED_ADVERTISING_MAX_MILLIS + - " milliseconds)"); - } - this.timeoutMillis = timeoutMillis; - return this; - } - - /** * Build the {@link AdvertisingSetParameters} object. */ public AdvertisingSetParameters build() { return new AdvertisingSetParameters(connectable, isLegacy, isAnonymous, includeTxPower, primaryPhy, - secondaryPhy, interval, txPowerLevel, - timeoutMillis); + secondaryPhy, interval, txPowerLevel); } } }
\ No newline at end of file diff --git a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java index c9f1d7a32efb..67fd1c86aa3b 100644 --- a/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java +++ b/core/java/android/bluetooth/le/BluetoothLeAdvertiser.java @@ -130,7 +130,6 @@ public final class BluetoothLeAdvertiser { AdvertisingSetParameters.Builder parameters = new AdvertisingSetParameters.Builder(); parameters.setLegacyMode(true); parameters.setConnectable(isConnectable); - parameters.setTimeout(settings.getTimeout()); if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_LOW_POWER) { parameters.setInterval(1600); // 1s } else if (settings.getMode() == AdvertiseSettings.ADVERTISE_MODE_BALANCED) { @@ -152,7 +151,7 @@ public final class BluetoothLeAdvertiser { AdvertisingSetCallback wrapped = wrapOldCallback(callback, settings); mLegacyAdvertisers.put(callback, wrapped); startAdvertisingSet(parameters.build(), advertiseData, scanResponse, null, null, - wrapped); + settings.getTimeout(), wrapped); } } @@ -216,8 +215,8 @@ public final class BluetoothLeAdvertiser { AdvertiseData advertiseData, AdvertiseData scanResponse, PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, AdvertisingSetCallback callback) { - startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters, - periodicData, callback, new Handler(Looper.getMainLooper())); + startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters, + periodicData, 0, callback, new Handler(Looper.getMainLooper())); } /** @@ -237,6 +236,49 @@ public final class BluetoothLeAdvertiser { PeriodicAdvertisingParameters periodicParameters, AdvertiseData periodicData, AdvertisingSetCallback callback, Handler handler) { + startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters, + periodicData, 0, callback, handler); + } + + /** + * Creates a new advertising set. If operation succeed, device will start advertising. This + * method returns immediately, the operation status is delivered through + * {@code callback.onAdvertisingSetStarted()}. + * <p> + * @param parameters advertising set parameters. + * @param advertiseData Advertisement data to be broadcasted. + * @param scanResponse Scan response associated with the advertisement data. + * @param periodicData Periodic advertising data. + * @param timeoutMillis Advertising time limit. May not exceed 180000 + * @param callback Callback for advertising set. + */ + public void startAdvertisingSet(AdvertisingSetParameters parameters, + AdvertiseData advertiseData, AdvertiseData scanResponse, + PeriodicAdvertisingParameters periodicParameters, + AdvertiseData periodicData, int timeoutMillis, + AdvertisingSetCallback callback) { + startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters, + periodicData, timeoutMillis, callback, new Handler(Looper.getMainLooper())); + } + + /** + * Creates a new advertising set. If operation succeed, device will start advertising. This + * method returns immediately, the operation status is delivered through + * {@code callback.onAdvertisingSetStarted()}. + * <p> + * @param parameters advertising set parameters. + * @param advertiseData Advertisement data to be broadcasted. + * @param scanResponse Scan response associated with the advertisement data. + * @param periodicData Periodic advertising data. + * @param timeoutMillis Advertising time limit. May not exceed 180000 + * @param callback Callback for advertising set. + * @param handler thread upon which the callbacks will be invoked. + */ + public void startAdvertisingSet(AdvertisingSetParameters parameters, + AdvertiseData advertiseData, AdvertiseData scanResponse, + PeriodicAdvertisingParameters periodicParameters, + AdvertiseData periodicData, int timeoutMillis, + AdvertisingSetCallback callback, Handler handler) { BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter); if (callback == null) { @@ -259,7 +301,7 @@ public final class BluetoothLeAdvertiser { try { gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters, - periodicData, wrapped); + periodicData, timeoutMillis, wrapped); } catch (RemoteException e) { Log.e(TAG, "Failed to start advertising set - ", e); throw new IllegalStateException("Failed to start advertising set"); |
