OSDN Git Service

Eleven: Remove wakelock
authormyfluxi <linflux@arcor.de>
Wed, 23 Dec 2015 00:00:41 +0000 (01:00 +0100)
committermyfluxi <linflux@arcor.de>
Wed, 23 Dec 2015 00:04:36 +0000 (01:04 +0100)
We do not need this, let the device sleep during
(offloaded) playback.

Change-Id: I596b480a6361745b96b547c93f1d5433e18069e0

src/com/cyanogenmod/eleven/MusicPlaybackService.java

index f52197d..1f5660c 100644 (file)
@@ -46,7 +46,6 @@ import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
 import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.provider.MediaStore;
@@ -275,34 +274,29 @@ public class MusicPlaybackService extends Service {
     private static final int TRACK_WENT_TO_NEXT = 2;
 
     /**
-     * Indicates when the release the wake lock
-     */
-    private static final int RELEASE_WAKELOCK = 3;
-
-    /**
      * Indicates the player died
      */
-    private static final int SERVER_DIED = 4;
+    private static final int SERVER_DIED = 3;
 
     /**
      * Indicates some sort of focus change, maybe a phone call
      */
-    private static final int FOCUSCHANGE = 5;
+    private static final int FOCUSCHANGE = 4;
 
     /**
      * Indicates to fade the volume down
      */
-    private static final int FADEDOWN = 6;
+    private static final int FADEDOWN = 5;
 
     /**
      * Indicates to fade the volume back up
      */
-    private static final int FADEUP = 7;
+    private static final int FADEUP = 6;
 
     /**
      * Notifies that there is a new timed text string
      */
-    private static final int LYRICS = 8;
+    private static final int LYRICS = 7;
 
     /**
      * Idle time before stopping the foreground notfication (5 minutes)
@@ -391,11 +385,6 @@ public class MusicPlaybackService extends Service {
     private String mFileToPlay;
 
     /**
-     * Keeps the service running when the screen is off
-     */
-    private WakeLock mWakeLock;
-
-    /**
      * Alarm intent for removing the notification when nothing is playing
      * for some time
      */
@@ -667,11 +656,6 @@ public class MusicPlaybackService extends Service {
         getContentResolver().registerContentObserver(
                 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver);
 
-        // Initialize the wake lock
-        final PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
-        mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName());
-        mWakeLock.setReferenceCounted(false);
-
         // Initialize the delayed shutdown intent
         final Intent shutdownIntent = new Intent(this, MusicPlaybackService.class);
         shutdownIntent.setAction(SHUTDOWN);
@@ -768,9 +752,6 @@ public class MusicPlaybackService extends Service {
 
         // deinitialize shake detector
         stopShakeDetector(true);
-
-        // Release the wake lock
-        mWakeLock.release();
     }
 
     /**
@@ -2960,9 +2941,6 @@ public class MusicPlaybackService extends Service {
                         service.mLyrics = (String) msg.obj;
                         service.notifyChange(NEW_LYRICS);
                         break;
-                    case RELEASE_WAKELOCK:
-                        service.mWakeLock.release();
-                        break;
                     case FOCUSCHANGE:
                         if (D) Log.d(TAG, "Received audio focus change event " + msg.arg1);
                         switch (msg.arg1) {
@@ -3079,7 +3057,6 @@ public class MusicPlaybackService extends Service {
          */
         public MultiPlayer(final MusicPlaybackService service) {
             mService = new WeakReference<MusicPlaybackService>(service);
-            mCurrentMediaPlayer.setWakeMode(mService.get(), PowerManager.PARTIAL_WAKE_LOCK);
             mSrtManager = new SrtManager() {
                 @Override
                 public void onTimedText(String text) {
@@ -3192,7 +3169,6 @@ public class MusicPlaybackService extends Service {
                 return;
             }
             mNextMediaPlayer = new MediaPlayer();
-            mNextMediaPlayer.setWakeMode(mService.get(), PowerManager.PARTIAL_WAKE_LOCK);
             mNextMediaPlayer.setAudioSessionId(getAudioSessionId());
             if (setDataSourceImpl(mNextMediaPlayer, path)) {
                 mNextMediaPath = path;
@@ -3327,7 +3303,6 @@ public class MusicPlaybackService extends Service {
                     mIsInitialized = false;
                     mCurrentMediaPlayer.release();
                     mCurrentMediaPlayer = new MediaPlayer();
-                    mCurrentMediaPlayer.setWakeMode(service, PowerManager.PARTIAL_WAKE_LOCK);
                     Message msg = mHandler.obtainMessage(SERVER_DIED, errorInfo);
                     mHandler.sendMessageDelayed(msg, 2000);
                     return true;
@@ -3350,9 +3325,7 @@ public class MusicPlaybackService extends Service {
                 mNextMediaPlayer = null;
                 mHandler.sendEmptyMessage(TRACK_WENT_TO_NEXT);
             } else {
-                mService.get().mWakeLock.acquire(30000);
                 mHandler.sendEmptyMessage(TRACK_ENDED);
-                mHandler.sendEmptyMessage(RELEASE_WAKELOCK);
             }
         }
     }