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