Merge "Bluetooth 5 move timeout parameter (1/2)"

am: d9f2f67a5f

Change-Id: Iee7d485461f5e02ab65ec9f7311e962deb603543
This commit is contained in:
Jakub Pawlowski
2017-03-17 22:34:24 +00:00
committed by android-build-merger
7 changed files with 63 additions and 51 deletions

View File

@@ -7506,7 +7506,7 @@ package android.bluetooth.le {
}
public final class AdvertisingSet {
method public void enableAdvertising(boolean);
method public void enableAdvertising(boolean, int);
method public void periodicAdvertisingEnable(boolean);
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
@@ -7539,7 +7539,6 @@ package android.bluetooth.le {
method public int getInterval();
method public int getPrimaryPhy();
method public int getSecondaryPhy();
method public int getTimeout();
method public int getTxPowerLevel();
method public boolean includeTxPower();
method public boolean isAnonymous();
@@ -7573,7 +7572,6 @@ package android.bluetooth.le {
method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}
@@ -7582,6 +7580,8 @@ package android.bluetooth.le {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}

View File

@@ -7810,7 +7810,7 @@ package android.bluetooth.le {
}
public final class AdvertisingSet {
method public void enableAdvertising(boolean);
method public void enableAdvertising(boolean, int);
method public void periodicAdvertisingEnable(boolean);
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
@@ -7843,7 +7843,6 @@ package android.bluetooth.le {
method public int getInterval();
method public int getPrimaryPhy();
method public int getSecondaryPhy();
method public int getTimeout();
method public int getTxPowerLevel();
method public boolean includeTxPower();
method public boolean isAnonymous();
@@ -7877,7 +7876,6 @@ package android.bluetooth.le {
method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}
@@ -7886,6 +7884,8 @@ package android.bluetooth.le {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}

View File

@@ -7515,7 +7515,7 @@ package android.bluetooth.le {
}
public final class AdvertisingSet {
method public void enableAdvertising(boolean);
method public void enableAdvertising(boolean, int);
method public void periodicAdvertisingEnable(boolean);
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
@@ -7548,7 +7548,6 @@ package android.bluetooth.le {
method public int getInterval();
method public int getPrimaryPhy();
method public int getSecondaryPhy();
method public int getTimeout();
method public int getTxPowerLevel();
method public boolean includeTxPower();
method public boolean isAnonymous();
@@ -7582,7 +7581,6 @@ package android.bluetooth.le {
method public android.bluetooth.le.AdvertisingSetParameters.Builder setLegacyMode(boolean);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setPrimaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setSecondaryPhy(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTimeout(int);
method public android.bluetooth.le.AdvertisingSetParameters.Builder setTxPowerLevel(int);
}
@@ -7591,6 +7589,8 @@ package android.bluetooth.le {
method public void startAdvertising(android.bluetooth.le.AdvertiseSettings, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback);
method public void startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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
@@ -379,31 +367,13 @@ public final class AdvertisingSetParameters implements Parcelable {
return this;
}
/**
* 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);
}
}
}

View File

@@ -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");