[PT06] Move setGlobalProxy into ProxyTracker
Test: runtest Change-Id: I6abd2221882db368a411b7174c66d8bd3b6b5110
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class PacManager {
|
||||
private volatile boolean mHasDownloaded;
|
||||
|
||||
private Handler mConnectivityHandler;
|
||||
private int mProxyMessage;
|
||||
private final int mProxyMessage;
|
||||
|
||||
/**
|
||||
* Used for locking when setting mProxyService and all references to mCurrentPac.
|
||||
@@ -99,7 +99,7 @@ public class PacManager {
|
||||
|
||||
/**
|
||||
* Runnable to download PAC script.
|
||||
* The behavior relies on the assamption it always run on mNetThread to guarantee that the
|
||||
* The behavior relies on the assumption it always runs on mNetThread to guarantee that the
|
||||
* latest data fetched from mPacUrl is stored in mProxyService.
|
||||
*/
|
||||
private Runnable mPacDownloader = new Runnable() {
|
||||
@@ -133,8 +133,6 @@ public class PacManager {
|
||||
}
|
||||
};
|
||||
|
||||
private final HandlerThread mNetThread = new HandlerThread("android.pacmanager",
|
||||
android.os.Process.THREAD_PRIORITY_DEFAULT);
|
||||
private final Handler mNetThreadHandler;
|
||||
|
||||
class PacRefreshIntentReceiver extends BroadcastReceiver {
|
||||
@@ -146,8 +144,10 @@ public class PacManager {
|
||||
public PacManager(Context context, Handler handler, int proxyMessage) {
|
||||
mContext = context;
|
||||
mLastPort = -1;
|
||||
mNetThread.start();
|
||||
mNetThreadHandler = new Handler(mNetThread.getLooper());
|
||||
final HandlerThread netThread = new HandlerThread("android.pacmanager",
|
||||
android.os.Process.THREAD_PRIORITY_DEFAULT);
|
||||
netThread.start();
|
||||
mNetThreadHandler = new Handler(netThread.getLooper());
|
||||
|
||||
mPacRefreshIntent = PendingIntent.getBroadcast(
|
||||
context, 0, new Intent(ACTION_PAC_REFRESH), 0);
|
||||
@@ -208,7 +208,7 @@ public class PacManager {
|
||||
/**
|
||||
* Does a post and reports back the status code.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException if the URL is malformed, or the PAC file is too big.
|
||||
*/
|
||||
private static String get(Uri pacUri) throws IOException {
|
||||
URL url = new URL(pacUri.toString());
|
||||
@@ -254,7 +254,7 @@ public class PacManager {
|
||||
private String getPacChangeDelay() {
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
|
||||
/** Check system properties for the default value then use secure settings value, if any. */
|
||||
// Check system properties for the default value then use secure settings value, if any.
|
||||
String defaultDelay = SystemProperties.get(
|
||||
"conn." + Settings.Global.PAC_CHANGE_DELAY,
|
||||
DEFAULT_DELAYS);
|
||||
@@ -276,10 +276,9 @@ public class PacManager {
|
||||
getAlarmManager().set(AlarmManager.ELAPSED_REALTIME, timeTillTrigger, mPacRefreshIntent);
|
||||
}
|
||||
|
||||
private boolean setCurrentProxyScript(String script) {
|
||||
private void setCurrentProxyScript(String script) {
|
||||
if (mProxyService == null) {
|
||||
Log.e(TAG, "setCurrentProxyScript: no proxy service");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
mProxyService.setPacFile(script);
|
||||
@@ -287,7 +286,6 @@ public class PacManager {
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Unable to set PAC file", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void bind() {
|
||||
@@ -351,7 +349,7 @@ public class PacManager {
|
||||
try {
|
||||
callbackService.getProxyPort(new IProxyPortListener.Stub() {
|
||||
@Override
|
||||
public void setProxyPort(int port) throws RemoteException {
|
||||
public void setProxyPort(int port) {
|
||||
if (mLastPort != -1) {
|
||||
// Always need to send if port changed
|
||||
mHasSentBroadcast = false;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user