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
This commit is contained in:
Udam Saini
2016-01-04 12:16:14 -08:00
parent 803faa182b
commit cd6454606c
4 changed files with 33 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.SdkConstant; import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType; import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; 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 * Tells the underlying networking system that the caller wants to
* begin using the named feature. The interpretation of {@code feature} * begin using the named feature. The interpretation of {@code feature}

View File

@@ -165,4 +165,6 @@ interface IConnectivityManager
in IBinder binder, String srcAddr, int srcPort, String dstAddr); in IBinder binder, String srcAddr, int srcPort, String dstAddr);
void stopKeepalive(in Network network, int slot); void stopKeepalive(in Network network, int slot);
String getCaptivePortalServerUrl();
} }

View File

@@ -4847,6 +4847,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
return success; return success;
} }
@Override
public String getCaptivePortalServerUrl() {
return NetworkMonitor.getCaptivePortalServerUrl(mContext);
}
@Override @Override
public void startNattKeepalive(Network network, int intervalSeconds, Messenger messenger, public void startNattKeepalive(Network network, int intervalSeconds, Messenger messenger,
IBinder binder, String srcAddr, int srcPort, String dstAddr) { IBinder binder, String srcAddr, int srcPort, String dstAddr) {

View File

@@ -59,6 +59,7 @@ import android.os.MessageQueue;
import android.os.MessageQueue.IdleHandler; import android.os.MessageQueue.IdleHandler;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log; import android.util.Log;
import android.util.LogPrinter; import android.util.LogPrinter;
@@ -1504,4 +1505,10 @@ public class ConnectivityServiceTest extends AndroidTestCase {
ka3.stop(); ka3.stop();
callback3.expectStopped(); callback3.expectStopped();
} }
@SmallTest
public void testGetCaptivePortalServerUrl() throws Exception {
String url = mCm.getCaptivePortalServerUrl();
assertEquals("http://connectivitycheck.gstatic.com/generate_204", url);
}
} }