public class BluetoothTestUtils
extends Assert
Constructor and Description |
---|
BluetoothTestUtils(Context context,
String tag)
Creates a utility instance for testing Bluetooth.
|
BluetoothTestUtils(Context context,
String tag,
String outputFile)
Creates a utility instance for testing Bluetooth.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptPair(BluetoothAdapter adapter,
BluetoothDevice device,
int passkey,
byte[] pin)
Accepts a pairing with a remote device and checks to make sure that the devices are paired
and that the correct actions were broadcast.
|
void |
close()
Closes the utility instance and unregisters any BroadcastReceivers.
|
void |
connectPan(BluetoothAdapter adapter,
BluetoothDevice device)
Connects the PANU to a remote NAP and checks to make sure that the PANU is connected and that
the correct actions were broadcast.
|
void |
connectProfile(BluetoothAdapter adapter,
BluetoothDevice device,
int profile,
String methodName)
Connects a profile from the local device to a remote device and checks to make sure that the
profile is connected and that the correct actions were broadcast.
|
void |
disable(BluetoothAdapter adapter)
Disables Bluetooth and checks to make sure that Bluetooth was turned off and that the correct
actions were broadcast.
|
void |
disablePan(BluetoothAdapter adapter)
Disables PAN tethering on the local device and checks to make sure that tethering is
disabled.
|
void |
disconnectPan(BluetoothAdapter adapter,
BluetoothDevice device)
Disconnects the PANU from a remote NAP and checks to make sure that the PANU is disconnected
and that the correct actions were broadcast.
|
void |
disconnectProfile(BluetoothAdapter adapter,
BluetoothDevice device,
int profile,
String methodName)
Disconnects a profile between the local device and a remote device and checks to make sure
that the profile is disconnected and that the correct actions were broadcast.
|
void |
discoverable(BluetoothAdapter adapter)
Puts the local device into discoverable mode and checks to make sure that the local device
is in discoverable mode and that the correct actions were broadcast.
|
void |
enable(BluetoothAdapter adapter)
Enables Bluetooth and checks to make sure that Bluetooth was turned on and that the correct
actions were broadcast.
|
void |
enablePan(BluetoothAdapter adapter)
Enables PAN tethering on the local device and checks to make sure that tethering is enabled.
|
void |
incomingPanConnection(BluetoothAdapter adapter,
BluetoothDevice device)
Checks that a remote PANU connects to the local NAP correctly and that the correct actions
were broadcast.
|
void |
incomingPanDisconnection(BluetoothAdapter adapter,
BluetoothDevice device)
Checks that a remote PANU disconnects from the local NAP correctly and that the correct
actions were broadcast.
|
void |
pair(BluetoothAdapter adapter,
BluetoothDevice device,
int passkey,
byte[] pin)
Initiates a pairing with a remote device and checks to make sure that the devices are paired
and that the correct actions were broadcast.
|
void |
startScan(BluetoothAdapter adapter)
Starts a scan for remote devices and checks to make sure that the local device is scanning
and that the correct actions were broadcast.
|
void |
startSco(BluetoothAdapter adapter,
BluetoothDevice device)
Opens a SCO channel using
AudioManager.startBluetoothSco() and checks
to make sure that the channel is opened and that the correct actions were broadcast. |
void |
stopScan(BluetoothAdapter adapter)
Stops a scan for remote devices and checks to make sure that the local device is not scanning
and that the correct actions were broadcast.
|
void |
stopSco(BluetoothAdapter adapter,
BluetoothDevice device)
Closes a SCO channel using
AudioManager.stopBluetoothSco() and checks
to make sure that the channel is closed and that the correct actions were broadcast. |
void |
undiscoverable(BluetoothAdapter adapter)
Puts the local device into connectable only mode and checks to make sure that the local
device is in in connectable mode and that the correct actions were broadcast.
|
void |
unpair(BluetoothAdapter adapter,
BluetoothDevice device)
Deletes a pairing with a remote device and checks to make sure that the devices are unpaired
and that the correct actions were broadcast.
|
void |
writeOutput(String s)
Writes a string to the logcat and a file if a file has been specified in the constructor.
|
public BluetoothTestUtils(Context context, String tag)
context
- The context of the application using the utility.tag
- The log tag of the application using the utility.public BluetoothTestUtils(Context context, String tag, String outputFile)
context
- The context of the application using the utility.tag
- The log tag of the application using the utility.outputFile
- The path to an output file if the utility is to write results to a
separate file.public void close()
public void enable(BluetoothAdapter adapter)
adapter
- The BT adapter.public void disable(BluetoothAdapter adapter)
adapter
- The BT adapter.public void discoverable(BluetoothAdapter adapter)
adapter
- The BT adapter.public void undiscoverable(BluetoothAdapter adapter)
adapter
- The BT adapter.public void startScan(BluetoothAdapter adapter)
adapter
- The BT adapter.public void stopScan(BluetoothAdapter adapter)
adapter
- The BT adapter.public void enablePan(BluetoothAdapter adapter)
adapter
- The BT adapter.public void disablePan(BluetoothAdapter adapter)
adapter
- The BT adapter.public void pair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, byte[] pin)
adapter
- The BT adapter.device
- The remote device.passkey
- The pairing passkey if pairing requires a passkey. Any value if not.pin
- The pairing pin if pairing requires a pin. Any value if not.public void acceptPair(BluetoothAdapter adapter, BluetoothDevice device, int passkey, byte[] pin)
adapter
- The BT adapter.device
- The remote device.passkey
- The pairing passkey if pairing requires a passkey. Any value if not.pin
- The pairing pin if pairing requires a pin. Any value if not.public void unpair(BluetoothAdapter adapter, BluetoothDevice device)
adapter
- The BT adapter.device
- The remote device.public void connectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile, String methodName)
adapter
- The BT adapter.device
- The remote device.profile
- The profile to connect. One of BluetoothProfile.A2DP
,
BluetoothProfile.HEADSET
, or BluetoothProfile.INPUT_DEVICE
.methodName
- The method name to printed in the logs. If null, will be
"connectProfile(profile=<profile>, device=<device>)"public void disconnectProfile(BluetoothAdapter adapter, BluetoothDevice device, int profile, String methodName)
adapter
- The BT adapter.device
- The remote device.profile
- The profile to disconnect. One of BluetoothProfile.A2DP
,
BluetoothProfile.HEADSET
, or BluetoothProfile.INPUT_DEVICE
.methodName
- The method name to printed in the logs. If null, will be
"connectProfile(profile=<profile>, device=<device>)"public void connectPan(BluetoothAdapter adapter, BluetoothDevice device)
adapter
- The BT adapter.device
- The remote device.public void incomingPanConnection(BluetoothAdapter adapter, BluetoothDevice device)
adapter
- The BT adapter.device
- The remote device.public void disconnectPan(BluetoothAdapter adapter, BluetoothDevice device)
adapter
- The BT adapter.device
- The remote device.public void incomingPanDisconnection(BluetoothAdapter adapter, BluetoothDevice device)
adapter
- The BT adapter.device
- The remote device.public void startSco(BluetoothAdapter adapter, BluetoothDevice device)
AudioManager.startBluetoothSco()
and checks
to make sure that the channel is opened and that the correct actions were broadcast.adapter
- The BT adapter.device
- The remote device.public void stopSco(BluetoothAdapter adapter, BluetoothDevice device)
AudioManager.stopBluetoothSco()
and checks
to make sure that the channel is closed and that the correct actions were broadcast.adapter
- The BT adapter.device
- The remote device.public void writeOutput(String s)
s
- The string to be written.