Refactored wake lock release.

This commit is contained in:
Dennis Guse
2020-01-05 18:44:15 +01:00
parent f6a27a1522
commit b5bf3aadc5
2 changed files with 14 additions and 9 deletions
@@ -268,7 +268,7 @@ public class TrackRecordingService extends Service {
binder = null;
// This should be the next to last operation
releaseWakeLock();
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
// Shutdown the executorService last to avoid sending events to a dead executor.
executorService.shutdown();
@@ -528,7 +528,7 @@ public class TrackRecordingService extends Service {
void stopGps(boolean stop) {
unregisterLocationListener();
showNotification(false);
releaseWakeLock();
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
if (stop) {
stopSelf();
}
@@ -728,13 +728,6 @@ public class TrackRecordingService extends Service {
locationManagerConnector.removeLocationUpdates(locationListener);
}
private void releaseWakeLock() {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
wakeLock = null;
}
}
private void showNotification(boolean isGpsStarted) {
// Dijkstra If
if (isRecording() && isPaused()) {
@@ -99,4 +99,16 @@ public class SystemUtils {
}
return wakeLock;
}
/**
* Releases the wake lock if it is held.
*
* @return null
*/
public static WakeLock releaseWakeLock(WakeLock wakeLock) {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
return null;
}
}