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

Commit ac1026e6 authored by Quang Luong's avatar Quang Luong
Browse files

Added AccessPoint cache integration for OSU AccessPoints

Cached OSU APs will be used instead of creating a new OSU AP on every
updateAccessPoints(). This will ensure that the OSU AP seen by
WifiTracker is the same as the OSU AP passed to the
AccessPointPreference, allowing the RSSI to be updated while retaining
information about the OSU provisioning status and failure code.

Tracking bug for adding robolectric tests: b/122849296

Bug: 118705403
Test: manual, build and log AP creation and cache access.
Change-Id: I0c3fdbeb2a28b5c4005a11ed1650f0c40a4f1d5c
parent 8d40a8ec
Loading
Loading
Loading
Loading
+34 −33
Original line number Diff line number Diff line
@@ -364,24 +364,13 @@ public class AccessPoint implements Comparable<AccessPoint> {
    /** Updates {@link #mKey} and should only called upon object creation/initialization. */
    private void updateKey() {
        // TODO(sghuman): Consolidate Key logic on ScanResultMatchInfo

        StringBuilder builder = new StringBuilder();

        if (isPasspoint()) {
            builder.append(KEY_PREFIX_FQDN).append(mConfig.FQDN);
            mKey = getKey(mConfig);
        } else if (isOsuProvider()) {
            builder.append(KEY_PREFIX_OSU).append(mOsuProvider.getOsuSsid());
            builder.append(',').append(mOsuProvider.getServerUri());
            mKey = getKey(mOsuProvider);
        } else { // Non-Passpoint AP
            builder.append(KEY_PREFIX_AP);
            if (TextUtils.isEmpty(getSsidStr())) {
                builder.append(getBssid());
            } else {
                builder.append(getSsidStr());
            }
            builder.append(',').append(getSecurity());
            mKey = getKey(getSsidStr(), getBssid(), getSecurity());
        }
        mKey = builder.toString();
    }

    /**
@@ -622,34 +611,46 @@ public class AccessPoint implements Comparable<AccessPoint> {
    }

    public static String getKey(ScanResult result) {
        StringBuilder builder = new StringBuilder();
        return getKey(result.SSID, result.BSSID, getSecurity(result));
    }

        builder.append(KEY_PREFIX_AP);
        if (TextUtils.isEmpty(result.SSID)) {
            builder.append(result.BSSID);
    /**
     * Returns the AccessPoint key for a WifiConfiguration.
     * This will return a special Passpoint key if the config is for Passpoint.
     */
    public static String getKey(WifiConfiguration config) {
        if (config.isPasspoint()) {
            return new StringBuilder()
                    .append(KEY_PREFIX_FQDN)
                    .append(config.FQDN).toString();
        } else {
            builder.append(result.SSID);
            return getKey(config.SSID, config.BSSID, getSecurity(config));
        }
    }

        builder.append(',').append(getSecurity(result));
        return builder.toString();
    /**
     * Returns the AccessPoint key corresponding to the OsuProvider.
     */
    public static String getKey(OsuProvider provider) {
        return new StringBuilder()
                .append(KEY_PREFIX_OSU)
                .append(provider.getOsuSsid())
                .append(',')
                .append(provider.getServerUri()).toString();
    }

    public static String getKey(WifiConfiguration config) {
    /**
     * Returns the AccessPoint key for a normal non-Passpoint network by ssid/bssid and security.
     */
    private static String getKey(String ssid, String bssid, int security) {
        StringBuilder builder = new StringBuilder();

        if (config.isPasspoint()) {
            builder.append(KEY_PREFIX_FQDN).append(config.FQDN);
        } else {
        builder.append(KEY_PREFIX_AP);
            if (TextUtils.isEmpty(config.SSID)) {
                builder.append(config.BSSID);
        if (TextUtils.isEmpty(ssid)) {
            builder.append(bssid);
        } else {
                builder.append(removeDoubleQuotes(config.SSID));
            }
            builder.append(',').append(getSecurity(config));
            builder.append(ssid);
        }

        builder.append(',').append(security);
        return builder.toString();
    }

+21 −3
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -628,9 +629,9 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
                            providersAndScans.keySet()).keySet();
            for (OsuProvider provider : providersAndScans.keySet()) {
                if (!alreadyProvisioned.contains(provider)) {
                    AccessPoint accessPointOsu = new AccessPoint(mContext, provider);
                    // TODO(b/118705403): accessPointOsu.setScanResults(Matching ScanResult with
                    // best RSSI)
                    // TODO(b/118705403): use real scan results for this provider
                    AccessPoint accessPointOsu =
                            getCachedOrCreateOsu(null, cachedAccessPoints, provider);
                    // TODO(b/118705403): Figure out if we would need to update an OSU AP (this will
                    // be used if we need to display it at the top of the picker as the "active" AP)
                    // Otherwise OSU APs should ignore attempts to update the active connection info
@@ -701,6 +702,23 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
        return accessPoint;
    }

    private AccessPoint getCachedOrCreateOsu(
            List<ScanResult> scanResults,
            List<AccessPoint> cache,
            OsuProvider provider) {
        ListIterator<AccessPoint> lit = cache.listIterator();
        while (lit.hasNext()) {
            final AccessPoint ret = lit.next();
            if (ret.getKey().equals(AccessPoint.getKey(provider))) {
                lit.remove();
                // TODO(b/118705403): Use real scan results for this.
                // ret.setScanResults(scanResults);
                return ret;
            }
        }
        return new AccessPoint(mContext, provider);
    }

    private void updateNetworkInfo(NetworkInfo networkInfo) {

        /* Sticky broadcasts can call this when wifi is disabled */