public class UnitTestBluetoothGatt extends java.lang.Object implements IBluetoothGatt
IBluetoothGatt.DefaultFactory, IBluetoothGatt.Factory
Modifier and Type | Field and Description |
---|---|
static int |
MAX_DELAY_TIME |
static int |
MIN_DELAY_TIME |
DEFAULT_FACTORY
Constructor and Description |
---|
UnitTestBluetoothGatt(IBleDevice device)
Default constructor to use when not providing a
GattDatabase instance. |
UnitTestBluetoothGatt(IBleDevice device,
GattDatabase gattDb)
Default constructor to use when providing a
GattDatabase instance. |
Modifier and Type | Method and Description |
---|---|
void |
abortReliableWrite(android.bluetooth.BluetoothDevice device)
Not hooked up in this class.
|
boolean |
beginReliableWrite()
Not hooked up in this class.
|
UhOhListener.UhOh |
closeGatt()
Another internal method that does nothing when unit testing.
|
void |
connect(IBluetoothDevice device,
android.content.Context context,
boolean useAutoConnect,
android.bluetooth.BluetoothGattCallback callback)
Connects to the device.
|
void |
disconnect()
Disconnects the device.
|
boolean |
discoverServices()
Called by the system when trying to discover it's services (gatt database).
|
boolean |
equals(P_GattHolder gatt) |
boolean |
executeReliableWrite()
Not hooked up in this class.
|
java.lang.Boolean |
getAuthRetryValue() |
BleDevice |
getBleDevice()
Returns the
BleDevice instance held in this class. |
BleService |
getBleService(java.util.UUID serviceUuid,
LogFunction logger)
Method used internally to retrieve a
BleService instance. |
Interval |
getDelayTime()
Returns the delay set via
setDelayTime(Interval) , or a random time range from MIN_DELAY_TIME to MAX_DELAY_TIME . |
android.bluetooth.BluetoothGatt |
getGatt()
Internal method which does nothing, and has no value when unit testing.
|
java.util.List<BleService> |
getNativeServiceList(LogFunction logger)
Returns a List of
BleService s that represent the backing gatt database. |
int |
getRssiValue()
Returns a random rssi value based off
BleDeviceConfig.rssi_min and BleDeviceConfig.rssi_max . |
boolean |
isGattNull()
Returns
true if the gatt instance is "null". |
void |
preDisconnect()
Sends the "native" callback to set the state to DISCONNECTED
|
boolean |
readCharacteristic(BleCharacteristic characteristic)
Called when the system is trying to read a characteristic.
|
boolean |
readDescriptor(BleDescriptor descriptor)
Called by the system when trying to read a descriptor.
|
boolean |
readPhy()
Read the PHY of the device.
|
boolean |
readRemoteRssi()
Called by the system when trying to read the rssi from the device.
|
boolean |
refreshGatt()
This method doesn't really make any sense in a unit testing environment as everything is mocked.
|
boolean |
requestConnectionPriority(BleConnectionPriority priority)
Called by the system when trying to request a change in connection priority.
|
boolean |
requestMtu(int mtu)
Called when the system wants to request a new MTU size.
|
void |
sendReadDescriptorResponse(BleDescriptor descriptor,
byte[] data)
Called by
readDescriptor(BleDescriptor) to send the response of the read back through the "native" callback. |
void |
sendReadResponse(BleCharacteristic characteristic,
byte[] data)
Called by
readCharacteristic(BleCharacteristic) to send the response of the read. |
void |
sendWriteDescResponse(BleDescriptor descriptor)
Called by
writeDescriptor(BleDescriptor) to send the response of writing to the descriptor to the native callback. |
void |
sendWriteResponse(BleCharacteristic characteristic)
Sends the response of writing to a characteristic.
|
boolean |
setCharacteristicNotification(BleCharacteristic characteristic,
boolean enable)
Called internally when enabling/disabling a notification on a characteristic.
|
boolean |
setCharValue(BleCharacteristic characteristic,
byte[] data)
Used internally when writing to a characteristic.
|
void |
setDatabase(GattDatabase database)
Set the
GattDatabase instance this gatt instance will use. |
void |
setDelayTime(Interval delay)
Sets the amount of time to delay each native callback (to simulate a real world scenario where callbacks aren't instant)
|
boolean |
setDescValue(BleDescriptor descriptor,
byte[] data)
Called internally when trying to write to a descriptor.
|
void |
setGatt(android.bluetooth.BluetoothGatt gatt)
Internal method used by the library.
|
void |
setGattNull(boolean isNull)
Sets the gatt instance to be
null |
boolean |
setPhy(Phy options)
Sets the PHY of the device.
|
void |
setServicesDiscovered()
Posts the response of discovering services to the native callback.
|
void |
setToConnected()
This sets the device state to CONNECTED, and posts the "native" callback
|
void |
setToConnecting()
This sets the device state to CONNECTING, and posts the "native" callback
|
boolean |
writeCharacteristic(BleCharacteristic characteristic)
Called when the library tries to write a characteristic.
|
boolean |
writeDescriptor(BleDescriptor descriptor)
Called when the system tries to write to a descriptor.
|
public static int MIN_DELAY_TIME
public static int MAX_DELAY_TIME
public UnitTestBluetoothGatt(IBleDevice device)
GattDatabase
instance.public UnitTestBluetoothGatt(IBleDevice device, GattDatabase gattDb)
GattDatabase
instance.public void setDatabase(GattDatabase database)
GattDatabase
instance this gatt instance will use.public final void setGatt(android.bluetooth.BluetoothGatt gatt)
setGatt
in interface IBluetoothGatt
public final UhOhListener.UhOh closeGatt()
closeGatt
in interface IBluetoothGatt
public android.bluetooth.BluetoothGatt getGatt()
getGatt
in interface IBluetoothGatt
public java.lang.Boolean getAuthRetryValue()
getAuthRetryValue
in interface IBluetoothGatt
public boolean equals(P_GattHolder gatt)
equals
in interface IBluetoothGatt
public java.util.List<BleService> getNativeServiceList(LogFunction logger)
BleService
s that represent the backing gatt database. This is managed for you, so there should be no reason
to override this method.getNativeServiceList
in interface IBluetoothGatt
public BleService getBleService(java.util.UUID serviceUuid, LogFunction logger)
BleService
instance. This is managed for you, so there should be no reason to override this
method.getBleService
in interface IBluetoothGatt
public boolean isGattNull()
true
if the gatt instance is "null". This is all faked, as we will never have a valid gatt instance during unit testing.isGattNull
in interface IBluetoothGatt
public void connect(IBluetoothDevice device, android.content.Context context, boolean useAutoConnect, android.bluetooth.BluetoothGattCallback callback)
setToConnecting()
, and setToConnected()
. You should override
those methods, instead of this one.connect
in interface IBluetoothGatt
setToConnecting()
,
setToConnected()
public void setGattNull(boolean isNull)
null
public void setToConnecting()
public void setToConnected()
public void disconnect()
preDisconnect()
to set the actual state.disconnect
in interface IBluetoothGatt
preDisconnect()
public void preDisconnect()
public boolean requestMtu(int mtu)
requestMtu
in interface IBluetoothGatt
public boolean refreshGatt()
refreshGatt
in interface IBluetoothGatt
public boolean setPhy(Phy options)
setPhy
in interface IBluetoothGatt
public boolean readPhy()
readPhy
in interface IBluetoothGatt
public boolean readCharacteristic(BleCharacteristic characteristic)
sendReadResponse(BleCharacteristic, byte[])
, which is the method
you should override to change behavior.readCharacteristic
in interface IBluetoothGatt
sendReadResponse(BleCharacteristic, byte[])
public void sendReadResponse(BleCharacteristic characteristic, byte[] data)
readCharacteristic(BleCharacteristic)
to send the response of the read.public boolean setCharValue(BleCharacteristic characteristic, byte[] data)
setCharValue
in interface IBluetoothGatt
public boolean writeCharacteristic(BleCharacteristic characteristic)
sendWriteResponse(BleCharacteristic)
, which is the method to overload to
change behavior.writeCharacteristic
in interface IBluetoothGatt
public void sendWriteResponse(BleCharacteristic characteristic)
public boolean setCharacteristicNotification(BleCharacteristic characteristic, boolean enable)
setCharacteristicNotification
in interface IBluetoothGatt
public boolean readDescriptor(BleDescriptor descriptor)
sendReadDescriptorResponse(BleDescriptor, byte[])
, which is the method
you should override to change behavior.readDescriptor
in interface IBluetoothGatt
public void sendReadDescriptorResponse(BleDescriptor descriptor, byte[] data)
readDescriptor(BleDescriptor)
to send the response of the read back through the "native" callback.public boolean setDescValue(BleDescriptor descriptor, byte[] data)
setDescValue
in interface IBluetoothGatt
public boolean writeDescriptor(BleDescriptor descriptor)
sendWriteDescResponse(BleDescriptor)
, which is the method to
override if you wish to change behavior.writeDescriptor
in interface IBluetoothGatt
public void sendWriteDescResponse(BleDescriptor descriptor)
writeDescriptor(BleDescriptor)
to send the response of writing to the descriptor to the native callback.public boolean requestConnectionPriority(BleConnectionPriority priority)
requestConnectionPriority
in interface IBluetoothGatt
public boolean discoverServices()
setServicesDiscovered()
, which is the
method to override to change behavior.discoverServices
in interface IBluetoothGatt
public void setServicesDiscovered()
public boolean executeReliableWrite()
executeReliableWrite
in interface IBluetoothGatt
public boolean beginReliableWrite()
beginReliableWrite
in interface IBluetoothGatt
public void abortReliableWrite(android.bluetooth.BluetoothDevice device)
abortReliableWrite
in interface IBluetoothGatt
public boolean readRemoteRssi()
readRemoteRssi
in interface IBluetoothGatt
public final BleDevice getBleDevice()
BleDevice
instance held in this class.getBleDevice
in interface IBluetoothGatt
public void setDelayTime(Interval delay)
public Interval getDelayTime()
setDelayTime(Interval)
, or a random time range from MIN_DELAY_TIME
to MAX_DELAY_TIME
.public int getRssiValue()
BleDeviceConfig.rssi_min
and BleDeviceConfig.rssi_max
.