1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2024-12-28 10:51:14 +00:00

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:host="www.netguard.me"
android:pathPrefix="/" android:pathPrefix="/"
android:scheme="https" /> android:scheme="https" />
</intent-filter> </intent-filter>`
<meta-data <meta-data
android:name="android.app.shortcuts" android:name="android.app.shortcuts"

View file

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