forked from upstream-mirrors/OpenTracks
Refactored wake lock release.
This commit is contained in:
@@ -268,7 +268,7 @@ public class TrackRecordingService extends Service {
|
|||||||
binder = null;
|
binder = null;
|
||||||
|
|
||||||
// This should be the next to last operation
|
// 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.
|
// Shutdown the executorService last to avoid sending events to a dead executor.
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
@@ -528,7 +528,7 @@ public class TrackRecordingService extends Service {
|
|||||||
void stopGps(boolean stop) {
|
void stopGps(boolean stop) {
|
||||||
unregisterLocationListener();
|
unregisterLocationListener();
|
||||||
showNotification(false);
|
showNotification(false);
|
||||||
releaseWakeLock();
|
wakeLock = SystemUtils.releaseWakeLock(wakeLock);
|
||||||
if (stop) {
|
if (stop) {
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
@@ -728,13 +728,6 @@ public class TrackRecordingService extends Service {
|
|||||||
locationManagerConnector.removeLocationUpdates(locationListener);
|
locationManagerConnector.removeLocationUpdates(locationListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void releaseWakeLock() {
|
|
||||||
if (wakeLock != null && wakeLock.isHeld()) {
|
|
||||||
wakeLock.release();
|
|
||||||
wakeLock = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showNotification(boolean isGpsStarted) {
|
private void showNotification(boolean isGpsStarted) {
|
||||||
// Dijkstra If
|
// Dijkstra If
|
||||||
if (isRecording() && isPaused()) {
|
if (isRecording() && isPaused()) {
|
||||||
|
|||||||
@@ -99,4 +99,16 @@ public class SystemUtils {
|
|||||||
}
|
}
|
||||||
return wakeLock;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user