Merge "[PT17] Small cleanup of PacManager" am: f9bb1a998f
am: 6fa5cc677b
Change-Id: I7feead64e6fd1c4a02ccaaf4a76f1ad684887e72
This commit is contained in:
@@ -43,8 +43,6 @@ import com.android.net.IProxyCallback;
|
|||||||
import com.android.net.IProxyPortListener;
|
import com.android.net.IProxyPortListener;
|
||||||
import com.android.net.IProxyService;
|
import com.android.net.IProxyService;
|
||||||
|
|
||||||
import libcore.io.Streams;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -71,6 +69,11 @@ public class PacManager {
|
|||||||
private static final int DELAY_LONG = 4;
|
private static final int DELAY_LONG = 4;
|
||||||
private static final long MAX_PAC_SIZE = 20 * 1000 * 1000;
|
private static final long MAX_PAC_SIZE = 20 * 1000 * 1000;
|
||||||
|
|
||||||
|
// Return values for #setCurrentProxyScriptUrl
|
||||||
|
enum ToSendOrNotToSendBroadcast {
|
||||||
|
DONT_SEND_BROADCAST, DO_SEND_BROADCAST
|
||||||
|
}
|
||||||
|
|
||||||
private String mCurrentPac;
|
private String mCurrentPac;
|
||||||
@GuardedBy("mProxyLock")
|
@GuardedBy("mProxyLock")
|
||||||
private volatile Uri mPacUrl = Uri.EMPTY;
|
private volatile Uri mPacUrl = Uri.EMPTY;
|
||||||
@@ -171,13 +174,13 @@ public class PacManager {
|
|||||||
* PacManager will trigger a new broadcast when it is ready.
|
* PacManager will trigger a new broadcast when it is ready.
|
||||||
*
|
*
|
||||||
* @param proxy Proxy information that is about to be broadcast.
|
* @param proxy Proxy information that is about to be broadcast.
|
||||||
* @return Returns true when the broadcast should not be sent
|
* @return Returns whether the broadcast should be sent : either DO_ or DONT_SEND_BROADCAST
|
||||||
*/
|
*/
|
||||||
synchronized boolean setCurrentProxyScriptUrl(ProxyInfo proxy) {
|
synchronized ToSendOrNotToSendBroadcast setCurrentProxyScriptUrl(ProxyInfo proxy) {
|
||||||
if (!Uri.EMPTY.equals(proxy.getPacFileUrl())) {
|
if (!Uri.EMPTY.equals(proxy.getPacFileUrl())) {
|
||||||
if (proxy.getPacFileUrl().equals(mPacUrl) && (proxy.getPort() > 0)) {
|
if (proxy.getPacFileUrl().equals(mPacUrl) && (proxy.getPort() > 0)) {
|
||||||
// Allow to send broadcast, nothing to do.
|
// Allow to send broadcast, nothing to do.
|
||||||
return false;
|
return ToSendOrNotToSendBroadcast.DO_SEND_BROADCAST;
|
||||||
}
|
}
|
||||||
mPacUrl = proxy.getPacFileUrl();
|
mPacUrl = proxy.getPacFileUrl();
|
||||||
mCurrentDelay = DELAY_1;
|
mCurrentDelay = DELAY_1;
|
||||||
@@ -185,7 +188,7 @@ public class PacManager {
|
|||||||
mHasDownloaded = false;
|
mHasDownloaded = false;
|
||||||
getAlarmManager().cancel(mPacRefreshIntent);
|
getAlarmManager().cancel(mPacRefreshIntent);
|
||||||
bind();
|
bind();
|
||||||
return true;
|
return ToSendOrNotToSendBroadcast.DONT_SEND_BROADCAST;
|
||||||
} else {
|
} else {
|
||||||
getAlarmManager().cancel(mPacRefreshIntent);
|
getAlarmManager().cancel(mPacRefreshIntent);
|
||||||
synchronized (mProxyLock) {
|
synchronized (mProxyLock) {
|
||||||
@@ -201,7 +204,7 @@ public class PacManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return ToSendOrNotToSendBroadcast.DO_SEND_BROADCAST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +299,7 @@ public class PacManager {
|
|||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setClassName(PAC_PACKAGE, PAC_SERVICE);
|
intent.setClassName(PAC_PACKAGE, PAC_SERVICE);
|
||||||
if ((mProxyConnection != null) && (mConnection != null)) {
|
if ((mProxyConnection != null) && (mConnection != null)) {
|
||||||
// Already bound no need to bind again, just download the new file.
|
// Already bound: no need to bind again, just download the new file.
|
||||||
mNetThreadHandler.post(mPacDownloader);
|
mNetThreadHandler.post(mPacDownloader);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,7 +208,10 @@ public class ProxyTracker {
|
|||||||
public void sendProxyBroadcast() {
|
public void sendProxyBroadcast() {
|
||||||
final ProxyInfo defaultProxy = getDefaultProxy();
|
final ProxyInfo defaultProxy = getDefaultProxy();
|
||||||
final ProxyInfo proxyInfo = null != defaultProxy ? defaultProxy : new ProxyInfo("", 0, "");
|
final ProxyInfo proxyInfo = null != defaultProxy ? defaultProxy : new ProxyInfo("", 0, "");
|
||||||
if (mPacManager.setCurrentProxyScriptUrl(proxyInfo)) return;
|
if (mPacManager.setCurrentProxyScriptUrl(proxyInfo)
|
||||||
|
== PacManager.ToSendOrNotToSendBroadcast.DONT_SEND_BROADCAST) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (DBG) Slog.d(TAG, "sending Proxy Broadcast for " + proxyInfo);
|
if (DBG) Slog.d(TAG, "sending Proxy Broadcast for " + proxyInfo);
|
||||||
Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
|
Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
|
||||||
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
|
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
|
||||||
|
|||||||
Reference in New Issue
Block a user