Snap for 4916303 from 20112b515c21b698601d488326464968c4591fc8 to pi-qpr1-release

Change-Id: I883ce89e4d3a59f5f5910dde2fcd58cfd67523f6
diff --git a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
index bd81bb8..c0c09b8 100644
--- a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
@@ -34,6 +34,7 @@
 import android.net.NetworkPolicy;
 import android.net.NetworkPolicyManager;
 import android.net.NetworkRequest;
+import android.net.ProxyInfo;
 import android.net.StringNetworkSpecifier;
 import android.os.Bundle;
 import android.os.RemoteException;
@@ -501,7 +502,6 @@
         PacketKeepaliveReceiver mPacketKeepaliveReceiver =
                 mPacketKeepaliveReceiverMap.get(key);
         if (mPacketKeepaliveReceiver != null) {
-            mPacketKeepaliveReceiverMap.remove(key);
             mPacketKeepaliveReceiver.mPacketKeepalive.stop();
             return true;
         } else {
@@ -509,6 +509,14 @@
         }
     }
 
+    /**
+     * Remove key from the PacketKeepaliveReceiver map
+     */
+    @Rpc(description = "remove PacketKeepaliveReceiver key")
+    public void connectivityRemovePacketKeepaliveReceiverKey(String key) {
+        mPacketKeepaliveReceiverMap.remove(key);
+    }
+
     @Rpc(description = "start listening for NattKeepalive Event")
     public Boolean connectivityNattKeepaliveStartListeningForEvent(String key, String eventString) {
         PacketKeepaliveReceiver mPacketKeepaliveReceiver =
@@ -1097,6 +1105,50 @@
         }
     }
 
+    /**
+     * Sets the global proxy using the given information.
+     *
+     * @param hostname hostname of the proxy
+     * @param port     port set on the proxy server
+     * @param exclList List of hostnames excluded
+     */
+    @Rpc(description = "Set global proxy")
+    public void connectivitySetGlobalProxy(String hostname, Integer port, String exclList) {
+        ProxyInfo proxyInfo = new ProxyInfo(hostname, port.intValue(), exclList);
+        mManager.setGlobalProxy(proxyInfo);
+    }
+
+    /**
+     * Sets the global proxy using a PAC URI.
+     *
+     * @param pac PAC URI in string
+     */
+    @Rpc(description = "Set global proxy with proxy autoconfig")
+    public void connectivitySetGlobalPacProxy(String pac) {
+        ProxyInfo proxyInfo = new ProxyInfo(pac);
+        mManager.setGlobalProxy(proxyInfo);
+    }
+
+    /**
+     * Gets the global proxy settings.
+     *
+     * @return ProxyInfo object in dictionary
+     */
+    @Rpc(description = "Get global proxy")
+    public ProxyInfo connectivityGetGlobalProxy() {
+        ProxyInfo proxyInfo = mManager.getGlobalProxy();
+        if (proxyInfo == null) return null;
+        return proxyInfo;
+    }
+
+    /**
+     * Resets the global proxy settings.
+     */
+    @Rpc(description = "Reset global proxy")
+    public void connectivityResetGlobalProxy() {
+        mManager.setGlobalProxy(null);
+    }
+
     @Override
     public void shutdown() {
         connectivityStopTrackingConnectivityStateChange();
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index 3e23c0c..94a96d4 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -35,6 +35,7 @@
 import android.net.LinkProperties;
 import android.net.Network;
 import android.net.NetworkInfo;
+import android.net.ProxyInfo;
 import android.net.RouteInfo;
 import android.net.Uri;
 import android.net.wifi.RttManager.RttCapabilities;
@@ -286,6 +287,9 @@
         if (data instanceof IpPrefix) {
             return buildIpPrefix((IpPrefix) data);
         }
+        if (data instanceof ProxyInfo) {
+            return buildProxyInfo((ProxyInfo) data);
+        }
         if (data instanceof byte[]) {
             JSONArray result = new JSONArray();
             for (byte b : (byte[]) data) {
@@ -1086,6 +1090,15 @@
         return info;
     }
 
+    private static JSONObject buildProxyInfo(ProxyInfo data) throws JSONException {
+        JSONObject info = new JSONObject();
+        info.put("Hostname", data.getHost());
+        info.put("Port", data.getPort());
+        info.put("ExclList", data.getExclusionListAsString());
+        info.put("PacUrl", data.getPacFileUrl().toString());
+        return info;
+    }
+
     private static <T> JSONObject buildCallEvent(InCallServiceImpl.CallEvent<T> callEvent)
             throws JSONException {
         JSONObject jsonEvent = new JSONObject();