Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eff74270 authored by Brandon McAnsh's avatar Brandon McAnsh
Browse files

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: default avatarBrandon McAnsh <brandon.mcansh@gmail.com>
parent 79f63d23
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -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,6 +170,13 @@ public class WifiSetupPage extends SetupPage {
                getCallbacks().onNextPage();
            }
        } else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) {
            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, "token_mismatch");
                launchWifiSetup();
            } else {
                if (resultCode == Activity.RESULT_CANCELED) {
                    SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
                            SetupStats.Action.EXTERNAL_PAGE_RESULT,
@@ -174,6 +188,7 @@ public class WifiSetupPage extends SetupPage {
                            SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "success");
                    getCallbacks().onNextPage();
                }
            }
        }  else {
            return false;
        }