Merge "Bluetooth 5 advertising duration refactoring (4/4)"
This commit is contained in:
@ -7495,7 +7495,7 @@ package android.bluetooth.le {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class AdvertisingSet {
|
public final class AdvertisingSet {
|
||||||
method public void enableAdvertising(boolean, int);
|
method public void enableAdvertising(boolean, int, int);
|
||||||
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
||||||
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
@ -7571,8 +7571,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 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);
|
||||||
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, 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, 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 startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
|
||||||
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
||||||
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
||||||
}
|
}
|
||||||
|
@ -7800,7 +7800,7 @@ package android.bluetooth.le {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class AdvertisingSet {
|
public final class AdvertisingSet {
|
||||||
method public void enableAdvertising(boolean, int);
|
method public void enableAdvertising(boolean, int, int);
|
||||||
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
||||||
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
@ -7876,8 +7876,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 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);
|
||||||
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, 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, 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 startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
|
||||||
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
||||||
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
||||||
}
|
}
|
||||||
|
@ -7504,7 +7504,7 @@ package android.bluetooth.le {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class AdvertisingSet {
|
public final class AdvertisingSet {
|
||||||
method public void enableAdvertising(boolean, int);
|
method public void enableAdvertising(boolean, int, int);
|
||||||
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
method public void setAdvertisingParameters(android.bluetooth.le.AdvertisingSetParameters);
|
||||||
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
method public void setPeriodicAdvertisingData(android.bluetooth.le.AdvertiseData);
|
||||||
@ -7580,8 +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 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);
|
||||||
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, 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, 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 startAdvertisingSet(android.bluetooth.le.AdvertisingSetParameters, android.bluetooth.le.AdvertiseData, android.bluetooth.le.AdvertiseData, android.bluetooth.le.PeriodicAdvertisingParameters, android.bluetooth.le.AdvertiseData, int, int, android.bluetooth.le.AdvertisingSetCallback, android.os.Handler);
|
||||||
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
method public void stopAdvertising(android.bluetooth.le.AdvertiseCallback);
|
||||||
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
method public void stopAdvertisingSet(android.bluetooth.le.AdvertisingSetCallback);
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,11 @@ interface IBluetoothGatt {
|
|||||||
|
|
||||||
void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData,
|
void startAdvertisingSet(in AdvertisingSetParameters parameters, in AdvertiseData advertiseData,
|
||||||
in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters,
|
in AdvertiseData scanResponse, in PeriodicAdvertisingParameters periodicParameters,
|
||||||
in AdvertiseData periodicData, in int timeout, in IAdvertisingSetCallback callback);
|
in AdvertiseData periodicData, in int duration, in int maxExtAdvEvents,
|
||||||
|
in IAdvertisingSetCallback callback);
|
||||||
void stopAdvertisingSet(in IAdvertisingSetCallback callback);
|
void stopAdvertisingSet(in IAdvertisingSetCallback callback);
|
||||||
|
|
||||||
void enableAdvertisingSet(in int advertiserId, in boolean enable, in int timeout);
|
void enableAdvertisingSet(in int advertiserId, in boolean enable, in int duration, in int maxExtAdvEvents);
|
||||||
void setAdvertisingData(in int advertiserId, in AdvertiseData data);
|
void setAdvertisingData(in int advertiserId, in AdvertiseData data);
|
||||||
void setScanResponseData(in int advertiserId, in AdvertiseData data);
|
void setScanResponseData(in int advertiserId, in AdvertiseData data);
|
||||||
void setAdvertisingParameters(in int advertiserId, in AdvertisingSetParameters parameters);
|
void setAdvertisingParameters(in int advertiserId, in AdvertisingSetParameters parameters);
|
||||||
|
@ -63,11 +63,18 @@ public final class AdvertisingSet {
|
|||||||
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
|
* Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}
|
||||||
*
|
*
|
||||||
* @param enable whether the advertising should be enabled (true), or disabled (false)
|
* @param enable whether the advertising should be enabled (true), or disabled (false)
|
||||||
* @param timeoutMillis duration for which that advertising set is enabled.
|
* @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to
|
||||||
|
* 65535 (655,350 ms)
|
||||||
|
* @param maxExtendedAdvertisingEvents maximum number of extended advertising events the
|
||||||
|
* controller shall attempt to send prior to terminating the extended
|
||||||
|
* advertising, even if the duration has not expired. Valid range is
|
||||||
|
* from 1 to 255.
|
||||||
*/
|
*/
|
||||||
public void enableAdvertising(boolean enable, int timeout) {
|
public void enableAdvertising(boolean enable, int duration,
|
||||||
|
int maxExtendedAdvertisingEvents) {
|
||||||
try {
|
try {
|
||||||
gatt.enableAdvertisingSet(this.advertiserId, enable, timeout);
|
gatt.enableAdvertisingSet(this.advertiserId, enable, duration,
|
||||||
|
maxExtendedAdvertisingEvents);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "remote exception - ", e);
|
Log.e(TAG, "remote exception - ", e);
|
||||||
}
|
}
|
||||||
|
@ -149,10 +149,16 @@ public final class BluetoothLeAdvertiser {
|
|||||||
parameters.setTxPowerLevel(1);
|
parameters.setTxPowerLevel(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int duration = 0;
|
||||||
|
int timeoutMillis = settings.getTimeout();
|
||||||
|
if (timeoutMillis > 0) {
|
||||||
|
duration = (timeoutMillis < 10) ? 1 : timeoutMillis/10;
|
||||||
|
}
|
||||||
|
|
||||||
AdvertisingSetCallback wrapped = wrapOldCallback(callback, settings);
|
AdvertisingSetCallback wrapped = wrapOldCallback(callback, settings);
|
||||||
mLegacyAdvertisers.put(callback, wrapped);
|
mLegacyAdvertisers.put(callback, wrapped);
|
||||||
startAdvertisingSet(parameters.build(), advertiseData, scanResponse, null, null,
|
startAdvertisingSet(parameters.build(), advertiseData, scanResponse, null, null,
|
||||||
settings.getTimeout(), wrapped);
|
duration, 0, wrapped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,8 +220,8 @@ public final class BluetoothLeAdvertiser {
|
|||||||
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
||||||
* advertisement is connectable, three bytes will be added for flags.
|
* advertisement is connectable, three bytes will be added for flags.
|
||||||
* @param scanResponse Scan response associated with the advertisement data. Size must not exceed
|
* @param scanResponse Scan response associated with the advertisement data. Size must not
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
* exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
||||||
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
||||||
* not be started.
|
* not be started.
|
||||||
* @param periodicData Periodic advertising data. Size must not exceed
|
* @param periodicData Periodic advertising data. Size must not exceed
|
||||||
@ -231,7 +237,7 @@ public final class BluetoothLeAdvertiser {
|
|||||||
PeriodicAdvertisingParameters periodicParameters,
|
PeriodicAdvertisingParameters periodicParameters,
|
||||||
AdvertiseData periodicData, AdvertisingSetCallback callback) {
|
AdvertiseData periodicData, AdvertisingSetCallback callback) {
|
||||||
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
||||||
periodicData, 0, callback, new Handler(Looper.getMainLooper()));
|
periodicData, 0, 0, callback, new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,8 +249,8 @@ public final class BluetoothLeAdvertiser {
|
|||||||
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
||||||
* advertisement is connectable, three bytes will be added for flags.
|
* advertisement is connectable, three bytes will be added for flags.
|
||||||
* @param scanResponse Scan response associated with the advertisement data. Size must not exceed
|
* @param scanResponse Scan response associated with the advertisement data. Size must not
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
* exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
||||||
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
||||||
* not be started.
|
* not be started.
|
||||||
* @param periodicData Periodic advertising data. Size must not exceed
|
* @param periodicData Periodic advertising data. Size must not exceed
|
||||||
@ -262,7 +268,7 @@ public final class BluetoothLeAdvertiser {
|
|||||||
AdvertiseData periodicData, AdvertisingSetCallback callback,
|
AdvertiseData periodicData, AdvertisingSetCallback callback,
|
||||||
Handler handler) {
|
Handler handler) {
|
||||||
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
||||||
periodicData, 0, callback, handler);
|
periodicData, 0, 0, callback, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,13 +280,18 @@ public final class BluetoothLeAdvertiser {
|
|||||||
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
||||||
* advertisement is connectable, three bytes will be added for flags.
|
* advertisement is connectable, three bytes will be added for flags.
|
||||||
* @param scanResponse Scan response associated with the advertisement data. Size must not exceed
|
* @param scanResponse Scan response associated with the advertisement data. Size must not
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
* exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
||||||
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
||||||
* not be started.
|
* not be started.
|
||||||
* @param periodicData Periodic advertising data. Size must not exceed
|
* @param periodicData Periodic advertising data. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}.
|
||||||
* @param timeoutMillis Advertising time limit. May not exceed 180000
|
* @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to
|
||||||
|
* 65535 (655,350 ms). 0 means advertising should continue until stopped.
|
||||||
|
* @param maxExtendedAdvertisingEvents maximum number of extended advertising events the
|
||||||
|
* controller shall attempt to send prior to terminating the extended
|
||||||
|
* advertising, even if the duration has not expired. Valid range is
|
||||||
|
* from 1 to 255. 0 means no maximum.
|
||||||
* @param callback Callback for advertising set.
|
* @param callback Callback for advertising set.
|
||||||
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
|
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
|
||||||
* size, or unsupported advertising PHY is selected, or when attempt to use
|
* size, or unsupported advertising PHY is selected, or when attempt to use
|
||||||
@ -290,10 +301,12 @@ public final class BluetoothLeAdvertiser {
|
|||||||
public void startAdvertisingSet(AdvertisingSetParameters parameters,
|
public void startAdvertisingSet(AdvertisingSetParameters parameters,
|
||||||
AdvertiseData advertiseData, AdvertiseData scanResponse,
|
AdvertiseData advertiseData, AdvertiseData scanResponse,
|
||||||
PeriodicAdvertisingParameters periodicParameters,
|
PeriodicAdvertisingParameters periodicParameters,
|
||||||
AdvertiseData periodicData, int timeoutMillis,
|
AdvertiseData periodicData, int duration,
|
||||||
|
int maxExtendedAdvertisingEvents,
|
||||||
AdvertisingSetCallback callback) {
|
AdvertisingSetCallback callback) {
|
||||||
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
||||||
periodicData, timeoutMillis, callback, new Handler(Looper.getMainLooper()));
|
periodicData, duration, maxExtendedAdvertisingEvents, callback,
|
||||||
|
new Handler(Looper.getMainLooper()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -301,29 +314,36 @@ public final class BluetoothLeAdvertiser {
|
|||||||
* method returns immediately, the operation status is delivered through
|
* method returns immediately, the operation status is delivered through
|
||||||
* {@code callback.onAdvertisingSetStarted()}.
|
* {@code callback.onAdvertisingSetStarted()}.
|
||||||
* <p>
|
* <p>
|
||||||
* @param parameters advertising set parameters.
|
* @param parameters Advertising set parameters.
|
||||||
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
* @param advertiseData Advertisement data to be broadcasted. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}. If the
|
||||||
* advertisement is connectable, three bytes will be added for flags.
|
* advertisement is connectable, three bytes will be added for flags.
|
||||||
* @param scanResponse Scan response associated with the advertisement data. Size must not exceed
|
* @param scanResponse Scan response associated with the advertisement data. Size must not
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
|
* exceed {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
|
||||||
* @param periodicParameters periodic advertisng parameters. If null, periodic advertising will
|
* @param periodicParameters Periodic advertisng parameters. If null, periodic advertising will
|
||||||
* not be started.
|
* not be started.
|
||||||
* @param periodicData Periodic advertising data. Size must not exceed
|
* @param periodicData Periodic advertising data. Size must not exceed
|
||||||
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
|
* {@link BluetoothAdapter#getLeMaximumAdvertisingDataLength}
|
||||||
* @param timeoutMillis Advertising time limit. May not exceed 180000
|
* @param duration advertising duration, in 10ms unit. Valid range is from 1 (10ms) to
|
||||||
|
* 65535 (655,350 ms). 0 means advertising should continue until stopped.
|
||||||
|
* @param maxExtendedAdvertisingEvents maximum number of extended advertising events the
|
||||||
|
* controller shall attempt to send prior to terminating the extended
|
||||||
|
* advertising, even if the duration has not expired. Valid range is
|
||||||
|
* from 1 to 255. 0 means no maximum.
|
||||||
* @param callback Callback for advertising set.
|
* @param callback Callback for advertising set.
|
||||||
* @param handler thread upon which the callbacks will be invoked.
|
* @param handler Thread upon which the callbacks will be invoked.
|
||||||
* @throws IllegalArgumentException when any of the data parameter exceed the maximum allowable
|
* @throws IllegalArgumentException When any of the data parameter exceed the maximum allowable
|
||||||
* size, or unsupported advertising PHY is selected, or when attempt to use
|
* size, or unsupported advertising PHY is selected, or when attempt to use
|
||||||
* Periodic Advertising feature is made when it's not supported by the
|
* Periodic Advertising feature is made when it's not supported by the
|
||||||
* controller.
|
* controller, or when maxExtendedAdvertisingEvents is used on a controller
|
||||||
|
* that doesn't support the LE Extended Advertising
|
||||||
*/
|
*/
|
||||||
public void startAdvertisingSet(AdvertisingSetParameters parameters,
|
public void startAdvertisingSet(AdvertisingSetParameters parameters,
|
||||||
AdvertiseData advertiseData, AdvertiseData scanResponse,
|
AdvertiseData advertiseData, AdvertiseData scanResponse,
|
||||||
PeriodicAdvertisingParameters periodicParameters,
|
PeriodicAdvertisingParameters periodicParameters,
|
||||||
AdvertiseData periodicData, int timeoutMillis,
|
AdvertiseData periodicData, int duration,
|
||||||
AdvertisingSetCallback callback, Handler handler) {
|
int maxExtendedAdvertisingEvents, AdvertisingSetCallback callback,
|
||||||
|
Handler handler) {
|
||||||
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
|
BluetoothLeUtils.checkAdapterStateOn(mBluetoothAdapter);
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
throw new IllegalArgumentException("callback cannot be null");
|
throw new IllegalArgumentException("callback cannot be null");
|
||||||
@ -372,6 +392,22 @@ public final class BluetoothLeAdvertiser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxExtendedAdvertisingEvents < 0 || maxExtendedAdvertisingEvents > 255) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"maxExtendedAdvertisingEvents out of range: " + maxExtendedAdvertisingEvents);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxExtendedAdvertisingEvents != 0 &&
|
||||||
|
!mBluetoothAdapter.isLePeriodicAdvertisingSupported()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Can't use maxExtendedAdvertisingEvents with controller that don't support " +
|
||||||
|
"LE Extended Advertising");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (duration < 0 || duration > 65535) {
|
||||||
|
throw new IllegalArgumentException("duration out of range: " + duration);
|
||||||
|
}
|
||||||
|
|
||||||
IBluetoothGatt gatt;
|
IBluetoothGatt gatt;
|
||||||
try {
|
try {
|
||||||
gatt = mBluetoothManager.getBluetoothGatt();
|
gatt = mBluetoothManager.getBluetoothGatt();
|
||||||
@ -388,7 +424,7 @@ public final class BluetoothLeAdvertiser {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
gatt.startAdvertisingSet(parameters, advertiseData, scanResponse, periodicParameters,
|
||||||
periodicData, timeoutMillis, wrapped);
|
periodicData, duration, maxExtendedAdvertisingEvents, wrapped);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Failed to start advertising set - ", e);
|
Log.e(TAG, "Failed to start advertising set - ", e);
|
||||||
throw new IllegalStateException("Failed to start advertising set");
|
throw new IllegalStateException("Failed to start advertising set");
|
||||||
|
Reference in New Issue
Block a user