WifiSetup: Pass the correct componentName and data for captivePortal

* CaptivePortal expects the networkid, which was not being passed on via the intent
* Also use the correct componentName to bring up the sign in page

Change-Id: I83d80dc3ec026d7a5a5d4b8bf4cf577214a13da4
Signed-off-by: Brandon McAnsh <brandon.mcansh@gmail.com>
This commit is contained in:
Brandon McAnsh 2015-06-27 16:41:39 -04:00
parent 79f63d23c1
commit eff742708f
1 changed files with 25 additions and 10 deletions

View File

@ -19,9 +19,11 @@ package com.cyanogenmod.setupwizard.setup;
import android.app.Activity;
import android.app.ActivityOptions;
import android.app.FragmentManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
@ -38,6 +40,7 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;
public class WifiSetupPage extends SetupPage {
@ -46,9 +49,6 @@ public class WifiSetupPage extends SetupPage {
private static final String DEFAULT_SERVER = "clients3.google.com";
private static final int CAPTIVE_PORTAL_SOCKET_TIMEOUT_MS = 10000;
private static final String CAPTIVE_PORTAL_LOGIN_ACTION
= "android.net.action.captive_portal_login";
private LoadingFragment mLoadingFragment;
private URL mCaptivePortalUrl;
@ -57,6 +57,8 @@ public class WifiSetupPage extends SetupPage {
private final Handler mHandler = new Handler();
private String mResponseToken;
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
@Override
public void run() {
@ -64,7 +66,12 @@ public class WifiSetupPage extends SetupPage {
try {
int netId = ConnectivityManager.from(mContext)
.getNetworkForType(ConnectivityManager.TYPE_WIFI).netId;
Intent intent = new Intent(CAPTIVE_PORTAL_LOGIN_ACTION);
mResponseToken = String.valueOf(new Random().nextLong());
Intent intent = new Intent();
intent.setData(Uri.fromParts("netid", Integer.toString(netId),
mResponseToken));
intent.setComponent(new ComponentName("com.android.captiveportallogin",
"com.android.captiveportallogin.CaptivePortalLoginActivity"));
intent.putExtra(Intent.EXTRA_TEXT, String.valueOf(netId));
intent.putExtra("status_bar_color",
mContext.getResources().getColor(R.color.primary_dark));
@ -163,16 +170,24 @@ public class WifiSetupPage extends SetupPage {
getCallbacks().onNextPage();
}
} else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) {
if (resultCode == Activity.RESULT_CANCELED) {
String token = data.getStringExtra("response_token");
if (token != null && !token.equals(mResponseToken)) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "canceled");
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "token_mismatch");
launchWifiSetup();
} else {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "success");
getCallbacks().onNextPage();
if (resultCode == Activity.RESULT_CANCELED) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "canceled");
launchWifiSetup();
} else {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "success");
getCallbacks().onNextPage();
}
}
} else {
return false;