From 8cbd2dd7e4fb0268db7cdf7666d0f62972531d3e Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Thu, 7 Jun 2018 18:37:59 +0900 Subject: [PATCH] [PT06] Move setGlobalProxy into ProxyTracker Test: runtest Change-Id: I6abd2221882db368a411b7174c66d8bd3b6b5110 --- .../android/server/ConnectivityService.java | 53 ++----------------- .../server/connectivity/ProxyTracker.java | 47 ++++++++++++++++ 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 3d923a9300..dadd3274ee 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -3292,57 +3292,10 @@ public class ConnectivityService extends IConnectivityManager.Stub } } - 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 89cacdcf0b..daaedd8131 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 @@ package com.android.server.connectivity; 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.net.Uri; 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 @@ public class ProxyTracker { 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); + } + } }