Skip to content

Commit

Permalink
Add preference to limit max location frequency to requested interval
Browse files Browse the repository at this point in the history
Fixes #1168
  • Loading branch information
growse committed May 12, 2022
1 parent 75acb77 commit ef974e6
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Use new Google Maps renderer on gms flavour: https://developers.google.com/maps/documentation/android-sdk/renderer
* OSM map now uses a blue dot and arrow for current location (#1078)
* Add preference to draw regions on the map (#1068)
* Add a preference to prevent location updates any faster than the requested interval (#1168)
* Update to Catalan, Japanese and Polish translations (thanks all!)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ class PreferencesActivityTests :

scrollToPreferenceWithText(R.string.preferencesMoveModeLocatorInterval)
clickOnAndWait(R.string.preferencesMoveModeLocatorInterval)

writeTo(android.R.id.edit, "5")
clickDialogPositiveButton()

scrollToPreferenceWithText(R.string.preferencesPegLocatorFastestIntervalToInterval)
clickOnAndWait(R.string.preferencesPegLocatorFastestIntervalToInterval)

scrollToPreferenceWithText(R.string.preferencesAutostart)
clickOnAndWait(R.string.preferencesAutostart)

Expand Down Expand Up @@ -116,6 +118,8 @@ class PreferencesActivityTests :
assertContains(R.id.effectiveConfiguration, "\"reverseGeocodeProvider\" : \"OpenCage\"")
assertContains(R.id.effectiveConfiguration, "\"opencageApiKey\" : \"geocodeAPIKey\"")
assertContains(R.id.effectiveConfiguration, "\"connectionTimeoutSeconds\" : 30")
assertContains(R.id.effectiveConfiguration, "\"pegLocatorFastestIntervalToInterval\" : true")


// Make sure that the MQTT-specific settings aren't present
assertNotContains(R.id.effectiveConfiguration, "\"host\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ private boolean setupLocationRequest() {
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
break;
}
if (preferences.getPegLocatorFastestIntervalToInterval()) {
request.setFastestInterval(request.getInterval());
}
Timber.d("location update request params: %s", request);
locationProviderClient.flushLocations();
locationProviderClient.requestLocationUpdates(request, locationCallback, runThingsOnOtherThreads.getBackgroundLooper());
Expand Down Expand Up @@ -747,7 +750,8 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
if (preferences.getPreferenceKey(R.string.preferenceKeyLocatorInterval).equals(key) ||
preferences.getPreferenceKey(R.string.preferenceKeyLocatorDisplacement).equals(key) ||
preferences.getPreferenceKey(R.string.preferenceKeyLocatorPriority).equals(key) ||
preferences.getPreferenceKey(R.string.preferenceKeyMoveModeLocatorInterval).equals(key)
preferences.getPreferenceKey(R.string.preferenceKeyMoveModeLocatorInterval).equals(key) ||
preferences.getPreferenceKey(R.string.preferenceKeyPegLocatorFastestIntervalToInterval).equals(key)
) {
Timber.d("locator preferences changed. Resetting location request.");
setupLocationRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,22 @@ class Preferences @Inject constructor(
setBoolean(R.string.preferenceKeyShowRegionsOnMap, newValue)
}

@get:Export(
keyResId = R.string.preferenceKeyPegLocatorFastestIntervalToInterval,
exportModeMqtt = true,
exportModeHttp = true
)
@set:Import(keyResId = R.string.preferenceKeyPegLocatorFastestIntervalToInterval)
var pegLocatorFastestIntervalToInterval: Boolean
get() = getBooleanOrDefault(
R.string.preferenceKeyPegLocatorFastestIntervalToInterval,
R.bool.valPegLocatorFastestIntervalToInterval
)
set(newValue) {
setBoolean(R.string.preferenceKeyPegLocatorFastestIntervalToInterval, newValue)
}


// Not used on public, as many people might use the same device type
private val deviceIdDefault: String
get() = // Use device name (Mako, Surnia, etc. and strip all non alpha digits)
Expand Down
1 change: 1 addition & 0 deletions project/app/src/main/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<bool name="valInfo">true</bool>
<bool name="valRemoteConfiguration">false</bool>
<bool name="valShowRegionsOnMap">false</bool>
<bool name="valPegLocatorFastestIntervalToInterval">false</bool>

<string name="valEmpty" translatable="false" />
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="preferenceKeyVersion">_build</string>
<string name="preferenceKeyWS">ws</string>
<string name="preferenceKeyShowRegionsOnMap">showRegionsOnMap</string>
<string name="preferenceKeyPegLocatorFastestIntervalToInterval">pegLocatorFastestIntervalToInterval</string>
<string-array name="geocoderValues" translatable="false">
<item>None</item>
<item>Device</item>
Expand Down
2 changes: 2 additions & 0 deletions project/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,6 @@
<string name="preferencesMap">Map</string>
<string name="preferencesShowRegionsOnMapSummary"></string>
<string name="preferencesShowRegionsOnMap">Show Regions</string>
<string name="preferencesPegLocatorFastestIntervalToInterval">Limit max locator frequency</string>
<string name="preferencesPegLocatorFastestIntervalToIntervalSummary">Request that the location provider deliver updates no faster than the requested locator interval</string>
</resources>
6 changes: 6 additions & 0 deletions project/app/src/main/res/xml/preferences_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
app:key="@string/preferenceKeyMoveModeLocatorInterval"
app:summary="@string/preferencesMoveModeLocatorIntervalSummary"
app:title="@string/preferencesMoveModeLocatorInterval" />
<androidx.preference.SwitchPreferenceCompat
app:defaultValue="@bool/valPegLocatorFastestIntervalToInterval"
app:iconSpaceReserved="false"
app:key="@string/preferenceKeyPegLocatorFastestIntervalToInterval"
app:summary="@string/preferencesPegLocatorFastestIntervalToIntervalSummary"
app:title="@string/preferencesPegLocatorFastestIntervalToInterval" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory
app:iconSpaceReserved="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ class PreferencesGettersAndSetters(
arrayOf("AutostartOnBoot", "autostartOnBoot", true, true, Boolean::class, false),
arrayOf("CleanSession", "cleanSession", true, true, Boolean::class, false),
arrayOf(
"ClientId",
"clientId",
"testClientId",
"testClientId",
String::class,
false
"ClientId", // Method name
"clientId", // Preference name
"testClientId", // Given preference value
"testClientId", // Expected preference value
String::class, // Preference type
false // HTTP only
),
arrayOf(
"ConnectionTimeoutSeconds",
Expand Down Expand Up @@ -291,6 +291,14 @@ class PreferencesGettersAndSetters(
String::class,
false
),
arrayOf(
"PegLocatorFastestIntervalToInterval",
"pegLocatorFastestIntervalToInterval",
false,
false,
Boolean::class,
false
),
arrayOf("Ping", "ping", 400, 400, Int::class, false),
arrayOf("Port", "port", 9999, 9999, Int::class, false),
arrayOf("Port", "port", -50, 0, Int::class, false),
Expand Down Expand Up @@ -429,6 +437,7 @@ class PreferencesGettersAndSetters(
on { getString(eq(R.string.defaultSubTopic)) } doReturn "owntracks/+/+"
on { getString(eq(R.string.valPubTopic)) } doReturn "owntracks/%u/%d"
on { getString(eq(R.string.preferenceKeyShowRegionsOnMap)) } doReturn "showRegionsOnMap"
on { getString(eq(R.string.preferenceKeyPegLocatorFastestIntervalToInterval)) } doReturn "pegLocatorFastestIntervalToInterval"
on { getString(eq(R.string.valDefaultGeocoder)) } doReturn "None"
on { getInteger(any()) } doReturn 0
on { getBoolean(any()) } doReturn false
Expand Down

0 comments on commit ef974e6

Please sign in to comment.