public final class Util_Native
extends java.lang.Object
UnitTestBluetoothGatt
, UnitTestBluetoothDevice
, and UnitTestBluetoothManager
use this class. If you are implementing your own
version of those classes, you will need to use this class to simulate the native callbacks.
This is not in the utils package as it accesses several package private methods.
Modifier and Type | Method and Description |
---|---|
static void |
addServiceSuccess(BleServer server,
BleService service,
Interval delay) |
static void |
advertiseDevice(BleManager mgr,
int rssi,
byte[] scanRecord,
java.lang.String macAddress)
Overload of
advertiseDevice(BleManager, int, byte[], String, Interval) with no delay. |
static void |
advertiseDevice(BleManager mgr,
int rssi,
byte[] scanRecord,
java.lang.String macAddress,
Interval delay)
Simulate a device that is advertising, so SweetBlue picks up on it (as long as scanning is occurring at the time you call this method).
|
static void |
advertiseDeviceList(BleManager mgr,
java.util.List<L_Util.ScanResult> devices,
Interval delay)
Simulate a batch of devices that are advertising, so SweetBlue picks up on it (as long as scanning is occuring at the time you call this method).
|
static void |
advertiseNewDevice(BleManager mgr,
int rssi,
byte[] scanRecord)
Simulate a device that is advertising, so SweetBlue picks up on it (as long as scanning is occurring at the time you call this method).
|
static void |
advertiseNewDevice(BleManager mgr,
int rssi,
java.lang.String deviceName)
Overload of
advertiseNewDevice(BleManager, int, byte[]) , which creates the byte[] scanRecord from the name you provide. |
static void |
bondFail(BleDevice device,
int failReason)
Overload of
bondFail(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
bondFail(BleDevice device,
int failReason,
Interval delay)
Send a callback that a bond has failed with the provided reason..something like
BleStatuses.UNBOND_REASON_AUTH_FAILED , or BleStatuses.UNBOND_REASON_REMOTE_DEVICE_DOWN , and
delays the callback by the amount specified. |
static void |
bondSuccess(BleDevice device)
Overload of
bondSuccess(BleDevice, Interval) which delays the callback by 50ms. |
static void |
bondSuccess(BleDevice device,
Interval delay)
Send the callback that a bond was successful, and delays the callback by the amount of time specified
|
static void |
failDiscoverServices(BleDevice device,
int gattStatus) |
static void |
failDiscoverServices(BleDevice device,
int gattStatus,
Interval delay) |
static void |
forceOn(BleManager manager) |
static void |
readDescError(BleDevice device,
BleDescriptor descriptor,
int gattStatus)
Overload of
readDescError(BleDevice, BleDescriptor, int, long) which delays the callback by 50ms. |
static void |
readDescError(BleDevice device,
BleDescriptor descriptor,
int gattStatus,
long delay)
Send a callback that a descriptor read failed with the given gattStatus, and delays the callback by the amount specified.
|
static void |
readDescSuccess(BleDevice device,
BleDescriptor descriptor,
byte[] data)
Overload of
readDescSuccess(BleDevice, BleDescriptor, byte[], Interval) which delays the callback by 50ms. |
static void |
readDescSuccess(BleDevice device,
BleDescriptor descriptor,
byte[] data,
Interval delay)
Send a callback that a descriptor read was successful, with the data to return, and delays the callback by the amount specified.
|
static void |
readError(BleDevice device,
BleCharacteristic characteristic,
int gattStatus)
Overload of
readError(BleDevice, BleCharacteristic, int, Interval) which delays the callback by 50ms. |
static void |
readError(BleDevice device,
BleCharacteristic characteristic,
int gattStatus,
Interval delay)
Send a callback that a read has failed, with the gattStatus provided, for instance
BleStatuses.GATT_ERROR , which delays the callback by the amount specified. |
static void |
readFromServer(BleServer server,
java.lang.String macAddress,
java.util.UUID characteristicUuid,
Interval delay) |
static void |
readPhyFailure(BleDevice device,
Phy phyOption,
int gattStatus)
Overload of
readPhyFailure(BleDevice, Phy, int, Interval) , which has a delay of 50ms. |
static void |
readPhyFailure(BleDevice device,
Phy phyOption,
int gattStatus,
Interval delay)
Send a callback that says a request to read the physical layer (bluetooth 5 feature) failed with the given gatt status code
|
static void |
readPhySuccess(BleDevice device,
Phy phyOption,
Interval delay)
Send a callback that says a request to read the physical layer (bluetooth 5 feature) was successful, with the given
Phy , and
the amount of time to delay before the callback is sent. |
static void |
readSuccess(BleDevice device,
BleCharacteristic characteristic,
byte[] data)
Overload of
readSuccess(BleDevice, BleCharacteristic, byte[], Interval) which delays the callback by 50ms. |
static void |
readSuccess(BleDevice device,
BleCharacteristic characteristic,
byte[] data,
Interval delay)
Send a callback that a read was successful, with the data to send back from the read, and delays the callback by the amount specified.
|
static void |
remoteRssiError(BleDevice device,
int gattStatus)
Overload of
remoteRssiError(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
remoteRssiError(BleDevice device,
int gattStatus,
Interval delay)
Send a callback that a remote rssi read has failed with the given gattStatus, and delay the callback by the amount specified.
|
static void |
remoteRssiSuccess(BleDevice device,
int rssi)
Overload of
remoteRssiSuccess(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
remoteRssiSuccess(BleDevice device,
int rssi,
Interval delay)
Send a callback that a read remote rssi succeeded with the given rssi value, and delay the callback by the amount specified.
|
static void |
requestMTUError(BleDevice device,
int mtu,
int gattStatus)
Overload of
requestMTUError(BleDevice, int, int, Interval) which delays the callback by 50ms. |
static void |
requestMTUError(BleDevice device,
int mtu,
int gattStatus,
Interval delay)
Send a callback that says an MTU request failed, with the given gattStatus, and delay the callback by the amount specified.
|
static void |
requestMTUSuccess(BleDevice device,
int mtu)
Overload of
requestMTUSuccess(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
requestMTUSuccess(BleDevice device,
int mtu,
Interval delay)
Send a callback that says an MTU request was successful, with the newly negotiated mtu size, and delay the callback by the amount specified.
|
static void |
sendBluetoothStateChange(BleManager manager,
int previousState,
int newState)
Overload of
sendBluetoothStateChange(BleManager, int, int, Interval) , with Interval.ZERO delay. |
static void |
sendBluetoothStateChange(BleManager manager,
int previousState,
int newState,
Interval delay)
Sends a bluetooth state change, such as
BluetoothAdapter.STATE_ON , BluetoothAdapter.STATE_OFF , etc. |
static void |
sendNotification(BleDevice device,
BleCharacteristic characteristic,
byte[] data)
Overload of
sendNotification(BleDevice, BleCharacteristic, byte[], Interval) which delays the callback by 50ms. |
static void |
sendNotification(BleDevice device,
BleCharacteristic characteristic,
byte[] data,
Interval delay)
Simulate a notification being received with the given data, and delay the callback by the amount specified.
|
static void |
sendWriteToServer(BleServer server,
java.lang.String macAddress,
java.util.UUID characteristicUuid,
byte[] value,
Interval delay)
Send a callback to a server instance, mimicking a peripheral writing to the server.
|
static void |
setBondStatusSuccess(BleDevice device,
int newState,
Interval delay)
Allows you to set a new bonding state, and pump it through the system as if it's a native callback.
|
static void |
setPhyFailure(BleDevice device,
Phy phyOptions,
int gattStatus)
Overload of
setPhyFailure(BleDevice, Phy, int, Interval) , which has a delay of 50ms. |
static void |
setPhyFailure(BleDevice device,
Phy phyOptions,
int gattStatus,
Interval delay)
Send a callback that says a request to change the physical layer (bluetooth 5 feature) failed with the given gatt status code
|
static void |
setPhySuccess(BleDevice device,
Phy phyOptions,
Interval delay)
Send a callback that says a request to change the physical layer (bluetooth 5 feature) was successful, with the given
Phy , and
the amount of time to delay before the callback is sent. |
static void |
setToAdvertising(BleManager mgr,
android.bluetooth.le.AdvertiseSettings settings,
L_Util.AdvertisingCallback callback) |
static void |
setToAdvertising(BleManager mgr,
android.bluetooth.le.AdvertiseSettings settings,
L_Util.AdvertisingCallback callback,
Interval delay) |
static void |
setToConnected(BleDevice device)
Overload of
setToConnected(BleDevice, int) which sets the gattStatus to BleStatuses.GATT_SUCCESS . |
static void |
setToConnected(BleDevice device,
int gattStatus)
Overload of
setToConnected(BleDevice, int, Interval) , which delays the callback by 50ms. |
static void |
setToConnected(BleDevice device,
int gattStatus,
boolean updateDeviceState,
Interval delay)
Send a callback to set a device's state to
BluetoothProfile.STATE_CONNECTED , with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified. |
static void |
setToConnected(BleDevice device,
int gattStatus,
Interval delay)
Overload of
setToConnected(BleDevice, int, boolean, Interval) which updates the internal state as well. |
static void |
setToConnected(BleServer server,
java.lang.String macAddress,
Interval delay)
Send a callback to set the server's state to
BluetoothProfile.STATE_CONNECTED , with the given gattStatus, and delay
the callback by the amount specified. |
static void |
setToConnecting(BleDevice device)
Overload of
setToConnecting(BleDevice, int) which sets the gattStatus to BleStatuses.GATT_SUCCESS . |
static void |
setToConnecting(BleDevice device,
int gattStatus)
Overload of
setToConnecting(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
setToConnecting(BleDevice device,
int gattStatus,
boolean updateDeviceState,
Interval delay)
Send a callback to set a device's state to
BluetoothProfile.STATE_CONNECTING , with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified. |
static void |
setToConnecting(BleDevice device,
int gattStatus,
Interval delay)
Overload of
setToConnecting(BleDevice, int, boolean, Interval) which updates the internal state as well. |
static void |
setToConnecting(BleServer server,
java.lang.String macAddress,
int gattStatus,
Interval delay)
Send a callback to set the server's state to
BluetoothProfile.STATE_CONNECTING , with the given gattStatus, and delay
the callback by the amount specified. |
static void |
setToDisconnected(BleDevice device)
Overload of
setToDisconnected(BleDevice, int) with sets the gattStatus to BleStatuses.GATT_SUCCESS . |
static void |
setToDisconnected(BleDevice device,
int gattStatus)
Overload of
setToDisconnected(BleDevice, int, Interval) which delays the callback by 50ms. |
static void |
setToDisconnected(BleDevice device,
int gattStatus,
boolean updateDeviceState,
Interval delay)
Send a callback to set a device's state to
BluetoothProfile.STATE_DISCONNECTED , with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified. |
static void |
setToDisconnected(BleDevice device,
int gattStatus,
Interval delay)
Overload of
setToDisconnected(BleDevice, int, boolean, Interval) which sets the device's internal state. |
static void |
setToDisconnected(BleServer server,
java.lang.String macAddress,
int gattStatus,
Interval delay)
Send a callback to set the server's state to
BluetoothProfile.STATE_DISCONNECTED , with the given gattStatus, and delay
the callback by the amount specified. |
static void |
simulateBleTurningOff(BleManager manager,
Interval delay)
Overload of
simulateBleTurningOff(BleManager, Interval, Interval) , with no start delay |
static void |
simulateBleTurningOff(BleManager manager,
Interval startDelay,
Interval delay) |
static void |
simulateBleTurningOn(BleManager manager,
Interval delay)
Overload of
simulateBleTurningOn(BleManager, Interval, Interval) with no start delay |
static void |
simulateBleTurningOn(BleManager manager,
Interval startDelay,
Interval delay)
Convenience method to simulate BLE being turned on.
|
static void |
succeedDiscoverServices(BleDevice device) |
static void |
unbondSuccess(BleDevice device,
Interval delay) |
static void |
writeDescError(BleDevice device,
BleDescriptor descriptor,
int gattStatus)
Overload of
writeDescError(BleDevice, BleDescriptor, int, Interval) which delays the callback by 50ms. |
static void |
writeDescError(BleDevice device,
BleDescriptor descriptor,
int gattStatus,
Interval delay)
Send a callback that a descriptor write failed, with the given gattStatus, and delay the callback by the amount specified.
|
static void |
writeDescSuccess(BleDevice device,
BleDescriptor descriptor)
Overload of
writeDescSuccess(BleDevice, BleDescriptor, Interval) which delays the callback by 50ms. |
static void |
writeDescSuccess(BleDevice device,
BleDescriptor descriptor,
Interval delay)
Send a callback that a descriptor write suceeded, and delay the callback by the amount specified.
|
static void |
writeError(BleDevice device,
BleCharacteristic characteristic,
int gattStatus)
Overload of
writeError(BleDevice, BleCharacteristic, int, Interval) which delays the callback by 50ms. |
static void |
writeError(BleDevice device,
BleCharacteristic characteristic,
int gattStatus,
Interval delay)
Send a callback that a write failed, with the given gattStatus, and delay the callback by the amount specified.
|
static void |
writeSuccess(BleDevice device,
BleCharacteristic characteristic)
Overload of
writeSuccess(BleDevice, BleCharacteristic, Interval) which delays the callback by 50ms. |
static void |
writeSuccess(BleDevice device,
BleCharacteristic characteristic,
Interval delay)
Send a callback that a write succeeded, and delay the callback by the amount specified.
|
public static void sendBluetoothStateChange(BleManager manager, int previousState, int newState)
sendBluetoothStateChange(BleManager, int, int, Interval)
, with Interval.ZERO
delay.public static void sendBluetoothStateChange(BleManager manager, int previousState, int newState, Interval delay)
BluetoothAdapter.STATE_ON
, BluetoothAdapter.STATE_OFF
, etc.public static void simulateBleTurningOn(BleManager manager, Interval delay)
simulateBleTurningOn(BleManager, Interval, Interval)
with no start delaypublic static void forceOn(BleManager manager)
public static void simulateBleTurningOn(BleManager manager, Interval startDelay, Interval delay)
sendBluetoothStateChange(BleManager, int, int, Interval)
twice.
Once to set the state to AdapterConst.STATE_TURNING_ON
, then again to AdapterConst.STATE_ON
. The first call is made after the given startDelay,
whereas the second is delayed by the amount given. If the given BleManager
reports it's already BleManagerState.ON
, then this method
will do nothing.public static void simulateBleTurningOff(BleManager manager, Interval delay)
simulateBleTurningOff(BleManager, Interval, Interval)
, with no start delaypublic static void simulateBleTurningOff(BleManager manager, Interval startDelay, Interval delay)
public static void bondSuccess(BleDevice device)
bondSuccess(BleDevice, Interval)
which delays the callback by 50ms.public static void bondSuccess(BleDevice device, Interval delay)
public static void setBondStatusSuccess(BleDevice device, int newState, Interval delay)
public static void bondFail(BleDevice device, int failReason)
bondFail(BleDevice, int, Interval)
which delays the callback by 50ms.public static void bondFail(BleDevice device, int failReason, Interval delay)
BleStatuses.UNBOND_REASON_AUTH_FAILED
, or BleStatuses.UNBOND_REASON_REMOTE_DEVICE_DOWN
, and
delays the callback by the amount specified.public static void readError(BleDevice device, BleCharacteristic characteristic, int gattStatus)
readError(BleDevice, BleCharacteristic, int, Interval)
which delays the callback by 50ms.public static void readError(BleDevice device, BleCharacteristic characteristic, int gattStatus, Interval delay)
BleStatuses.GATT_ERROR
, which delays the callback by the amount specified.public static void readSuccess(BleDevice device, BleCharacteristic characteristic, byte[] data)
readSuccess(BleDevice, BleCharacteristic, byte[], Interval)
which delays the callback by 50ms.public static void readSuccess(BleDevice device, BleCharacteristic characteristic, byte[] data, Interval delay)
public static void readDescSuccess(BleDevice device, BleDescriptor descriptor, byte[] data)
readDescSuccess(BleDevice, BleDescriptor, byte[], Interval)
which delays the callback by 50ms.public static void readDescSuccess(BleDevice device, BleDescriptor descriptor, byte[] data, Interval delay)
public static void readDescError(BleDevice device, BleDescriptor descriptor, int gattStatus)
readDescError(BleDevice, BleDescriptor, int, long)
which delays the callback by 50ms.public static void readDescError(BleDevice device, BleDescriptor descriptor, int gattStatus, long delay)
public static void writeDescSuccess(BleDevice device, BleDescriptor descriptor)
writeDescSuccess(BleDevice, BleDescriptor, Interval)
which delays the callback by 50ms.public static void writeDescSuccess(BleDevice device, BleDescriptor descriptor, Interval delay)
public static void writeDescError(BleDevice device, BleDescriptor descriptor, int gattStatus)
writeDescError(BleDevice, BleDescriptor, int, Interval)
which delays the callback by 50ms.public static void writeDescError(BleDevice device, BleDescriptor descriptor, int gattStatus, Interval delay)
public static void writeSuccess(BleDevice device, BleCharacteristic characteristic)
writeSuccess(BleDevice, BleCharacteristic, Interval)
which delays the callback by 50ms.public static void writeSuccess(BleDevice device, BleCharacteristic characteristic, Interval delay)
public static void writeError(BleDevice device, BleCharacteristic characteristic, int gattStatus)
writeError(BleDevice, BleCharacteristic, int, Interval)
which delays the callback by 50ms.public static void writeError(BleDevice device, BleCharacteristic characteristic, int gattStatus, Interval delay)
public static void sendWriteToServer(BleServer server, java.lang.String macAddress, java.util.UUID characteristicUuid, byte[] value, Interval delay)
public static void readFromServer(BleServer server, java.lang.String macAddress, java.util.UUID characteristicUuid, Interval delay)
public static void addServiceSuccess(BleServer server, BleService service, Interval delay)
public static void requestMTUSuccess(BleDevice device, int mtu)
requestMTUSuccess(BleDevice, int, Interval)
which delays the callback by 50ms.public static void requestMTUSuccess(BleDevice device, int mtu, Interval delay)
public static void requestMTUError(BleDevice device, int mtu, int gattStatus)
requestMTUError(BleDevice, int, int, Interval)
which delays the callback by 50ms.public static void requestMTUError(BleDevice device, int mtu, int gattStatus, Interval delay)
public static void setPhySuccess(BleDevice device, Phy phyOptions, Interval delay)
Phy
, and
the amount of time to delay before the callback is sent.public static void setPhyFailure(BleDevice device, Phy phyOptions, int gattStatus)
setPhyFailure(BleDevice, Phy, int, Interval)
, which has a delay of 50ms.public static void setPhyFailure(BleDevice device, Phy phyOptions, int gattStatus, Interval delay)
public static void readPhySuccess(BleDevice device, Phy phyOption, Interval delay)
Phy
, and
the amount of time to delay before the callback is sent.public static void readPhyFailure(BleDevice device, Phy phyOption, int gattStatus)
readPhyFailure(BleDevice, Phy, int, Interval)
, which has a delay of 50ms.public static void readPhyFailure(BleDevice device, Phy phyOption, int gattStatus, Interval delay)
public static void remoteRssiSuccess(BleDevice device, int rssi)
remoteRssiSuccess(BleDevice, int, Interval)
which delays the callback by 50ms.public static void remoteRssiSuccess(BleDevice device, int rssi, Interval delay)
public static void remoteRssiError(BleDevice device, int gattStatus)
remoteRssiError(BleDevice, int, Interval)
which delays the callback by 50ms.public static void remoteRssiError(BleDevice device, int gattStatus, Interval delay)
public static void sendNotification(BleDevice device, BleCharacteristic characteristic, byte[] data)
sendNotification(BleDevice, BleCharacteristic, byte[], Interval)
which delays the callback by 50ms.public static void sendNotification(BleDevice device, BleCharacteristic characteristic, byte[] data, Interval delay)
public static void succeedDiscoverServices(BleDevice device)
public static void failDiscoverServices(BleDevice device, int gattStatus)
public static void failDiscoverServices(BleDevice device, int gattStatus, Interval delay)
public static void setToConnecting(BleDevice device)
setToConnecting(BleDevice, int)
which sets the gattStatus to BleStatuses.GATT_SUCCESS
.public static void setToConnecting(BleDevice device, int gattStatus)
setToConnecting(BleDevice, int, Interval)
which delays the callback by 50ms.public static void setToConnecting(BleDevice device, int gattStatus, Interval delay)
setToConnecting(BleDevice, int, boolean, Interval)
which updates the internal state as well.public static void setToConnecting(BleDevice device, int gattStatus, boolean updateDeviceState, Interval delay)
BluetoothProfile.STATE_CONNECTING
, with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified.public static void setToConnecting(BleServer server, java.lang.String macAddress, int gattStatus, Interval delay)
BluetoothProfile.STATE_CONNECTING
, with the given gattStatus, and delay
the callback by the amount specified.public static void setToConnected(BleDevice device)
setToConnected(BleDevice, int)
which sets the gattStatus to BleStatuses.GATT_SUCCESS
.public static void setToConnected(BleDevice device, int gattStatus)
setToConnected(BleDevice, int, Interval)
, which delays the callback by 50ms.public static void setToConnected(BleDevice device, int gattStatus, Interval delay)
setToConnected(BleDevice, int, boolean, Interval)
which updates the internal state as well.public static void setToConnected(BleDevice device, int gattStatus, boolean updateDeviceState, Interval delay)
BluetoothProfile.STATE_CONNECTED
, with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified.public static void setToConnected(BleServer server, java.lang.String macAddress, Interval delay)
BluetoothProfile.STATE_CONNECTED
, with the given gattStatus, and delay
the callback by the amount specified.public static void setToDisconnected(BleDevice device)
setToDisconnected(BleDevice, int)
with sets the gattStatus to BleStatuses.GATT_SUCCESS
.public static void setToDisconnected(BleDevice device, int gattStatus)
setToDisconnected(BleDevice, int, Interval)
which delays the callback by 50ms.public static void setToDisconnected(BleDevice device, int gattStatus, Interval delay)
setToDisconnected(BleDevice, int, boolean, Interval)
which sets the device's internal state.public static void setToDisconnected(BleDevice device, int gattStatus, boolean updateDeviceState, Interval delay)
BluetoothProfile.STATE_DISCONNECTED
, with the given gattStatus, whether or not to update the internal state, and delay
the callback by the amount specified.public static void setToDisconnected(BleServer server, java.lang.String macAddress, int gattStatus, Interval delay)
BluetoothProfile.STATE_DISCONNECTED
, with the given gattStatus, and delay
the callback by the amount specified.public static void advertiseNewDevice(BleManager mgr, int rssi, byte[] scanRecord)
Utils_ScanRecord.newScanRecord(String)
, Utils_ScanRecord.newScanRecord(String, UUID)
, etc to get the byte[] of the scan record easily.
This will generate a random mac address for the device.public static void advertiseDevice(BleManager mgr, int rssi, byte[] scanRecord, java.lang.String macAddress)
advertiseDevice(BleManager, int, byte[], String, Interval)
with no delay.public static void advertiseDevice(BleManager mgr, int rssi, byte[] scanRecord, java.lang.String macAddress, Interval delay)
Utils_ScanRecord.newScanRecord(String)
, Utils_ScanRecord.newScanRecord(String, UUID)
, etc to get the byte[] of the scan record easily.
You can use this method to "update" a device's scan record, but you must make sure to use the same mac address for this to work.public static void advertiseDeviceList(BleManager mgr, java.util.List<L_Util.ScanResult> devices, Interval delay)
public static void advertiseNewDevice(BleManager mgr, int rssi, java.lang.String deviceName)
advertiseNewDevice(BleManager, int, byte[])
, which creates the byte[] scanRecord from the name you provide.public static void setToAdvertising(BleManager mgr, android.bluetooth.le.AdvertiseSettings settings, L_Util.AdvertisingCallback callback)
public static void setToAdvertising(BleManager mgr, android.bluetooth.le.AdvertiseSettings settings, L_Util.AdvertisingCallback callback, Interval delay)