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:
@@ -50,7 +50,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link SliceBackgroundWorker} for Wi-Fi, used by WifiSlice.
|
||||
* {@link SliceBackgroundWorker} for Wi-Fi, used by {@link WifiSlice}.
|
||||
*/
|
||||
public class WifiScanWorker extends SliceBackgroundWorker<AccessPoint> implements
|
||||
WifiTracker.WifiListener {
|
||||
@@ -84,7 +84,7 @@ public class WifiScanWorker extends SliceBackgroundWorker<AccessPoint> implement
|
||||
protected void onSliceUnpinned() {
|
||||
mWifiTracker.onStop();
|
||||
unregisterNetworkCallback();
|
||||
clearClickedWifi();
|
||||
clearClickedWifiOnSliceUnpinned();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -157,6 +157,14 @@ public class WifiScanWorker extends SliceBackgroundWorker<AccessPoint> implement
|
||||
return !TextUtils.isEmpty(ssid) && TextUtils.equals(ssid, sClickedWifiSsid);
|
||||
}
|
||||
|
||||
protected void clearClickedWifiOnSliceUnpinned() {
|
||||
clearClickedWifi();
|
||||
}
|
||||
|
||||
protected boolean isSessionValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void registerNetworkCallback(Network wifiNetwork) {
|
||||
if (wifiNetwork == null) {
|
||||
return;
|
||||
@@ -224,12 +232,13 @@ public class WifiScanWorker extends SliceBackgroundWorker<AccessPoint> implement
|
||||
|
||||
// Automatically start captive portal
|
||||
if (!prevIsCaptivePortal && mIsCaptivePortal
|
||||
&& isWifiClicked(mWifiTracker.getManager().getConnectionInfo())) {
|
||||
&& isWifiClicked(mWifiTracker.getManager().getConnectionInfo())
|
||||
&& isSessionValid()) {
|
||||
final Intent intent = new Intent(mContext, ConnectToWifiHandler.class)
|
||||
.putExtra(ConnectivityManager.EXTRA_NETWORK, network)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
// Starting activity in the system process needs to specify a user
|
||||
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
|
||||
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
// Sending a broadcast in the system process needs to specify a user
|
||||
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user