Adding two methods (startService and startServiceIntent) to expose startService functionality for sl4a.

[DO NOT MERGE]

b/26186302

Change-Id: Id8b50ca3f7c52fd80ac22dfc2e05657713239785
diff --git a/sl4a/Common/src/com/googlecode/android_scripting/facade/AndroidFacade.java b/sl4a/Common/src/com/googlecode/android_scripting/facade/AndroidFacade.java
index e20ac91..0ba729d 100644
--- a/sl4a/Common/src/com/googlecode/android_scripting/facade/AndroidFacade.java
+++ b/sl4a/Common/src/com/googlecode/android_scripting/facade/AndroidFacade.java
@@ -385,7 +385,10 @@
 
   private Intent buildIntent(String action, String uri, String type, JSONObject extras,
       String packagename, String classname, JSONArray categories) throws JSONException {
-    Intent intent = new Intent(action);
+    Intent intent = new Intent();
+    if (action != null) {
+      intent.setAction(action);
+    }
     intent.setDataAndType(uri != null ? Uri.parse(uri) : null, type);
     if (packagename != null && classname != null) {
       intent.setComponent(new ComponentName(packagename, classname));
@@ -670,6 +673,24 @@
     }
   }
 
+  @Rpc(description = "Starts a service.")
+  public void startService(
+      @RpcParameter(name = "uri")
+      @RpcOptional String uri,
+      @RpcParameter(name = "extras", description = "a Map of extras to add to the Intent")
+      @RpcOptional JSONObject extras,
+      @RpcParameter(name = "packagename",
+                    description = "name of package. If used, requires classname to be useful")
+      @RpcOptional String packagename,
+      @RpcParameter(name = "classname",
+                    description = "name of class. If used, requires packagename to be useful")
+      @RpcOptional String classname
+      ) throws Exception {
+    final Intent intent = buildIntent(null /* action */, uri, null /* type */, extras, packagename,
+                                      classname, null /* categories */);
+    mService.startService(intent);
+  }
+
   @Rpc(description = "Create an Intent.", returns = "An object representing an Intent")
   public Intent makeIntent(
       @RpcParameter(name = "action")
@@ -720,6 +741,15 @@
     mService.sendBroadcast(intent);
   }
 
+  @Rpc(description = "Start Service using Intent")
+  public void startServiceIntent(
+      @RpcParameter(name = "intent",
+                    description = "Intent in the format as returned from makeIntent")
+      Intent intent
+      ) throws Exception {
+    mService.startService(intent);
+  }
+
   @Rpc(description = "Vibrates the phone or a specified duration in milliseconds.")
   public void vibrate(
       @RpcParameter(name = "duration", description = "duration in milliseconds")