mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Fixing wake lock being held for too long in the service.
This commit is contained in:
@@ -295,7 +295,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
* Tries to acquire a partial wake lock if not already acquired. Logs errors
|
||||
* and gives up trying in case the wake lock cannot be acquired.
|
||||
*/
|
||||
public void acquireWakeLock() {
|
||||
private void acquireWakeLock() {
|
||||
try {
|
||||
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||
if (pm == null) {
|
||||
@@ -326,6 +326,16 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases the wake lock if it's currently held.
|
||||
*/
|
||||
private void releaseWakeLock() {
|
||||
if (wakeLock != null && wakeLock.isHeld()) {
|
||||
wakeLock.release();
|
||||
wakeLock = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notification message and icon in the notification bar.
|
||||
*/
|
||||
@@ -626,7 +636,6 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
|
||||
prefManager = new PreferenceManager(this);
|
||||
registerLocationListener();
|
||||
acquireWakeLock();
|
||||
/**
|
||||
* After 5 min, check every minute that location listener still is
|
||||
* registered and spit out additional debugging info to the logs:
|
||||
@@ -696,15 +705,13 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
Log.d(MyTracksConstants.TAG, "TrackRecordingService.onDestroy");
|
||||
checkLocationListener.cancel();
|
||||
timer.cancel();
|
||||
if (wakeLock != null && wakeLock.isHeld()) {
|
||||
wakeLock.release();
|
||||
}
|
||||
isRecording = false;
|
||||
showNotification();
|
||||
unregisterLocationListener();
|
||||
shutdownAnnouncer();
|
||||
signalManager.shutdown();
|
||||
splitManager.shutdown();
|
||||
releaseWakeLock();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -934,7 +941,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
if (recordingTrackId == -1 || !isRecording) {
|
||||
throw new IllegalStateException("No recording track in progress!");
|
||||
}
|
||||
|
||||
|
||||
shutdownAnnouncer();
|
||||
isRecording = false;
|
||||
Track recordingTrack = providerUtils.getTrack(recordingTrackId);
|
||||
@@ -956,6 +963,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
}
|
||||
showNotification();
|
||||
prefManager.setRecordingTrack(recordingTrackId = -1);
|
||||
releaseWakeLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -980,6 +988,7 @@ public class TrackRecordingService extends Service implements LocationListener {
|
||||
}
|
||||
|
||||
long startTime = System.currentTimeMillis();
|
||||
acquireWakeLock();
|
||||
|
||||
Track track = new Track();
|
||||
TripStatistics trackStats = track.getStatistics();
|
||||
|
||||
Reference in New Issue
Block a user