add logic for setting/re-setting "Fdroid" name tag for bluetooth device

This commit is contained in:
n8fr8 2015-07-13 14:41:21 -04:00
parent d662c15fb8
commit cc6b2736ce

View File

@ -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;