Fix automatically directing the user to the captive portal in Wi-Fi Slice

The feature failed after the CL "Force the adapter to rebind cards with
a toggle".

Because toggle slices have been forced to rebind after starting another
activity and when any slice is updating. This unpins Wi-Fi slice and
stops WifiScanWorker and then clears the saved clicked network.

Solution:
1. Change ConnectToWifiHandler from activity to receiver and send
   broadcasts to it with FLAG_RECEIVER_FOREGROUND, so Wi-Fi slice won't
   be forced to rebind.
2. Seperate Wi-Fi scan worker and contextual Wi-Fi scan worker. Keep the
   original logic for the generic one, and then add the logic below to
   the contextual one.
3. Do not clear the saved clicked network when slice is unppined because
   it happens frequently in contextual homepage.
4. Introduce a static long in ContextualWifiScanWorker that updates once
   in every visible UI session. A session is when the screen is visible
   to user.
5. Use session token to determine whether auto-starting captive portal
   is needed.

Fixes: 128056349
Test: robotest, visual in homepage and network panel
Change-Id: I9e03c379806e124fa7253b2a635574b2433f6afc
This commit is contained in:
Jason Chiu
2019-04-30 14:41:19 +08:00
parent 42aac32823
commit 2c3e6c6434
13 changed files with 303 additions and 103 deletions

View File

@@ -16,7 +16,9 @@
package com.android.settings.wifi.slice;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.wifi.WifiManager;
@@ -30,35 +32,36 @@ import com.android.settings.wifi.WifiUtils;
import com.android.settingslib.wifi.AccessPoint;
/**
* This activity helps connect to the Wi-Fi network which is open or saved
* This receiver helps connect to Wi-Fi network
*/
public class ConnectToWifiHandler extends Activity {
public class ConnectToWifiHandler extends BroadcastReceiver {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onReceive(Context context, Intent intent) {
if (context == null || intent == null) {
return;
}
final Network network = getIntent().getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
final Bundle accessPointState = getIntent().getBundleExtra(
final Network network = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK);
final Bundle accessPointState = intent.getBundleExtra(
WifiDialogActivity.KEY_ACCESS_POINT_STATE);
if (network != null) {
WifiScanWorker.clearClickedWifi();
final ConnectivityManager cm = getSystemService(ConnectivityManager.class);
final ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
// start captive portal app to sign in to network
cm.startCaptivePortalApp(network);
} else if (accessPointState != null) {
connect(new AccessPoint(this, accessPointState));
connect(context, new AccessPoint(context, accessPointState));
}
finish();
}
@VisibleForTesting
void connect(AccessPoint accessPoint) {
void connect(Context context, AccessPoint accessPoint) {
ContextualWifiScanWorker.saveSession();
WifiScanWorker.saveClickedWifi(accessPoint);
final WifiConnectListener connectListener = new WifiConnectListener(this);
final WifiConnectListener connectListener = new WifiConnectListener(context);
switch (WifiUtils.getConnectingType(accessPoint)) {
case WifiUtils.CONNECT_TYPE_OSU_PROVISION:
accessPoint.startOsuProvisioning(connectListener);
@@ -68,7 +71,7 @@ public class ConnectToWifiHandler extends Activity {
accessPoint.generateOpenNetworkConfig();
case WifiUtils.CONNECT_TYPE_SAVED_NETWORK:
final WifiManager wifiManager = getSystemService(WifiManager.class);
final WifiManager wifiManager = context.getSystemService(WifiManager.class);
wifiManager.connect(accessPoint.getConfig(), connectListener);
break;
}