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

Commit 494b20c8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Store the number of saved networks in WifiTracker."

parents 72ba815c a80ae0c0
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ public class WifiTracker {

    private WifiTrackerNetworkCallback mNetworkCallback;

    private boolean mSavedNetworksExist;
    private int mNumSavedNetworks;
    private boolean mRegistered;

    /** Updated using main handler. Clone of this collection is returned
@@ -363,11 +363,11 @@ public class WifiTracker {
    }

    /**
     * @return true when there are saved networks on the device, regardless
     * of whether the WifiTracker is tracking saved networks.
     * Returns the number of saved networks on the device, regardless of whether the WifiTracker
     * is tracking saved networks.
     */
    public boolean doSavedNetworksExist() {
        return mSavedNetworksExist;
    public int getNumSavedNetworks() {
        return mNumSavedNetworks;
    }

    public boolean isConnected() {
@@ -461,11 +461,12 @@ public class WifiTracker {

        final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
        if (configs != null) {
            mSavedNetworksExist = configs.size() != 0;
            mNumSavedNetworks = 0;
            for (WifiConfiguration config : configs) {
                if (config.selfAdded && config.numAssociation == 0) {
                    continue;
                }
                mNumSavedNetworks++;
                AccessPoint accessPoint = getCachedOrCreate(config, cachedAccessPoints);
                if (mLastInfo != null && mLastNetworkInfo != null) {
                    accessPoint.update(connectionConfig, mLastInfo, mLastNetworkInfo);
+20 −0
Original line number Diff line number Diff line
@@ -394,6 +394,26 @@ public class WifiTrackerTest {
                .unregisterNetworkScoreCache(NetworkKey.TYPE_WIFI, scoreCache);
    }

    @Test
    public void testGetNumSavedNetworks() throws InterruptedException {
        WifiConfiguration validConfig = new WifiConfiguration();
        validConfig.SSID = SSID_1;
        validConfig.BSSID = BSSID_1;

        WifiConfiguration selfAddedNoAssociation = new WifiConfiguration();
        selfAddedNoAssociation.selfAdded = true;
        selfAddedNoAssociation.numAssociation = 0;
        selfAddedNoAssociation.SSID = SSID_2;
        selfAddedNoAssociation.BSSID = BSSID_2;

        when(mockWifiManager.getConfiguredNetworks())
                .thenReturn(Arrays.asList(validConfig, selfAddedNoAssociation));

        WifiTracker tracker = createTrackerWithImmediateBroadcastsAndInjectInitialScanResults();

        assertEquals(1, tracker.getNumSavedNetworks());
    }

    @Test
    public void startTrackingShouldSetConnectedAccessPointAsActive() throws InterruptedException {
        WifiTracker tracker =  createTrackerWithScanResultsAndAccessPoint1Connected();