[Android] Check the state of the wake-lock before aquiring/releasing it

Ludovic Fauvet git at videolan.org
Mon Nov 5 14:48:17 CET 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Nov  5 14:47:40 2012 +0100| [0493588fa48fcd8ff345a0653c135490786fd7e7] | committer: Ludovic Fauvet

Check the state of the wake-lock before aquiring/releasing it

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=0493588fa48fcd8ff345a0653c135490786fd7e7
---

 vlc-android/src/org/videolan/vlc/AudioService.java |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index 7a5609f..02a06ab 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -205,7 +205,8 @@ public class AudioService extends Service {
     @Override
     public void onDestroy() {
         super.onDestroy();
-        mWakeLock.release();
+        if (mWakeLock.isHeld())
+            mWakeLock.release();
         unregisterReceiver(serviceReceiver);
     }
 
@@ -335,7 +336,8 @@ public class AudioService extends Service {
                     Log.i(TAG, "MediaPlayerPlaying");
                     service.changeAudioFocus(true);
                     service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
-                    service.mWakeLock.acquire();
+                    if (!service.mWakeLock.isHeld())
+                        service.mWakeLock.acquire();
                     break;
                 case EventManager.MediaPlayerPaused:
                     Log.i(TAG, "MediaPlayerPaused");
@@ -343,19 +345,22 @@ public class AudioService extends Service {
                     // also hide notification if phone ringing
                     service.hideNotification();
                     service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
-                    service.mWakeLock.release();
+                    if (service.mWakeLock.isHeld())
+                        service.mWakeLock.release();
                     break;
                 case EventManager.MediaPlayerStopped:
                     Log.i(TAG, "MediaPlayerStopped");
                     service.executeUpdate();
                     service.setRemoteControlClientPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
-                    service.mWakeLock.release();
+                    if (service.mWakeLock.isHeld())
+                        service.mWakeLock.release();
                     break;
                 case EventManager.MediaPlayerEndReached:
                     Log.i(TAG, "MediaPlayerEndReached");
                     service.executeUpdate();
                     service.next();
-                    service.mWakeLock.release();
+                    if (service.mWakeLock.isHeld())
+                        service.mWakeLock.release();
                     break;
                 case EventManager.MediaPlayerVout:
                     if(msg.getData().getInt("data") > 0) {



More information about the Android mailing list