forked from upstream-mirrors/OpenTracks
TrackRecordingService: extract EGM2008CorrectionManager into HandlerServer.
Part of #882.
This commit is contained in:
+2
-2
@@ -39,7 +39,7 @@ public class HandlerServerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
subject.stop(context);
|
||||
subject.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,7 +58,7 @@ public class HandlerServerTest {
|
||||
int accuracy = 50;
|
||||
|
||||
// when
|
||||
subject.sendTrackPoint(trackPoint, accuracy);
|
||||
subject.onNewTrackPoint(trackPoint, accuracy);
|
||||
|
||||
// then
|
||||
Thread.sleep(10); // Wait for executor service
|
||||
|
||||
+4
-4
@@ -60,7 +60,7 @@ public class LocationHandlerTest {
|
||||
locationHandler.onLocationChanged(createLocation(45f, 35f, 3, 5, System.currentTimeMillis()));
|
||||
|
||||
// then
|
||||
verify(handlerServer, times(1)).sendTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
verify(handlerServer, times(1)).onNewTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ public class LocationHandlerTest {
|
||||
locationHandler.onLocationChanged(createLocation(latitude, 35f, 3, 5, System.currentTimeMillis()));
|
||||
|
||||
// then
|
||||
verify(handlerServer, times(0)).sendTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
verify(handlerServer, times(0)).onNewTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +92,7 @@ public class LocationHandlerTest {
|
||||
|
||||
// then
|
||||
// no newTrackPoint called
|
||||
verify(handlerServer, times(0)).sendTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
verify(handlerServer, times(0)).onNewTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +105,7 @@ public class LocationHandlerTest {
|
||||
locationHandler.onLocationChanged(createLocation(99.0, 35.0, Long.MAX_VALUE, 15, System.currentTimeMillis()));
|
||||
|
||||
// then
|
||||
verify(handlerServer, times(1)).sendTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
verify(handlerServer, times(1)).onNewTrackPoint(any(TrackPoint.class), any(Integer.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,6 @@ import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.io.file.exporter.ExportServiceResultReceiver;
|
||||
import de.dennisguse.opentracks.services.handlers.EGM2008CorrectionManager;
|
||||
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
|
||||
import de.dennisguse.opentracks.services.handlers.HandlerServer;
|
||||
import de.dennisguse.opentracks.services.sensors.AltitudeSumManager;
|
||||
@@ -135,8 +134,6 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
private BluetoothRemoteSensorManager remoteSensorManager;
|
||||
private AltitudeSumManager altitudeSumManager;
|
||||
|
||||
private EGM2008CorrectionManager egm2008CorrectionManager;
|
||||
|
||||
private TrackStatisticsUpdater trackStatisticsUpdater;
|
||||
private TrackPoint lastTrackPoint;
|
||||
private boolean isIdle;
|
||||
@@ -168,8 +165,6 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
||||
|
||||
egm2008CorrectionManager = new EGM2008CorrectionManager();
|
||||
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
sharedPreferenceChangeListener.onSharedPreferenceChanged(sharedPreferences, null);
|
||||
@@ -189,7 +184,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
public void onDestroy() {
|
||||
handler = null;
|
||||
|
||||
handlerServer.stop(this);
|
||||
handlerServer.stop();
|
||||
handlerServer = null;
|
||||
|
||||
if (remoteSensorManager != null) {
|
||||
@@ -202,8 +197,6 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
altitudeSumManager = null;
|
||||
}
|
||||
|
||||
egm2008CorrectionManager = null;
|
||||
|
||||
// Reverse order from onCreate
|
||||
showNotification(false); //TODO Why?
|
||||
|
||||
@@ -481,7 +474,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
lastTrackPoint = null;
|
||||
|
||||
handlerServer.stop(this);
|
||||
handlerServer.stop();
|
||||
|
||||
stopGps(trackStopped);
|
||||
}
|
||||
@@ -498,7 +491,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
void stopGps(boolean shutdown) {
|
||||
if (!isRecording()) return;
|
||||
|
||||
handlerServer.stop(this);
|
||||
handlerServer.stop();
|
||||
showNotification(false);
|
||||
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||
if (shutdown) {
|
||||
@@ -538,8 +531,6 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
|
||||
|
||||
remoteSensorManager.fill(trackPoint);
|
||||
|
||||
egm2008CorrectionManager.correctAltitude(this, trackPoint);
|
||||
|
||||
notificationManager.updateTrackPoint(this, track.getTrackStatistics(), trackPoint, recordingGpsAccuracy);
|
||||
|
||||
//TODO Figure out how to avoid loading the lastValidTrackPoint from the database
|
||||
|
||||
@@ -16,22 +16,28 @@ public class HandlerServer {
|
||||
|
||||
private static final String TAG = HandlerServer.class.getSimpleName();
|
||||
|
||||
private final LocationHandler locationHandler;
|
||||
private Context context;
|
||||
|
||||
private final HandlerServerInterface service;
|
||||
|
||||
private ExecutorService serviceExecutor;
|
||||
|
||||
private final LocationHandler locationHandler;
|
||||
private final EGM2008CorrectionManager egm2008CorrectionManager = new EGM2008CorrectionManager();
|
||||
|
||||
public HandlerServer(HandlerServerInterface service) {
|
||||
this.locationHandler = new LocationHandler(this);
|
||||
this.service = service;
|
||||
this.locationHandler = new LocationHandler(this);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
HandlerServer(LocationHandler locationHandler, HandlerServerInterface service) {
|
||||
this.locationHandler = locationHandler;
|
||||
this.service = service;
|
||||
this.locationHandler = locationHandler;
|
||||
}
|
||||
|
||||
public void start(Context context) {
|
||||
public void start(@NonNull Context context) {
|
||||
this.context = context;
|
||||
serviceExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||
@@ -39,23 +45,28 @@ public class HandlerServer {
|
||||
locationHandler.onSharedPreferenceChanged(context, sharedPreferences, null);
|
||||
}
|
||||
|
||||
public void stop(Context context) {
|
||||
public void stop() {
|
||||
locationHandler.onStop(context);
|
||||
|
||||
if (serviceExecutor != null) {
|
||||
serviceExecutor.shutdownNow();
|
||||
}
|
||||
serviceExecutor = null;
|
||||
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(@NonNull Context context, @NonNull SharedPreferences preferences, String key) {
|
||||
locationHandler.onSharedPreferenceChanged(context, preferences, key);
|
||||
}
|
||||
|
||||
public void sendTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy) {
|
||||
public void onNewTrackPoint(TrackPoint trackPoint, int recordingGpsAccuracy) {
|
||||
if (serviceExecutor == null || serviceExecutor.isTerminated() || serviceExecutor.isShutdown()) {
|
||||
return;
|
||||
}
|
||||
|
||||
egm2008CorrectionManager.correctAltitude(context, trackPoint);
|
||||
|
||||
serviceExecutor.execute(() -> service.newTrackPoint(trackPoint, recordingGpsAccuracy));
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ class LocationHandler implements HandlerServer.Handler, LocationListener, GpsSta
|
||||
}
|
||||
|
||||
lastValidTrackPoint = trackPoint;
|
||||
handlerServer.sendTrackPoint(trackPoint, recordingGpsAccuracy);
|
||||
handlerServer.onNewTrackPoint(trackPoint, recordingGpsAccuracy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user