Add get current playback state to facade am: b7fe2a10bb am: 4088a4ffb7
am: 2704a2edb4

Change-Id: I65c8bc3ea5fc97c2ed9f79781d919e37e68a291f
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
index ba5695a..6f21376 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothMediaFacade.java
@@ -366,6 +366,28 @@
     }
 
     /**
+     * Relevance - Phone and Car.
+     * Returns the currently playing media's playback state.
+     * Can be queried on the car and the phone in the middle of a streaming session to
+     * verify they are in sync.
+     *
+     * @return Currently playing Media's playback state
+     */
+    @Rpc(description = "Gets the state of current playback")
+    public PlaybackState bluetoothMediaGetCurrentPlaybackState() throws Exception {
+        if (mMediaController == null) {
+            Log.e(TAG + "MediaController not set");
+            throw new Exception("MediaController not set");
+        }
+        PlaybackState playbackState = mMediaController.getPlaybackState();
+        if (playbackState == null) {
+            Log.d("No playback state available.");
+            return null;
+        }
+        return playbackState;
+    }
+
+    /**
      * Relevance - Phone and Car
      * Returns the current active media sessions for the device. This is useful to see if a
      * Media Session we are interested in is currently active.
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index d74361e..08f83b3 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -29,6 +29,7 @@
 import android.graphics.Point;
 import android.location.Address;
 import android.location.Location;
+import android.media.session.PlaybackState;
 import android.net.DhcpInfo;
 import android.net.IpPrefix;
 import android.net.LinkAddress;
@@ -213,6 +214,9 @@
         if (data instanceof BluetoothDevice) {
             return buildJsonBluetoothDevice((BluetoothDevice) data);
         }
+        if (data instanceof PlaybackState) {
+            return buildJsonPlaybackState((PlaybackState) data);
+        }
         if (data instanceof CellLocation) {
             return buildJsonCellLocation((CellLocation) data);
         }
@@ -606,6 +610,16 @@
         return result;
     }
 
+    private static JSONObject buildJsonPlaybackState(PlaybackState playbackState)
+            throws JSONException {
+        JSONObject result = new JSONObject();
+        result.put("state", playbackState.getState());
+        result.put("position", playbackState.getPosition());
+        result.put("speed", playbackState.getPlaybackSpeed());
+        result.put("actions", playbackState.getActions());
+        return result;
+    }
+
     private static JSONObject buildJsonScanResult(ScanResult scanResult)
             throws JSONException {
         JSONObject result = new JSONObject();