Skip to content

Commit b749315

Browse files
Chia-chi YehAndroid (Google) Code Review
authored andcommitted
Merge "VPN: temporarily disable the default proxy when VPN is active."
2 parents 893783e + 4c12a47 commit b749315

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

services/java/com/android/server/ConnectivityService.java

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
284284

285285
// track the current default http proxy - tell the world if we get a new one (real change)
286286
private ProxyProperties mDefaultProxy = null;
287+
private Object mDefaultProxyLock = new Object();
288+
private boolean mDefaultProxyDisabled = false;
289+
287290
// track the global proxy.
288291
private ProxyProperties mGlobalProxy = null;
289292
private final Object mGlobalProxyLock = new Object();
@@ -1770,7 +1773,7 @@ private void handleConnectivityChange(int netType, boolean doReset) {
17701773
}
17711774
}
17721775
if (mNetConfigs[netType].isDefault()) {
1773-
handleApplyDefaultProxy(netType);
1776+
handleApplyDefaultProxy(newLp.getHttpProxy());
17741777
}
17751778
} else {
17761779
if (VDBG) {
@@ -2549,8 +2552,10 @@ private void handleInetConditionHoldEnd(int netType, int sequence) {
25492552
return;
25502553
}
25512554

2552-
public synchronized ProxyProperties getProxy() {
2553-
return mDefaultProxy;
2555+
public ProxyProperties getProxy() {
2556+
synchronized (mDefaultProxyLock) {
2557+
return mDefaultProxyDisabled ? null : mDefaultProxy;
2558+
}
25542559
}
25552560

25562561
public void setGlobalProxy(ProxyProperties proxyProperties) {
@@ -2604,20 +2609,19 @@ public ProxyProperties getGlobalProxy() {
26042609
}
26052610
}
26062611

2607-
private void handleApplyDefaultProxy(int type) {
2608-
// check if new default - push it out to all VM if so
2609-
ProxyProperties proxy = mNetTrackers[type].getLinkProperties().getHttpProxy();
2610-
synchronized (this) {
2612+
private void handleApplyDefaultProxy(ProxyProperties proxy) {
2613+
if (proxy != null && TextUtils.isEmpty(proxy.getHost())) {
2614+
proxy = null;
2615+
}
2616+
synchronized (mDefaultProxyLock) {
26112617
if (mDefaultProxy != null && mDefaultProxy.equals(proxy)) return;
26122618
if (mDefaultProxy == proxy) return;
2613-
if (proxy != null && !TextUtils.isEmpty(proxy.getHost())) {
2614-
mDefaultProxy = proxy;
2615-
} else {
2616-
mDefaultProxy = null;
2619+
mDefaultProxy = proxy;
2620+
2621+
if (!mDefaultProxyDisabled) {
2622+
sendProxyBroadcast(proxy);
26172623
}
26182624
}
2619-
if (VDBG) log("changing default proxy to " + proxy);
2620-
sendProxyBroadcast(proxy);
26212625
}
26222626

26232627
private void handleDeprecatedGlobalHttpProxy() {
@@ -2845,17 +2849,30 @@ public void override(List<String> dnsServers, List<String> searchDomains) {
28452849
bumpDns();
28462850
}
28472851

2848-
// TODO: temporarily remove http proxy?
2852+
// Temporarily disable the default proxy.
2853+
synchronized (mDefaultProxyLock) {
2854+
mDefaultProxyDisabled = true;
2855+
if (mDefaultProxy != null) {
2856+
sendProxyBroadcast(null);
2857+
}
2858+
}
2859+
2860+
// TODO: support proxy per network.
28492861
}
28502862

28512863
public void restore() {
28522864
synchronized (mDnsLock) {
2853-
if (!mDnsOverridden) {
2854-
return;
2865+
if (mDnsOverridden) {
2866+
mDnsOverridden = false;
2867+
mHandler.sendEmptyMessage(EVENT_RESTORE_DNS);
2868+
}
2869+
}
2870+
synchronized (mDefaultProxyLock) {
2871+
mDefaultProxyDisabled = false;
2872+
if (mDefaultProxy != null) {
2873+
sendProxyBroadcast(mDefaultProxy);
28552874
}
2856-
mDnsOverridden = false;
28572875
}
2858-
mHandler.sendEmptyMessage(EVENT_RESTORE_DNS);
28592876
}
28602877
}
28612878
}

0 commit comments

Comments
 (0)