From cd6454606cfb258c512c5db45bea9e0af7eb59ec Mon Sep 17 00:00:00 2001 From: Udam Saini Date: Mon, 4 Jan 2016 12:16:14 -0800 Subject: [PATCH] Makes captive portal server calculation in one place. This also creates a hidden api for the captive portal server calculation so that the Setup Wizard can use this as well. bug:13246857 Change-Id: I4dfd0916df97cfce13252c7cc15f7bd05ed95f77 --- .../java/android/net/ConnectivityManager.java | 19 +++++++++++++++++++ .../android/net/IConnectivityManager.aidl | 2 ++ .../android/server/ConnectivityService.java | 5 +++++ .../server/ConnectivityServiceTest.java | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 515e9a27ee..595e4c6333 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -19,6 +19,7 @@ import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.SdkConstant; import android.annotation.SdkConstant.SdkConstantType; +import android.annotation.SystemApi; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; @@ -897,6 +898,24 @@ public class ConnectivityManager { } } + /** + * Gets the URL that should be used for resolving whether a captive portal is present. + * 1. This URL should respond with a 204 response to a GET request to indicate no captive + * portal is present. + * 2. This URL must be HTTP as redirect responses are used to find captive portal + * sign-in pages. Captive portals cannot respond to HTTPS requests with redirects. + * + * @hide + */ + @SystemApi + public String getCaptivePortalServerUrl() { + try { + return mService.getCaptivePortalServerUrl(); + } catch (RemoteException e) { + return null; + } + } + /** * Tells the underlying networking system that the caller wants to * begin using the named feature. The interpretation of {@code feature} diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl index d4dd669211..ef911373d4 100644 --- a/core/java/android/net/IConnectivityManager.aidl +++ b/core/java/android/net/IConnectivityManager.aidl @@ -165,4 +165,6 @@ interface IConnectivityManager in IBinder binder, String srcAddr, int srcPort, String dstAddr); void stopKeepalive(in Network network, int slot); + + String getCaptivePortalServerUrl(); } diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 65a27c8559..37a6c02439 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -4847,6 +4847,11 @@ public class ConnectivityService extends IConnectivityManager.Stub return success; } + @Override + public String getCaptivePortalServerUrl() { + return NetworkMonitor.getCaptivePortalServerUrl(mContext); + } + @Override public void startNattKeepalive(Network network, int intervalSeconds, Messenger messenger, IBinder binder, String srcAddr, int srcPort, String dstAddr) { diff --git a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java index 27deb720c4..27d5207165 100644 --- a/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/ConnectivityServiceTest.java @@ -59,6 +59,7 @@ import android.os.MessageQueue; import android.os.MessageQueue.IdleHandler; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.LargeTest; +import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; import android.util.LogPrinter; @@ -1504,4 +1505,10 @@ public class ConnectivityServiceTest extends AndroidTestCase { ka3.stop(); callback3.expectStopped(); } + + @SmallTest + public void testGetCaptivePortalServerUrl() throws Exception { + String url = mCm.getCaptivePortalServerUrl(); + assertEquals("http://connectivitycheck.gstatic.com/generate_204", url); + } }