diff options
author | Etan Cohen <etancohen@google.com> | 2015-04-24 13:58:45 -0700 |
---|---|---|
committer | Etan Cohen <etancohen@google.com> | 2015-04-24 13:58:45 -0700 |
commit | a179962b61a9c41e8859ce642471928f1ad33c60 (patch) | |
tree | fb959b39f5734a9188712c29555ed6712f7d3687 /packages/CaptivePortalLogin/src | |
parent | f491a5844a2ee989e4a0aa109c62fa62ad07737f (diff) | |
parent | 25a217c0fbda9bbaf58ec08b91115e99f73b727f (diff) | |
download | frameworks_base-a179962b61a9c41e8859ce642471928f1ad33c60.zip frameworks_base-a179962b61a9c41e8859ce642471928f1ad33c60.tar.gz frameworks_base-a179962b61a9c41e8859ce642471928f1ad33c60.tar.bz2 |
Merge commit '25a217c' into merge2
Change-Id: I116a9dbf19e95651a7c50393e4dcd7fb59ca3f3f
Diffstat (limited to 'packages/CaptivePortalLogin/src')
-rw-r--r-- | packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java index e4054ac..b86fc4b 100644 --- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java @@ -56,24 +56,13 @@ public class CaptivePortalLoginActivity extends Activity { private static final String DEFAULT_SERVER = "connectivitycheck.android.com"; private static final int SOCKET_TIMEOUT_MS = 10000; - // Keep this in sync with NetworkMonitor. - // Intent broadcast to ConnectivityService indicating sign-in is complete. - // Extras: - // EXTRA_TEXT = netId - // LOGGED_IN_RESULT = one of the CAPTIVE_PORTAL_APP_RETURN_* values below. - // RESPONSE_TOKEN = data fragment from launching Intent - private static final String ACTION_CAPTIVE_PORTAL_LOGGED_IN = - "android.net.netmon.captive_portal_logged_in"; - private static final String LOGGED_IN_RESULT = "result"; - private static final int CAPTIVE_PORTAL_APP_RETURN_APPEASED = 0; - private static final int CAPTIVE_PORTAL_APP_RETURN_UNWANTED = 1; - private static final int CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS = 2; - private static final String RESPONSE_TOKEN = "response_token"; + private enum Result { DISMISSED, UNWANTED, WANTED_AS_IS }; private URL mURL; - private int mNetId; + private Network mNetwork; private String mResponseToken; private NetworkCallback mNetworkCallback; + private ConnectivityManager mCm; @Override protected void onCreate(Bundle savedInstanceState) { @@ -81,23 +70,19 @@ public class CaptivePortalLoginActivity extends Activity { String server = Settings.Global.getString(getContentResolver(), "captive_portal_server"); if (server == null) server = DEFAULT_SERVER; + mCm = ConnectivityManager.from(this); try { mURL = new URL("http", server, "/generate_204"); - final Uri dataUri = getIntent().getData(); - if (!dataUri.getScheme().equals("netid")) { - throw new MalformedURLException(); - } - mNetId = Integer.parseInt(dataUri.getSchemeSpecificPart()); - mResponseToken = dataUri.getFragment(); - } catch (MalformedURLException|NumberFormatException e) { + } catch (MalformedURLException e) { // System misconfigured, bail out in a way that at least provides network access. - done(CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS); + Log.e(TAG, "Invalid captive portal URL, server=" + server); + done(Result.WANTED_AS_IS); } + mNetwork = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK); + mResponseToken = getIntent().getStringExtra(ConnectivityManager.EXTRA_CAPTIVE_PORTAL_TOKEN); - final ConnectivityManager cm = ConnectivityManager.from(this); - final Network network = new Network(mNetId); // Also initializes proxy system properties. - cm.bindProcessToNetwork(network); + mCm.bindProcessToNetwork(mNetwork); // Proxy system properties must be initialized before setContentView is called because // setContentView initializes the WebView logic which in turn reads the system properties. @@ -106,7 +91,7 @@ public class CaptivePortalLoginActivity extends Activity { getActionBar().setDisplayShowHomeEnabled(false); // Exit app if Network disappears. - final NetworkCapabilities networkCapabilities = cm.getNetworkCapabilities(network); + final NetworkCapabilities networkCapabilities = mCm.getNetworkCapabilities(mNetwork); if (networkCapabilities == null) { finish(); return; @@ -114,14 +99,14 @@ public class CaptivePortalLoginActivity extends Activity { mNetworkCallback = new NetworkCallback() { @Override public void onLost(Network lostNetwork) { - if (network.equals(lostNetwork)) done(CAPTIVE_PORTAL_APP_RETURN_UNWANTED); + if (mNetwork.equals(lostNetwork)) done(Result.UNWANTED); } }; final NetworkRequest.Builder builder = new NetworkRequest.Builder(); for (int transportType : networkCapabilities.getTransportTypes()) { builder.addTransportType(transportType); } - cm.registerNetworkCallback(builder.build(), mNetworkCallback); + mCm.registerNetworkCallback(builder.build(), mNetworkCallback); final WebView myWebView = (WebView) findViewById(R.id.webview); myWebView.clearCache(true); @@ -158,15 +143,21 @@ public class CaptivePortalLoginActivity extends Activity { } } - private void done(int result) { + private void done(Result result) { if (mNetworkCallback != null) { - ConnectivityManager.from(this).unregisterNetworkCallback(mNetworkCallback); + mCm.unregisterNetworkCallback(mNetworkCallback); + } + switch (result) { + case DISMISSED: + mCm.reportCaptivePortalDismissed(mNetwork, mResponseToken); + break; + case UNWANTED: + mCm.ignoreNetworkWithCaptivePortal(mNetwork, mResponseToken); + break; + case WANTED_AS_IS: + mCm.useNetworkWithCaptivePortal(mNetwork, mResponseToken); + break; } - Intent intent = new Intent(ACTION_CAPTIVE_PORTAL_LOGGED_IN); - intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(mNetId)); - intent.putExtra(LOGGED_IN_RESULT, String.valueOf(result)); - intent.putExtra(RESPONSE_TOKEN, mResponseToken); - sendBroadcast(intent); finish(); } @@ -190,11 +181,11 @@ public class CaptivePortalLoginActivity extends Activity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_use_network) { - done(CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS); + done(Result.WANTED_AS_IS); return true; } if (id == R.id.action_do_not_use_network) { - done(CAPTIVE_PORTAL_APP_RETURN_UNWANTED); + done(Result.UNWANTED); return true; } return super.onOptionsItemSelected(item); @@ -223,7 +214,7 @@ public class CaptivePortalLoginActivity extends Activity { if (urlConnection != null) urlConnection.disconnect(); } if (httpResponseCode == 204) { - done(CAPTIVE_PORTAL_APP_RETURN_APPEASED); + done(Result.DISMISSED); } } }).start(); |