[ConnectivityManagerFacade] APIs for proxy testing
CHERRY PICKED FROM AOSP
Bug: 111309129
Test: Verified the changes
Change-Id: I5bff2876fe8f456462d941b4157a6752543e23e9
Merged-In: I4026f4640cd9ef64372fc6631946299f5d6fcba2
diff --git a/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java b/Common/src/com/googlecode/android_scripting/facade/ConnectivityManagerFacade.java
index 2b3697f..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;
@@ -1104,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();