From ab89e16acd972d252c7ce596ff6810e48a295307 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 7 Jan 2018 12:09:23 +0100 Subject: [PATCH] PARTIAL_WAKE_LOCK for NSClientService --- .../services/NSClientService.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index abd0f2b26b..1ef71c2f75 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -114,6 +114,18 @@ public class NSClientService extends Service { initialize(); } + @Override + public void onCreate() { + super.onCreate(); + mWakeLock.acquire(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mWakeLock.release(); + } + public class LocalBinder extends Binder { public NSClientService getServiceInstance() { return NSClientService.this; @@ -182,8 +194,6 @@ public class NSClientService extends Service { public void initialize() { dataCounter = 0; - NSClientService.mWakeLock.acquire(); - readPreferences(); if (!nsAPISecret.equals("")) @@ -221,7 +231,6 @@ public class NSClientService extends Service { MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "No NS URL specified")); MainApp.bus().post(new EventNSClientStatus("Not configured")); } - NSClientService.mWakeLock.release(); } private Emitter.Listener onConnect = new Emitter.Listener() { @@ -242,6 +251,15 @@ public class NSClientService extends Service { public void destroy() { if (mSocket != null) { + mSocket.off(Socket.EVENT_CONNECT); + mSocket.off(Socket.EVENT_DISCONNECT); + mSocket.off(Socket.EVENT_PING); + mSocket.off("dataUpdate"); + mSocket.off("announcement"); + mSocket.off("alarm"); + mSocket.off("urgent_alarm"); + mSocket.off("clear_alarm"); + MainApp.bus().post(new EventNSClientNewLog("NSCLIENT", "destroy")); isConnected = false; hasWriteAuth = false;