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