From 03bf1abdd4442892952e146c83357feaab0e877a Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 27 Aug 2017 11:57:06 +0200 Subject: [PATCH] add WakeLock#isHeld() --- .../main/java/info/nightscout/androidaps/MainActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index b9bdc1c17d..2cb501b99a 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -95,9 +95,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); if (ev.lock) { mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AAPS"); - mWakeLock.acquire(); + if (!mWakeLock.isHeld()) + mWakeLock.acquire(); } else { - if (mWakeLock != null) + if (mWakeLock != null && mWakeLock.isHeld()) mWakeLock.release(); } }