[PT06] Move setGlobalProxy into ProxyTracker
Test: runtest
Change-Id: I6abd2221882db368a411b7174c66d8bd3b6b5110
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 3d923a9..dadd327 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -3292,57 +3292,10 @@
}
}
- public void setGlobalProxy(ProxyInfo proxyProperties) {
+ @Override
+ public void setGlobalProxy(final ProxyInfo proxyProperties) {
enforceConnectivityInternalPermission();
-
- synchronized (mProxyTracker.mProxyLock) {
- if (proxyProperties == mProxyTracker.mGlobalProxy) return;
- if (proxyProperties != null && proxyProperties.equals(mProxyTracker.mGlobalProxy)) {
- return;
- }
- if (mProxyTracker.mGlobalProxy != null
- && mProxyTracker.mGlobalProxy.equals(proxyProperties)) {
- return;
- }
-
- String host = "";
- int port = 0;
- String exclList = "";
- String pacFileUrl = "";
- if (proxyProperties != null && (!TextUtils.isEmpty(proxyProperties.getHost()) ||
- !Uri.EMPTY.equals(proxyProperties.getPacFileUrl()))) {
- if (!proxyProperties.isValid()) {
- if (DBG)
- log("Invalid proxy properties, ignoring: " + proxyProperties.toString());
- return;
- }
- mProxyTracker.mGlobalProxy = new ProxyInfo(proxyProperties);
- host = mProxyTracker.mGlobalProxy.getHost();
- port = mProxyTracker.mGlobalProxy.getPort();
- exclList = mProxyTracker.mGlobalProxy.getExclusionListAsString();
- if (!Uri.EMPTY.equals(proxyProperties.getPacFileUrl())) {
- pacFileUrl = proxyProperties.getPacFileUrl().toString();
- }
- } else {
- mProxyTracker.mGlobalProxy = null;
- }
- ContentResolver res = mContext.getContentResolver();
- final long token = Binder.clearCallingIdentity();
- try {
- Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host);
- Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port);
- Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
- exclList);
- Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl);
- } finally {
- Binder.restoreCallingIdentity(token);
- }
-
- if (mProxyTracker.mGlobalProxy == null) {
- proxyProperties = mProxyTracker.mDefaultProxy;
- }
- mProxyTracker.sendProxyBroadcast(proxyProperties);
- }
+ mProxyTracker.setGlobalProxy(proxyProperties);
}
private void loadGlobalProxy() {
diff --git a/services/core/java/com/android/server/connectivity/ProxyTracker.java b/services/core/java/com/android/server/connectivity/ProxyTracker.java
index 89cacdc..daaedd8 100644
--- a/services/core/java/com/android/server/connectivity/ProxyTracker.java
+++ b/services/core/java/com/android/server/connectivity/ProxyTracker.java
@@ -18,6 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Proxy;
@@ -26,6 +27,7 @@
import android.os.Binder;
import android.os.Handler;
import android.os.UserHandle;
+import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
@@ -134,4 +136,49 @@
Binder.restoreCallingIdentity(ident);
}
}
+
+ public void setGlobalProxy(@Nullable ProxyInfo proxyProperties) {
+ synchronized (mProxyLock) {
+ if (proxyProperties == mGlobalProxy) return;
+ if (proxyProperties != null && proxyProperties.equals(mGlobalProxy)) return;
+ if (mGlobalProxy != null && mGlobalProxy.equals(proxyProperties)) return;
+
+ String host = "";
+ int port = 0;
+ String exclList = "";
+ String pacFileUrl = "";
+ if (proxyProperties != null && (!TextUtils.isEmpty(proxyProperties.getHost()) ||
+ !Uri.EMPTY.equals(proxyProperties.getPacFileUrl()))) {
+ if (!proxyProperties.isValid()) {
+ if (DBG) Slog.d(TAG, "Invalid proxy properties, ignoring: " + proxyProperties);
+ return;
+ }
+ mGlobalProxy = new ProxyInfo(proxyProperties);
+ host = mGlobalProxy.getHost();
+ port = mGlobalProxy.getPort();
+ exclList = mGlobalProxy.getExclusionListAsString();
+ if (!Uri.EMPTY.equals(proxyProperties.getPacFileUrl())) {
+ pacFileUrl = proxyProperties.getPacFileUrl().toString();
+ }
+ } else {
+ mGlobalProxy = null;
+ }
+ final ContentResolver res = mContext.getContentResolver();
+ final long token = Binder.clearCallingIdentity();
+ try {
+ Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host);
+ Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port);
+ Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
+ exclList);
+ Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_PAC, pacFileUrl);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+
+ if (mGlobalProxy == null) {
+ proxyProperties = mDefaultProxy;
+ }
+ sendProxyBroadcast(proxyProperties);
+ }
+ }
}