|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.openuat.util.BluetoothPeerManager
public class BluetoothPeerManager
This class implements a Bluetooth peer device manager that handles automatic background discovery. Users of this class should implement the BluetoothPeerManager.DiscoveryEventsHandler interface and register itself with addListener/removeListener to react to events. Parameters for automatic background discovery can be set with setSleepBetweenInquiriesTime, setAutomaticServiceDiscovery, and setAutomaticServiceDiscoveryUUID. The whole inquiry process is started by calling startInquiry, which can either be a one-shot operation or be started as a continuous background thread (which can be stopped with stopInquiry). Services of discovered devices can be found by either calling startServiceSearch directly or setting automaticServiceDiscovery to true. There are two ways of querying the discovered information: either explicitly via getPeers and getServices, or by using the arguments passed to events.
| Nested Class Summary | |
|---|---|
static interface |
BluetoothPeerManager.PeerEventsListener
Users of BluetoothPeerManager should most probably implement this interface and register themselves with addListener. |
| Field Summary | |
|---|---|
static int |
DEFAULT_SLEEP_TIME
The default sleep time between two inquiry runs in milliseconds. |
static int |
MAXIMUM_SLEEP_TIME
The maximum sleep time between two inquiry runs in milliseconds. |
static int |
MINIMUM_SLEEP_TIME
The minimum sleep time between two inquiry runs in milliseconds. |
static int |
SCAN_SERVICES_FACTOR
Re-scan services every nth time that a device is discovered by the inquiry process. |
static int |
TIMEOUT_SERVICE_SEARCH
The maximum time we wait for a service search to finish in milliseconds. |
| Constructor Summary | |
|---|---|
BluetoothPeerManager()
|
|
| Method Summary | |
|---|---|
boolean |
addListener(BluetoothPeerManager.PeerEventsListener listener)
Add a new event listener. |
boolean |
getAdaptiveSleepTime()
Returns the value of adaptiveSleepTime. |
boolean |
getAutomaticServiceDiscovery()
Returns the state of automatic service discovery. |
javax.bluetooth.UUID |
getAutomaticServiceDiscoveryUUID()
Returns the UUID used for automatically discovering only specific service UUID. |
int |
getCurrentSleepBetweenInquiriesTime()
Returns the time to sleep in between two inquiries when startInquiry is called with continuousBackground=true. |
javax.bluetooth.RemoteDevice[] |
getPeers()
Returns the list of devices that have been discovered until now. |
static java.lang.String |
getRemoteServiceURL(java.lang.String remoteAddress,
javax.bluetooth.UUID serviceUuid,
int authenticateEncryptMode,
int timeoutMs)
This is a helper function to return a remote service given a UUID and Bluetooth MAC address. |
javax.bluetooth.ServiceRecord[] |
getServices(javax.bluetooth.RemoteDevice device)
Returns the list of services that have been discovered for a device. |
boolean |
isInquiryActive()
Returns true if the inquiry thread is currently running. |
static void |
main(java.lang.String[] args)
|
boolean |
removeListener(BluetoothPeerManager.PeerEventsListener listener)
Remove a registered event listener. |
static java.lang.String |
resolveName(javax.bluetooth.RemoteDevice device)
This is a helper function for resolving a remote device name. |
void |
setAdaptiveSleepTime(boolean value)
Sets the value of adaptiveSleepTime. |
void |
setAutomaticServiceDiscovery(boolean automaticServiceDiscovery)
Sets the state of automatic service discovery. |
void |
setAutomaticServiceDiscoveryUUID(javax.bluetooth.UUID uuid)
Sets the UUID used for automatically discovering only specific service UUID. |
void |
setSleepBetweenInquiriesTime(int milliseconds)
Sets the time to sleep in between two inquiries when startInquiry is called with continuousBackground=true. |
boolean |
startInquiry(boolean continuousBackground)
Starts a Bluetooth inquiry. |
boolean |
startServiceSearch(javax.bluetooth.RemoteDevice device,
javax.bluetooth.UUID specificService)
Start to search for the list of services on a remote device. |
boolean |
stopInquiry(boolean force)
Stops a background inquiry. |
boolean |
waitForBackgroundSearchToFinish(int timeoutMs)
Wait for any background inquiry or service search that may be running to finish. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_SLEEP_TIME
public static final int MAXIMUM_SLEEP_TIME
public static final int MINIMUM_SLEEP_TIME
public static final int TIMEOUT_SERVICE_SEARCH
public static final int SCAN_SERVICES_FACTOR
| Constructor Detail |
|---|
public BluetoothPeerManager()
throws java.io.IOException
java.io.IOException| Method Detail |
|---|
public int getCurrentSleepBetweenInquiriesTime()
sleepBetweenInquiriespublic void setSleepBetweenInquiriesTime(int milliseconds)
milliseconds - The sleep time in ms.sleepBetweenInquiries,
getAdaptiveSleepTime(),
setAdaptiveSleepTime(boolean)public boolean getAdaptiveSleepTime()
public void setAdaptiveSleepTime(boolean value)
value - true if the sleep time between two subsequent inquiry runs
should be adapted automatically depending on the "volatility"
of the Bluetooth inquiry results.public boolean getAutomaticServiceDiscovery()
automaticServiceDiscoverypublic void setAutomaticServiceDiscovery(boolean automaticServiceDiscovery)
automaticServiceDiscovery - Set to true if services should be
discovered automatically for newly found
devices.automaticServiceDiscoverypublic javax.bluetooth.UUID getAutomaticServiceDiscoveryUUID()
automaticServiceDiscoveryUUIDpublic void setAutomaticServiceDiscoveryUUID(javax.bluetooth.UUID uuid)
uuid - The service UUID used for automatic service discovery. Set
to null to not restrict the discovery but search for all
available services.automaticServiceDiscoveryUUIDpublic boolean startInquiry(boolean continuousBackground)
continuousBackground - If set to true, this start a continuous
inquiry in the background, with the time
set by setSleepBetweenInquiriesTime between
two inquiries. If set to false, it just
starts a one-shot inquiry.
public boolean stopInquiry(boolean force)
force - If set to true, then any inquiry or service search that
may be running in the background will be canceled. If
set to false, they will be left running (and
waitForBackgroundSearchToFinish can be used to wait for
them to finish).
public boolean isInquiryActive()
public boolean waitForBackgroundSearchToFinish(int timeoutMs)
throws java.lang.InterruptedException
timeoutMs - The maximum amount of time to wait in milliseconds.
java.lang.InterruptedException
public boolean startServiceSearch(javax.bluetooth.RemoteDevice device,
javax.bluetooth.UUID specificService)
device - The remote device to get the service list from.specificService - The UUID of a specific service to search for. If
set to null, arbitrary services are returned.
The UUID 0x0100 (for L2CAP support) is always
included in the search, because we only support
L2CAP connections anyway (no SCO).
public javax.bluetooth.RemoteDevice[] getPeers()
public javax.bluetooth.ServiceRecord[] getServices(javax.bluetooth.RemoteDevice device)
device - The device for which the services should be returned.
This device must have been discovered before, i.e. it must
be in the list of devices returned by getPeers.
public boolean addListener(BluetoothPeerManager.PeerEventsListener listener)
public boolean removeListener(BluetoothPeerManager.PeerEventsListener listener)
public static java.lang.String resolveName(javax.bluetooth.RemoteDevice device)
device - The remote device to resolve the name for.
public static java.lang.String getRemoteServiceURL(java.lang.String remoteAddress,
javax.bluetooth.UUID serviceUuid,
int authenticateEncryptMode,
int timeoutMs)
throws java.io.IOException
remoteAddress - The Bluetooth MAC address of the remote device.serviceUuid - The UUID of the service to search for.authenticateEncryptMode - See ServiceRecord, use e.g.
ServiceRecord.NOAUTHENTICATE_NOENCRYPTtimeoutMs - The maximum amount of time to wait in milliseconds.
java.io.IOException
public static void main(java.lang.String[] args)
throws java.io.IOException
java.io.IOException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||