Prevent lingering wake locks

This commit is contained in:
M66B 2017-08-15 06:46:17 +02:00
parent 549c9ad0dc
commit 1b8ca1cdc6
2 changed files with 13 additions and 2 deletions

View File

@ -85,7 +85,7 @@
android:host="www.netguard.me"
android:pathPrefix="/"
android:scheme="https" />
</intent-filter>
</intent-filter>`
<meta-data
android:name="android.app.shortcuts"

View File

@ -237,6 +237,14 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
return wlInstance;
}
synchronized private static void releaseLock(Context context) {
if (wlInstance != null) {
while (wlInstance.isHeld())
wlInstance.release();
wlInstance = null;
}
}
private final class CommandHandler extends Handler {
public int queue = 0;
@ -433,7 +441,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
// Stop service if needed
if (!prefs.getBoolean("enabled", false) && !prefs.getBoolean("show_stats", false))
stopSelf();
stopForeground(true);
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
@ -2402,6 +2410,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS
logLooper.quit();
statsLooper.quit();
commandHandler.removeMessages(MSG_SERVICE_INTENT);
releaseLock(this);
// Registered in command loop
if (registeredInteractiveState) {
unregisterReceiver(interactiveStateReceiver);