Loading app/src/main/java/net/fabiszewski/ulogger/LocationHelper.java +21 −5 Original line number Diff line number Diff line Loading @@ -212,18 +212,34 @@ class LocationHelper { * @return True if location accuracy within limit */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean hasRequiredAccuracy(Location location) { boolean hasRequiredAccuracy(@NonNull Location location) { boolean ret = location.hasAccuracy() && location.getAccuracy() <= maxAccuracy; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredAccuracy: " + ret + "]"); } return ret; } /** * Check location distance meets user criteria * @param location Current location * @param lastLocation Previous location * @return True if location distance within limit */ boolean hasRequiredDistance(@NonNull Location location, @Nullable Location lastLocation) { if (lastLocation == null) { return true; } float distance = location.distanceTo(lastLocation); boolean ret = distance >= minDistance; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredDistance: " + ret + "]"); } return ret; } /** * Check location time meets user criteria when compared to current time * @param location Location * @return True if location time within limit */ boolean hasRequiredTime(Location location) { boolean hasRequiredTime(@NonNull Location location) { long elapsedMillis = SystemClock.elapsedRealtime() - location.getElapsedRealtimeNanos() / 1000000; boolean ret = elapsedMillis <= maxTimeMillis; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredTime: " + ret + "]"); } Loading @@ -235,7 +251,7 @@ class LocationHelper { * @param location Location * @return True if is from GPS */ static boolean isGps(Location location) { static boolean isGps(@NonNull Location location) { boolean ret = location.getProvider().equals(LocationManager.GPS_PROVIDER); if (Logger.DEBUG) { Log.d(TAG, "[isGps: " + ret + "]"); } return ret; Loading @@ -246,7 +262,7 @@ class LocationHelper { * @param location Location * @return True if is from Network */ static boolean isNetwork(Location location) { static boolean isNetwork(@NonNull Location location) { boolean ret = location.getProvider().equals(LocationManager.NETWORK_PROVIDER); if (Logger.DEBUG) { Log.d(TAG, "[isNetwork: " + ret + "]"); } return ret; Loading @@ -267,7 +283,7 @@ class LocationHelper { * https://galileognss.eu/gps-week-number-rollover-april-6-2019/ * @param location Location */ static void handleRolloverBug(Location location) { static void handleRolloverBug(@NonNull Location location) { long gpsTime = location.getTime(); if (gpsTime > FIRST_ROLLOVER_TIMESTAMP && gpsTime < SECOND_ROLLOVER_TIMESTAMP) { if (Logger.DEBUG) { Log.d(TAG, "[Fixing GPS rollover bug: " + gpsTime + "]"); } Loading app/src/main/java/net/fabiszewski/ulogger/LoggerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,10 @@ public class LoggerService extends Service { * @return True if matches */ private boolean meetsCriteria(Location location) { // skip if distance is below user criterion if (!locationHelper.hasRequiredDistance(location, lastLocation)) { return false; } // accuracy radius too high if (!locationHelper.hasRequiredAccuracy(location)) { if (Logger.DEBUG) { Log.d(TAG, "[location accuracy above limit: " + location.getAccuracy() + "]"); } Loading Loading
app/src/main/java/net/fabiszewski/ulogger/LocationHelper.java +21 −5 Original line number Diff line number Diff line Loading @@ -212,18 +212,34 @@ class LocationHelper { * @return True if location accuracy within limit */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean hasRequiredAccuracy(Location location) { boolean hasRequiredAccuracy(@NonNull Location location) { boolean ret = location.hasAccuracy() && location.getAccuracy() <= maxAccuracy; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredAccuracy: " + ret + "]"); } return ret; } /** * Check location distance meets user criteria * @param location Current location * @param lastLocation Previous location * @return True if location distance within limit */ boolean hasRequiredDistance(@NonNull Location location, @Nullable Location lastLocation) { if (lastLocation == null) { return true; } float distance = location.distanceTo(lastLocation); boolean ret = distance >= minDistance; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredDistance: " + ret + "]"); } return ret; } /** * Check location time meets user criteria when compared to current time * @param location Location * @return True if location time within limit */ boolean hasRequiredTime(Location location) { boolean hasRequiredTime(@NonNull Location location) { long elapsedMillis = SystemClock.elapsedRealtime() - location.getElapsedRealtimeNanos() / 1000000; boolean ret = elapsedMillis <= maxTimeMillis; if (Logger.DEBUG) { Log.d(TAG, "[hasRequiredTime: " + ret + "]"); } Loading @@ -235,7 +251,7 @@ class LocationHelper { * @param location Location * @return True if is from GPS */ static boolean isGps(Location location) { static boolean isGps(@NonNull Location location) { boolean ret = location.getProvider().equals(LocationManager.GPS_PROVIDER); if (Logger.DEBUG) { Log.d(TAG, "[isGps: " + ret + "]"); } return ret; Loading @@ -246,7 +262,7 @@ class LocationHelper { * @param location Location * @return True if is from Network */ static boolean isNetwork(Location location) { static boolean isNetwork(@NonNull Location location) { boolean ret = location.getProvider().equals(LocationManager.NETWORK_PROVIDER); if (Logger.DEBUG) { Log.d(TAG, "[isNetwork: " + ret + "]"); } return ret; Loading @@ -267,7 +283,7 @@ class LocationHelper { * https://galileognss.eu/gps-week-number-rollover-april-6-2019/ * @param location Location */ static void handleRolloverBug(Location location) { static void handleRolloverBug(@NonNull Location location) { long gpsTime = location.getTime(); if (gpsTime > FIRST_ROLLOVER_TIMESTAMP && gpsTime < SECOND_ROLLOVER_TIMESTAMP) { if (Logger.DEBUG) { Log.d(TAG, "[Fixing GPS rollover bug: " + gpsTime + "]"); } Loading
app/src/main/java/net/fabiszewski/ulogger/LoggerService.java +4 −0 Original line number Diff line number Diff line Loading @@ -317,6 +317,10 @@ public class LoggerService extends Service { * @return True if matches */ private boolean meetsCriteria(Location location) { // skip if distance is below user criterion if (!locationHelper.hasRequiredDistance(location, lastLocation)) { return false; } // accuracy radius too high if (!locationHelper.hasRequiredAccuracy(location)) { if (Logger.DEBUG) { Log.d(TAG, "[location accuracy above limit: " + location.getAccuracy() + "]"); } Loading