From cc6b2736cea697e4b170c0318e5518990b341a4b Mon Sep 17 00:00:00 2001 From: n8fr8 Date: Mon, 13 Jul 2015 14:41:21 -0400 Subject: [PATCH] add logic for setting/re-setting "Fdroid" name tag for bluetooth device --- .../fdroid/net/bluetooth/BluetoothServer.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java index 493cc47be..08b5264bf 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java @@ -29,6 +29,9 @@ public class BluetoothServer extends Thread { private final Context context; + private String deviceBluetoothName = null; + public final static String BLUETOOTH_NAME_TAG = "FDroid:"; + public BluetoothServer(Context context) { this.context = context.getApplicationContext(); } @@ -43,14 +46,26 @@ public class BluetoothServer extends Thread { Utils.closeQuietly(serverSocket); } + BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + adapter.setName(deviceBluetoothName.replace(BLUETOOTH_NAME_TAG,"")); + } @Override public void run() { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); + + + //store the original bluetoothname, and update this one to be unique + deviceBluetoothName = adapter.getName(); + + if (!deviceBluetoothName.contains(BLUETOOTH_NAME_TAG)) + adapter.setName(BLUETOOTH_NAME_TAG + deviceBluetoothName); + + try { - serverSocket = adapter.listenUsingRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid()); + serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid()); } catch (IOException e) { Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now - " + e.getMessage()); return;