Merge "Return ServiceState from telephonyGetServiceState"
diff --git a/Common/src/com/googlecode/android_scripting/facade/EventFacade.java b/Common/src/com/googlecode/android_scripting/facade/EventFacade.java
index 9ce6628..42c3f83 100644
--- a/Common/src/com/googlecode/android_scripting/facade/EventFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/EventFacade.java
@@ -371,6 +371,12 @@
         return eventWaitFor(eventName, removeEvent, timeout);
     }
 
+    @Rpc(description = "sl4a session is shutting down, send terminate event to client.")
+    public void closeSl4aSession() {
+        eventClearBuffer();
+        postEvent("EventDispatcherShutdown", null);
+    }
+
     @Override
     public void shutdown() {
         mGlobalEventObservers.clear();
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
index 6945f9e..f5e65a3 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothConnectionFacade.java
@@ -305,6 +305,7 @@
                 return;
             }
 
+            // Switch Only Necessary for Old implementation. Left in for backwards compatability.
             int profile = -1;
             switch (action) {
                 case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
@@ -337,11 +338,18 @@
                 Log.e("Action does not match any given profiles " + action);
             }
 
+            // The newer implementation will just post the Bundle with the literal event
+            // intead of the old implemenatation of posting BluetoothProfileConnectionStateChanged
+            // with the action inside of the Bundle. This makes for cleaner connection handling
+            // from test frameworks. Left the old implemenation in for backwards compatability.
+
             // Post an event to Facade.
             Bundle news = new Bundle();
-            news.putInt("profile", profile);
             news.putInt("state", state);
             news.putString("addr", device.getAddress());
+            mEventFacade.postEvent(action, news);
+
+            news.putInt("profile", profile);
             news.putString("action", action);
             mEventFacade.postEvent("BluetoothProfileConnectionStateChanged", news);
         }
@@ -515,6 +523,25 @@
         return results;
     }
 
+    /**
+     * Return a list of service UUIDS supported by the bonded device.
+     * @param macAddress the String mac address of the bonded device.
+     *
+     * @return the String list of supported UUIDS.
+     * @throws Exception
+     */
+    @Rpc(description = "Return a list of service UUIDS supported by the bonded device")
+    public List<String> bluetoothGetBondedDeviceUuids(
+        @RpcParameter(name = "macAddress") String macAddress) throws Exception {
+        BluetoothDevice mDevice = BluetoothFacade.getDevice(mBluetoothAdapter.getBondedDevices(),
+                macAddress);
+        ArrayList<String> uuidStrings = new ArrayList<>();
+        for (ParcelUuid parcelUuid : mDevice.getUuids()) {
+            uuidStrings.add(parcelUuid.toString());
+        }
+        return uuidStrings;
+    }
+
     @Rpc(description = "Return a list of devices connected through bluetooth LE")
     public List<BluetoothDevice> bluetoothGetConnectedLeDevices(Integer profile) {
         return mBluetoothManager.getConnectedDevices(profile);