ConnectivityManagerFacade: Add startTethering

Tests using wifi tethering need to start tethering through the
ConnectivityManager.startTethering() call.  They used to rely on the
setWifiApEnabled call.  This no longer works due to changes in the
implementation to start the wifi hotspot.

BUG: 30112957
Change-Id: I44132fc0bd15aac1f830deb760d60483f20bec5f
(cherry picked from commit 1e507299559210d759c4ec44a8c3d422bc3880b2)
diff --git a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
index 594c934..dec75ea 100644
--- a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
@@ -401,6 +401,21 @@
         return TelephonyConstants.PacketKeepaliveCallbackInvalid;
     }
 
+    /**
+     * Callbacks used in ConnectivityManager to confirm tethering has started/failed.
+     */
+    class OnStartTetheringCallback extends ConnectivityManager.OnStartTetheringCallback {
+        @Override
+        public void onTetheringStarted() {
+            mEventFacade.postEvent(TelephonyConstants.TetheringStartedCallback, null);
+        }
+
+        @Override
+        public void onTetheringFailed() {
+            mEventFacade.postEvent(TelephonyConstants.TetheringFailedCallback, null);
+        }
+    }
+
     private final ConnectivityManager mManager;
     private final Service mService;
     private final Context mContext;
@@ -714,6 +729,20 @@
         return mManager.isTetheringSupported();
     }
 
+    @Rpc(description = "Call to start tethering with a provisioning check if needed")
+    public void connectivityStartTethering(@RpcParameter(name = "type") Integer type,
+            @RpcParameter(name = "showProvisioningUi") Boolean showProvisioningUi) {
+        Log.d("startTethering for type: " + type + " showProvUi: " + showProvisioningUi);
+        OnStartTetheringCallback tetherCallback = new OnStartTetheringCallback();
+        mManager.startTethering(type, showProvisioningUi, tetherCallback);
+    }
+
+    @Rpc(description = "Call to stop tethering")
+    public void connectivityStopTethering(@RpcParameter(name = "type") Integer type) {
+        Log.d("stopTethering for type: " + type);
+        mManager.stopTethering(type);
+    }
+
     @Override
     public void shutdown() {
         connectivityStopTrackingConnectivityStateChange();
diff --git a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
index 519ad9b..a899e11 100644
--- a/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
+++ b/Common/src/com/googlecode/android_scripting/facade/telephony/TelephonyConstants.java
@@ -361,7 +361,7 @@
 
     /**
      * Constant for Network Call Back
-     * **/
+     */
     public static final String EventNetworkCallback = "NetworkCallback";
 
     /*Sub-Event Names*/
@@ -377,8 +377,14 @@
     public static final String NetworkCallbackInvalid = "Invalid";
 
     /**
+     * Constants for OnStartTetheringCallback
+     */
+    public static final String TetheringStartedCallback = "ConnectivityManagerOnTetheringStarted";
+    public static final String TetheringFailedCallback = "ConnectivityManagerOnTetheringFailed";
+
+    /**
      * Constant for Signal Strength fields
-     * **/
+     */
     public static class SignalStrengthContainer {
         public static final String SIGNAL_STRENGTH_GSM = "gsmSignalStrength";
         public static final String SIGNAL_STRENGTH_GSM_DBM = "gsmDbm";