diff options
| author | 2014-05-13 15:14:49 +0000 | |
|---|---|---|
| committer | 2014-05-13 15:14:50 +0000 | |
| commit | b01c6855c08a25636806eff56c7acabfabed3f9f (patch) | |
| tree | 188a223cbeaae0e3f87cffb716c9fd23c5b013c5 | |
| parent | 590afb8bbd4c963a7dac850645fe26a203560100 (diff) | |
| parent | 83520b95124e0fcaaf3154a7a267f6be0205bc74 (diff) | |
Merge "Switch PacUrl storage from String to Uri"
| -rw-r--r-- | core/java/android/app/ActivityThread.java | 3 | ||||
| -rw-r--r-- | core/java/android/app/ApplicationThreadNative.java | 7 | ||||
| -rw-r--r-- | core/java/android/app/IApplicationThread.java | 3 | ||||
| -rw-r--r-- | core/java/android/net/Proxy.java | 10 | ||||
| -rw-r--r-- | core/java/android/net/ProxyInfo.java | 54 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 6 | ||||
| -rw-r--r-- | services/core/java/com/android/server/connectivity/PacManager.java | 14 |
7 files changed, 58 insertions, 39 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 161cb7655276..4cf30ae60d59 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -47,6 +47,7 @@ import android.hardware.display.DisplayManagerGlobal; import android.net.IConnectivityManager; import android.net.Proxy; import android.net.ProxyInfo; +import android.net.Uri; import android.opengl.GLUtils; import android.os.AsyncTask; import android.os.Binder; @@ -839,7 +840,7 @@ public final class ActivityThread { InetAddress.clearDnsCache(); } - public void setHttpProxy(String host, String port, String exclList, String pacFileUrl) { + public void setHttpProxy(String host, String port, String exclList, Uri pacFileUrl) { Proxy.setHttpProxySystemProperty(host, port, exclList, pacFileUrl); } diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java index e7902a9d9825..0029efa2c56b 100644 --- a/core/java/android/app/ApplicationThreadNative.java +++ b/core/java/android/app/ApplicationThreadNative.java @@ -25,6 +25,7 @@ import android.content.pm.ProviderInfo; import android.content.pm.ServiceInfo; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; +import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Debug; @@ -339,7 +340,7 @@ public abstract class ApplicationThreadNative extends Binder final String proxy = data.readString(); final String port = data.readString(); final String exclList = data.readString(); - final String pacFileUrl = data.readString(); + final Uri pacFileUrl = Uri.CREATOR.createFromParcel(data); setHttpProxy(proxy, port, exclList, pacFileUrl); return true; } @@ -1008,13 +1009,13 @@ class ApplicationThreadProxy implements IApplicationThread { } public void setHttpProxy(String proxy, String port, String exclList, - String pacFileUrl) throws RemoteException { + Uri pacFileUrl) throws RemoteException { Parcel data = Parcel.obtain(); data.writeInterfaceToken(IApplicationThread.descriptor); data.writeString(proxy); data.writeString(port); data.writeString(exclList); - data.writeString(pacFileUrl); + pacFileUrl.writeToParcel(data, 0); mRemote.transact(SET_HTTP_PROXY_TRANSACTION, data, null, IBinder.FLAG_ONEWAY); data.recycle(); } diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java index a8320342d45d..d5fbd0bd61d6 100644 --- a/core/java/android/app/IApplicationThread.java +++ b/core/java/android/app/IApplicationThread.java @@ -25,6 +25,7 @@ import android.content.pm.ProviderInfo; import android.content.pm.ServiceInfo; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; +import android.net.Uri; import android.os.Bundle; import android.os.Debug; import android.os.ParcelFileDescriptor; @@ -106,7 +107,7 @@ public interface IApplicationThread extends IInterface { void updateTimeZone() throws RemoteException; void clearDnsCache() throws RemoteException; void setHttpProxy(String proxy, String port, String exclList, - String pacFileUrl) throws RemoteException; + Uri pacFileUrl) throws RemoteException; void processInBackground() throws RemoteException; void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) throws RemoteException; diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java index daf0065d1c47..6a78c29c15ac 100644 --- a/core/java/android/net/Proxy.java +++ b/core/java/android/net/Proxy.java @@ -273,21 +273,19 @@ public final class Proxy { String host = null; String port = null; String exclList = null; - String pacFileUrl = null; + Uri pacFileUrl = Uri.EMPTY; if (p != null) { host = p.getHost(); port = Integer.toString(p.getPort()); exclList = p.getExclusionListAsString(); - if (p.getPacFileUrl() != null) { - pacFileUrl = p.getPacFileUrl().toString(); - } + pacFileUrl = p.getPacFileUrl(); } setHttpProxySystemProperty(host, port, exclList, pacFileUrl); } /** @hide */ public static final void setHttpProxySystemProperty(String host, String port, String exclList, - String pacFileUrl) { + Uri pacFileUrl) { if (exclList != null) exclList = exclList.replace(",", "|"); if (false) Log.d(TAG, "setHttpProxySystemProperty :"+host+":"+port+" - "+exclList); if (host != null) { @@ -311,7 +309,7 @@ public final class Proxy { System.clearProperty("http.nonProxyHosts"); System.clearProperty("https.nonProxyHosts"); } - if (!TextUtils.isEmpty(pacFileUrl)) { + if (!Uri.EMPTY.equals(pacFileUrl)) { ProxySelector.setDefault(new PacProxySelector()); } else { ProxySelector.setDefault(sDefaultProxySelector); diff --git a/core/java/android/net/ProxyInfo.java b/core/java/android/net/ProxyInfo.java index b40941fe9c2b..991d9dacd723 100644 --- a/core/java/android/net/ProxyInfo.java +++ b/core/java/android/net/ProxyInfo.java @@ -44,7 +44,7 @@ public class ProxyInfo implements Parcelable { private String mExclusionList; private String[] mParsedExclusionList; - private String mPacFileUrl; + private Uri mPacFileUrl; /** *@hide */ @@ -85,7 +85,7 @@ public class ProxyInfo implements Parcelable { * at the specified URL. */ public static ProxyInfo buildPacProxy(Uri pacUri) { - return new ProxyInfo(pacUri.toString()); + return new ProxyInfo(pacUri); } /** @@ -96,27 +96,45 @@ public class ProxyInfo implements Parcelable { mHost = host; mPort = port; setExclusionList(exclList); + mPacFileUrl = Uri.EMPTY; } /** * Create a ProxyProperties that points at a PAC URL. * @hide */ - public ProxyInfo(String pacFileUrl) { + public ProxyInfo(Uri pacFileUrl) { mHost = LOCAL_HOST; mPort = LOCAL_PORT; setExclusionList(LOCAL_EXCL_LIST); + if (pacFileUrl == null) { + throw new NullPointerException(); + } mPacFileUrl = pacFileUrl; } /** + * Create a ProxyProperties that points at a PAC URL. + * @hide + */ + public ProxyInfo(String pacFileUrl) { + mHost = LOCAL_HOST; + mPort = LOCAL_PORT; + setExclusionList(LOCAL_EXCL_LIST); + mPacFileUrl = Uri.parse(pacFileUrl); + } + + /** * Only used in PacManager after Local Proxy is bound. * @hide */ - public ProxyInfo(String pacFileUrl, int localProxyPort) { + public ProxyInfo(Uri pacFileUrl, int localProxyPort) { mHost = LOCAL_HOST; mPort = localProxyPort; setExclusionList(LOCAL_EXCL_LIST); + if (pacFileUrl == null) { + throw new NullPointerException(); + } mPacFileUrl = pacFileUrl; } @@ -125,7 +143,7 @@ public class ProxyInfo implements Parcelable { mPort = port; mExclusionList = exclList; mParsedExclusionList = parsedExclList; - mPacFileUrl = null; + mPacFileUrl = Uri.EMPTY; } // copy constructor instead of clone @@ -137,6 +155,9 @@ public class ProxyInfo implements Parcelable { mHost = source.getHost(); mPort = source.getPort(); mPacFileUrl = source.mPacFileUrl; + if (mPacFileUrl == null) { + mPacFileUrl = Uri.EMPTY; + } mExclusionList = source.getExclusionListAsString(); mParsedExclusionList = source.mParsedExclusionList; } @@ -158,10 +179,7 @@ public class ProxyInfo implements Parcelable { * no PAC script. */ public Uri getPacFileUrl() { - if (TextUtils.isEmpty(mPacFileUrl)) { - return null; - } - return Uri.parse(mPacFileUrl); + return mPacFileUrl; } /** @@ -210,7 +228,7 @@ public class ProxyInfo implements Parcelable { * @hide */ public boolean isValid() { - if (!TextUtils.isEmpty(mPacFileUrl)) return true; + if (!Uri.EMPTY.equals(mPacFileUrl)) return true; return Proxy.PROXY_VALID == Proxy.validate(mHost == null ? "" : mHost, mPort == 0 ? "" : Integer.toString(mPort), mExclusionList == null ? "" : mExclusionList); @@ -234,7 +252,7 @@ public class ProxyInfo implements Parcelable { @Override public String toString() { StringBuilder sb = new StringBuilder(); - if (mPacFileUrl != null) { + if (!Uri.EMPTY.equals(mPacFileUrl)) { sb.append("PAC Script: "); sb.append(mPacFileUrl); } else if (mHost != null) { @@ -257,13 +275,15 @@ public class ProxyInfo implements Parcelable { ProxyInfo p = (ProxyInfo)o; // If PAC URL is present in either then they must be equal. // Other parameters will only be for fall back. - if (!TextUtils.isEmpty(mPacFileUrl)) { + if (!Uri.EMPTY.equals(mPacFileUrl)) { return mPacFileUrl.equals(p.getPacFileUrl()) && mPort == p.mPort; } - if (!TextUtils.isEmpty(p.mPacFileUrl)) { + if (!Uri.EMPTY.equals(p.mPacFileUrl)) { + return false; + } + if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) { return false; } - if (mExclusionList != null && !mExclusionList.equals(p.getExclusionListAsString())) return false; if (mHost != null && p.getHost() != null && mHost.equals(p.getHost()) == false) { return false; } @@ -296,9 +316,9 @@ public class ProxyInfo implements Parcelable { * @hide */ public void writeToParcel(Parcel dest, int flags) { - if (mPacFileUrl != null) { + if (!Uri.EMPTY.equals(mPacFileUrl)) { dest.writeByte((byte)1); - dest.writeString(mPacFileUrl); + mPacFileUrl.writeToParcel(dest, 0); dest.writeInt(mPort); return; } else { @@ -325,7 +345,7 @@ public class ProxyInfo implements Parcelable { String host = null; int port = 0; if (in.readByte() != 0) { - String url = in.readString(); + Uri url = Uri.CREATOR.createFromParcel(in); int localPort = in.readInt(); return new ProxyInfo(url, localPort); } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 5358c1aaca52..344268aa962e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1328,14 +1328,12 @@ public final class ActivityManagerService extends ActivityManagerNative String host = ""; String port = ""; String exclList = ""; - String pacFileUrl = ""; + Uri pacFileUrl = Uri.EMPTY; if (proxy != null) { host = proxy.getHost(); port = Integer.toString(proxy.getPort()); exclList = proxy.getExclusionListAsString(); - if (proxy.getPacFileUrl() != null) { - pacFileUrl = proxy.getPacFileUrl().toString(); - } + pacFileUrl = proxy.getPacFileUrl(); } synchronized (ActivityManagerService.this) { for (int i = mLruProcesses.size() - 1 ; i >= 0 ; i--) { diff --git a/services/core/java/com/android/server/connectivity/PacManager.java b/services/core/java/com/android/server/connectivity/PacManager.java index 0749f242311b..63178eb0e06b 100644 --- a/services/core/java/com/android/server/connectivity/PacManager.java +++ b/services/core/java/com/android/server/connectivity/PacManager.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.net.ProxyInfo; +import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; @@ -32,7 +33,6 @@ import android.os.ServiceManager; import android.os.SystemClock; import android.os.SystemProperties; import android.provider.Settings; -import android.text.TextUtils; import android.util.Log; import com.android.internal.annotations.GuardedBy; @@ -71,7 +71,7 @@ public class PacManager { public static final String KEY_PROXY = "keyProxy"; private String mCurrentPac; @GuardedBy("mProxyLock") - private String mPacUrl; + private Uri mPacUrl; private AlarmManager mAlarmManager; @GuardedBy("mProxyLock") @@ -100,7 +100,7 @@ public class PacManager { public void run() { String file; synchronized (mProxyLock) { - if (mPacUrl == null) return; + if (Uri.EMPTY.equals(mPacUrl)) return; try { file = get(mPacUrl); } catch (IOException ioe) { @@ -158,13 +158,13 @@ public class PacManager { * @return Returns true when the broadcast should not be sent */ public synchronized boolean setCurrentProxyScriptUrl(ProxyInfo proxy) { - if (proxy.getPacFileUrl() != null) { + if (!Uri.EMPTY.equals(proxy.getPacFileUrl())) { if (proxy.getPacFileUrl().equals(mPacUrl) && (proxy.getPort() > 0)) { // Allow to send broadcast, nothing to do. return false; } synchronized (mProxyLock) { - mPacUrl = proxy.getPacFileUrl().toString(); + mPacUrl = proxy.getPacFileUrl(); } mCurrentDelay = DELAY_1; mHasSentBroadcast = false; @@ -196,8 +196,8 @@ public class PacManager { * * @throws IOException */ - private static String get(String urlString) throws IOException { - URL url = new URL(urlString); + private static String get(Uri pacUri) throws IOException { + URL url = new URL(pacUri.toString()); URLConnection urlConnection = url.openConnection(java.net.Proxy.NO_PROXY); return new String(Streams.readFully(urlConnection.getInputStream())); } |