Class IDs may be in nested lists. Don't ask me why.

This commit is contained in:
akwizgran
2011-10-28 16:46:51 +01:00
parent 559cdfaeba
commit d3060a3bd6
3 changed files with 36 additions and 36 deletions

View File

@@ -1,10 +1,14 @@
package net.sf.briar.plugins.bluetooth;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicInteger;
import javax.bluetooth.DataElement;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.UUID;
abstract class AbstractListener implements DiscoveryListener {
@@ -46,4 +50,15 @@ abstract class AbstractListener implements DiscoveryListener {
}
return null;
}
protected void findNestedClassIds(Object o, Collection<String> ids) {
o = getDataElementValue(o);
if(o instanceof Enumeration) {
for(Object o1 : Collections.list((Enumeration<?>) o)) {
findNestedClassIds(o1, ids);
}
} else if(o instanceof UUID) {
ids.add(o.toString());
}
}
}

View File

@@ -1,14 +1,14 @@
package net.sf.briar.plugins.bluetooth;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DataElement;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.RemoteDevice;
@@ -76,21 +76,14 @@ class ContactListener extends AbstractListener {
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if(serviceUrl == null) continue;
// Does this service have the UUID we're looking for?
DataElement classIds = record.getAttributeValue(0x1);
Object o = getDataElementValue(classIds);
if(o instanceof Enumeration) {
Enumeration<?> e = (Enumeration<?>) o;
for(Object o1 : Collections.list(e)) {
Object o2 = getDataElementValue(o1);
if(o2 instanceof UUID) {
UUID serviceUuid = (UUID) o2;
if(uuid.equalsIgnoreCase(serviceUuid.toString())) {
// The UUID matches - store the URL
urls.put(c, serviceUrl);
}
}
Collection<String> uuids = new TreeSet<String>();
findNestedClassIds(record.getAttributeValue(0x1), uuids);
for(String u : uuids) {
if(uuid.equalsIgnoreCase(u.toString())) {
// The UUID matches - store the URL
urls.put(c, serviceUrl);
}
}
}
}
}
}

View File

@@ -1,12 +1,11 @@
package net.sf.briar.plugins.bluetooth;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Collection;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DataElement;
import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.RemoteDevice;
@@ -56,23 +55,16 @@ class InvitationListener extends AbstractListener {
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
if(serviceUrl == null) continue;
// Does this service have the UUID we're looking for?
DataElement classIds = record.getAttributeValue(0x1);
Object o = getDataElementValue(classIds);
if(o instanceof Enumeration) {
Enumeration<?> e = (Enumeration<?>) o;
for(Object o1 : Collections.list(e)) {
Object o2 = getDataElementValue(o1);
if(o2 instanceof UUID) {
UUID serviceUuid = (UUID) o2;
if(uuid.equalsIgnoreCase(serviceUuid.toString())) {
// The UUID matches - store the URL
synchronized(this) {
url = serviceUrl;
finished = true;
notifyAll();
return;
}
}
Collection<String> uuids = new TreeSet<String>();
findNestedClassIds(record.getAttributeValue(0x1), uuids);
for(String u : uuids) {
if(uuid.equalsIgnoreCase(u)) {
// The UUID matches - store the URL
synchronized(this) {
url = serviceUrl;
finished = true;
notifyAll();
return;
}
}
}