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

Commit 06ec3bed authored by Sundeep Ghuman's avatar Sundeep Ghuman
Browse files

Display connected AP when there are no scanresults

Bug: 68030053
Test: runtest --path
    frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java
1. Visual verification of UI when opening WifiSettings directly from
screen off longer than 5 minutes (no scan results scenario).

Change-Id: I7e4d9a3abb861b485b0a952a1a4b822f2460bdc2
parent 062bf5a9
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -527,10 +527,7 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro

        WifiConfiguration connectionConfig = null;
        if (mLastInfo != null) {
            // TODO(sghuman): Refactor to match config network id when updating configs below, and
            // then update network info and wifi info only on match
            connectionConfig = getWifiConfigurationForNetworkId(
                    mLastInfo.getNetworkId(), configs);
            connectionConfig = getWifiConfigurationForNetworkId(mLastInfo.getNetworkId(), configs);
        }

        // Rather than dropping and reacquiring the lock multiple times in this method, we lock
@@ -564,6 +561,17 @@ public class WifiTracker implements LifecycleObserver, OnStart, OnStop, OnDestro
                accessPoints.add(accessPoint);
            }

            // If there were no scan results, create an AP for the currently connected network (if
            // it exists).
            // TODO(sghuman): Investigate if this works for an ephemeral (auto-connected) network
            // when there are no scan results, as it may not have a valid WifiConfiguration
            if (accessPoints.isEmpty() && connectionConfig != null) {
                AccessPoint activeAp = new AccessPoint(mContext, connectionConfig);
                activeAp.update(connectionConfig, mLastInfo, mLastNetworkInfo);
                accessPoints.add(activeAp);
                scoresToRequest.add(NetworkKey.createFromWifiInfo(mLastInfo));
            }

            requestScoresForNetworkKeys(scoresToRequest);
            for (AccessPoint ap : accessPoints) {
                ap.update(mScoreCache, mNetworkScoringUiEnabled, mMaxSpeedLabelScoreCacheAge);
+30 −0
Original line number Diff line number Diff line
@@ -695,6 +695,36 @@ public class WifiTrackerTest {
        assertThat(tracker.getAccessPoints().get(0).isActive()).isTrue();
    }

    @Test
    public void onStartShouldDisplayConnectedAccessPointWhenThereAreNoScanResults()
            throws Exception {
        Network mockNetwork = mock(Network.class);
        when(mockWifiManager.getCurrentNetwork()).thenReturn(mockNetwork);

        when(mockWifiManager.getConnectionInfo()).thenReturn(CONNECTED_AP_1_INFO);

        NetworkInfo networkInfo = new NetworkInfo(
                ConnectivityManager.TYPE_WIFI, 0, "Type Wifi", "subtype");
        networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "connected", "test");
        when(mockConnectivityManager.getNetworkInfo(any(Network.class))).thenReturn(networkInfo);

        // Don't return any scan results
        when(mockWifiManager.getScanResults()).thenReturn(new ArrayList<>());

        WifiTracker tracker = createMockedWifiTracker();
        startTracking(tracker);

        verify(mockWifiManager).getConnectionInfo();
        verify(mockWifiManager, times(1)).getConfiguredNetworks();
        verify(mockConnectivityManager).getNetworkInfo(any(Network.class));

        // mStaleAccessPoints is true
        verify(mockWifiListenerExecutor, never()).onAccessPointsChanged();

        assertThat(tracker.getAccessPoints().size()).isEqualTo(1);
        assertThat(tracker.getAccessPoints().get(0).isActive()).isTrue();
    }

    @Test
    public void stopTrackingShouldRemoveAllPendingWork() throws Exception {
        WifiTracker tracker = createMockedWifiTracker();