Package org.robolectric.shadows
Class ShadowBluetoothGatt
java.lang.Object
org.robolectric.shadows.ShadowBluetoothGatt
Shadow implementation of
BluetoothGatt.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.robolectric.shadows.ShadowBluetoothGatt.BluetoothGattReflector -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidvoidallowCharacteristicNotification(BluetoothGattCharacteristic characteristic) Allows the incoming characteristic to be set to enable notification.protected booleanprotected voidclose()Close this Bluetooth GATT client.protected booleanconnect()Connect to a remote device, and performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if aBluetoothGattCallbackhas been set bysetGattCallback(android.bluetooth.BluetoothGattCallback)voiddisallowCharacteristicNotification(BluetoothGattCharacteristic characteristic) Disallows the incoming characteristic to be set to enable notification.protected voidDisconnects an established connection, or cancels a connection attempt currently in progress.protected booleanOverridesBluetoothGatt.discoverServices()to always return false unless there are discoverable services made available byaddDiscoverableService(android.bluetooth.BluetoothGattService)protected booleanorg.robolectric.shadows.BluetoothConnectionManagerintbyte[]byte[]protected BluetoothGattServicegetService(UUID uuid) OverridesBluetoothGatt.getService(UUID)to return a service with given UUID.protected List<BluetoothGattService> OverridesBluetoothGatt.getServices()to always return a list of services discovered.booleanisClosed()booleanstatic BluetoothGattnewInstance(BluetoothDevice device) voidnotifyConnection(String remoteAddress) Simulate a successful Gatt Client Connection withBluetoothConnectionManager.voidnotifyDisconnection(String remoteAddress) Simulate a successful Gatt Client Disconnection withBluetoothConnectionManager.protected booleanreadCharacteristic(BluetoothGattCharacteristic characteristic) protected booleanreadDescriptor(BluetoothGattDescriptor descriptor) booleanreadIncomingCharacteristic(BluetoothGattCharacteristic characteristic) Writes bytes from incoming characteristic if properties are valid and callback is set.protected voidreadPhy()OverridesBluetoothGatt.readPhy()to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after.protected booleanvoidprotected booleanrequestConnectionPriority(int priority) Request a connection parameter update.protected booleanrequestMtu(int mtu) OverridesBluetoothGatt.requestMtu(int)to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after.protected intrequestSubrateMode(int subrateMode) voidsetBeginReliableWriteResult(boolean beginReliableWriteResult) protected booleansetCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable) OverridesBluetoothGatt.setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean)so it returns true (false) if allowCharacteristicNotification (disallowCharacteristicNotification) is called.voidsetGattCallback(BluetoothGattCallback bluetoothGattCallback) voidsetPhy(int txPhy, int rxPhy) Sets the values to be returned byBluetoothGatt.readPhy()protected voidsetPreferredPhy(int txPhy, int rxPhy, int phyOptions) OverridesBluetoothGatt.setPreferredPhy(int, int, int)to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after.voidsetRequestConnectionPriorityResult(boolean requestConnectionPriorityResult) Sets the return value forBluetoothGatt.requestConnectionPriority(int).voidsetRssi(int rssi) Sets the RSSI value to be returned byreadRemoteRssi().protected booleanwriteCharacteristic(BluetoothGattCharacteristic characteristic) protected intwriteCharacteristic(BluetoothGattCharacteristic characteristic, byte[] value, int writeType) protected booleanwriteDescriptor(BluetoothGattDescriptor descriptor) protected intwriteDescriptor(BluetoothGattDescriptor descriptor, byte[] value) booleanwriteIncomingCharacteristic(BluetoothGattCharacteristic characteristic) Reads bytes from incoming characteristic if properties are valid and callback is set.
-
Field Details
-
bluetoothGattReflector
@ReflectorObject protected org.robolectric.shadows.ShadowBluetoothGatt.BluetoothGattReflector bluetoothGattReflector
-
-
Constructor Details
-
ShadowBluetoothGatt
public ShadowBluetoothGatt()
-
-
Method Details
-
newInstance
-
connect
Connect to a remote device, and performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if aBluetoothGattCallbackhas been set bysetGattCallback(android.bluetooth.BluetoothGattCallback)- Returns:
- true, if a
BluetoothGattCallbackhas been set bysetGattCallback(android.bluetooth.BluetoothGattCallback)
-
disconnect
Disconnects an established connection, or cancels a connection attempt currently in progress. -
close
Close this Bluetooth GATT client. -
setRequestConnectionPriorityResult
public void setRequestConnectionPriorityResult(boolean requestConnectionPriorityResult) Sets the return value forBluetoothGatt.requestConnectionPriority(int). -
requestConnectionPriority
Request a connection parameter update.- Parameters:
priority- Request a specific connection priority. Must be one ofBluetoothGatt.CONNECTION_PRIORITY_BALANCED,BluetoothGatt.CONNECTION_PRIORITY_HIGHorBluetoothGatt.CONNECTION_PRIORITY_LOW_POWER.- Returns:
- true if operation is successful.
- Throws:
IllegalArgumentException- If the parameters are outside of their specified range.
-
requestMtu
OverridesBluetoothGatt.requestMtu(int)to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after. -
setPreferredPhy
OverridesBluetoothGatt.setPreferredPhy(int, int, int)to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after. -
readPhy
OverridesBluetoothGatt.readPhy()to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after. -
setPhy
public void setPhy(int txPhy, int rxPhy) Sets the values to be returned byBluetoothGatt.readPhy() -
discoverServices
OverridesBluetoothGatt.discoverServices()to always return false unless there are discoverable services made available byaddDiscoverableService(android.bluetooth.BluetoothGattService)- Returns:
- true if discoverable service is available and callback response is possible
-
getServices
OverridesBluetoothGatt.getServices()to always return a list of services discovered.- Returns:
- list of services that have been discovered through
discoverServices(), empty if none.
-
getService
OverridesBluetoothGatt.getService(UUID)to return a service with given UUID.- Returns:
- a service with given UUID that have been discovered through
discoverServices().
-
setCharacteristicNotification
@Implementation(minSdk=26) protected boolean setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable) OverridesBluetoothGatt.setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean)so it returns true (false) if allowCharacteristicNotification (disallowCharacteristicNotification) is called. -
readDescriptor
-
setRssi
public void setRssi(int rssi) Sets the RSSI value to be returned byreadRemoteRssi().- Parameters:
rssi- The RSSI value.
-
readRemoteRssi
-
setBeginReliableWriteResult
public void setBeginReliableWriteResult(boolean beginReliableWriteResult) -
beginReliableWrite
-
executeReliableWrite
-
abortReliableWrite
-
requestSubrateMode
-
writeDescriptor
-
writeDescriptor
@Implementation(minSdk=33) protected int writeDescriptor(BluetoothGattDescriptor descriptor, byte[] value) -
writeCharacteristic
@Implementation(minSdk=26) protected boolean writeCharacteristic(BluetoothGattCharacteristic characteristic) -
writeCharacteristic
@Implementation(minSdk=33) protected int writeCharacteristic(BluetoothGattCharacteristic characteristic, byte[] value, int writeType) -
readCharacteristic
@Implementation(minSdk=26) protected boolean readCharacteristic(BluetoothGattCharacteristic characteristic) -
writeIncomingCharacteristic
Reads bytes from incoming characteristic if properties are valid and callback is set. Callback responds withBluetoothGattCallback.onCharacteristicWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)and returns true when successful.- Parameters:
characteristic- Characteristic to read- Returns:
- true, if the read operation was initiated successfully
- Throws:
IllegalStateException- if aBluetoothGattCallbackhas not been set bysetGattCallback(android.bluetooth.BluetoothGattCallback)
-
readIncomingCharacteristic
Writes bytes from incoming characteristic if properties are valid and callback is set. Callback responds with BluetoothGattCallback#onCharacteristicRead and returns true when successful.- Parameters:
characteristic- Characteristic to read- Returns:
- true, if the read operation was initiated successfully
- Throws:
IllegalStateException- if aBluetoothGattCallbackhas not been set bysetGattCallback(android.bluetooth.BluetoothGattCallback)
-
allowCharacteristicNotification
Allows the incoming characteristic to be set to enable notification. -
disallowCharacteristicNotification
Disallows the incoming characteristic to be set to enable notification. -
addDiscoverableService
-
removeDiscoverableService
-
getGattCallback
-
setGattCallback
-
isConnected
public boolean isConnected() -
isClosed
public boolean isClosed() -
getConnectionPriority
public int getConnectionPriority() -
getLatestWrittenBytes
public byte[] getLatestWrittenBytes() -
getLatestReadBytes
public byte[] getLatestReadBytes() -
getBluetoothConnectionManager
public org.robolectric.shadows.BluetoothConnectionManager getBluetoothConnectionManager() -
notifyConnection
Simulate a successful Gatt Client Connection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
remoteAddress- address of Gatt client
-
notifyDisconnection
Simulate a successful Gatt Client Disconnection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
remoteAddress- address of Gatt client
-