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:
parent
79f63d23c1
commit
eff742708f
|
@ -19,9 +19,11 @@ package com.cyanogenmod.setupwizard.setup;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityOptions;
|
import android.app.ActivityOptions;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
@ -38,6 +40,7 @@ import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class WifiSetupPage extends SetupPage {
|
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 String DEFAULT_SERVER = "clients3.google.com";
|
||||||
private static final int CAPTIVE_PORTAL_SOCKET_TIMEOUT_MS = 10000;
|
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 LoadingFragment mLoadingFragment;
|
||||||
|
|
||||||
private URL mCaptivePortalUrl;
|
private URL mCaptivePortalUrl;
|
||||||
|
@ -57,6 +57,8 @@ public class WifiSetupPage extends SetupPage {
|
||||||
|
|
||||||
private final Handler mHandler = new Handler();
|
private final Handler mHandler = new Handler();
|
||||||
|
|
||||||
|
private String mResponseToken;
|
||||||
|
|
||||||
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
|
private Runnable mFinishCaptivePortalCheckRunnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -64,7 +66,12 @@ public class WifiSetupPage extends SetupPage {
|
||||||
try {
|
try {
|
||||||
int netId = ConnectivityManager.from(mContext)
|
int netId = ConnectivityManager.from(mContext)
|
||||||
.getNetworkForType(ConnectivityManager.TYPE_WIFI).netId;
|
.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(Intent.EXTRA_TEXT, String.valueOf(netId));
|
||||||
intent.putExtra("status_bar_color",
|
intent.putExtra("status_bar_color",
|
||||||
mContext.getResources().getColor(R.color.primary_dark));
|
mContext.getResources().getColor(R.color.primary_dark));
|
||||||
|
@ -163,16 +170,24 @@ public class WifiSetupPage extends SetupPage {
|
||||||
getCallbacks().onNextPage();
|
getCallbacks().onNextPage();
|
||||||
}
|
}
|
||||||
} else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) {
|
} 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.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
|
||||||
SetupStats.Action.EXTERNAL_PAGE_RESULT,
|
SetupStats.Action.EXTERNAL_PAGE_RESULT,
|
||||||
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "canceled");
|
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "token_mismatch");
|
||||||
launchWifiSetup();
|
launchWifiSetup();
|
||||||
} else {
|
} else {
|
||||||
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
|
if (resultCode == Activity.RESULT_CANCELED) {
|
||||||
SetupStats.Action.EXTERNAL_PAGE_RESULT,
|
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
|
||||||
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "success");
|
SetupStats.Action.EXTERNAL_PAGE_RESULT,
|
||||||
getCallbacks().onNextPage();
|
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 {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue