Search in sources :

Example 1 with IBluetoothCallback

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);
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IBluetoothCallback(android.bluetooth.IBluetoothCallback) RemoteException(android.os.RemoteException)

Example 2 with IBluetoothCallback

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();
        }
    }
}
Also used : IBluetoothCallback(android.bluetooth.IBluetoothCallback) RemoteException(android.os.RemoteException)

Aggregations

IBluetoothCallback (android.bluetooth.IBluetoothCallback)2 RemoteException (android.os.RemoteException)2 ParcelUuid (android.os.ParcelUuid)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1