getProxy in ConnectivityService returns port w/PAC
Changes the PacManager to report message back to ConnectivityService
to send a broadcast once the download has completed. This allows the
ConnectivityService to store the correct proxy info for getProxy().
This made the problem arise that ProxyProperties was not handling port
while it had PAC. Added small fix for equals() and parcelization.
The combination of these fixes seems to resolve Bug: 11028616.
Bug: 11168706
Change-Id: I92d1343a8e804391ab77596b8167a2ef8d76b378
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 5695ee5..70418e8 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -353,6 +353,11 @@
*/
private static final int EVENT_SAMPLE_INTERVAL_ELAPSED = 15;
+ /**
+ * PAC manager has received new port.
+ */
+ private static final int EVENT_PROXY_HAS_CHANGED = 16;
+
/** Handler used for internal events. */
private InternalHandler mHandler;
/** Handler used for incoming {@link NetworkStateTracker} events. */
@@ -679,7 +684,7 @@
},
new IntentFilter(filter));
- mPacManager = new PacManager(mContext);
+ mPacManager = new PacManager(mContext, mHandler, EVENT_PROXY_HAS_CHANGED);
filter = new IntentFilter();
filter.addAction(CONNECTED_TO_PROVISIONING_NETWORK_ACTION);
@@ -3124,6 +3129,10 @@
handleNetworkSamplingTimeout();
break;
}
+ case EVENT_PROXY_HAS_CHANGED: {
+ handleApplyDefaultProxy((ProxyProperties)msg.obj);
+ break;
+ }
}
}
}
diff --git a/services/java/com/android/server/connectivity/PacManager.java b/services/java/com/android/server/connectivity/PacManager.java
index 1cb2fe3..837fb05 100644
--- a/services/java/com/android/server/connectivity/PacManager.java
+++ b/services/java/com/android/server/connectivity/PacManager.java
@@ -27,6 +27,7 @@
import android.net.Proxy;
import android.net.ProxyProperties;
import android.os.Binder;
+import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -89,6 +90,9 @@
private boolean mHasSentBroadcast;
private boolean mHasDownloaded;
+ private Handler mConnectivityHandler;
+ private int mProxyMessage;
+
/**
* Used for locking when setting mProxyService and all references to mPacUrl or mCurrentPac.
*/
@@ -128,7 +132,7 @@
}
}
- public PacManager(Context context) {
+ public PacManager(Context context, Handler handler, int proxyMessage) {
mContext = context;
mLastPort = -1;
@@ -136,6 +140,8 @@
context, 0, new Intent(ACTION_PAC_REFRESH), 0);
context.registerReceiver(new PacRefreshIntentReceiver(),
new IntentFilter(ACTION_PAC_REFRESH));
+ mConnectivityHandler = handler;
+ mProxyMessage = proxyMessage;
}
private AlarmManager getAlarmManager() {
@@ -156,6 +162,10 @@
*/
public synchronized boolean setCurrentProxyScriptUrl(ProxyProperties proxy) {
if (!TextUtils.isEmpty(proxy.getPacFileUrl())) {
+ if (proxy.getPacFileUrl().equals(mPacUrl)) {
+ // Allow to send broadcast, nothing to do.
+ return false;
+ }
synchronized (mProxyLock) {
mPacUrl = proxy.getPacFileUrl();
}
@@ -356,16 +366,7 @@
}
private void sendPacBroadcast(ProxyProperties proxy) {
- Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
- intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING |
- Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
- intent.putExtra(Proxy.EXTRA_PROXY_INFO, proxy);
- final long ident = Binder.clearCallingIdentity();
- try {
- mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
- } finally {
- Binder.restoreCallingIdentity(ident);
- }
+ mConnectivityHandler.sendMessage(mConnectivityHandler.obtainMessage(mProxyMessage, proxy));
}
private synchronized void sendProxyIfNeeded() {