diff --git a/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java b/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java index 3996ced56a319c9cd0232a9f96d67edfa86e74f2..df250dede35cad9c12c3df79b57900dd89c062f9 100644 --- a/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java +++ b/src/net/sf/briar/plugins/droidtooth/DroidtoothPlugin.java @@ -259,12 +259,8 @@ class DroidtoothPlugin implements DuplexPlugin { // Try to connect BluetoothDevice d = adapter.getRemoteDevice(address); try { - if(LOG.isLoggable(INFO)) - LOG.info("Creating socket for " + address); BluetoothSocket s = InsecureBluetooth.createSocket(d, u); - if(LOG.isLoggable(INFO)) LOG.info("Connecting"); s.connect(); - if(LOG.isLoggable(INFO)) LOG.info("Connected"); return new DroidtoothTransportConnection(s); } catch(IOException e) { if(LOG.isLoggable(WARNING)) LOG.warning(e.toString()); @@ -328,7 +324,6 @@ class DroidtoothPlugin implements DuplexPlugin { if(LOG.isLoggable(WARNING)) LOG.warning(e.toString()); return null; } - if(LOG.isLoggable(INFO)) LOG.info("Listening"); // Return the first connection received by the socket, if any try { return new DroidtoothTransportConnection(ss.accept((int) timeout)); @@ -387,14 +382,11 @@ class DroidtoothPlugin implements DuplexPlugin { public void onReceive(Context ctx, Intent intent) { String action = intent.getAction(); if(action.equals(DISCOVERY_FINISHED)) { - if(LOG.isLoggable(INFO)) LOG.info("Discovery finished"); ctx.unregisterReceiver(this); connectToDiscoveredDevices(); } else if(action.equals(FOUND)) { BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE); - String address = d.getAddress(); - if(LOG.isLoggable(INFO)) LOG.info("Discovered " + address); - addresses.add(address); + addresses.add(d.getAddress()); } } diff --git a/src/net/sf/briar/plugins/droidtooth/InsecureBluetooth.java b/src/net/sf/briar/plugins/droidtooth/InsecureBluetooth.java index cff43fafb95c5026f2ebb9c258f0bd84fd3187ed..5537dde0aad67861a13357991e6b8d903f5ff5ee 100644 --- a/src/net/sf/briar/plugins/droidtooth/InsecureBluetooth.java +++ b/src/net/sf/briar/plugins/droidtooth/InsecureBluetooth.java @@ -21,6 +21,8 @@ import android.os.ParcelUuid; // Based on http://stanford.edu/~tpurtell/InsecureBluetooth.java by T.J. Purtell class InsecureBluetooth { + private static final int TYPE_RFCOMM = 1; + @SuppressLint("NewApi") static BluetoothServerSocket listen(BluetoothAdapter adapter, String name, UUID uuid) throws IOException { @@ -102,13 +104,10 @@ class InsecureBluetooth { if(constructor == null) throw new IOException("Can't find server socket constructor"); constructor.setAccessible(true); - Field f = BluetoothSocket.class.getDeclaredField("TYPE_RFCOMM"); + socket = constructor.newInstance(TYPE_RFCOMM, false, false, port); + Field f = socket.getClass().getDeclaredField("mSocket"); f.setAccessible(true); - int rfcommType = (Integer) f.get(null); - socket = constructor.newInstance(rfcommType, false, false, port); - Field f1 = socket.getClass().getDeclaredField("mSocket"); - f1.setAccessible(true); - Object mSocket = f1.get(socket); + Object mSocket = f.get(socket); Method bindListen = mSocket.getClass().getDeclaredMethod( "bindListen", new Class[0]); bindListen.setAccessible(true); @@ -150,16 +149,11 @@ class InsecureBluetooth { if(constructor == null) throw new IOException("Can't find socket constructor"); constructor.setAccessible(true); - Field f = BluetoothSocket.class.getDeclaredField("TYPE_RFCOMM"); - f.setAccessible(true); - int typeRfcomm = (Integer) f.get(null); - socket = constructor.newInstance(typeRfcomm, -1, false, true, + socket = constructor.newInstance(TYPE_RFCOMM, -1, false, true, device, -1, uuid != null ? new ParcelUuid(uuid) : null); return socket; } catch(NoSuchMethodException e) { throw new IOException(e.toString()); - } catch(NoSuchFieldException e) { - throw new IOException(e.toString()); } catch(IllegalAccessException e) { throw new IOException(e.toString()); } catch(InstantiationException e) {