Merge "Move shared Proxy method and constants to shared lib"
This commit is contained in:
@@ -30,8 +30,6 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.ProxySelector;
|
import java.net.ProxySelector;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A convenience class for accessing the user and default proxy
|
* A convenience class for accessing the user and default proxy
|
||||||
@@ -64,40 +62,9 @@ public final class Proxy {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public static final String EXTRA_PROXY_INFO = "android.intent.extra.PROXY_INFO";
|
public static final String EXTRA_PROXY_INFO = "android.intent.extra.PROXY_INFO";
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_VALID = 0;
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_HOSTNAME_EMPTY = 1;
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_HOSTNAME_INVALID = 2;
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_PORT_EMPTY = 3;
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_PORT_INVALID = 4;
|
|
||||||
/** @hide */
|
|
||||||
public static final int PROXY_EXCLLIST_INVALID = 5;
|
|
||||||
|
|
||||||
private static ConnectivityManager sConnectivityManager = null;
|
private static ConnectivityManager sConnectivityManager = null;
|
||||||
|
|
||||||
// Hostname / IP REGEX validation
|
|
||||||
// Matches blank input, ips, and domain names
|
|
||||||
private static final String NAME_IP_REGEX =
|
|
||||||
"[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*(\\.[a-zA-Z0-9]+(\\-[a-zA-Z0-9]+)*)*";
|
|
||||||
|
|
||||||
private static final String HOSTNAME_REGEXP = "^$|^" + NAME_IP_REGEX + "$";
|
|
||||||
|
|
||||||
private static final Pattern HOSTNAME_PATTERN;
|
|
||||||
|
|
||||||
private static final String EXCL_REGEX =
|
|
||||||
"[a-zA-Z0-9*]+(\\-[a-zA-Z0-9*]+)*(\\.[a-zA-Z0-9*]+(\\-[a-zA-Z0-9*]+)*)*";
|
|
||||||
|
|
||||||
private static final String EXCLLIST_REGEXP = "^$|^" + EXCL_REGEX + "(," + EXCL_REGEX + ")*$";
|
|
||||||
|
|
||||||
private static final Pattern EXCLLIST_PATTERN;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
HOSTNAME_PATTERN = Pattern.compile(HOSTNAME_REGEXP);
|
|
||||||
EXCLLIST_PATTERN = Pattern.compile(EXCLLIST_REGEXP);
|
|
||||||
sDefaultProxySelector = ProxySelector.getDefault();
|
sDefaultProxySelector = ProxySelector.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,33 +183,6 @@ public final class Proxy {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate syntax of hostname, port and exclusion list entries
|
|
||||||
* {@hide}
|
|
||||||
*/
|
|
||||||
public static int validate(String hostname, String port, String exclList) {
|
|
||||||
Matcher match = HOSTNAME_PATTERN.matcher(hostname);
|
|
||||||
Matcher listMatch = EXCLLIST_PATTERN.matcher(exclList);
|
|
||||||
|
|
||||||
if (!match.matches()) return PROXY_HOSTNAME_INVALID;
|
|
||||||
|
|
||||||
if (!listMatch.matches()) return PROXY_EXCLLIST_INVALID;
|
|
||||||
|
|
||||||
if (hostname.length() > 0 && port.length() == 0) return PROXY_PORT_EMPTY;
|
|
||||||
|
|
||||||
if (port.length() > 0) {
|
|
||||||
if (hostname.length() == 0) return PROXY_HOSTNAME_EMPTY;
|
|
||||||
int portVal = -1;
|
|
||||||
try {
|
|
||||||
portVal = Integer.parseInt(port);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
return PROXY_PORT_INVALID;
|
|
||||||
}
|
|
||||||
if (portVal <= 0 || portVal > 0xFFFF) return PROXY_PORT_INVALID;
|
|
||||||
}
|
|
||||||
return PROXY_VALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @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) {
|
public static final void setHttpProxySystemProperty(ProxyInfo p) {
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.net.module.util.ProxyUtils;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -233,7 +235,7 @@ public class ProxyInfo implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
if (!Uri.EMPTY.equals(mPacFileUrl)) return true;
|
if (!Uri.EMPTY.equals(mPacFileUrl)) return true;
|
||||||
return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost,
|
return ProxyUtils.PROXY_VALID == ProxyUtils.validate(mHost == null ? "" : mHost,
|
||||||
mPort == 0 ? "" : Integer.toString(mPort),
|
mPort == 0 ? "" : Integer.toString(mPort),
|
||||||
mExclusionList == null ? "" : mExclusionList);
|
mExclusionList == null ? "" : mExclusionList);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user