Package org.robolectric.shadows
Class ShadowBluetoothGatt
java.lang.Object
org.robolectric.shadows.ShadowBluetoothGatt
Shadow implementation of 
BluetoothGatt.- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected org.robolectric.shadows.ShadowBluetoothGatt.BluetoothGattReflector
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidvoidallowCharacteristicNotification(BluetoothGattCharacteristic characteristic) Allows the incoming characteristic to be set to enable notification.protected 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)org.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.booleanreadIncomingCharacteristic(BluetoothGattCharacteristic characteristic) Writes bytes from incoming characteristic if properties are valid and callback is set.voidprotected 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 booleansetCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enable) OverridesBluetoothGatt.setCharacteristicNotification(android.bluetooth.BluetoothGattCharacteristic, boolean)so it returns true (false) if allowCharacteristicNotification (disallowCharacteristicNotification) is called.voidsetGattCallback(BluetoothGattCallback bluetoothGattCallback) 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- 
ShadowBluetoothGattpublic ShadowBluetoothGatt()
 
- 
- 
Method Details- 
newInstance
- 
connectConnect 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)
 
- 
disconnectDisconnects an established connection, or cancels a connection attempt currently in progress.
- 
closeClose this Bluetooth GATT client.
- 
requestConnectionPriorityRequest a connection parameter update.- Parameters:
- priority- Request a specific connection priority. Must be one of- BluetoothGatt.CONNECTION_PRIORITY_BALANCED,- BluetoothGatt.CONNECTION_PRIORITY_HIGHor- BluetoothGatt.CONNECTION_PRIORITY_LOW_POWER.
- Returns:
- true if operation is successful.
- Throws:
- IllegalArgumentException- If the parameters are outside of their specified range.
 
- 
requestMtuOverridesBluetoothGatt.requestMtu(int)to always fail beforesetGattCallback(android.bluetooth.BluetoothGattCallback)is called, and always succeed after.
- 
discoverServicesOverridesBluetoothGatt.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
 
- 
getServicesOverridesBluetoothGatt.getServices()to always return a list of services discovered.- Returns:
- list of services that have been discovered through discoverServices(), empty if none.
 
- 
getServiceOverridesBluetoothGatt.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.
- 
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) 
- 
writeIncomingCharacteristicReads 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 a- BluetoothGattCallbackhas not been set by- setGattCallback(android.bluetooth.BluetoothGattCallback)
 
- 
readIncomingCharacteristicWrites 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 a- BluetoothGattCallbackhas not been set by- setGattCallback(android.bluetooth.BluetoothGattCallback)
 
- 
allowCharacteristicNotificationAllows the incoming characteristic to be set to enable notification.
- 
disallowCharacteristicNotificationDisallows the incoming characteristic to be set to enable notification.
- 
addDiscoverableService
- 
removeDiscoverableService
- 
getGattCallback
- 
setGattCallback
- 
isConnectedpublic boolean isConnected()
- 
isClosedpublic boolean isClosed()
- 
getConnectionPrioritypublic int getConnectionPriority()
- 
getLatestWrittenBytespublic byte[] getLatestWrittenBytes()
- 
getLatestReadBytespublic byte[] getLatestReadBytes()
- 
getBluetoothConnectionManagerpublic org.robolectric.shadows.BluetoothConnectionManager getBluetoothConnectionManager()
- 
notifyConnectionSimulate a successful Gatt Client Connection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
- remoteAddress- address of Gatt client
 
- 
notifyDisconnectionSimulate a successful Gatt Client Disconnection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
- remoteAddress- address of Gatt client
 
 
-