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

Commit df9ca469 authored by Jeff Davidson's avatar Jeff Davidson
Browse files

Fix WifiTile's Connected indicator for ephemeral networks.

Such networks do not have a WifiConfiguration and need to be matched
by SSID.

Note a subtle difference with platform settings: in platform settings,
selecting an ephemeral network saves it for future use. That feels out
of place here, where normally clicking on the connected network does
nothing.

Bug: 18489098
Change-Id: I6aebd14054af47f078ffd8d754668817dff90436
parent 8ccf071a
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -42,6 +42,9 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.List;


// TODO: Unify this logic with platform settings (see WifiSettings and AccessPoint). There is a
// fair amount of complexity here in statuses and logic beyond just connected/disconnected.
public class AccessPointControllerImpl implements NetworkController.AccessPointController {
    private static final String TAG = "AccessPointController";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -142,8 +145,7 @@ public class AccessPointControllerImpl implements NetworkController.AccessPointC
                && v.charAt(v.length() - 1) == '\"' ? v.substring(1, v.length() - 1) : v;
    }

    private int getConnectedNetworkId() {
        final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    private int getConnectedNetworkId(WifiInfo wifiInfo) {
        return wifiInfo != null ? wifiInfo.getNetworkId() : AccessPoint.NO_NETWORK;
    }

@@ -158,7 +160,8 @@ public class AccessPointControllerImpl implements NetworkController.AccessPointC
    }

    private void updateAccessPoints() {
        final int connectedNetworkId = getConnectedNetworkId();
        final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
        final int connectedNetworkId = getConnectedNetworkId(wifiInfo);
        if (DEBUG) Log.d(TAG, "connectedNetworkId: " + connectedNetworkId);
        final List<ScanResult> scanResults = mWifiManager.getScanResults();
        final ArrayMap<String, WifiConfiguration> configured = getConfiguredNetworksBySsid();
@@ -179,8 +182,13 @@ public class AccessPointControllerImpl implements NetworkController.AccessPointC
            ap.networkId = config != null ? config.networkId : AccessPoint.NO_NETWORK;
            ap.ssid = ssid;
            ap.iconId = ICONS[level];
            ap.isConnected = ap.networkId != AccessPoint.NO_NETWORK
                    && ap.networkId == connectedNetworkId;
            // Connected if either:
            // -The network ID in the active WifiInfo matches this network's ID.
            // -The network is ephemeral (no configuration) but the SSID matches.
            ap.isConnected = (ap.networkId != AccessPoint.NO_NETWORK
                    && ap.networkId == connectedNetworkId) ||
                    (ap.networkId == WifiConfiguration.INVALID_NETWORK_ID && wifiInfo != null &&
                    ap.ssid.equals(trimDoubleQuotes(wifiInfo.getSSID())));
            ap.level = level;
            // Based on Settings AccessPoint#getSecurity, keep up to date
            // with better methods of determining no security or not.