add logic for setting/re-setting "Fdroid" name tag for bluetooth device
This commit is contained in:
parent
d662c15fb8
commit
cc6b2736ce
@ -29,6 +29,9 @@ public class BluetoothServer extends Thread {
|
|||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
|
private String deviceBluetoothName = null;
|
||||||
|
public final static String BLUETOOTH_NAME_TAG = "FDroid:";
|
||||||
|
|
||||||
public BluetoothServer(Context context) {
|
public BluetoothServer(Context context) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
}
|
}
|
||||||
@ -43,14 +46,26 @@ public class BluetoothServer extends Thread {
|
|||||||
Utils.closeQuietly(serverSocket);
|
Utils.closeQuietly(serverSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
adapter.setName(deviceBluetoothName.replace(BLUETOOTH_NAME_TAG,""));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
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 {
|
try {
|
||||||
serverSocket = adapter.listenUsingRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid());
|
serverSocket = adapter.listenUsingInsecureRfcommWithServiceRecord("FDroid App Swap", BluetoothConstants.fdroidUuid());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now - " + e.getMessage());
|
Log.e(TAG, "Error starting Bluetooth server socket, will stop the server now - " + e.getMessage());
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user