diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-10-17 18:41:46 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-10-17 18:42:37 +0200 |
commit | ed6a803dfd93e60b531e6e6244fc990d3838fd04 (patch) | |
tree | 701acec618d1f1a598b46bdb743808b8b11ee1bf | |
parent | 1ca36be0ab0be6d7b3d8659a427430b9a2807961 (diff) | |
download | AudioPlayer-ed6a803dfd93e60b531e6e6244fc990d3838fd04.tar.gz |
Do not acquire wakelock when Prestissimo backed mediaplayer is created
see https://github.com/AntennaPod/AntennaPod/pull/1198
-rw-r--r-- | library/build.gradle | 2 | ||||
-rw-r--r-- | library/src/main/java/org/antennapod/audio/ServiceBackedAudioPlayer.java | 27 |
2 files changed, 18 insertions, 11 deletions
diff --git a/library/build.gradle b/library/build.gradle index 54df7f1..f4c7b5c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,7 +7,7 @@ android { minSdkVersion 3 targetSdkVersion 22 versionCode 1 - versionName "1.0.1" + versionName "1.0.2" } buildTypes { release { diff --git a/library/src/main/java/org/antennapod/audio/ServiceBackedAudioPlayer.java b/library/src/main/java/org/antennapod/audio/ServiceBackedAudioPlayer.java index 238de3a..9ddf8af 100644 --- a/library/src/main/java/org/antennapod/audio/ServiceBackedAudioPlayer.java +++ b/library/src/main/java/org/antennapod/audio/ServiceBackedAudioPlayer.java @@ -855,19 +855,24 @@ public class ServiceBackedAudioPlayer extends AbstractAudioPlayer { // the client app's responsibility to request that permission public void setWakeMode(Context context, int mode) { Log.d(SBMP_TAG, "setWakeMode(context, " + mode + ")"); - if ((this.mWakeLock != null) - && (this.mWakeLock.isHeld())) { - this.mWakeLock.release(); + boolean wasHeld = false; + if (mWakeLock != null) { + if(mWakeLock.isHeld()) { + wasHeld = true; + Log.d(SBMP_TAG, "Releasing wakelock"); + mWakeLock.release(); + } + mWakeLock = null; } if (mode != 0) { - if (this.mWakeLock == null) { - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - // Since mode can't be changed on the fly, we have to allocate a new one - this.mWakeLock = pm.newWakeLock(mode, this.getClass().getName()); - this.mWakeLock.setReferenceCounted(false); - } + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(mode, this.getClass().getName()); + mWakeLock.setReferenceCounted(false); - this.mWakeLock.acquire(); + if(wasHeld) { + Log.d(SBMP_TAG, "Acquiring wakelock"); + mWakeLock.acquire(); + } } } @@ -879,8 +884,10 @@ public class ServiceBackedAudioPlayer extends AbstractAudioPlayer { if (BuildConfig.DEBUG) Log.d(SBMP_TAG, "stayAwake(" + awake + ")"); if (mWakeLock != null) { if (awake && !mWakeLock.isHeld()) { + Log.d(SBMP_TAG, "Acquiring wakelock"); mWakeLock.acquire(); } else if (!awake && mWakeLock.isHeld()) { + Log.d(SBMP_TAG, "Releasing wakelock"); mWakeLock.release(); } } |