mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Class IDs may be in nested lists. Don't ask me why.
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
package net.sf.briar.plugins.bluetooth;
|
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 java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import javax.bluetooth.DataElement;
|
import javax.bluetooth.DataElement;
|
||||||
import javax.bluetooth.DiscoveryAgent;
|
import javax.bluetooth.DiscoveryAgent;
|
||||||
import javax.bluetooth.DiscoveryListener;
|
import javax.bluetooth.DiscoveryListener;
|
||||||
|
import javax.bluetooth.UUID;
|
||||||
|
|
||||||
abstract class AbstractListener implements DiscoveryListener {
|
abstract class AbstractListener implements DiscoveryListener {
|
||||||
|
|
||||||
@@ -46,4 +50,15 @@ abstract class AbstractListener implements DiscoveryListener {
|
|||||||
}
|
}
|
||||||
return null;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package net.sf.briar.plugins.bluetooth;
|
package net.sf.briar.plugins.bluetooth;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.bluetooth.BluetoothStateException;
|
import javax.bluetooth.BluetoothStateException;
|
||||||
import javax.bluetooth.DataElement;
|
|
||||||
import javax.bluetooth.DeviceClass;
|
import javax.bluetooth.DeviceClass;
|
||||||
import javax.bluetooth.DiscoveryAgent;
|
import javax.bluetooth.DiscoveryAgent;
|
||||||
import javax.bluetooth.RemoteDevice;
|
import javax.bluetooth.RemoteDevice;
|
||||||
@@ -76,19 +76,12 @@ class ContactListener extends AbstractListener {
|
|||||||
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
|
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
|
||||||
if(serviceUrl == null) continue;
|
if(serviceUrl == null) continue;
|
||||||
// Does this service have the UUID we're looking for?
|
// Does this service have the UUID we're looking for?
|
||||||
DataElement classIds = record.getAttributeValue(0x1);
|
Collection<String> uuids = new TreeSet<String>();
|
||||||
Object o = getDataElementValue(classIds);
|
findNestedClassIds(record.getAttributeValue(0x1), uuids);
|
||||||
if(o instanceof Enumeration) {
|
for(String u : uuids) {
|
||||||
Enumeration<?> e = (Enumeration<?>) o;
|
if(uuid.equalsIgnoreCase(u.toString())) {
|
||||||
for(Object o1 : Collections.list(e)) {
|
// The UUID matches - store the URL
|
||||||
Object o2 = getDataElementValue(o1);
|
urls.put(c, serviceUrl);
|
||||||
if(o2 instanceof UUID) {
|
|
||||||
UUID serviceUuid = (UUID) o2;
|
|
||||||
if(uuid.equalsIgnoreCase(serviceUuid.toString())) {
|
|
||||||
// The UUID matches - store the URL
|
|
||||||
urls.put(c, serviceUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package net.sf.briar.plugins.bluetooth;
|
package net.sf.briar.plugins.bluetooth;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
import java.util.TreeSet;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import javax.bluetooth.BluetoothStateException;
|
import javax.bluetooth.BluetoothStateException;
|
||||||
import javax.bluetooth.DataElement;
|
|
||||||
import javax.bluetooth.DeviceClass;
|
import javax.bluetooth.DeviceClass;
|
||||||
import javax.bluetooth.DiscoveryAgent;
|
import javax.bluetooth.DiscoveryAgent;
|
||||||
import javax.bluetooth.RemoteDevice;
|
import javax.bluetooth.RemoteDevice;
|
||||||
@@ -56,23 +55,16 @@ class InvitationListener extends AbstractListener {
|
|||||||
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
|
ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
|
||||||
if(serviceUrl == null) continue;
|
if(serviceUrl == null) continue;
|
||||||
// Does this service have the UUID we're looking for?
|
// Does this service have the UUID we're looking for?
|
||||||
DataElement classIds = record.getAttributeValue(0x1);
|
Collection<String> uuids = new TreeSet<String>();
|
||||||
Object o = getDataElementValue(classIds);
|
findNestedClassIds(record.getAttributeValue(0x1), uuids);
|
||||||
if(o instanceof Enumeration) {
|
for(String u : uuids) {
|
||||||
Enumeration<?> e = (Enumeration<?>) o;
|
if(uuid.equalsIgnoreCase(u)) {
|
||||||
for(Object o1 : Collections.list(e)) {
|
// The UUID matches - store the URL
|
||||||
Object o2 = getDataElementValue(o1);
|
synchronized(this) {
|
||||||
if(o2 instanceof UUID) {
|
url = serviceUrl;
|
||||||
UUID serviceUuid = (UUID) o2;
|
finished = true;
|
||||||
if(uuid.equalsIgnoreCase(serviceUuid.toString())) {
|
notifyAll();
|
||||||
// The UUID matches - store the URL
|
return;
|
||||||
synchronized(this) {
|
|
||||||
url = serviceUrl;
|
|
||||||
finished = true;
|
|
||||||
notifyAll();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user