Fix BlueCove address and URL format.

This commit is contained in:
akwizgran
2022-02-21 16:04:00 +00:00
parent 1020c70c22
commit b3e1c62aff

View File

@@ -21,7 +21,9 @@ import javax.microedition.io.StreamConnectionNotifier;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger; import static java.util.logging.Logger.getLogger;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
import static org.briarproject.bramble.util.StringUtils.fromHexString;
import static org.briarproject.bramble.util.StringUtils.isValidMac; import static org.briarproject.bramble.util.StringUtils.isValidMac;
import static org.briarproject.bramble.util.StringUtils.macToString;
@MethodsNotNullByDefault @MethodsNotNullByDefault
@ParametersNotNullByDefault @ParametersNotNullByDefault
@@ -65,12 +67,13 @@ class JavaBluetoothPlugin extends
@Nullable @Nullable
@Override @Override
String getBluetoothAddress() { String getBluetoothAddress() {
return localDevice.getBluetoothAddress(); if (localDevice == null) return null;
return macToString(fromHexString(localDevice.getBluetoothAddress()));
} }
@Override @Override
StreamConnectionNotifier openServerSocket(String uuid) throws IOException { StreamConnectionNotifier openServerSocket(String uuid) throws IOException {
String url = makeUrl("localhost", uuid); String url = makeServerSocketUrl(uuid);
return (StreamConnectionNotifier) Connector.open(url); return (StreamConnectionNotifier) Connector.open(url);
} }
@@ -97,9 +100,7 @@ class JavaBluetoothPlugin extends
@Override @Override
DuplexTransportConnection connectTo(String address, String uuid) DuplexTransportConnection connectTo(String address, String uuid)
throws IOException { throws IOException {
String url = makeUrl(address, uuid); throw new IOException("Not implemented"); // TODO
StreamConnection s = (StreamConnection) Connector.open(url);
return connectionFactory.wrapSocket(this, s);
} }
@Override @Override
@@ -113,7 +114,9 @@ class JavaBluetoothPlugin extends
// TODO // TODO
} }
private String makeUrl(String address, String uuid) { private String makeServerSocketUrl(String uuid) {
return "btspp://" + address + ":" + uuid + ";name=RFCOMM"; uuid = uuid.replaceAll("-", "");
return "btspp://" + "localhost" + ":" + uuid
+ ";encrypt=false;authenticate=false";
} }
} }