Fix duplicate network request entry during connection

When connecting to a network request, a new NetworkRequestEntry is
created by WifiPickerTracker alongside the unsaved regular network,
which results in two of the same network appearing during the L2
connection phase. To fix this, filter out any disconnected networks that
have the same SSID and security type as the currently connecting
network.

Bug: 292064115
Test: manually verify no duplicate network appears when connecting to
network request

Change-Id: I3d6abb0d0a1e4eeab1b8fa396660851ba090c611
This commit is contained in:
Quang Anh Luong
2023-07-26 13:38:58 +09:00
parent b1feaf710d
commit ae485a6774

View File

@@ -18,8 +18,6 @@ package com.android.settings.wifi;
import static com.android.wifitrackerlib.Utils.getSecurityTypesFromScanResult;
import static java.util.stream.Collectors.toList;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
@@ -273,19 +271,31 @@ public class NetworkRequestDialogFragment extends NetworkRequestDialogBaseFragme
@VisibleForTesting
void updateWifiEntries() {
final List<WifiEntry> wifiEntries = new ArrayList<>();
if (mWifiPickerTracker.getConnectedWifiEntry() != null) {
wifiEntries.add(mWifiPickerTracker.getConnectedWifiEntry());
WifiEntry connectedWifiEntry = mWifiPickerTracker.getConnectedWifiEntry();
String connectedSsid;
if (connectedWifiEntry != null) {
connectedSsid = connectedWifiEntry.getSsid();
wifiEntries.add(connectedWifiEntry);
} else {
connectedSsid = null;
}
wifiEntries.addAll(mWifiPickerTracker.getWifiEntries());
mFilteredWifiEntries.clear();
mFilteredWifiEntries.addAll(wifiEntries.stream()
.filter(entry -> isMatchedWifiEntry(entry))
.filter(entry -> isMatchedWifiEntry(entry, connectedSsid))
.limit(mShowLimitedItem ? MAX_NUMBER_LIST_ITEM : Long.MAX_VALUE)
.collect(toList()));
.toList());
}
private boolean isMatchedWifiEntry(WifiEntry entry) {
private boolean isMatchedWifiEntry(WifiEntry entry, String connectedSsid) {
if (entry.getConnectedState() == WifiEntry.CONNECTED_STATE_DISCONNECTED
&& TextUtils.equals(entry.getSsid(), connectedSsid)) {
// WifiPickerTracker may return a duplicate unsaved network that is separate from
// the connecting app-requested network, so make sure we only show the connected
// app-requested one.
return false;
}
for (MatchWifi wifi : mMatchWifis) {
if (!TextUtils.equals(entry.getSsid(), wifi.mSsid)) {
continue;