Fix: Allow selection of internal sensors when Bluetooth is disabled

This commit is contained in:
stickflowerfightclub
2026-04-12 10:27:19 +02:00
parent e1e34452ae
commit 3f6a4975fa
@@ -191,26 +191,6 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
List<ParcelUuid> serviceUUIDs = getArguments().getParcelableArrayList(ARG_BLE_SERVICE_UUIDS);
boolean includeInternalSensor = getArguments().getBoolean(ARG_INCLUDE_INTERNAL);
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(getContext());
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Log.w(TAG, "Bluetooth adapter is present or not enabled.");
Toast.makeText(getContext(), R.string.bluetooth_disabled, Toast.LENGTH_SHORT).show();
dismiss();
return;
}
if (bluetoothAdapter.isDiscovering()) {
Log.i(TAG, "Cancelling ongoing Bluetooth discovery.");
bluetoothAdapter.cancelDiscovery();
}
scanner = bluetoothAdapter.getBluetoothLeScanner();
if (scanner == null) {
Log.e(TAG, "BluetoothLeScanner is null.");
dismiss();
return;
}
listAdapter.add(SensorType.NONE.getPreferenceValue(), getContext().getString(DEVICE_NONE_RESOURCEID));
selectedEntryIndex = 0;
@@ -228,6 +208,28 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
selectedEntryIndex = !includeInternalSensor ? 1 : 2;
}
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getAdapter(getContext());
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
Log.w(TAG, "Bluetooth adapter is present or not enabled. Skipping BLE scan.");
Toast.makeText(getContext(), R.string.bluetooth_disabled, Toast.LENGTH_SHORT).show();
if (!includeInternalSensor) {
dismiss();
}
return;
}
if (bluetoothAdapter.isDiscovering()) {
Log.i(TAG, "Cancelling ongoing Bluetooth discovery.");
bluetoothAdapter.cancelDiscovery();
}
scanner = bluetoothAdapter.getBluetoothLeScanner();
if (scanner == null) {
Log.e(TAG, "BluetoothLeScanner is null.");
dismiss();
return;
}
List<ScanFilter> scanFilter = null;
if (PreferencesUtils.getBluetoothFilterEnabled()) {
scanFilter = serviceUUIDs.stream()