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

Commit af1715e4 authored by Quang Luong's avatar Quang Luong Committed by Android (Google) Code Review
Browse files

Merge "Fix duplicate network request entry during connection" into udc-qpr-dev

parents baf2971e ae485a67
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -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;