diff options
author | Paul Jensen <pauljensen@google.com> | 2014-11-26 19:42:10 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-11-26 19:42:10 +0000 |
commit | 70629916864bee1cf7a0df3fa1566efa9e7c300f (patch) | |
tree | 60155e1f060d9fae7979b1a0b55fbf25acb60ff8 /packages/CaptivePortalLogin | |
parent | e63c22242721a84259015374abd1477355098df8 (diff) | |
parent | f19f90b229c9d15b33895988fd5e4e13d786f616 (diff) | |
download | frameworks_base-70629916864bee1cf7a0df3fa1566efa9e7c300f.zip frameworks_base-70629916864bee1cf7a0df3fa1566efa9e7c300f.tar.gz frameworks_base-70629916864bee1cf7a0df3fa1566efa9e7c300f.tar.bz2 |
am f19f90b2: am 58a493ac: am be3736d3: Merge "Don\'t let NetworkMonitor state stop user-initiated transitions." into lmp-mr1-dev
* commit 'f19f90b229c9d15b33895988fd5e4e13d786f616':
Don't let NetworkMonitor state stop user-initiated transitions.
Diffstat (limited to 'packages/CaptivePortalLogin')
-rw-r--r-- | packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java index 7a262de..1c7b033 100644 --- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java +++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java @@ -62,13 +62,19 @@ public class CaptivePortalLoginActivity extends Activity { // Intent broadcast to ConnectivityService indicating sign-in is complete. // Extras: // EXTRA_TEXT = netId - // LOGGED_IN_RESULT = "1" if we should use network, "0" if not. + // 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 URL mURL; private int mNetId; + private String mResponseToken; private NetworkCallback mNetworkCallback; @Override @@ -78,12 +84,18 @@ public class CaptivePortalLoginActivity extends Activity { String server = Settings.Global.getString(getContentResolver(), "captive_portal_server"); if (server == null) server = DEFAULT_SERVER; try { - mURL = new URL("http://" + server + "/generate_204"); - } catch (MalformedURLException e) { - done(true); + 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) { + // System misconfigured, bail out in a way that at least provides network access. + done(CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS); } - mNetId = Integer.parseInt(getIntent().getStringExtra(Intent.EXTRA_TEXT)); final Network network = new Network(mNetId); ConnectivityManager.setProcessDefaultNetwork(network); @@ -121,7 +133,7 @@ public class CaptivePortalLoginActivity extends Activity { mNetworkCallback = new NetworkCallback() { @Override public void onLost(Network lostNetwork) { - if (network.equals(lostNetwork)) done(false); + if (network.equals(lostNetwork)) done(CAPTIVE_PORTAL_APP_RETURN_UNWANTED); } }; final NetworkRequest.Builder builder = new NetworkRequest.Builder(); @@ -165,11 +177,14 @@ public class CaptivePortalLoginActivity extends Activity { } } - private void done(boolean use_network) { - ConnectivityManager.from(this).unregisterNetworkCallback(mNetworkCallback); + private void done(int result) { + if (mNetworkCallback != null) { + ConnectivityManager.from(this).unregisterNetworkCallback(mNetworkCallback); + } Intent intent = new Intent(ACTION_CAPTIVE_PORTAL_LOGGED_IN); intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(mNetId)); - intent.putExtra(LOGGED_IN_RESULT, use_network ? "1" : "0"); + intent.putExtra(LOGGED_IN_RESULT, String.valueOf(result)); + intent.putExtra(RESPONSE_TOKEN, mResponseToken); sendBroadcast(intent); finish(); } @@ -194,11 +209,11 @@ public class CaptivePortalLoginActivity extends Activity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_use_network) { - done(true); + done(CAPTIVE_PORTAL_APP_RETURN_WANTED_AS_IS); return true; } if (id == R.id.action_do_not_use_network) { - done(false); + done(CAPTIVE_PORTAL_APP_RETURN_UNWANTED); return true; } return super.onOptionsItemSelected(item); @@ -227,7 +242,7 @@ public class CaptivePortalLoginActivity extends Activity { if (urlConnection != null) urlConnection.disconnect(); } if (httpResponseCode == 204) { - done(true); + done(CAPTIVE_PORTAL_APP_RETURN_APPEASED); } } }).start(); |