@Implements(android.bluetooth.BluetoothAdapter.class) public class ShadowBluetoothAdapter extends Object
Constructor | Description |
---|---|
ShadowBluetoothAdapter() |
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 of
closeProfileProxy(int,android.bluetooth.BluetoothProfile) if setProfileProxy(int, android.bluetooth.BluetoothProfile) has been previously called. |
protected boolean |
disable() |
|
protected boolean |
enable() |
|
protected String |
getAddress() |
|
protected BluetoothLeScanner |
getBluetoothLeScanner() |
|
protected Set<BluetoothDevice> |
getBondedDevices() |
|
protected static BluetoothAdapter |
getDefaultAdapter() |
|
protected int |
getDiscoverableTimeout() |
|
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 Bluetooth
profile , defaulting to BluetoothProfile.STATE_DISCONNECTED if the profile's connection state was never set. |
protected boolean |
getProfileProxy(Context context,
BluetoothProfile.ServiceListener listener,
int profile) |
Overrides behavior of
getProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int) if setProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called. |
protected int |
getScanMode() |
|
BluetoothAdapter.LeScanCallback |
getSingleLeScanCallback() |
|
protected int |
getState() |
|
boolean |
hasActiveProfileProxy(int profile) |
|
protected boolean |
isBleScanAlwaysAvailable() |
When true, overrides the value of
getLeState() . |
protected boolean |
isDiscovering() |
|
protected boolean |
isEnabled() |
|
protected boolean |
isLeExtendedAdvertisingSupported() |
Returns the last value of
setIsLeExtendedAdvertisingSupported(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 for
isBleScanAlwaysAvailable . |
void |
setBondedDevices(Set<BluetoothDevice> bluetoothDevices) |
|
protected void |
setDiscoverableTimeout(int timeout) |
|
void |
setEnabled(boolean enabled) |
|
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 feature
|
void |
setIsMultipleAdvertisementSupported(boolean supported) |
Sets the value for
isMultipleAdvertisementSupported . |
protected boolean |
setName(String name) |
|
void |
setProfileConnectionState(int profile,
int state) |
Sets the connection state
state for the given BluetoothProfile profile |
void |
setProfileProxy(int profile,
BluetoothProfile proxy) |
Sets the active BluetoothProfile
proxy for the given profile . |
protected boolean |
setScanMode(int scanMode) |
|
protected boolean |
setScanMode(int scanMode,
int discoverableTimeout) |
|
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) |
@Resetter public static void reset()
@Implementation protected static BluetoothAdapter getDefaultAdapter()
public static void setIsBluetoothSupported(boolean supported)
@Implementation(minSdk=21) protected BluetoothLeScanner getBluetoothLeScanner()
@Implementation protected Set<BluetoothDevice> getBondedDevices()
public void setBondedDevices(Set<BluetoothDevice> bluetoothDevices)
@Implementation protected BluetoothServerSocket listenUsingInsecureRfcommWithServiceRecord(String serviceName, UUID uuid)
@Implementation protected BluetoothServerSocket listenUsingRfcommWithServiceRecord(String serviceName, UUID uuid) throws IOException
IOException
@Implementation protected boolean startDiscovery()
@Implementation protected boolean cancelDiscovery()
@Implementation(minSdk=23) protected boolean isBleScanAlwaysAvailable()
getLeState()
. By default, this is false.@Implementation(minSdk=23) public int getLeState()
LE is enabled if either Bluetooth or BLE scans are enabled. LE is always off if Airplane Mode is enabled.
@Implementation(minSdk=18) protected boolean startLeScan(BluetoothAdapter.LeScanCallback callback)
@Implementation(minSdk=18) protected boolean startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)
@Implementation(minSdk=18) protected void stopLeScan(BluetoothAdapter.LeScanCallback callback)
public Set<BluetoothAdapter.LeScanCallback> getLeScanCallbacks()
public BluetoothAdapter.LeScanCallback getSingleLeScanCallback()
@Implementation protected boolean isDiscovering()
@Implementation protected boolean isEnabled()
@Implementation protected boolean enable()
@Implementation protected boolean disable()
@Implementation protected String getAddress()
@Implementation protected int getState()
@Implementation protected String getName()
@Implementation protected boolean setName(String name)
@Implementation protected boolean setScanMode(int scanMode)
@Implementation protected boolean setScanMode(int scanMode, int discoverableTimeout)
@Implementation protected int getScanMode()
@Implementation protected int getDiscoverableTimeout()
@Implementation protected void setDiscoverableTimeout(int timeout)
@Implementation(minSdk=21) protected boolean isMultipleAdvertisementSupported()
@Implementation protected static boolean checkBluetoothAddress(String address)
address
- Bluetooth address as string@Implementation protected int getProfileConnectionState(int profile)
profile
, defaulting to BluetoothProfile.STATE_DISCONNECTED
if the profile's connection state was never set.
Set a Bluetooth profile's connection state via setProfileConnectionState(int, int)
.
public void setAddress(String address)
public void setState(int state)
public void setEnabled(boolean enabled)
public void setBleScanAlwaysAvailable(boolean alwaysAvailable)
isBleScanAlwaysAvailable
. If true, getLeState()
will always
return true.public void setIsMultipleAdvertisementSupported(boolean supported)
isMultipleAdvertisementSupported
.public void setProfileConnectionState(int profile, int state)
state
for the given BluetoothProfile profile
public void setProfileProxy(int profile, @Nullable BluetoothProfile proxy)
proxy
for the given profile
. Will always
affect behavior of BluetoothAdapter.getProfileProxy(android.content.Context, android.bluetooth.BluetoothProfile.ServiceListener, int)
and BluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile)
. Call to BluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile)
can
remove the set active proxy.proxy
- can be 'null' to simulate the situation where BluetoothAdapter.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.public boolean hasActiveProfileProxy(int profile)
setProfileProxy(int, android.bluetooth.BluetoothProfile)
for the given profile
AND it has not been
"deactivated" by a call to BluetoothAdapter.closeProfileProxy(int, android.bluetooth.BluetoothProfile)
. Only meaningful if
setProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called.@Implementation protected boolean getProfileProxy(Context context, BluetoothProfile.ServiceListener listener, int profile)
getProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)
if setProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called.
If active (non-null) proxy has been set by setProfileProxy(int,android.bluetooth.BluetoothProfile)
for the given
profile
, getProfileProxy(android.content.Context,android.bluetooth.BluetoothProfile.ServiceListener,int)
will immediately call onServiceConnected
of the given
BluetoothProfile.ServiceListener listener
.setProfileProxy(int,android.bluetooth.BluetoothProfile)
for the given
BluetoothProfile profile
@Implementation protected void closeProfileProxy(int profile, BluetoothProfile proxy)
closeProfileProxy(int,android.bluetooth.BluetoothProfile)
if setProfileProxy(int, android.bluetooth.BluetoothProfile)
has been previously called.
If the given non-null BluetoothProfile proxy
was previously set for the given
profile
by setProfileProxy(int, android.bluetooth.BluetoothProfile)
, this proxy will be "deactivated".@Implementation(minSdk=26) protected boolean isLeExtendedAdvertisingSupported()
setIsLeExtendedAdvertisingSupported(boolean)
, defaulting to true.public void setIsLeExtendedAdvertisingSupported(boolean supported)