Merge "Use formal API for ActivityThread to set proxy"

This commit is contained in:
Treehugger Robot
2021-02-19 05:42:06 +00:00
committed by Gerrit Code Review
2 changed files with 18 additions and 4 deletions

View File

@@ -4606,7 +4606,7 @@ public class ConnectivityManager {
// Set HTTP proxy system properties to match network. // Set HTTP proxy system properties to match network.
// TODO: Deprecate this static method and replace it with a non-static version. // TODO: Deprecate this static method and replace it with a non-static version.
try { try {
Proxy.setHttpProxySystemProperty(getInstance().getDefaultProxy()); Proxy.setHttpProxyConfiguration(getInstance().getDefaultProxy());
} catch (SecurityException e) { } catch (SecurityException e) {
// The process doesn't have ACCESS_NETWORK_STATE, so we can't fetch the proxy. // The process doesn't have ACCESS_NETWORK_STATE, so we can't fetch the proxy.
Log.e(TAG, "Can't set proxy properties", e); Log.e(TAG, "Can't set proxy properties", e);

View File

@@ -16,8 +16,10 @@
package android.net; package android.net;
import android.annotation.Nullable;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage; import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
@@ -185,7 +187,19 @@ public final class Proxy {
/** @hide */ /** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final void setHttpProxySystemProperty(ProxyInfo p) { @Deprecated
public static void setHttpProxySystemProperty(ProxyInfo p) {
setHttpProxyConfiguration(p);
}
/**
* Set HTTP proxy configuration for the process to match the provided ProxyInfo.
*
* If the provided ProxyInfo is null, the proxy configuration will be cleared.
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static void setHttpProxyConfiguration(@Nullable ProxyInfo p) {
String host = null; String host = null;
String port = null; String port = null;
String exclList = null; String exclList = null;
@@ -196,11 +210,11 @@ public final class Proxy {
exclList = ProxyUtils.exclusionListAsString(p.getExclusionList()); exclList = ProxyUtils.exclusionListAsString(p.getExclusionList());
pacFileUrl = p.getPacFileUrl(); pacFileUrl = p.getPacFileUrl();
} }
setHttpProxySystemProperty(host, port, exclList, pacFileUrl); setHttpProxyConfiguration(host, port, exclList, pacFileUrl);
} }
/** @hide */ /** @hide */
public static final void setHttpProxySystemProperty(String host, String port, String exclList, public static void setHttpProxyConfiguration(String host, String port, String exclList,
Uri pacFileUrl) { Uri pacFileUrl) {
if (exclList != null) exclList = exclList.replace(",", "|"); if (exclList != null) exclList = exclList.replace(",", "|");
if (false) Log.d(TAG, "setHttpProxySystemProperty :"+host+":"+port+" - "+exclList); if (false) Log.d(TAG, "setHttpProxySystemProperty :"+host+":"+port+" - "+exclList);