Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
SebaDro committed Oct 17, 2022
2 parents 0e691ab + 502f57f commit f0517f0
Show file tree
Hide file tree
Showing 28 changed files with 378 additions and 62 deletions.
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<string name="yesterday">Gestern</string>

<string name="cancel">Abbrechen</string>
<string name="wait">Warten</string>
<string name="finish">Beenden</string>

<string name="fuel_type">Kraftstoffart</string>
<string name="car">Fahrzeug</string>
Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values-de/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
<string name="pref_version">Version</string>
<string name="pref_other">Anderes</string>

<string name="pref_gps_connection_title">GPS-Verbindungsdauer</string>
<string name="pref_gps_connection_summary">Zeitintervall, in dem die GPS-Verbindung aufrechterhalten wird. Sollte innerhalb dieses Zeitintervalls keine neue GPS-Messung vorliegen, wird der Nutzer gefragt, ob die Trackaufnahme beendet werden soll. Wenn der Benutzer nichts unternimmt, wird die Aufzeichnung nach einigen Sekunden automatisch gestopp.</string>
<string name="pref_gps_mode_ar_title">Automatische GPS Aufzeichnung</string>
<string name="pref_gps_mode_ar_summary">Aktiviert die automatische Aufzeichnung von GPS-basierten Fahrten basierend auf Mechanismen der Aktivitätserkennung.\n\nHinweis: Diese Androidfunktion läuft bei einigen Smartphonemodellen nicht zuverlässig.</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<string name="dashboard_dialog_stop_track">Aufzeichnung beenden?</string>
<string name="dashboard_dialog_stop_track_content">Möchten Sie wirklich die Aufzeichung beenden und die derzeitige Fahrt finalisieren?</string>
<string name="dashboard_dialog_no_gps_stop_track_content">Kein GPS-Signal seit %s Sekunden vorhanden. Möchten Sie die Aufzeichung beenden und die bisherige Fahrt finalisieren oder weitere %s Sekunden warten?</string>
<string name="dashboard_dialog_obd_not_found">OBD Adapter nicht gefunden</string>
<string name="dashboard_dialog_obd_not_found_content_template">\'%s\' nicht gefunden. Bitte vergewissern Sie sich, dass der OBD Adapter in Reichweite und korrekt im OBD Steckplatz eingesteckt ist.</string>

Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values-de/strings_track_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
<string name="track_list_num_stops">Anzahl Stopps</string>
<string name="track_list_total_stoptime">Gesamtstoppzeit</string>
<string name="track_list_details_diesel_not_supported">DIESEL NICHT\nUNTERSTÜTZT</string>
<string name="track_list_details_no_fuel_consumption">* = Diese Werte konnten nicht berechnet werden.</string>
<string name="track_list_details_no_fuel_consumption_missing_properties">* = Diese Werte konnten aufgrund fehlender Messparameter nicht berechnet werden: %s</string>

<string name="track_list_upload_all_tracks_title">Alle Fahrten Hochladen?</string>
<string name="track_list_upload_all_tracks_content">Sie sind dabei alle ihre Fahrten auf den enviroCar Server als Open Data hochzuladen. Alle Fahrten werden damit ihrem Benutzerkonto zugewiesen und anaonymisiert für andere zugreifbar.\n\nMöchten Sie fortfahren?</string>
Expand Down
4 changes: 4 additions & 0 deletions org.envirocar.app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<string name="today">Today</string>
<string name="yesterday">Yesterday</string>
<string name="cancel">Cancel</string>
<string name="wait">Wait</string>
<string name="finish">Finish</string>

<string name="app_name" translatable="false">enviroCar</string>

Expand Down Expand Up @@ -145,6 +147,8 @@
<string name="prefkey_search_interval" tools:ignore="MissingTranslation">pref_search_interval</string>
<string name="prefkey_automatic_recording" tools:ignore="MissingTranslation">pref_automatic_recording</string>
<string name="prefkey_samplingrate" tools:ignore="MissingTranslation">pref_samplingrate</string>
<string name="prefkey_gps_connection" tools:ignore="MissingTranslation">pref_gps_connection</string>

<string name="prefkey_privacy" tools:ignore="MissingTranslation">pref_privacy</string>
<string name="prefkey_imperial_unit" tools:ignore="MissingTranslation">pref_imperial_unit</string>
<string name="prefkey_text_to_speech" tools:ignore="MissingTranslation">pref_text_to_speech</string>
Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values/strings_activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
<string name="pref_other">Other</string>
<string name="pref_settings_title">Settings</string>

<string name="pref_gps_connection_title">GPS connection duration</string>
<string name="pref_gps_connection_summary">GPS connection will be maintained in this time interval. If there is no new GPS location within this time interval, the user will be asked whether the track recording should be stopped. If user takes no action, recording will be stopped automatically after some seconds.</string>
<string name="pref_gps_mode_ar_title">Automatic Recording (GPS)</string>
<string name="pref_gps_mode_ar_summary">Activates automatic recording of GPS-based trips based on activity detection mechanisms.\n\nNote: This Android function does not work reliably on some smartphone models.</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

<string name="dashboard_dialog_stop_track">Stop Track?</string>
<string name="dashboard_dialog_stop_track_content">Do you really want to stop the recording and finish the current track?</string>
<string name="dashboard_dialog_no_gps_stop_track_content">No GPS signal for %s seconds available. Do you want to stop recording and finish the current track or do you want to wait for another %s seconds?</string>
<string name="dashboard_dialog_obd_not_found">OBD-II adapter not found</string>
<string name="dashboard_dialog_obd_not_found_content_template">\'%s\' not found. Please ensure that the OBD-II device is in range and correctly inserted into the OBD-II port of your car.</string>

Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/res/values/strings_track_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<string name="track_list_num_stops">Number of Stops</string>
<string name="track_list_total_stoptime">Total stop time</string>
<string name="track_list_details_diesel_not_supported">NOT SUPPORTED\nFOR DIESEL</string>
<string name="track_list_details_no_fuel_consumption">* = These values could not be calculated.</string>
<string name="track_list_details_no_fuel_consumption_missing_properties">* = These values could not be calculated due to missing measurement parameters: %s</string>

<string name="track_list_upload_all_tracks_title">Upload All Local Tracks?</string>
<string name="track_list_upload_all_tracks_content">You are about to upload all tracks. This means that all tracks will be uploaded and assigned to your account.\n\nDo you want to continue?</string>
Expand Down
6 changes: 6 additions & 0 deletions org.envirocar.app/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
<PreferenceCategory
android:title="@string/pref_gps_recording"
app:iconSpaceReserved="false">
<org.envirocar.app.views.settings.custom.GPSConnectionDurationPreference
android:defaultValue="120"
android:key="@string/prefkey_gps_connection"
android:summary="@string/pref_gps_connection_summary"
android:title="@string/pref_gps_connection_title"
app:iconSpaceReserved="false" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/prefkey_enable_gps_based_track_recording"
Expand Down
3 changes: 3 additions & 0 deletions org.envirocar.app/src/org/envirocar/app/BaseApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void onCreate() {
.doOnNext(this::setDebugLogging)
.doOnError(LOG::error)
.subscribe());
this.setDebugLogging(ApplicationSettings.isDebugLoggingEnabled(this));

// obfuscation setting changed listener
this.disposables.add(
Expand All @@ -148,6 +149,8 @@ public void onCreate() {
})
.doOnError(LOG::error)
.subscribe());

LOG.info("BaseApplication started: " + this.hashCode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.envirocar.app.events;

import org.envirocar.app.recording.strategy.RecordingStrategy;

public class GpsNotChangedEvent {

private long seconds;

public GpsNotChangedEvent(long seconds) {
this.seconds = seconds;
}

public long getSeconds() {
return seconds;
}

@Override
public String toString() {
return super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.envirocar.app.events;

import org.envirocar.core.entity.Track;

public class TrackRecordingContinueEvent {
private Track track;

public TrackRecordingContinueEvent(Track track) {
this.track = track;
}

public Track getTrack() {
return track;
}

@Override
public String toString() {
return super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package org.envirocar.app.events;

import org.envirocar.core.entity.Track;

public class TrackchunkEndUploadedEvent {

public TrackchunkEndUploadedEvent() {
private Track track;

public TrackchunkEndUploadedEvent(Track track) {
this.track = track;
}

public Track getTrack() {
return this.track;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ApplicationSettings {
public static final boolean DEFAULT_OBFUSCATION = false;
public static final int DEFAULT_BLUETOOTH_DISCOVERY_INTERVAL = 60;
public static final int DEFAULT_TRACK_TRIM_DURATION = 110;
public static final int DEFAULT_GPS_CONNECTION_DURATION = 120;
public static final boolean DEFAULT_DEBUG_LOGGING = false;
public static final int DEFAULT_SAMPLING_RATE = 5;
public static final String DEFAULT_CAMPAIGN_PROFILE = "DEFAULT_COMANND_PROFILE";
Expand Down Expand Up @@ -168,6 +169,10 @@ public static Observable<Boolean> getDebugLoggingObservable(Context context) {
.asObservable();
}

public static boolean isDebugLoggingEnabled(Context context) {
return getSharedPreferences(context).getBoolean(s(context, R.string.prefkey_enable_debug_logging), DEFAULT_DEBUG_LOGGING);
}

public static boolean isDieselConsumptionEnabled(Context context) {
return getSharedPreferences(context).getBoolean(s(context, R.string.prefkey_enable_diesel_consumption), false);
}
Expand All @@ -178,6 +183,12 @@ public static Observable<Boolean> getDieselConsumptionObservable(Context context
.asObservable();
}

public static Observable<Integer> getGPSConnectionDurationObservable(final Context context) {
return RxSharedPreferences.create(getSharedPreferences(context))
.getInteger(s(context, R.string.prefkey_gps_connection), DEFAULT_GPS_CONNECTION_DURATION)
.asObservable();
}

public static Observable<Integer> getTrackTrimDurationObservable(final Context context) {
return RxSharedPreferences.create(getSharedPreferences(context))
.getInteger(s(context, R.string.prefkey_track_trim_duration), DEFAULT_TRACK_TRIM_DURATION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.envirocar.app.BaseApplication;
import org.envirocar.app.R;
import org.envirocar.app.events.TrackRecordingContinueEvent;
import org.envirocar.app.handler.agreement.AgreementManager;
import org.envirocar.app.handler.preferences.CarPreferenceHandler;
import org.envirocar.app.handler.preferences.UserPreferenceHandler;
Expand Down Expand Up @@ -141,6 +142,13 @@ public Single<Track> finishCurrentTrackObservable() {
.doOnSuccess(track -> mBus.post(new TrackRecordingServiceStateChangedEvent(BluetoothServiceState.SERVICE_STOPPED)));
}

public void continueCurrentTrackRecording() {
getActiveTrackReference(false).subscribe
(track -> {
mBus.post(new TrackRecordingContinueEvent(track));
});
}


public void finishTrackAutomatic() {
deleteMeasurementsAutomatic()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
Expand All @@ -41,12 +40,13 @@
import org.envirocar.algorithm.MeasurementProvider;
import org.envirocar.app.BuildConfig;
import org.envirocar.app.events.DrivingDetectedEvent;
import org.envirocar.app.events.GpsNotChangedEvent;
import org.envirocar.app.events.TrackRecordingContinueEvent;
import org.envirocar.app.handler.ApplicationSettings;
import org.envirocar.app.handler.preferences.CarPreferenceHandler;
import org.envirocar.app.recording.RecordingState;
import org.envirocar.app.recording.provider.LocationProvider;
import org.envirocar.app.recording.provider.TrackDatabaseSink;
import org.envirocar.app.rxutils.RxBroadcastReceiver;
import org.envirocar.app.services.trackchunks.TrackchunkUploadService;
import org.envirocar.core.entity.Car;
import org.envirocar.core.entity.Measurement;
Expand All @@ -68,7 +68,6 @@
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

Expand Down Expand Up @@ -100,6 +99,7 @@ public class GPSRecordingStrategy implements LifecycleObserver, RecordingStrateg
private int trackTrimDuration = 55 * 2;
private boolean drivingDetected = false;
private long startingTime;
private int gpsConnectionDuration = 60 * 2;
private Disposable stopDrivingFuture;

private boolean isTrackFinished = false;
Expand Down Expand Up @@ -129,6 +129,9 @@ protected void onCreate() {

}

private void setGpsConnectionDuration(Integer integer) {
}

@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
protected void onDestroy() {
LOG.info("Destroying GPSRecordingStrategy");
Expand Down Expand Up @@ -197,6 +200,10 @@ public void startRecording(Service service, RecordingListener listener) {
disposables.add(ApplicationSettings.getTrackTrimDurationObservable(context)
.doOnNext(newDuration -> this.trackTrimDuration = newDuration)
.subscribe());

disposables.add(ApplicationSettings.getGPSConnectionDurationObservable(context)
.doOnNext(duration -> this.gpsConnectionDuration = duration)
.subscribe());
}

@Override
Expand Down Expand Up @@ -379,26 +386,51 @@ private void stopGPSConnectionRecognizer() {
* Private internal class for detecting
*/
private final class GPSOnlyConnectionRecognizer {
private static final long GPS_INTERVAL = 1000 * 60 * 2; // 2 minutes;

private static final long GPS_PENDING_INTERVAL = 1000 * 30; // 30 seconds
private final Scheduler.Worker backgroundWorker = Schedulers.io().createWorker();
private Disposable gpsCheckerSubscription;
private Disposable gpsPendingSubscription;

private final Runnable gpsConnectionCloser = () -> {
LOG.warn("CONNECTION CLOSED due to no GPS values");
if(isTrackRecording) {
stopRecording();
}
};

private final Runnable gpsNotChangedNotifier = () -> {
LOG.warn("No GPS values. Connection may be closed.");
eventBus.post(new GpsNotChangedEvent(gpsConnectionDuration));
// Just wait for another 30 seconds, whether user decides for continuing recording or not.
// If there is no decision during this time interval, stop recording
gpsPendingSubscription = backgroundWorker.schedule(gpsConnectionCloser,
GPS_PENDING_INTERVAL, TimeUnit.MILLISECONDS);
};

@Subscribe
public void onReceiveContinueRecordingEvent(TrackRecordingContinueEvent event) {
LOG.info("Continue recording of track '%s' despite missing GPS connection." +
" No stop required via GPS Connection Recognizer.",
String.valueOf(event.getTrack().getName()));
scheduleGpsConnection();
}

@Subscribe
public void onReceiveGpsLocationChangedEvent(GpsLocationChangedEvent event) {
LOG.info("Received GPS Update. No stop required via GPS Connection Recognizer.");
scheduleGpsConnection();
}

private void scheduleGpsConnection() {
if (gpsPendingSubscription != null) {
gpsPendingSubscription.dispose();
gpsPendingSubscription = null;
}
if (gpsCheckerSubscription != null) {
gpsCheckerSubscription.dispose();
gpsCheckerSubscription = null;
}
gpsCheckerSubscription = backgroundWorker.schedule(gpsConnectionCloser,
GPS_INTERVAL, TimeUnit.MILLISECONDS);
gpsCheckerSubscription = backgroundWorker.schedule(gpsNotChangedNotifier,
gpsConnectionDuration * 1000, TimeUnit.MILLISECONDS);
}

public void shutDown() {
Expand Down
Loading

0 comments on commit f0517f0

Please sign in to comment.