Skip to content

Commit f091efd

Browse files
committed
fix(location): create preference for enabling GNSS in significant mode
- Background service checks this preference if Android >16 and sets HIGH_POWER if it's set - Preference screen update
1 parent 2f2b2e8 commit f091efd

10 files changed

Lines changed: 32 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This release addresses a security advisory covering several intent-handling vuln
2020
- New **Remote Control** preferences screen showing the intent auth key (with a copy-to-clipboard button) for use with automation apps such as Tasker
2121
- Config import screen now shows a structured diff of what is changing, with human-readable preference names, highlighting new values alongside the current values — unchanged settings are summarised rather than listed in full
2222
- Waypoints in an imported config are listed individually in the import review screen
23-
- Preference setting to allow user to enable GNSS location source for Significant Monitoring mode (#2155)
23+
- Preference setting (Android 16 and later only) to allow user to enable GNSS location source for Significant Monitoring mode (#2155)
2424

2525
### Bug fixes
2626

justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ local-stack:
7272
mqtt-subscribe:
7373
mosquitto_sub -v -L mqtt://localhost/owntracks/# -u test -P test
7474

75+
[group('device')]
76+
install: (gradle "app:assembleGmsDebug")
77+
adb install -r project/app/build/outputs/apk/gms/debug/app-gms-debug.apk
78+
7579
[group('device')]
7680
wipe-device:
7781
adb uninstall org.owntracks.android; adb uninstall org.owntracks.android.debug; adb uninstall androidx.test.orchestrator ; adb uninstall androidx.test.services; adb uninstall androidx.test.tools.crawler; adb uninstall androidx.test.tools.crawler.stubapp; echo "done"

project/app/src/main/java/org/owntracks/android/preferences/DefaultsProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ interface DefaultsProvider {
4444
Preferences::locatorDisplacement -> 500
4545
Preferences::locatorInterval -> 60
4646
Preferences::locatorPriority -> null
47+
Preferences::useGNSSInSignificantMonitoringMode -> false
4748
Preferences::mode -> ConnectionMode.MQTT
4849
Preferences::monitoring -> MonitoringMode.Significant
4950
Preferences::moveModeLocatorInterval -> 10

project/app/src/main/java/org/owntracks/android/preferences/Preferences.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ constructor(
272272

273273
@Preference var locatorPriority: LocatorPriority? by preferencesStore
274274

275+
@Preference var useGNSSInSignificantMonitoringMode: Boolean by preferencesStore
276+
275277
@Preference var mapLayerStyle: MapLayerStyle by preferencesStore
276278

277279
@Preference var mode: ConnectionMode by preferencesStore

project/app/src/main/java/org/owntracks/android/services/BackgroundService.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,18 @@ class BackgroundService : LifecycleService(), Preferences.OnPreferenceChangeList
536536
MonitoringMode.Significant -> {
537537
interval = Duration.ofSeconds(preferences.locatorInterval.toLong())
538538
smallestDisplacement = preferences.locatorDisplacement.toFloat()
539-
priority = preferences.locatorPriority ?: if(Build.VERSION.SDK_INT>Build.VERSION_CODES.Q) {
540-
LocatorPriority.BalancedPowerAccuracy}
541-
else {LocatorPriority.BalancedPowerAccuracy
542-
}
539+
// QPR1 (where balanced-accuracy stopped using GNSS, per #2155) isn't separately
540+
// detectable from the Android 16 GA release, so we gate on Android 16+ generally.
541+
val useGnss =
542+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA &&
543+
preferences.useGNSSInSignificantMonitoringMode
544+
priority =
545+
preferences.locatorPriority
546+
?: if (useGnss) {
547+
LocatorPriority.HighAccuracy
548+
} else {
549+
LocatorPriority.BalancedPowerAccuracy
550+
}
543551
}
544552

545553
MonitoringMode.Move -> {

project/app/src/main/java/org/owntracks/android/ui/preferences/AdvancedFragment.kt

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.owntracks.android.ui.preferences
22

33
import android.content.Context
4+
import android.os.Build
45
import android.os.Bundle
56
import android.widget.TextView
67
import androidx.preference.ListPreference
78
import androidx.preference.Preference
89
import androidx.preference.SwitchPreferenceCompat
9-
import org.owntracks.android.location.LocatorPriority
1010
import com.google.android.material.dialog.MaterialAlertDialogBuilder
1111
import dagger.hilt.android.AndroidEntryPoint
1212
import javax.inject.Inject
@@ -60,14 +60,9 @@ class AdvancedFragment @Inject constructor() :
6060
findPreference<Preference>("autostartWarning")?.isVisible =
6161
!requirementsChecker.hasBackgroundLocationPermission()
6262

63-
findPreference<SwitchPreferenceCompat>("useGnss")?.apply {
64-
isChecked = preferences.locatorPriority == LocatorPriority.HighAccuracy
65-
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
66-
preferences.locatorPriority =
67-
if (newValue as Boolean) LocatorPriority.HighAccuracy else null
68-
true
69-
}
70-
}
63+
findPreference<SwitchPreferenceCompat>(
64+
Preferences::useGNSSInSignificantMonitoringMode.name)
65+
?.isVisible = Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA
7166

7267
findPreference<ListPreference>(Preferences::reverseGeocodeProvider.name)
7368
?.onPreferenceChangeListener =
@@ -104,9 +99,5 @@ class AdvancedFragment @Inject constructor() :
10499
if (properties.contains(Preferences::reverseGeocodeProvider.name)) {
105100
setOpenCageAPIKeyPreferenceVisibility()
106101
}
107-
if (properties.contains(Preferences::locatorPriority.name)) {
108-
findPreference<SwitchPreferenceCompat>("useGnss")?.isChecked =
109-
preferences.locatorPriority == LocatorPriority.HighAccuracy
110-
}
111102
}
112103
}

project/app/src/main/java/org/owntracks/android/ui/preferences/load/PreferenceKeyLabels.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ val PREFERENCE_KEY_LABELS: Map<String, Int> =
6565
"tlsClientCertInstall" to R.string.preferencesClientCrtInstall,
6666
"tlsClientCrt" to R.string.preferencesClientCrt,
6767
"url" to R.string.preferencesUrl,
68+
"useGNSSInSignificantMonitoringMode" to
69+
R.string.preferencesUseGNSSInSignificantMonitoringMode,
6870
"username" to R.string.preferencesUsername,
6971
"ws" to R.string.preferencesWebsocket,
7072
)

project/app/src/main/res/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ To allow this, please enable Location in the device settings."</string>
273273
<string name="preferencesParameters">"Parameters"</string>
274274
<string name="preferencesPegLocatorFastestIntervalToInterval">"Limit max locator frequency"</string>
275275
<string name="preferencesPegLocatorFastestIntervalToIntervalSummary">"Request that the location provider deliver updates no faster than the requested locator interval"</string>
276-
<string name="preferencesGnssInSignificantMode">"Use GNSS in significant mode"</string>
277-
<string name="preferencesGnssInSignificantModeSummary">"Request GPS-level accuracy in significant monitoring mode. Required for accurate location on Android 16 and later. Disable to save battery at the cost of accuracy."</string>
276+
<string name="preferencesUseGNSSInSignificantMonitoringMode">"Use GNSS in significant mode"</string>
277+
<string name="preferencesUseGNSSInSignificantMonitoringModeSummary">"Request GPS-level accuracy in significant monitoring mode. Some Android 16 versions (from QPR1) stop using GNSS for the default accuracy mode, so this is required for accurate location on those versions. Disable to save battery at the cost of accuracy."</string>
278278
<string name="preferencesPort">"Port"</string>
279279
<string name="preferencesPortValidationError">"Port must be a number between 1 and 65535"</string>
280280
<string name="preferencesProfileId">"Mode"</string>

project/app/src/main/res/xml/preferences_advanced.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
app:title="@string/preferencesPegLocatorFastestIntervalToInterval" />
4444
<androidx.preference.SwitchPreferenceCompat
4545
app:iconSpaceReserved="false"
46-
app:key="useGnss"
47-
app:persistent="false"
48-
app:summary="@string/preferencesGnssInSignificantModeSummary"
49-
app:title="@string/preferencesGnssInSignificantMode" />
46+
app:key="useGNSSInSignificantMonitoringMode"
47+
app:summary="@string/preferencesUseGNSSInSignificantMonitoringModeSummary"
48+
app:title="@string/preferencesUseGNSSInSignificantMonitoringMode" />
5049
</androidx.preference.PreferenceCategory>
5150
<androidx.preference.PreferenceCategory
5251
app:iconSpaceReserved="false"

project/app/src/test/java/org/owntracks/android/preferences/PreferencesGettersAndSetters.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class PreferencesGettersAndSetters(private val parameter: Parameter) {
135135
LocatorPriority::class,
136136
false,
137137
preferenceValueInConfiguration = "HighAccuracy"),
138+
Parameter("useGNSSInSignificantMonitoringMode", true, Boolean::class, false),
138139
Parameter(
139140
"mode",
140141
ConnectionMode.HTTP,

0 commit comments

Comments
 (0)