use of android.bluetooth.IBluetoothCallback in project XobotOS by xamarin.
the class BluetoothService method updateDeviceServiceChannelCache.
/*package*/
void updateDeviceServiceChannelCache(String address) {
if (DBG)
Log.d(TAG, "updateDeviceServiceChannelCache(" + address + ")");
// We are storing the rfcomm channel numbers only for the uuids
// we are interested in.
ParcelUuid[] deviceUuids = getRemoteUuids(address);
ArrayList<ParcelUuid> applicationUuids = new ArrayList<ParcelUuid>();
synchronized (this) {
for (RemoteService service : mUuidCallbackTracker.keySet()) {
if (service.address.equals(address)) {
applicationUuids.add(service.uuid);
}
}
}
Map<ParcelUuid, Integer> uuidToChannelMap = new HashMap<ParcelUuid, Integer>();
// Retrieve RFCOMM channel for default uuids
for (ParcelUuid uuid : RFCOMM_UUIDS) {
if (BluetoothUuid.isUuidPresent(deviceUuids, uuid)) {
int channel = getDeviceServiceChannelForUuid(address, uuid);
uuidToChannelMap.put(uuid, channel);
if (DBG)
Log.d(TAG, "\tuuid(system): " + uuid + " " + channel);
}
}
// Retrieve RFCOMM channel for application requested uuids
for (ParcelUuid uuid : applicationUuids) {
if (BluetoothUuid.isUuidPresent(deviceUuids, uuid)) {
int channel = getDeviceServiceChannelForUuid(address, uuid);
uuidToChannelMap.put(uuid, channel);
if (DBG)
Log.d(TAG, "\tuuid(application): " + uuid + " " + channel);
}
}
synchronized (this) {
// Make application callbacks
for (Iterator<RemoteService> iter = mUuidCallbackTracker.keySet().iterator(); iter.hasNext(); ) {
RemoteService service = iter.next();
if (service.address.equals(address)) {
if (uuidToChannelMap.containsKey(service.uuid)) {
int channel = uuidToChannelMap.get(service.uuid);
if (DBG)
Log.d(TAG, "Making callback for " + service.uuid + " with result " + channel);
IBluetoothCallback callback = mUuidCallbackTracker.get(service);
if (callback != null) {
try {
callback.onRfcommChannelFound(channel);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
}
iter.remove();
}
}
}
// Update cache
mDeviceServiceChannelCache.put(address, uuidToChannelMap);
}
}
use of android.bluetooth.IBluetoothCallback in project XobotOS by xamarin.
the class BluetoothService method makeServiceChannelCallbacks.
/*package*/
synchronized void makeServiceChannelCallbacks(String address) {
for (Iterator<RemoteService> iter = mUuidCallbackTracker.keySet().iterator(); iter.hasNext(); ) {
RemoteService service = iter.next();
if (service.address.equals(address)) {
if (DBG)
Log.d(TAG, "Cleaning up failed UUID channel lookup: " + service.address + " " + service.uuid);
IBluetoothCallback callback = mUuidCallbackTracker.get(service);
if (callback != null) {
try {
callback.onRfcommChannelFound(-1);
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
}
iter.remove();
}
}
}
Aggregations