OSDN Git Service

[PT08] Move setDefaultProxy to ProxyTracker
authorChalard Jean <jchalard@google.com>
Fri, 8 Jun 2018 03:20:15 +0000 (12:20 +0900)
committerChalard Jean <jchalard@google.com>
Tue, 12 Jun 2018 10:03:16 +0000 (19:03 +0900)
Test: runtest
Change-Id: Idb7d2f2895aac63d54e3a6481379b739a726eff6

services/core/java/com/android/server/ConnectivityService.java
services/core/java/com/android/server/connectivity/ProxyTracker.java

index dadd327..69b2bbf 100644 (file)
@@ -3334,35 +3334,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                 && Uri.EMPTY.equals(proxy.getPacFileUrl())) {
             proxy = null;
         }
-        synchronized (mProxyTracker.mProxyLock) {
-            if (mProxyTracker.mDefaultProxy != null && mProxyTracker.mDefaultProxy.equals(proxy)) {
-                return;
-            }
-            if (mProxyTracker.mDefaultProxy == proxy) return; // catches repeated nulls
-            if (proxy != null &&  !proxy.isValid()) {
-                if (DBG) log("Invalid proxy properties, ignoring: " + proxy.toString());
-                return;
-            }
-
-            // This call could be coming from the PacManager, containing the port of 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.
-            // TODO: Switch PacManager to have its own message to send back rather than
-            // reusing EVENT_HAS_CHANGED_PROXY and this call to handleApplyDefaultProxy.
-            if ((mProxyTracker.mGlobalProxy != null) && (proxy != null)
-                    && (!Uri.EMPTY.equals(proxy.getPacFileUrl()))
-                    && proxy.getPacFileUrl().equals(mProxyTracker.mGlobalProxy.getPacFileUrl())) {
-                mProxyTracker.mGlobalProxy = proxy;
-                mProxyTracker.sendProxyBroadcast(mProxyTracker.mGlobalProxy);
-                return;
-            }
-            mProxyTracker.mDefaultProxy = proxy;
-
-            if (mProxyTracker.mGlobalProxy != null) return;
-            if (!mProxyTracker.mDefaultProxyDisabled) {
-                mProxyTracker.sendProxyBroadcast(proxy);
-            }
-        }
+        mProxyTracker.setDefaultProxy(proxy);
     }
 
     // If the proxy has changed from oldLp to newLp, resend proxy broadcast with default proxy.
index 3722166..98c161d 100644 (file)
@@ -120,7 +120,7 @@ public class ProxyTracker {
         return mPacManager.setCurrentProxyScriptUrl(proxy);
     }
 
-    // TODO : make the argument NonNull final
+    // TODO : make the argument NonNull final and the method private
     public void sendProxyBroadcast(@Nullable ProxyInfo proxy) {
         if (proxy == null) proxy = new ProxyInfo("", 0, "");
         if (setCurrentProxyScriptUrl(proxy)) return;
@@ -182,4 +182,36 @@ public class ProxyTracker {
             sendProxyBroadcast(mGlobalProxy == null ? mDefaultProxy : proxyProperties);
         }
     }
+
+    public void setDefaultProxy(@Nullable ProxyInfo proxy) {
+        synchronized (mProxyLock) {
+            if (mDefaultProxy != null && mDefaultProxy.equals(proxy)) {
+                return;
+            }
+            if (mDefaultProxy == proxy) return; // catches repeated nulls
+            if (proxy != null &&  !proxy.isValid()) {
+                if (DBG) Slog.d(TAG, "Invalid proxy properties, ignoring: " + proxy);
+                return;
+            }
+
+            // This call could be coming from the PacManager, containing the port of 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.
+            // TODO: Switch PacManager to have its own message to send back rather than
+            // reusing EVENT_HAS_CHANGED_PROXY and this call to handleApplyDefaultProxy.
+            if ((mGlobalProxy != null) && (proxy != null)
+                    && (!Uri.EMPTY.equals(proxy.getPacFileUrl()))
+                    && proxy.getPacFileUrl().equals(mGlobalProxy.getPacFileUrl())) {
+                mGlobalProxy = proxy;
+                sendProxyBroadcast(mGlobalProxy);
+                return;
+            }
+            mDefaultProxy = proxy;
+
+            if (mGlobalProxy != null) return;
+            if (!mDefaultProxyDisabled) {
+                sendProxyBroadcast(proxy);
+            }
+        }
+    }
 }