mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Prevent companion device connection with bluetooth off
This commit is contained in:
+11
-1
@@ -19,6 +19,7 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State.WAITING_FOR_RECONNECT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.impl.GBDevice.State.WAITING_FOR_SCAN;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -63,7 +64,7 @@ public class BluetoothConnectReceiver extends BroadcastReceiver {
|
||||
observedDevice(address);
|
||||
}
|
||||
|
||||
public static void observedDevice(String address) {
|
||||
public static void observedDevice(final String address) {
|
||||
final DeviceManager manager = GBApplication.app().getDeviceManager();
|
||||
final GBDevice gbDevice = manager.getDeviceByAddress(address);
|
||||
if (gbDevice == null) {
|
||||
@@ -71,6 +72,15 @@ public class BluetoothConnectReceiver extends BroadcastReceiver {
|
||||
return;
|
||||
}
|
||||
|
||||
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (adapter == null) {
|
||||
LOG.warn("Bluetooth adapter not found - ignoring observed device");
|
||||
return;
|
||||
} else if (!adapter.isEnabled()) {
|
||||
LOG.warn("Bluetooth adapter is disabled - ignoring observed device");
|
||||
return;
|
||||
}
|
||||
|
||||
final GBDevice.State state = gbDevice.getState();
|
||||
if (state == WAITING_FOR_RECONNECT || state == WAITING_FOR_SCAN) {
|
||||
LOG.debug("re-connecting to observed device due to state {}", state);
|
||||
|
||||
Reference in New Issue
Block a user