From 664913a2ffab00b67b164ace425674b71a0e28db Mon Sep 17 00:00:00 2001 From: Mygod Date: Fri, 22 Feb 2019 13:36:02 +0800 Subject: [PATCH] Prevent crash caused by wakelock released by other people --- .../main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt index 90c53a1e..45261e1b 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiDoubleLock.kt @@ -55,7 +55,7 @@ class WifiDoubleLock(lockType: Int) : AutoCloseable { private val power = service.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "vpnhotspot:power").apply { acquire() } override fun close() { - wifi.release() - power.release() + if (wifi.isHeld) wifi.release() + if (power.isHeld) power.release() } }