Merge changes from topic "pacproxy-service"
* changes: Make PacProxyService be a system service Revert^2 "Refactor setCurrentProxyScriptUrl to a void method"
This commit is contained in:
@@ -129,7 +129,7 @@ public class ProxyInfo implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used in PacProxyInstaller after Local Proxy is bound.
|
* Only used in PacProxyService after Local Proxy is bound.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) {
|
public ProxyInfo(@NonNull Uri pacFileUrl, int localProxyPort) {
|
||||||
|
|||||||
@@ -4423,7 +4423,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EVENT_PROXY_HAS_CHANGED: {
|
case EVENT_PROXY_HAS_CHANGED: {
|
||||||
handleApplyDefaultProxy((ProxyInfo)msg.obj);
|
final Pair<Network, ProxyInfo> arg = (Pair<Network, ProxyInfo>) msg.obj;
|
||||||
|
handleApplyDefaultProxy(arg.second);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EVENT_REGISTER_NETWORK_PROVIDER: {
|
case EVENT_REGISTER_NETWORK_PROVIDER: {
|
||||||
|
|||||||
@@ -27,15 +27,19 @@ import android.annotation.Nullable;
|
|||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.PacProxyManager;
|
||||||
import android.net.Proxy;
|
import android.net.Proxy;
|
||||||
import android.net.ProxyInfo;
|
import android.net.ProxyInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.HandlerExecutor;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.internal.annotations.GuardedBy;
|
import com.android.internal.annotations.GuardedBy;
|
||||||
import com.android.net.module.util.ProxyUtils;
|
import com.android.net.module.util.ProxyUtils;
|
||||||
@@ -67,7 +71,7 @@ public class ProxyTracker {
|
|||||||
// is not set. Individual networks have their own settings that override this. This member
|
// is not set. Individual networks have their own settings that override this. This member
|
||||||
// is set through setDefaultProxy, which is called when the default network changes proxies
|
// is set through setDefaultProxy, which is called when the default network changes proxies
|
||||||
// in its LinkProperties, or when ConnectivityService switches to a new default network, or
|
// in its LinkProperties, or when ConnectivityService switches to a new default network, or
|
||||||
// when PacProxyInstaller resolves the proxy.
|
// when PacProxyService resolves the proxy.
|
||||||
@Nullable
|
@Nullable
|
||||||
@GuardedBy("mProxyLock")
|
@GuardedBy("mProxyLock")
|
||||||
private volatile ProxyInfo mDefaultProxy = null;
|
private volatile ProxyInfo mDefaultProxy = null;
|
||||||
@@ -77,16 +81,31 @@ public class ProxyTracker {
|
|||||||
|
|
||||||
private final Handler mConnectivityServiceHandler;
|
private final Handler mConnectivityServiceHandler;
|
||||||
|
|
||||||
// The object responsible for Proxy Auto Configuration (PAC).
|
private final PacProxyManager mPacProxyManager;
|
||||||
@NonNull
|
|
||||||
private final PacProxyInstaller mPacProxyInstaller;
|
private class PacProxyInstalledListener implements PacProxyManager.PacProxyInstalledListener {
|
||||||
|
private final int mEvent;
|
||||||
|
|
||||||
|
PacProxyInstalledListener(int event) {
|
||||||
|
mEvent = event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPacProxyInstalled(@Nullable Network network, @NonNull ProxyInfo proxy) {
|
||||||
|
mConnectivityServiceHandler
|
||||||
|
.sendMessage(mConnectivityServiceHandler
|
||||||
|
.obtainMessage(mEvent, new Pair<>(network, proxy)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ProxyTracker(@NonNull final Context context,
|
public ProxyTracker(@NonNull final Context context,
|
||||||
@NonNull final Handler connectivityServiceInternalHandler, final int pacChangedEvent) {
|
@NonNull final Handler connectivityServiceInternalHandler, final int pacChangedEvent) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mConnectivityServiceHandler = connectivityServiceInternalHandler;
|
mConnectivityServiceHandler = connectivityServiceInternalHandler;
|
||||||
mPacProxyInstaller = new PacProxyInstaller(
|
mPacProxyManager = context.getSystemService(PacProxyManager.class);
|
||||||
context, connectivityServiceInternalHandler, pacChangedEvent);
|
|
||||||
|
PacProxyInstalledListener listener = new PacProxyInstalledListener(pacChangedEvent);
|
||||||
|
mPacProxyManager.addPacProxyInstalledListener(
|
||||||
|
new HandlerExecutor(mConnectivityServiceHandler), listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert empty ProxyInfo's to null as null-checks are used to determine if proxies are present
|
// Convert empty ProxyInfo's to null as null-checks are used to determine if proxies are present
|
||||||
@@ -182,7 +201,7 @@ public class ProxyTracker {
|
|||||||
|
|
||||||
if (!TextUtils.isEmpty(pacFileUrl)) {
|
if (!TextUtils.isEmpty(pacFileUrl)) {
|
||||||
mConnectivityServiceHandler.post(
|
mConnectivityServiceHandler.post(
|
||||||
() -> mPacProxyInstaller.setCurrentProxyScriptUrl(proxyProperties));
|
() -> mPacProxyManager.setCurrentProxyScriptUrl(proxyProperties));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,9 +245,9 @@ public class ProxyTracker {
|
|||||||
final ProxyInfo defaultProxy = getDefaultProxy();
|
final ProxyInfo defaultProxy = getDefaultProxy();
|
||||||
final ProxyInfo proxyInfo = null != defaultProxy ?
|
final ProxyInfo proxyInfo = null != defaultProxy ?
|
||||||
defaultProxy : ProxyInfo.buildDirectProxy("", 0, Collections.emptyList());
|
defaultProxy : ProxyInfo.buildDirectProxy("", 0, Collections.emptyList());
|
||||||
|
mPacProxyManager.setCurrentProxyScriptUrl(proxyInfo);
|
||||||
|
|
||||||
if (mPacProxyInstaller.setCurrentProxyScriptUrl(proxyInfo)
|
if (!shouldSendBroadcast(proxyInfo)) {
|
||||||
== PacProxyInstaller.DONT_SEND_BROADCAST) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DBG) Log.d(TAG, "sending Proxy Broadcast for " + proxyInfo);
|
if (DBG) Log.d(TAG, "sending Proxy Broadcast for " + proxyInfo);
|
||||||
@@ -244,6 +263,10 @@ public class ProxyTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean shouldSendBroadcast(ProxyInfo proxy) {
|
||||||
|
return Uri.EMPTY.equals(proxy.getPacFileUrl()) || proxy.getPort() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the global proxy in memory. Also writes the values to the global settings of the device.
|
* Sets the global proxy in memory. Also writes the values to the global settings of the device.
|
||||||
*
|
*
|
||||||
@@ -308,10 +331,10 @@ public class ProxyTracker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This call could be coming from the PacProxyInstaller, containing the port of the
|
// This call could be coming from the PacProxyService, containing the port of the
|
||||||
// local proxy. If this new proxy matches the global proxy then copy this proxy to the
|
// local proxy. If this new proxy matches the global proxy then copy this proxy to the
|
||||||
// global (to get the correct local port), and send a broadcast.
|
// global (to get the correct local port), and send a broadcast.
|
||||||
// TODO: Switch PacProxyInstaller to have its own message to send back rather than
|
// TODO: Switch PacProxyService to have its own message to send back rather than
|
||||||
// reusing EVENT_HAS_CHANGED_PROXY and this call to handleApplyDefaultProxy.
|
// reusing EVENT_HAS_CHANGED_PROXY and this call to handleApplyDefaultProxy.
|
||||||
if ((mGlobalProxy != null) && (proxyInfo != null)
|
if ((mGlobalProxy != null) && (proxyInfo != null)
|
||||||
&& (!Uri.EMPTY.equals(proxyInfo.getPacFileUrl()))
|
&& (!Uri.EMPTY.equals(proxyInfo.getPacFileUrl()))
|
||||||
|
|||||||
Reference in New Issue
Block a user