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

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

Merge "Display connected AP when there are no scanresults"

parents e3ecb7a0 06ec3bed
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();