Package org.robolectric.shadows
Class ShadowBluetoothAdapter
- java.lang.Object
-
- org.robolectric.shadows.ShadowBluetoothAdapter
-
@Implements(value=android.bluetooth.BluetoothAdapter.class, looseSignatures=true) public class ShadowBluetoothAdapter extends Object
-
-
Constructor Summary
Constructors Constructor Description ShadowBluetoothAdapter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected boolean
cancelDiscovery()
protected static boolean
checkBluetoothAddress(String address)
Validate a Bluetooth address, such as "00:43:A8:23:10:F0" Alphabetic characters must be uppercase to be valid.protected void
closeProfileProxy(int profile, BluetoothProfile proxy)
Overrides behavior ofcloseProfileProxy(int,android.bluetooth.BluetoothProfile)
ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called.protected boolean
disable()
protected boolean
enable()
protected String
getAddress()
protected Set<BluetoothDevice>
getBondedDevices()
protected static BluetoothAdapter
getDefaultAdapter()
protected int
getDiscoverableTimeout()
protected int
getLeMaximumAdvertisingDataLength()
Set<BluetoothAdapter.LeScanCallback>
getLeScanCallbacks()
int
getLeState()
Decides the correct LE state.protected String
getName()
protected int
getProfileConnectionState(int profile)
Returns the connection state for the given Bluetoothprofile
, defaulting toBluetoothProfile.STATE_DISCONNECTED
if the profile's connection state was never set.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.protected BluetoothDevice
getRemoteDevice(String address)
protected int
getScanMode()
BluetoothAdapter.LeScanCallback
getSingleLeScanCallback()
protected int
getState()
boolean
hasActiveProfileProxy(int profile)
protected boolean
isBleScanAlwaysAvailable()
When true, overrides the value ofgetLeState()
.protected boolean
isDiscovering()
protected boolean
isEnabled()
protected boolean
isLeExtendedAdvertisingSupported()
Returns the last value ofsetIsLeExtendedAdvertisingSupported(boolean)
, defaulting to true.protected boolean
isMultipleAdvertisementSupported()
protected BluetoothServerSocket
listenUsingInsecureRfcommWithServiceRecord(String serviceName, UUID uuid)
protected BluetoothServerSocket
listenUsingRfcommWithServiceRecord(String serviceName, UUID uuid)
static void
reset()
void
setAddress(String address)
void
setBleScanAlwaysAvailable(boolean alwaysAvailable)
Sets the value forisBleScanAlwaysAvailable
.void
setBluetoothLeAdvertiser(BluetoothLeAdvertiser advertiser)
Deprecated.use real BluetoothLeAdvertiser insteadvoid
setBondedDevices(Set<BluetoothDevice> bluetoothDevices)
protected void
setDiscoverableTimeout(int timeout)
void
setEnabled(boolean enabled)
Deprecated.static void
setIsBluetoothSupported(boolean supported)
Determines if getDefaultAdapter() returns the default local adapter (true) or null (false).void
setIsLeExtendedAdvertisingSupported(boolean supported)
Sets the isLeExtendedAdvertisingSupported to enable/disable LE extended advertisements featurevoid
setIsMultipleAdvertisementSupported(boolean supported)
Sets the value forisMultipleAdvertisementSupported
.protected boolean
setName(String name)
void
setProfileConnectionState(int profile, int state)
Sets the connection statestate
for the given BluetoothProfileprofile
void
setProfileProxy(int profile, BluetoothProfile proxy)
Sets the active BluetoothProfileproxy
for the givenprofile
.protected Object
setScanMode(int scanMode)
protected boolean
setScanMode(int scanMode, int discoverableTimeout)
protected boolean
setScanMode(int scanMode, long durationMillis)
void
setState(int state)
protected boolean
startDiscovery()
protected boolean
startLeScan(BluetoothAdapter.LeScanCallback callback)
protected boolean
startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)
protected void
stopLeScan(BluetoothAdapter.LeScanCallback callback)
-
-
-
Method Detail
-
reset
@Resetter public static void reset()
-
getDefaultAdapter
@Implementation protected static BluetoothAdapter getDefaultAdapter()
-
setIsBluetoothSupported
public static void setIsBluetoothSupported(boolean supported)
Determines if getDefaultAdapter() returns the default local adapter (true) or null (false).
-
setBluetoothLeAdvertiser
@Deprecated public void setBluetoothLeAdvertiser(BluetoothLeAdvertiser advertiser)
Deprecated.use real BluetoothLeAdvertiser instead
-
getRemoteDevice
@Implementation protected BluetoothDevice getRemoteDevice(String address)
-
getBondedDevices
@Implementation protected Set<BluetoothDevice> getBondedDevices()
-
setBondedDevices
public void setBondedDevices(Set<BluetoothDevice> bluetoothDevices)
-
listenUsingInsecureRfcommWithServiceRecord
@Implementation protected BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String serviceName, UUID uuid)
-
listenUsingRfcommWithServiceRecord
@Implementation protected BluetoothServerSocket listenUsingRfcommWithServiceRecord(String serviceName, UUID uuid) throws IOException
- Throws:
IOException
-
startDiscovery
@Implementation protected boolean startDiscovery()
-
cancelDiscovery
@Implementation protected boolean cancelDiscovery()
-
isBleScanAlwaysAvailable
@Implementation(minSdk=23) protected boolean isBleScanAlwaysAvailable()
When true, overrides the value ofgetLeState()
. By default, this is false.
-
getLeState
@Implementation(minSdk=23) public int 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
@Implementation(minSdk=18) protected boolean startLeScan(BluetoothAdapter.LeScanCallback callback)
-
startLeScan
@Implementation(minSdk=18) protected boolean startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)
-
stopLeScan
@Implementation(minSdk=18) protected void stopLeScan(BluetoothAdapter.LeScanCallback callback)
-
getLeScanCallbacks
public Set<BluetoothAdapter.LeScanCallback> getLeScanCallbacks()
-
getSingleLeScanCallback
public BluetoothAdapter.LeScanCallback getSingleLeScanCallback()
-
isDiscovering
@Implementation protected boolean isDiscovering()
-
isEnabled
@Implementation protected boolean isEnabled()
-
enable
@Implementation protected boolean enable()
-
disable
@Implementation protected boolean disable()
-
getAddress
@Implementation protected String getAddress()
-
getState
@Implementation protected int getState()
-
getName
@Implementation protected String getName()
-
setName
@Implementation protected boolean setName(String name)
-
setScanMode
@Implementation protected Object setScanMode(int scanMode)
-
setScanMode
@Implementation(maxSdk=29) protected boolean setScanMode(int scanMode, int discoverableTimeout)
-
setScanMode
@Implementation(minSdk=30) protected boolean setScanMode(int scanMode, long durationMillis)
-
getScanMode
@Implementation protected int getScanMode()
-
getDiscoverableTimeout
@Implementation protected int getDiscoverableTimeout()
-
setDiscoverableTimeout
@Implementation protected void setDiscoverableTimeout(int timeout)
-
isMultipleAdvertisementSupported
@Implementation(minSdk=21) protected boolean isMultipleAdvertisementSupported()
-
checkBluetoothAddress
@Implementation protected static boolean checkBluetoothAddress(String address)
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
@Implementation protected int getProfileConnectionState(int profile)
Returns the connection state for the given Bluetoothprofile
, defaulting toBluetoothProfile.STATE_DISCONNECTED
if the profile's connection state was never set.Set a Bluetooth profile's connection state via
setProfileConnectionState(int, int)
.
-
setAddress
public void setAddress(String address)
-
setState
public void setState(int state)
-
setEnabled
@Deprecated public void setEnabled(boolean enabled)
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 statestate
for the given BluetoothProfileprofile
-
setProfileProxy
public void setProfileProxy(int profile, @Nullable BluetoothProfile proxy)
Sets the active BluetoothProfileproxy
for 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 givenprofile
AND 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 by
setProfileProxy(int,android.bluetooth.BluetoothProfile)
for the givenprofile
,getProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)
will immediately callonServiceConnected
of the given BluetoothProfile.ServiceListenerlistener
.- Returns:
- 'true' if a proxy object has been set by
setProfileProxy(int,android.bluetooth.BluetoothProfile)
for the given BluetoothProfileprofile
-
closeProfileProxy
@Implementation protected void closeProfileProxy(int profile, BluetoothProfile proxy)
Overrides behavior ofcloseProfileProxy(int,android.bluetooth.BluetoothProfile)
ifsetProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called. If the given non-null BluetoothProfileproxy
was previously set for the givenprofile
bysetProfileProxy(int, android.bluetooth.BluetoothProfile)
, this proxy will be "deactivated".
-
isLeExtendedAdvertisingSupported
@Implementation(minSdk=26) protected boolean 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
@Implementation(minSdk=26) protected int getLeMaximumAdvertisingDataLength()
-
-