forked from upstream-mirrors/OpenTracks
Fix: Allow selection of internal sensors when Bluetooth is disabled
This commit is contained in:
+22
-20
@@ -191,26 +191,6 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
|
|||||||
List<ParcelUuid> serviceUUIDs = getArguments().getParcelableArrayList(ARG_BLE_SERVICE_UUIDS);
|
List<ParcelUuid> serviceUUIDs = getArguments().getParcelableArrayList(ARG_BLE_SERVICE_UUIDS);
|
||||||
boolean includeInternalSensor = getArguments().getBoolean(ARG_INCLUDE_INTERNAL);
|
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));
|
listAdapter.add(SensorType.NONE.getPreferenceValue(), getContext().getString(DEVICE_NONE_RESOURCEID));
|
||||||
selectedEntryIndex = 0;
|
selectedEntryIndex = 0;
|
||||||
|
|
||||||
@@ -228,6 +208,28 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
|
|||||||
selectedEntryIndex = !includeInternalSensor ? 1 : 2;
|
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;
|
List<ScanFilter> scanFilter = null;
|
||||||
if (PreferencesUtils.getBluetoothFilterEnabled()) {
|
if (PreferencesUtils.getBluetoothFilterEnabled()) {
|
||||||
scanFilter = serviceUUIDs.stream()
|
scanFilter = serviceUUIDs.stream()
|
||||||
|
|||||||
Reference in New Issue
Block a user