forked from upstream-mirrors/OpenTracks
Cosmetic and unused method changes.
This commit is contained in:
@@ -93,13 +93,13 @@ public class PreferenceManager implements OnSharedPreferenceChangeListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(minRecordingDistanceKey)) {
|
if (key == null || key.equals(minRecordingDistanceKey)) {
|
||||||
service.setMinRecordingDistance(
|
int minRecordingDistance = sharedPreferences.getInt(
|
||||||
sharedPreferences.getInt(
|
minRecordingDistanceKey,
|
||||||
minRecordingDistanceKey,
|
Constants.DEFAULT_MIN_RECORDING_DISTANCE);
|
||||||
Constants.DEFAULT_MIN_RECORDING_DISTANCE));
|
service.setMinRecordingDistance(minRecordingDistance);
|
||||||
Log.d(Constants.TAG,
|
Log.d(Constants.TAG,
|
||||||
"TrackRecordingService: minRecordingDistance = "
|
"TrackRecordingService: minRecordingDistance = "
|
||||||
+ service.getMinRecordingDistance());
|
+ minRecordingDistance);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(maxRecordingDistanceKey)) {
|
if (key == null || key.equals(maxRecordingDistanceKey)) {
|
||||||
service.setMaxRecordingDistance(sharedPreferences.getInt(
|
service.setMaxRecordingDistance(sharedPreferences.getInt(
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import android.location.Location;
|
|||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -89,8 +90,8 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
private int minRequiredAccuracy =
|
private int minRequiredAccuracy =
|
||||||
Constants.DEFAULT_MIN_REQUIRED_ACCURACY;
|
Constants.DEFAULT_MIN_REQUIRED_ACCURACY;
|
||||||
private int autoResumeTrackTimeout =
|
private int autoResumeTrackTimeout =
|
||||||
Constants.DEFAULT_AUTO_RESUME_TRACK_TIMEOUT;
|
Constants.DEFAULT_AUTO_RESUME_TRACK_TIMEOUT;
|
||||||
|
|
||||||
private long recordingTrackId = -1;
|
private long recordingTrackId = -1;
|
||||||
|
|
||||||
private long currentWaypointId = -1;
|
private long currentWaypointId = -1;
|
||||||
@@ -120,9 +121,9 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
private PeriodicTaskExecutor splitExecutor;
|
private PeriodicTaskExecutor splitExecutor;
|
||||||
|
|
||||||
private SensorManager sensorManager;
|
private SensorManager sensorManager;
|
||||||
|
|
||||||
private PreferenceManager prefManager;
|
private PreferenceManager prefManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interval in milliseconds that we have requested to be notified of gps
|
* The interval in milliseconds that we have requested to be notified of gps
|
||||||
* readings.
|
* readings.
|
||||||
@@ -171,7 +172,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
* The most recent recording track.
|
* The most recent recording track.
|
||||||
*/
|
*/
|
||||||
private Track recordingTrack;
|
private Track recordingTrack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the service currently recording a track?
|
* Is the service currently recording a track?
|
||||||
*/
|
*/
|
||||||
@@ -356,7 +357,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
/**
|
/**
|
||||||
* Shows the notification message and icon in the notification bar.
|
* Shows the notification message and icon in the notification bar.
|
||||||
*/
|
*/
|
||||||
public void showNotification() {
|
private void showNotification() {
|
||||||
final ApiPlatformAdapter apiPlatformAdapter =
|
final ApiPlatformAdapter apiPlatformAdapter =
|
||||||
ApiFeatures.getInstance().getApiPlatformAdapter();
|
ApiFeatures.getInstance().getApiPlatformAdapter();
|
||||||
if (isRecording) {
|
if (isRecording) {
|
||||||
@@ -376,7 +377,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerLocationListener() {
|
private void registerLocationListener() {
|
||||||
if (locationManager == null) {
|
if (locationManager == null) {
|
||||||
Log.e(TAG,
|
Log.e(TAG,
|
||||||
"TrackRecordingService: Do not have any location manager.");
|
"TrackRecordingService: Do not have any location manager.");
|
||||||
@@ -401,7 +402,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterLocationListener() {
|
private void unregisterLocationListener() {
|
||||||
if (locationManager == null) {
|
if (locationManager == null) {
|
||||||
Log.e(TAG,
|
Log.e(TAG,
|
||||||
"TrackRecordingService: Do not have any location manager.");
|
"TrackRecordingService: Do not have any location manager.");
|
||||||
@@ -411,7 +412,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"Location listener now unregistered w/ TrackRecordingService.");
|
"Location listener now unregistered w/ TrackRecordingService.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Track getRecordingTrack() {
|
private Track getRecordingTrack() {
|
||||||
if (recordingTrackId < 0) {
|
if (recordingTrackId < 0) {
|
||||||
return null;
|
return null;
|
||||||
@@ -423,7 +424,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
private void restoreStats(Track track) {
|
private void restoreStats(Track track) {
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"Restoring stats of track with ID: " + track.getId());
|
"Restoring stats of track with ID: " + track.getId());
|
||||||
|
|
||||||
TripStatistics stats = track.getStatistics();
|
TripStatistics stats = track.getStatistics();
|
||||||
statsBuilder = new TripStatisticsBuilder(stats.getStartTime());
|
statsBuilder = new TripStatisticsBuilder(stats.getStartTime());
|
||||||
statsBuilder.setMinRecordingDistance(minRecordingDistance);
|
statsBuilder.setMinRecordingDistance(minRecordingDistance);
|
||||||
@@ -481,6 +482,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Location listener implementation: =================================
|
* Location listener implementation: =================================
|
||||||
|
* TODO: Move to inner class.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(final Location location) {
|
public void onLocationChanged(final Location location) {
|
||||||
@@ -700,7 +702,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
this, new StatusAnnouncerFactory(ApiFeatures.getInstance()));
|
this, new StatusAnnouncerFactory(ApiFeatures.getInstance()));
|
||||||
splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory());
|
splitExecutor = new PeriodicTaskExecutor(this, new SplitTask.Factory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shutdownTaskExecutors() {
|
private void shutdownTaskExecutors() {
|
||||||
Log.d(TAG, "TrackRecordingService.shutdownExecuters");
|
Log.d(TAG, "TrackRecordingService.shutdownExecuters");
|
||||||
try {
|
try {
|
||||||
@@ -743,7 +745,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
// This should be the last operation.
|
// This should be the last operation.
|
||||||
releaseWakeLock();
|
releaseWakeLock();
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,13 +761,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
return super.onUnbind(intent);
|
return super.onUnbind(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean stopService(Intent name) {
|
|
||||||
Log.d(TAG, "TrackRecordingService.stopService");
|
|
||||||
unregisterLocationListener();
|
|
||||||
return super.stopService(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Intent intent, int startId) {
|
public void onStart(Intent intent, int startId) {
|
||||||
handleStartCommand(intent, startId);
|
handleStartCommand(intent, startId);
|
||||||
@@ -792,7 +787,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
"TrackRecordingService: Not resuming, because the previous track ("
|
"TrackRecordingService: Not resuming, because the previous track ("
|
||||||
+ recordingTrack + ") doesn't exist or is too old");
|
+ recordingTrack + ") doesn't exist or is too old");
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
prefManager.setRecordingTrack(recordingTrackId = -1);
|
prefManager.setRecordingTrack(recordingTrackId = -1);
|
||||||
stopSelfResult(startId);
|
stopSelfResult(startId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -800,21 +795,21 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
Log.i(TAG, "TrackRecordingService: resuming");
|
Log.i(TAG, "TrackRecordingService: resuming");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAutoResumeTrackRetries(
|
private void setAutoResumeTrackRetries(
|
||||||
SharedPreferences sharedPreferences, int retryAttempts) {
|
SharedPreferences sharedPreferences, int retryAttempts) {
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"Updating auto-resume retry attempts to: " + retryAttempts);
|
"Updating auto-resume retry attempts to: " + retryAttempts);
|
||||||
prefManager.setAutoResumeTrackCurrentRetry(retryAttempts);
|
prefManager.setAutoResumeTrackCurrentRetry(retryAttempts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldResumeTrack(Track track) {
|
private boolean shouldResumeTrack(Track track) {
|
||||||
Log.d(TAG, "shouldResumeTrack: autoResumeTrackTimeout = "
|
Log.d(TAG, "shouldResumeTrack: autoResumeTrackTimeout = "
|
||||||
+ autoResumeTrackTimeout);
|
+ autoResumeTrackTimeout);
|
||||||
|
|
||||||
// Check if we haven't exceeded the maximum number of retry attempts.
|
// Check if we haven't exceeded the maximum number of retry attempts.
|
||||||
SharedPreferences sharedPreferences =
|
SharedPreferences sharedPreferences =
|
||||||
getSharedPreferences(Constants.SETTINGS_NAME, 0);
|
getSharedPreferences(Constants.SETTINGS_NAME, 0);
|
||||||
int retries = sharedPreferences.getInt(
|
int retries = sharedPreferences.getInt(
|
||||||
getString(R.string.auto_resume_track_current_retry_key), 0);
|
getString(R.string.auto_resume_track_current_retry_key), 0);
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
@@ -832,7 +827,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
// Check for special cases.
|
// Check for special cases.
|
||||||
if (autoResumeTrackTimeout == 0) {
|
if (autoResumeTrackTimeout == 0) {
|
||||||
// Never resume.
|
// Never resume.
|
||||||
Log.d(TAG,
|
Log.d(TAG,
|
||||||
"shouldResumeTrack: Auto-resume disabled (never resume)");
|
"shouldResumeTrack: Auto-resume disabled (never resume)");
|
||||||
return false;
|
return false;
|
||||||
@@ -850,7 +845,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
"shouldResumeTrack: lastModified = " + lastModified
|
"shouldResumeTrack: lastModified = " + lastModified
|
||||||
+ ", autoResumeTrackTimeout: " + autoResumeTrackTimeout);
|
+ ", autoResumeTrackTimeout: " + autoResumeTrackTimeout);
|
||||||
return lastModified > 0 && System.currentTimeMillis() - lastModified <=
|
return lastModified > 0 && System.currentTimeMillis() - lastModified <=
|
||||||
autoResumeTrackTimeout * 60 * 1000;
|
autoResumeTrackTimeout * 60 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRecording() {
|
public boolean isRecording() {
|
||||||
@@ -940,27 +935,27 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
// Create a new stats keeper for the next marker.
|
// Create a new stats keeper for the next marker.
|
||||||
waypointStatsBuilder = new TripStatisticsBuilder(time);
|
waypointStatsBuilder = new TripStatisticsBuilder(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceBinder binder = new ServiceBinder(this);
|
private ServiceBinder binder = new ServiceBinder(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: There is a bug in Android that leaks Binder instances. This bug is
|
* TODO: There is a bug in Android that leaks Binder instances. This bug is
|
||||||
* especially visible if we have a non-static class, as there is no way to
|
* especially visible if we have a non-static class, as there is no way to
|
||||||
* nullify reference to the outer class (the service).
|
* nullify reference to the outer class (the service).
|
||||||
* A workaround is to use a static class and explicitly clear service
|
* A workaround is to use a static class and explicitly clear service
|
||||||
* and detach it from the underlying Binder. With this approach, we minimize
|
* and detach it from the underlying Binder. With this approach, we minimize
|
||||||
* the leak to 24 bytes per each service instance.
|
* the leak to 24 bytes per each service instance.
|
||||||
*
|
*
|
||||||
* For more details, see the following bug:
|
* For more details, see the following bug:
|
||||||
* http://code.google.com/p/android/issues/detail?id=6426.
|
* http://code.google.com/p/android/issues/detail?id=6426.
|
||||||
*/
|
*/
|
||||||
private static class ServiceBinder extends ITrackRecordingService.Stub {
|
private static class ServiceBinder extends ITrackRecordingService.Stub {
|
||||||
private TrackRecordingService service;
|
private TrackRecordingService service;
|
||||||
|
|
||||||
public ServiceBinder(TrackRecordingService service) {
|
public ServiceBinder(TrackRecordingService service) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the reference to the outer class to minimize the leak.
|
* Clears the reference to the outer class to minimize the leak.
|
||||||
*/
|
*/
|
||||||
@@ -983,13 +978,13 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getRecordingTrackId() {
|
public long getRecordingTrackId() {
|
||||||
checkService();
|
checkService();
|
||||||
return service.recordingTrackId;
|
return service.recordingTrackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasRecorded() {
|
public boolean hasRecorded() {
|
||||||
checkService();
|
checkService();
|
||||||
return service.providerUtils.getLastTrackId() >= 0;
|
return service.providerUtils.getLastTrackId() >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1027,13 +1022,13 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void recordLocation(Location loc) {
|
public void recordLocation(Location loc) {
|
||||||
checkService();
|
checkService();
|
||||||
service.onLocationChanged(loc);
|
service.onLocationChanged(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getSensorData() {
|
public byte[] getSensorData() {
|
||||||
checkService();
|
checkService();
|
||||||
if (service.sensorManager == null) {
|
if (service.sensorManager == null) {
|
||||||
Log.d(TAG, "No sensor manager for data.");
|
Log.d(TAG, "No sensor manager for data.");
|
||||||
return null;
|
return null;
|
||||||
@@ -1047,7 +1042,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSensorState() {
|
public int getSensorState() {
|
||||||
checkService();
|
checkService();
|
||||||
if (service.sensorManager == null) {
|
if (service.sensorManager == null) {
|
||||||
Log.d(TAG, "No sensor manager for data.");
|
Log.d(TAG, "No sensor manager for data.");
|
||||||
return Sensor.SensorState.NONE.getNumber();
|
return Sensor.SensorState.NONE.getNumber();
|
||||||
@@ -1135,12 +1130,12 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
showNotification();
|
showNotification();
|
||||||
long recordedTrackId = recordingTrackId;
|
long recordedTrackId = recordingTrackId;
|
||||||
prefManager.setRecordingTrack(recordingTrackId = -1);
|
prefManager.setRecordingTrack(recordingTrackId = -1);
|
||||||
|
|
||||||
if (sensorManager != null) {
|
if (sensorManager != null) {
|
||||||
sensorManager.shutdown();
|
sensorManager.shutdown();
|
||||||
sensorManager = null;
|
sensorManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseWakeLock();
|
releaseWakeLock();
|
||||||
|
|
||||||
// Notify the world that we're no longer recording.
|
// Notify the world that we're no longer recording.
|
||||||
@@ -1169,23 +1164,15 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
return recordingTrackId;
|
return recordingTrackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecordingTrackId(long recordingTrackId) {
|
void setRecordingTrackId(long recordingTrackId) {
|
||||||
this.recordingTrackId = recordingTrackId;
|
this.recordingTrackId = recordingTrackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxRecordingDistance() {
|
void setMaxRecordingDistance(int maxRecordingDistance) {
|
||||||
return maxRecordingDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxRecordingDistance(int maxRecordingDistance) {
|
|
||||||
this.maxRecordingDistance = maxRecordingDistance;
|
this.maxRecordingDistance = maxRecordingDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinRecordingDistance() {
|
void setMinRecordingDistance(int minRecordingDistance) {
|
||||||
return minRecordingDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinRecordingDistance(int minRecordingDistance) {
|
|
||||||
this.minRecordingDistance = minRecordingDistance;
|
this.minRecordingDistance = minRecordingDistance;
|
||||||
if (statsBuilder != null && waypointStatsBuilder != null) {
|
if (statsBuilder != null && waypointStatsBuilder != null) {
|
||||||
statsBuilder.setMinRecordingDistance(minRecordingDistance);
|
statsBuilder.setMinRecordingDistance(minRecordingDistance);
|
||||||
@@ -1193,40 +1180,27 @@ public class TrackRecordingService extends Service implements LocationListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinRequiredAccuracy() {
|
void setMinRequiredAccuracy(int minRequiredAccuracy) {
|
||||||
return minRequiredAccuracy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMinRequiredAccuracy(int minRequiredAccuracy) {
|
|
||||||
this.minRequiredAccuracy = minRequiredAccuracy;
|
this.minRequiredAccuracy = minRequiredAccuracy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocationListenerPolicy getLocationListenerPolicy() {
|
void setLocationListenerPolicy(LocationListenerPolicy locationListenerPolicy) {
|
||||||
return locationListenerPolicy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationListenerPolicy(
|
|
||||||
LocationListenerPolicy locationListenerPolicy) {
|
|
||||||
this.locationListenerPolicy = locationListenerPolicy;
|
this.locationListenerPolicy = locationListenerPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAutoResumeTrackTimeout() {
|
void setAutoResumeTrackTimeout(int autoResumeTrackTimeout) {
|
||||||
return autoResumeTrackTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAutoResumeTrackTimeout(int autoResumeTrackTimeout) {
|
|
||||||
this.autoResumeTrackTimeout = autoResumeTrackTimeout;
|
this.autoResumeTrackTimeout = autoResumeTrackTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAnnouncementFrequency(int announcementFrequency) {
|
void setAnnouncementFrequency(int announcementFrequency) {
|
||||||
announcementExecutor.setTaskFrequency(announcementFrequency);
|
announcementExecutor.setTaskFrequency(announcementFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSplitFrequency(int frequency) {
|
void setSplitFrequency(int frequency) {
|
||||||
splitExecutor.setTaskFrequency(frequency);
|
splitExecutor.setTaskFrequency(frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMetricUnits(boolean metric) {
|
void setMetricUnits(boolean metric) {
|
||||||
announcementExecutor.setMetricUnits(metric);
|
announcementExecutor.setMetricUnits(metric);
|
||||||
splitExecutor.setMetricUnits(metric);
|
splitExecutor.setMetricUnits(metric);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user