[PT06] Move setGlobalProxy into ProxyTracker

Test: runtest
Change-Id: I6abd2221882db368a411b7174c66d8bd3b6b5110
This commit is contained in:
Chalard Jean
2018-06-07 18:37:59 +09:00
parent 5c0ca509d5
commit 8cbd2dd7e4
2 changed files with 50 additions and 50 deletions

View File

@@ -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() {

View File

@@ -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);
}
}
}