Skip to content

Commit

Permalink
Merge pull request #1122 from mendhak/milestone130
Browse files Browse the repository at this point in the history
Milestone 130 - choose point with best accuracy, faster custom url autosend
  • Loading branch information
mendhak authored Mar 14, 2024
2 parents 2380ce5 + 932837d commit d9e6b84
Show file tree
Hide file tree
Showing 23 changed files with 535 additions and 1,878 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v1

- name: Set up Java 11
uses: actions/setup-java@v3
- name: Set up Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'

- name: Build with Gradle
run: ./gradlew assembleDebugUnitTest -Dpre-dex=false
Expand Down
2 changes: 1 addition & 1 deletion assets/generate-pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1><a href="https://gpslogger.app/">GPSLogger for Android</a></h1>
<a href="#frequentlyaskedquestionsandissues" class="button">FAQ</a>
<a href="#morescreenshots" class="button">Screenshots</a>

<a href="https://github.com/mendhak/gpslogger/" class="pull-right">
<a href="https://github.com/mendhak/gpslogger/releases" class="pull-right">
<img src="images/GitHub_Logo.png" height="40px" class="pull-right" style="margin-top:10px;">
<img src="images/GitHub-Mark-64px.png" height="40px" class="pull-right" style="margin-top:10px;">
</a>
Expand Down
2,168 changes: 344 additions & 1,824 deletions assets/generate-pages/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/testharness/1.setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export SERVERIP=`hostname -I | cut -f1 -d' '`
echo $SERVERIP

make-ssl-cert generate-default-snakeoil
docker-compose up -d
docker compose up -d
docker ps -a

docker exec gpslogger-ftpd-server bash -c 'echo -e "Passw0rd\nPassw0rd" > /tmp/bobp.txt'
Expand Down
2 changes: 1 addition & 1 deletion assets/testharness/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ services:

https:
container_name: gpslogger-https-server
image: mendhak/http-https-echo:18
image: mendhak/http-https-echo:31
ports:
- "0.0.0.0:8081:8080"
- "0.0.0.0:8443:8443"
Expand Down
8 changes: 8 additions & 0 deletions assets/text/faq/faq08-what-settings-mean.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

![7b](images/7b.png)

**Log GPS/GNSS locations** - Logs points from the satellite location listener.

**Log network locations** - Logs points from the cell tower location listener.

**Log passive locations** - Logs points from other apps, is subject to some restrictions. It will log GPS/network points if those were selected above. It may bypass other filters such as time, distance, and retry duration.

**Logging interval** - How long to wait after a point has been logged to try logging again.

**Distance filter** - When a point becomes available, the app will check to ensure that this much distance exists between the previous and current points. If it isn't this distance, the point is discarded.
Expand All @@ -10,6 +16,8 @@

**Duration to match accuracy** - When searching for a point, the app can continue searching for this many seconds until it finds a point that meets the accuracy and distance filter criteria above.

**Choose best accuracy in duration** - After matching a point with the desired accuracy, the app will continue searching for the 'duration to match accuracy' and pick the point with the best accuracy. This is useful if you are in a location where GPS accuracy is poor, and don't need the location point immediately.

**Absolute timeout** - When searching for a point and trying over and over, the app will give up when this timeout is reached. This is useful for when you're inside buildings, GPS tends to keep searching and finding nothing.

**Keep GPS on between fixes** - Normally, the app stops using GPS between points, to save battery. This means when it's time to log the next point, the GPS needs to be 'woken up' again and this takes a little time. Keeping GPS on between fixes causes this 'wake up' time to be reduced.
Expand Down
1 change: 0 additions & 1 deletion assets/text/faq/faq97-download-it.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ You can download the [APK directly here](https://github.com/mendhak/gpslogger/re

You can download it from [F-Droid](https://f-droid.org/en/packages/com.mendhak.gpslogger/)

Also available on [Izzy's F-Droid](https://apt.izzysoft.de/fdroid/index/apk/com.mendhak.gpslogger)

Binary file modified assets/text/faq/images/7b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/130.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* New accuracy option - run for the duration of retry interval, and chooses the most accurate point.
* Passive listener will now match other selected listeners (GNSS/Network). If neither are selected, all points are accepted.
* Faster Custom URL uploads for auto-send.
* New stoponapplaunch property, only available via .properties file
4 changes: 2 additions & 2 deletions gpslogger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ android {
minSdkVersion 16
targetSdkVersion 30

versionCode 129
versionName "129"
versionCode 130
versionName "130-rc2"

manifestPlaceholders = [
appAuthRedirectScheme: 'com.mendhak.gpslogger'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,9 @@ void onLocationChanged(Location loc) {
return;
}

if(!isPassiveLocation && !isFromValidListener(loc)){
// Check that it's a user selected valid listener, even if it's a passive location.
// In other words, if user wants satellite only, then don't log passive network locations.
if(!isFromSelectedListener(loc)){
LOG.debug("Received location, but it's not from a selected listener. Ignoring.");
return;
}
Expand Down Expand Up @@ -901,6 +903,40 @@ void onLocationChanged(Location loc) {
//Success, reset timestamp for next time.
session.setFirstRetryTimeStamp(0);
}
//If the user wants the best possible accuracy, store the point, only if it's the best so far.
// Then retry until the time limit is reached.
// Exception - if it's a passive location, or it's an annotation, or single point mode.
// I don't think we need to pick the best point in the case of passive locations (not sure).
else if(preferenceHelper.shouldGetBestPossibleAccuracy() && !isPassiveLocation && !session.hasDescription() && !session.isSinglePointMode()) {

if(session.getFirstRetryTimeStamp() == 0){
//It's the first loop so reset timestamp and temporary location
session.setTemporaryLocationForBestAccuracy(null);
session.setFirstRetryTimeStamp(System.currentTimeMillis());
}

if(session.getTemporaryLocationForBestAccuracy() == null || loc.getAccuracy() < session.getTemporaryLocationForBestAccuracy().getAccuracy()){
LOG.debug("New point with accuracy of " + String.valueOf(loc.getAccuracy()) + " m." );
session.setTemporaryLocationForBestAccuracy(loc);
}

if (currentTimeStamp - session.getFirstRetryTimeStamp() <= preferenceHelper.getLoggingRetryPeriod() * 1000) {
// return and keep trying
return;
}

if (currentTimeStamp - session.getFirstRetryTimeStamp() > preferenceHelper.getLoggingRetryPeriod() * 1000) {
// We've reached the end of the retry period, use the best point we've got so far.
LOG.debug("Retry timeout reached, using best point so far with accuracy of " + String.valueOf(session.getTemporaryLocationForBestAccuracy().getAccuracy()) + " m.");
loc = session.getTemporaryLocationForBestAccuracy();

//reset for next time
session.setTemporaryLocationForBestAccuracy(null);
session.setFirstRetryTimeStamp(0);

}

}
}

//Don't do anything until the user-defined distance has been traversed
Expand Down Expand Up @@ -967,14 +1003,15 @@ private String getLocationDisplayForLogs(Location loc) {
return logLine.toString();
}

private boolean isFromValidListener(Location loc) {
private boolean isFromSelectedListener(Location loc) {

if(!preferenceHelper.shouldLogSatelliteLocations() && !preferenceHelper.shouldLogNetworkLocations()){
return true;
// Special case - if both satellite and network are deselected, but passive is selected, then accept all passive types!
return preferenceHelper.shouldLogPassiveLocations();
}

if(!preferenceHelper.shouldLogNetworkLocations()){
return loc.getProvider().equalsIgnoreCase(LocationManager.GPS_PROVIDER);
return !loc.getProvider().equalsIgnoreCase(LocationManager.NETWORK_PROVIDER);
}

if(!preferenceHelper.shouldLogSatelliteLocations()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ protected void onCreate(Bundle savedInstanceState) {
LOG.debug("Start logging on app launch");
EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(true));
}

if(preferenceHelper.shouldStopLoggingOnAppLaunch()){
LOG.debug("Stop logging on app launch");
EventBus.getDefault().postSticky(new CommandEvents.RequestStartStop(false));
logSinglePoint();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,15 @@ public void setLoggingRetryPeriod(int retryInterval) {
prefs.edit().putString(PreferenceNames.LOGGING_RETRY_TIME, String.valueOf(retryInterval)).apply();
}

@ProfilePreference(name=PreferenceNames.LOGGING_RETRY_SHOULD_GET_BEST_POSSIBLE_ACCURACY)
public boolean shouldGetBestPossibleAccuracy() {
return prefs.getBoolean(PreferenceNames.LOGGING_RETRY_SHOULD_GET_BEST_POSSIBLE_ACCURACY, false);
}

public void setShouldGetBestPossibleAccuracy(boolean value){
prefs.edit().putBoolean(PreferenceNames.LOGGING_RETRY_SHOULD_GET_BEST_POSSIBLE_ACCURACY, value).apply();
}

/**
* How long to keep retrying for an accurate point before giving up
*/
Expand All @@ -447,6 +456,14 @@ public boolean shouldStartLoggingOnAppLaunch() {
return prefs.getBoolean(PreferenceNames.START_LOGGING_ON_APP_LAUNCH, false);
}

/**
* Whether to stop logging on application launch
*/
@ProfilePreference(name= PreferenceNames.STOP_LOGGING_ON_APP_LAUNCH)
public boolean shouldStopLoggingOnAppLaunch() {
return prefs.getBoolean(PreferenceNames.STOP_LOGGING_ON_APP_LAUNCH, false);
}

/**
* Whether to start logging when phone is booted up
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public class PreferenceNames {
public static final String MINIMUM_ACCURACY = "accuracy_before_logging";
public static final String KEEP_GPS_ON_BETWEEN_FIXES = "keep_fix";
public static final String LOGGING_RETRY_TIME = "retry_time";

public static final String LOGGING_RETRY_SHOULD_GET_BEST_POSSIBLE_ACCURACY = "retry_get_best_possible_accuracy";
public static final String ABSOLUTE_TIMEOUT = "absolute_timeout";
public static final String START_LOGGING_ON_APP_LAUNCH = "startonapplaunch";
public static final String STOP_LOGGING_ON_APP_LAUNCH = "stoponapplaunch";
public static final String START_LOGGING_ON_BOOTUP = "startonbootup";
public static final String LOG_TO_KML = "log_kml";
public static final String LOG_TO_GPX = "log_gpx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Session {
private Location previousLocationInfo;
private Location currentLocationInfo;

private Location temporaryLocationForBestAccuracy;

private Session() {

}
Expand Down Expand Up @@ -375,6 +377,19 @@ public long getFirstRetryTimeStamp() {
}


/**
* When retrying to get best accuracy, this can store a location object representing the best so far.
* @param loc
*/
public void setTemporaryLocationForBestAccuracy(Location loc) {
temporaryLocationForBestAccuracy = loc;
}


/**
* Returns the temporary location, stored for best accuracy
* @return
*/
public Location getTemporaryLocationForBestAccuracy() {
return temporaryLocationForBestAccuracy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import org.slf4j.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.Map;

import javax.net.ssl.X509TrustManager;
Expand All @@ -49,52 +51,75 @@ public class CustomUrlJob extends Job {
private static final Logger LOG = Logs.of(CustomUrlJob.class);

private UploadEvents.BaseUploadEvent callbackEvent;
private CustomUrlRequest urlRequest;

public CustomUrlJob(CustomUrlRequest urlRequest, UploadEvents.BaseUploadEvent callbackEvent) {
private File csvFile;
private ArrayList<CustomUrlRequest> urlRequests;

public CustomUrlJob(ArrayList<CustomUrlRequest> urlRequests, File csvFile, UploadEvents.BaseUploadEvent callbackEvent) {
super(new Params(1).requireNetwork().persist());

this.callbackEvent = callbackEvent;
this.urlRequest = urlRequest;
this.urlRequests = urlRequests;
this.csvFile = csvFile;
}


@Override
public void onAdded() {
}

@Override
public void onRun() throws Throwable {

LOG.info("HTTP Request - " + urlRequest.getLogURL());
boolean success = true;
String responseError = null;
String responseThrowableMessage = null;

OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.sslSocketFactory(Networks.getSocketFactory(AppSettings.getInstance()),
(X509TrustManager) Networks.getTrustManager(AppSettings.getInstance()));
Request.Builder requestBuilder = new Request.Builder().url(urlRequest.getLogURL());
if(urlRequests != null && urlRequests.size() > 0){

for(Map.Entry<String,String> header : urlRequest.getHttpHeaders().entrySet()){
requestBuilder.addHeader(header.getKey(), header.getValue());
}
for (CustomUrlRequest urlRequest : urlRequests) {
LOG.info("HTTP Request - " + urlRequest.getLogURL());

if ( ! urlRequest.getHttpMethod().equalsIgnoreCase("GET")) {
RequestBody body = RequestBody.create(null, urlRequest.getHttpBody());
requestBuilder = requestBuilder.method(urlRequest.getHttpMethod(),body);
}
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.sslSocketFactory(Networks.getSocketFactory(AppSettings.getInstance()),
(X509TrustManager) Networks.getTrustManager(AppSettings.getInstance()));
Request.Builder requestBuilder = new Request.Builder().url(urlRequest.getLogURL());

for(Map.Entry<String,String> header : urlRequest.getHttpHeaders().entrySet()){
requestBuilder.addHeader(header.getKey(), header.getValue());
}

if ( ! urlRequest.getHttpMethod().equalsIgnoreCase("GET")) {
RequestBody body = RequestBody.create(null, urlRequest.getHttpBody());
requestBuilder = requestBuilder.method(urlRequest.getHttpMethod(),body);
}

Request request = requestBuilder.build();
Response response = okBuilder.build().newCall(request).execute();
Request request = requestBuilder.build();
Response response = okBuilder.build().newCall(request).execute();

if (response.isSuccessful()) {
LOG.debug("HTTP request complete with successful response code " + response);
if (response.isSuccessful()) {
LOG.debug("HTTP request complete with successful response code " + response);
}
else {
LOG.error("HTTP request complete with unexpected response code " + response );
responseError = "Unexpected code " + response;
responseThrowableMessage = response.body().string();
success = false;
}

response.body().close();

if(!success){
break;
}
}
}

if(success){
EventBus.getDefault().post(callbackEvent.succeeded());
}
else {
LOG.error("HTTP request complete with unexpected response code " + response );
EventBus.getDefault().post(callbackEvent.failed("Unexpected code " + response,new Throwable(response.body().string())));
EventBus.getDefault().post(callbackEvent.failed("Unexpected code " + responseError, new Throwable(responseThrowableMessage)));
}

response.body().close();
}

@Override
Expand Down
Loading

0 comments on commit d9e6b84

Please sign in to comment.