Package org.robolectric.shadows
Class ShadowBluetoothGatt
- java.lang.Object
-
- org.robolectric.shadows.ShadowBluetoothGatt
-
@Implements(value=android.bluetooth.BluetoothGatt.class, minSdk=18) public class ShadowBluetoothGatt extends Object
Shadow implementation ofBluetoothGatt.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.robolectric.shadows.ShadowBluetoothGatt.BluetoothGattReflectorbluetoothGattReflector
-
Constructor Summary
Constructors Constructor Description ShadowBluetoothGatt()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDiscoverableService(BluetoothGattService service)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)protected voiddisconnect()Disconnects an established connection, or cancels a connection attempt currently in progress.protected booleandiscoverServices()OverridesBluetoothGatt.discoverServices()to always return false unless there are discoverable services made available byaddDiscoverableService(android.bluetooth.BluetoothGattService)org.robolectric.shadows.BluetoothConnectionManagergetBluetoothConnectionManager()intgetConnectionPriority()BluetoothGattCallbackgetGattCallback()byte[]getLatestReadBytes()byte[]getLatestWrittenBytes()protected List<BluetoothGattService>getServices()OverridesBluetoothGatt.getServices()to always return a list of services discovered.booleanisClosed()booleanisConnected()static BluetoothGattnewInstance(BluetoothDevice device)voidnotifyConnection(String remoteAddress)Simulate a successful Gatt Client Conection 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.voidremoveDiscoverableService(BluetoothGattService service)protected booleanrequestConnectionPriority(int priority)Request a connection parameter update.voidsetGattCallback(BluetoothGattCallback bluetoothGattCallback)booleanwriteIncomingCharacteristic(BluetoothGattCharacteristic characteristic)Reads bytes from incoming characteristic if properties are valid and callback is set.
-
-
-
Method Detail
-
newInstance
public static BluetoothGatt newInstance(BluetoothDevice device)
-
connect
@Implementation(minSdk=18) protected boolean 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
@Implementation(minSdk=18) protected void disconnect()
Disconnects an established connection, or cancels a connection attempt currently in progress.
-
close
@Implementation(minSdk=18) protected void close()
Close this Bluetooth GATT client.
-
requestConnectionPriority
@Implementation(minSdk=26) protected boolean requestConnectionPriority(int priority)
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.
-
discoverServices
@Implementation(minSdk=26) protected boolean 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
@Implementation(minSdk=26) protected List<BluetoothGattService> getServices()
OverridesBluetoothGatt.getServices()to always return a list of services discovered.- Returns:
- list of services that have been discovered through
discoverServices(), empty if none.
-
writeIncomingCharacteristic
public boolean writeIncomingCharacteristic(BluetoothGattCharacteristic characteristic)
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
public boolean readIncomingCharacteristic(BluetoothGattCharacteristic characteristic)
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)
-
addDiscoverableService
public void addDiscoverableService(BluetoothGattService service)
-
removeDiscoverableService
public void removeDiscoverableService(BluetoothGattService service)
-
getGattCallback
public BluetoothGattCallback getGattCallback()
-
setGattCallback
public void setGattCallback(BluetoothGattCallback bluetoothGattCallback)
-
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
public void notifyConnection(String remoteAddress)
Simulate a successful Gatt Client Conection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
remoteAddress- address of Gatt client
-
notifyDisconnection
public void notifyDisconnection(String remoteAddress)
Simulate a successful Gatt Client Disconnection withBluetoothConnectionManager. Performs aBluetoothGattCallback.onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)if available.- Parameters:
remoteAddress- address of Gatt client
-
-