Fields Summary |
---|
private static final String | TAG |
private static final boolean | DBG |
private static final boolean | VDBG |
public static final String | ACTION_CONNECTION_STATE_CHANGED |
private IBluetoothMap | mService |
private final android.content.Context | mContext |
private ServiceListener | mServiceListener |
private BluetoothAdapter | mAdapter |
public static final int | STATE_ERRORThere was an error trying to obtain the state |
public static final int | RESULT_FAILURE |
public static final int | RESULT_SUCCESS |
public static final int | RESULT_CANCELEDConnection canceled before completion. |
private final IBluetoothStateChangeCallback | mBluetoothStateChangeCallback |
private final android.content.ServiceConnection | mConnection |
Methods Summary |
---|
public synchronized void | close()Close the connection to the backing service.
Other public functions of BluetoothMap will return default error
results once close() has been called. Multiple invocations of close()
are ok.
IBluetoothManager mgr = mAdapter.getBluetoothManager();
if (mgr != null) {
try {
mgr.unregisterStateChangeCallback(mBluetoothStateChangeCallback);
} catch (Exception e) {
Log.e(TAG,"",e);
}
}
synchronized (mConnection) {
if (mService != null) {
try {
mService = null;
mContext.unbindService(mConnection);
} catch (Exception re) {
Log.e(TAG,"",re);
}
}
}
mServiceListener = null;
|
public boolean | connect(BluetoothDevice device)Initiate connection. Initiation of outgoing connections is not
supported for MAP server.
if (DBG) log("connect(" + device + ")" + "not supported for MAPS");
return false;
|
public boolean | disconnect(BluetoothDevice device)Initiate disconnect.
if (DBG) log("disconnect(" + device + ")");
if (mService != null && isEnabled() &&
isValidDevice(device)) {
try {
return mService.disconnect(device);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return false;
|
boolean | doBind()
Intent intent = new Intent(IBluetoothMap.class.getName());
ComponentName comp = intent.resolveSystemService(mContext.getPackageManager(), 0);
intent.setComponent(comp);
if (comp == null || !mContext.bindServiceAsUser(intent, mConnection, 0,
android.os.Process.myUserHandle())) {
Log.e(TAG, "Could not bind to Bluetooth MAP Service with " + intent);
return false;
}
return true;
|
public static boolean | doesClassMatchSink(BluetoothClass btClass)Check class bits for possible Map support.
This is a simple heuristic that tries to guess if a device with the
given class bits might support Map. It is not accurate for all
devices. It tries to err on the side of false positives.
// TODO optimize the rule
switch (btClass.getDeviceClass()) {
case BluetoothClass.Device.COMPUTER_DESKTOP:
case BluetoothClass.Device.COMPUTER_LAPTOP:
case BluetoothClass.Device.COMPUTER_SERVER:
case BluetoothClass.Device.COMPUTER_UNCATEGORIZED:
return true;
default:
return false;
}
|
protected void | finalize()
try {
close();
} finally {
super.finalize();
}
|
public BluetoothDevice | getClient()Get the currently connected remote Bluetooth device (PCE).
if (VDBG) log("getClient()");
if (mService != null) {
try {
return mService.getClient();
} catch (RemoteException e) {Log.e(TAG, e.toString());}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
}
return null;
|
public java.util.List | getConnectedDevices()Get the list of connected devices. Currently at most one.
if (DBG) log("getConnectedDevices()");
if (mService != null && isEnabled()) {
try {
return mService.getConnectedDevices();
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return new ArrayList<BluetoothDevice>();
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return new ArrayList<BluetoothDevice>();
|
public int | getConnectionState(BluetoothDevice device)Get connection state of device
if (DBG) log("getConnectionState(" + device + ")");
if (mService != null && isEnabled() &&
isValidDevice(device)) {
try {
return mService.getConnectionState(device);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return BluetoothProfile.STATE_DISCONNECTED;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return BluetoothProfile.STATE_DISCONNECTED;
|
public java.util.List | getDevicesMatchingConnectionStates(int[] states)Get the list of devices matching specified states. Currently at most one.
if (DBG) log("getDevicesMatchingStates()");
if (mService != null && isEnabled()) {
try {
return mService.getDevicesMatchingConnectionStates(states);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return new ArrayList<BluetoothDevice>();
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return new ArrayList<BluetoothDevice>();
|
public int | getPriority(BluetoothDevice device)Get the priority of the profile.
The priority can be any of:
{@link #PRIORITY_AUTO_CONNECT}, {@link #PRIORITY_OFF},
{@link #PRIORITY_ON}, {@link #PRIORITY_UNDEFINED}
if (VDBG) log("getPriority(" + device + ")");
if (mService != null && isEnabled() &&
isValidDevice(device)) {
try {
return mService.getPriority(device);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return PRIORITY_OFF;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return PRIORITY_OFF;
|
public int | getState()Get the current state of the BluetoothMap service.
if (VDBG) log("getState()");
if (mService != null) {
try {
return mService.getState();
} catch (RemoteException e) {Log.e(TAG, e.toString());}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
}
return BluetoothMap.STATE_ERROR;
|
public boolean | isConnected(BluetoothDevice device)Returns true if the specified Bluetooth device is connected.
Returns false if not connected, or if this proxy object is not
currently connected to the Map service.
if (VDBG) log("isConnected(" + device + ")");
if (mService != null) {
try {
return mService.isConnected(device);
} catch (RemoteException e) {Log.e(TAG, e.toString());}
} else {
Log.w(TAG, "Proxy not attached to service");
if (DBG) log(Log.getStackTraceString(new Throwable()));
}
return false;
|
private boolean | isEnabled()
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null && adapter.getState() == BluetoothAdapter.STATE_ON) return true;
log("Bluetooth is Not enabled");
return false;
|
private boolean | isValidDevice(BluetoothDevice device)
if (device == null) return false;
if (BluetoothAdapter.checkBluetoothAddress(device.getAddress())) return true;
return false;
|
private static void | log(java.lang.String msg)
Log.d(TAG, msg);
|
public boolean | setPriority(BluetoothDevice device, int priority)Set priority of the profile
The device should already be paired.
Priority can be one of {@link #PRIORITY_ON} or
{@link #PRIORITY_OFF},
if (DBG) log("setPriority(" + device + ", " + priority + ")");
if (mService != null && isEnabled() &&
isValidDevice(device)) {
if (priority != BluetoothProfile.PRIORITY_OFF &&
priority != BluetoothProfile.PRIORITY_ON) {
return false;
}
try {
return mService.setPriority(device, priority);
} catch (RemoteException e) {
Log.e(TAG, Log.getStackTraceString(new Throwable()));
return false;
}
}
if (mService == null) Log.w(TAG, "Proxy not attached to service");
return false;
|