store the current Bluetooth name and restore it when swap is done
fdroid/fdroidclient#1669
This commit is contained in:
parent
7f35420e37
commit
6e8c4eb1bf
@ -86,6 +86,10 @@ public class BluetoothManager {
|
|||||||
localBroadcastManager.registerReceiver(bluetoothDeviceFound,
|
localBroadcastManager.registerReceiver(bluetoothDeviceFound,
|
||||||
new IntentFilter(BluetoothDevice.ACTION_FOUND));
|
new IntentFilter(BluetoothDevice.ACTION_FOUND));
|
||||||
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
|
String name = bluetoothAdapter.getName();
|
||||||
|
if (name != null) {
|
||||||
|
SwapService.putBluetoothNameBeforeSwap(name);
|
||||||
|
}
|
||||||
if (!bluetoothAdapter.enable()) {
|
if (!bluetoothAdapter.enable()) {
|
||||||
sendBroadcast(STATUS_ERROR, context.getString(R.string.swap_error_cannot_start_bluetooth));
|
sendBroadcast(STATUS_ERROR, context.getString(R.string.swap_error_cannot_start_bluetooth));
|
||||||
return;
|
return;
|
||||||
@ -113,6 +117,10 @@ public class BluetoothManager {
|
|||||||
if (!SwapService.wasBluetoothEnabledBeforeSwap()) {
|
if (!SwapService.wasBluetoothEnabledBeforeSwap()) {
|
||||||
bluetoothAdapter.disable();
|
bluetoothAdapter.disable();
|
||||||
}
|
}
|
||||||
|
String name = SwapService.getBluetoothNameBeforeSwap();
|
||||||
|
if (name != null) {
|
||||||
|
bluetoothAdapter.setName(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handlerThread.quit();
|
handlerThread.quit();
|
||||||
handlerThread = null;
|
handlerThread = null;
|
||||||
|
@ -58,6 +58,7 @@ public class SwapService extends Service {
|
|||||||
private static final String KEY_BLUETOOTH_ENABLED = "bluetoothEnabled";
|
private static final String KEY_BLUETOOTH_ENABLED = "bluetoothEnabled";
|
||||||
private static final String KEY_WIFI_ENABLED = "wifiEnabled";
|
private static final String KEY_WIFI_ENABLED = "wifiEnabled";
|
||||||
private static final String KEY_BLUETOOTH_ENABLED_BEFORE_SWAP = "bluetoothEnabledBeforeSwap";
|
private static final String KEY_BLUETOOTH_ENABLED_BEFORE_SWAP = "bluetoothEnabledBeforeSwap";
|
||||||
|
private static final String KEY_BLUETOOTH_NAME_BEFORE_SWAP = "bluetoothNameBeforeSwap";
|
||||||
private static final String KEY_WIFI_ENABLED_BEFORE_SWAP = "wifiEnabledBeforeSwap";
|
private static final String KEY_WIFI_ENABLED_BEFORE_SWAP = "wifiEnabledBeforeSwap";
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@ -301,6 +302,14 @@ public class SwapService extends Service {
|
|||||||
swapPreferences.edit().putBoolean(SwapService.KEY_BLUETOOTH_ENABLED_BEFORE_SWAP, visible).apply();
|
swapPreferences.edit().putBoolean(SwapService.KEY_BLUETOOTH_ENABLED_BEFORE_SWAP, visible).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getBluetoothNameBeforeSwap() {
|
||||||
|
return swapPreferences.getString(SwapService.KEY_BLUETOOTH_NAME_BEFORE_SWAP, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void putBluetoothNameBeforeSwap(String name) {
|
||||||
|
swapPreferences.edit().putString(SwapService.KEY_BLUETOOTH_NAME_BEFORE_SWAP, name).apply();
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean wasWifiEnabledBeforeSwap() {
|
public static boolean wasWifiEnabledBeforeSwap() {
|
||||||
return swapPreferences.getBoolean(SwapService.KEY_WIFI_ENABLED_BEFORE_SWAP, false);
|
return swapPreferences.getBoolean(SwapService.KEY_WIFI_ENABLED_BEFORE_SWAP, false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user