Package org.robolectric.shadows
Class ShadowBluetoothAdapter
java.lang.Object
org.robolectric.shadows.ShadowBluetoothAdapter
@Implements(android.bluetooth.BluetoothAdapter.class) public class ShadowBluetoothAdapter extends Object
-
Constructor Summary
Constructors Constructor Description ShadowBluetoothAdapter() -
Method Summary
Modifier and Type Method Description protected booleancancelDiscovery()protected static booleancheckBluetoothAddress(String address)Validate a Bluetooth address, such as "00:43:A8:23:10:F0" Alphabetic characters must be uppercase to be valid.protected voidcloseProfileProxy(int profile, BluetoothProfile proxy)Overrides behavior ofcloseProfileProxy(int,android.bluetooth.BluetoothProfile)ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)has been previously called.protected booleandisable()protected booleanenable()protected StringgetAddress()protected Set<BluetoothDevice>getBondedDevices()protected static BluetoothAdaptergetDefaultAdapter()protected intgetDiscoverableTimeout()protected intgetLeMaximumAdvertisingDataLength()Set<BluetoothAdapter.LeScanCallback>getLeScanCallbacks()intgetLeState()Decides the correct LE state.protected StringgetName()protected intgetProfileConnectionState(int profile)Returns the connection state for the given Bluetoothprofile, defaulting toBluetoothProfile.STATE_DISCONNECTEDif the profile's connection state was never set.protected booleangetProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)Overrides behavior ofgetProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)has been previously called.protected intgetScanMode()BluetoothAdapter.LeScanCallbackgetSingleLeScanCallback()protected intgetState()booleanhasActiveProfileProxy(int profile)protected booleanisBleScanAlwaysAvailable()When true, overrides the value ofgetLeState().protected booleanisDiscovering()protected booleanisEnabled()protected booleanisLeExtendedAdvertisingSupported()Returns the last value ofsetIsLeExtendedAdvertisingSupported(boolean), defaulting to true.protected booleanisMultipleAdvertisementSupported()protected BluetoothServerSocketlistenUsingInsecureRfcommWithServiceRecord(String serviceName, UUID uuid)protected BluetoothServerSocketlistenUsingRfcommWithServiceRecord(String serviceName, UUID uuid)static voidreset()voidsetAddress(String address)voidsetBleScanAlwaysAvailable(boolean alwaysAvailable)Sets the value forisBleScanAlwaysAvailable.voidsetBluetoothLeAdvertiser(BluetoothLeAdvertiser advertiser)Deprecated.use real BluetoothLeAdvertiser insteadvoidsetBondedDevices(Set<BluetoothDevice> bluetoothDevices)protected voidsetDiscoverableTimeout(int timeout)voidsetEnabled(boolean enabled)Deprecated.static voidsetIsBluetoothSupported(boolean supported)Determines if getDefaultAdapter() returns the default local adapter (true) or null (false).voidsetIsLeExtendedAdvertisingSupported(boolean supported)Sets the isLeExtendedAdvertisingSupported to enable/disable LE extended advertisements featurevoidsetIsMultipleAdvertisementSupported(boolean supported)Sets the value forisMultipleAdvertisementSupported.protected booleansetName(String name)voidsetProfileConnectionState(int profile, int state)Sets the connection statestatefor the given BluetoothProfileprofilevoidsetProfileProxy(int profile, BluetoothProfile proxy)Sets the active BluetoothProfileproxyfor the givenprofile.protected booleansetScanMode(int scanMode)protected booleansetScanMode(int scanMode, int discoverableTimeout)protected booleansetScanMode(int scanMode, long durationMillis)voidsetState(int state)protected booleanstartDiscovery()protected booleanstartLeScan(BluetoothAdapter.LeScanCallback callback)protected booleanstartLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)protected voidstopLeScan(BluetoothAdapter.LeScanCallback callback)
-
Constructor Details
-
ShadowBluetoothAdapter
public ShadowBluetoothAdapter()
-
-
Method Details
-
reset
-
getDefaultAdapter
-
setIsBluetoothSupported
public static void setIsBluetoothSupported(boolean supported)Determines if getDefaultAdapter() returns the default local adapter (true) or null (false). -
setBluetoothLeAdvertiser
Deprecated.use real BluetoothLeAdvertiser instead -
getBondedDevices
-
setBondedDevices
-
listenUsingInsecureRfcommWithServiceRecord
@Implementation protected BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String serviceName, UUID uuid) -
listenUsingRfcommWithServiceRecord
@Implementation protected BluetoothServerSocket listenUsingRfcommWithServiceRecord(String serviceName, UUID uuid) throws IOException- Throws:
IOException
-
startDiscovery
-
cancelDiscovery
-
isBleScanAlwaysAvailable
When true, overrides the value ofgetLeState(). By default, this is false. -
getLeState
Decides the correct LE state. When off, BLE calls will fail or return null.LE is enabled if either Bluetooth or BLE scans are enabled. LE is always off if Airplane Mode is enabled.
-
startLeScan
-
startLeScan
@Implementation(minSdk=18) protected boolean startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback) -
stopLeScan
-
getLeScanCallbacks
-
getSingleLeScanCallback
-
isDiscovering
-
isEnabled
-
enable
-
disable
-
getAddress
-
getState
-
getName
-
setName
-
setScanMode
-
setScanMode
-
setScanMode
-
getScanMode
-
getDiscoverableTimeout
-
setDiscoverableTimeout
-
isMultipleAdvertisementSupported
-
checkBluetoothAddress
Validate a Bluetooth address, such as "00:43:A8:23:10:F0" Alphabetic characters must be uppercase to be valid.- Parameters:
address- Bluetooth address as string- Returns:
- true if the address is valid, false otherwise
-
getProfileConnectionState
Returns the connection state for the given Bluetoothprofile, defaulting toBluetoothProfile.STATE_DISCONNECTEDif the profile's connection state was never set.Set a Bluetooth profile's connection state via
setProfileConnectionState(int, int). -
setAddress
-
setState
public void setState(int state) -
setEnabled
Deprecated. -
setBleScanAlwaysAvailable
public void setBleScanAlwaysAvailable(boolean alwaysAvailable)Sets the value forisBleScanAlwaysAvailable. If true,getLeState()will always return true. -
setIsMultipleAdvertisementSupported
public void setIsMultipleAdvertisementSupported(boolean supported)Sets the value forisMultipleAdvertisementSupported. -
setProfileConnectionState
public void setProfileConnectionState(int profile, int state)Sets the connection statestatefor the given BluetoothProfileprofile -
setProfileProxy
Sets the active BluetoothProfileproxyfor the givenprofile. Will always affect behavior ofBluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)andBluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile). Call toBluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile)can remove the set active proxy.- Parameters:
proxy- can be 'null' to simulate the situation whereBluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)would return 'false'. This can happen on older Android versions for Bluetooth profiles introduced in later Android versions.
-
hasActiveProfileProxy
public boolean hasActiveProfileProxy(int profile)- Returns:
- 'true' if active (non-null) proxy has been set by
setProfileProxy(int, android.bluetooth.BluetoothProfile)for the givenprofileAND it has not been "deactivated" by a call toBluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile). Only meaningful ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)has been previously called.
-
getProfileProxy
@Implementation protected boolean getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)Overrides behavior ofgetProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)has been previously called. If active (non-null) proxy has been set bysetProfileProxy(int,android.bluetooth.BluetoothProfile)for the givenprofile,getProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)will immediately callonServiceConnectedof the given BluetoothProfile.ServiceListenerlistener.- Returns:
- 'true' if a proxy object has been set by
setProfileProxy(int,android.bluetooth.BluetoothProfile)for the given BluetoothProfileprofile
-
closeProfileProxy
Overrides behavior ofcloseProfileProxy(int,android.bluetooth.BluetoothProfile)ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)has been previously called. If the given non-null BluetoothProfileproxywas previously set for the givenprofilebysetProfileProxy(int, android.bluetooth.BluetoothProfile), this proxy will be "deactivated". -
isLeExtendedAdvertisingSupported
Returns the last value ofsetIsLeExtendedAdvertisingSupported(boolean), defaulting to true. -
setIsLeExtendedAdvertisingSupported
public void setIsLeExtendedAdvertisingSupported(boolean supported)Sets the isLeExtendedAdvertisingSupported to enable/disable LE extended advertisements feature -
getLeMaximumAdvertisingDataLength
-