handle media keys

This lets Eleven respond to physical media keys on some devices
as well as when the volumn buttons are long pressed when the screen
is off and the 'Playback control' preference is true in settings.
Change-Id: Ide906efdf90a6f42f3fcb6c5386328301165cb7c
diff --git a/src/com/cyanogenmod/eleven/MusicPlaybackService.java b/src/com/cyanogenmod/eleven/MusicPlaybackService.java
index 1f5660c..22e641d 100644
--- a/src/com/cyanogenmod/eleven/MusicPlaybackService.java
+++ b/src/com/cyanogenmod/eleven/MusicPlaybackService.java
@@ -66,7 +66,6 @@
 import com.cyanogenmod.eleven.service.MusicPlaybackTrack;
 import com.cyanogenmod.eleven.utils.BitmapWithColors;
 import com.cyanogenmod.eleven.utils.Lists;
-import com.cyanogenmod.eleven.utils.PreferenceUtils;
 import com.cyanogenmod.eleven.utils.ShakeDetector;
 import com.cyanogenmod.eleven.utils.SrtManager;
 
@@ -705,6 +704,7 @@
             }
         });
         mSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
+        mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
     }
 
     /**
@@ -1488,8 +1488,16 @@
                 ? PlaybackState.STATE_PLAYING
                 : PlaybackState.STATE_PAUSED;
 
+        long playBackStateActions = PlaybackState.ACTION_PLAY |
+                PlaybackState.ACTION_PLAY_PAUSE |
+                PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
+                PlaybackState.ACTION_PAUSE |
+                PlaybackState.ACTION_SKIP_TO_NEXT |
+                PlaybackState.ACTION_SKIP_TO_PREVIOUS;
+
         if (what.equals(PLAYSTATE_CHANGED) || what.equals(POSITION_CHANGED)) {
             mSession.setPlaybackState(new PlaybackState.Builder()
+                    .setActions(playBackStateActions)
                     .setState(playState, position(), 1.0f).build());
         } else if (what.equals(META_CHANGED) || what.equals(QUEUE_CHANGED)) {
             Bitmap albumArt = getAlbumArt(false).getBitmap();
@@ -1517,6 +1525,7 @@
                     .build());
 
             mSession.setPlaybackState(new PlaybackState.Builder()
+                    .setActions(playBackStateActions)
                     .setState(playState, position(), 1.0f).build());
         }
     }