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

Commit 995b8190 authored by Weng Su's avatar Weng Su
Browse files

[Provider Model] Listen for callback to highlight WiFi network

- The Highlighting WiFi network refers to the
WifiEntry#hasInternetAccess() function.

- The WifiEntry#hasInternetAccess() might not be updated immediately
when ConnectivityManager calls back a connected WiFi entry with Internet
capabilities.

- Need to listen the WifiEntry.onUpdated() callback to aware that
WifiEntry#hasInternetAccess() has been updated correctly.

- Also fixed a missing update for the WiFi max count issue

- See b/208701968#comment4 for the result video.

Bug: 208701968
Test: manual test
atest -c InternetAdapterTest \
         InternetDialogControllerTest \
         InternetDialogTest

Change-Id: I59be23643678c892f37ab8d4c7d2e33cb8c8f5b2
parent c5d0caf2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -466,9 +466,9 @@ public class InternetDialog extends SystemUIDialog implements
        }
        final int wifiListMaxCount = getWifiListMaxCount();
        if (mAdapter.getItemCount() > wifiListMaxCount) {
            mAdapter.setMaxEntriesCount(wifiListMaxCount);
            mHasMoreWifiEntries = true;
        }
        mAdapter.setMaxEntriesCount(wifiListMaxCount);
        final int wifiListMinHeight = mWifiNetworkHeight * wifiListMaxCount;
        if (mWifiRecyclerView.getMinimumHeight() != wifiListMinHeight) {
            mWifiRecyclerView.setMinimumHeight(wifiListMinHeight);
+56 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.qs.tiles.dialog;

import static com.android.settingslib.mobile.MobileMappings.getIconKey;
import static com.android.settingslib.mobile.MobileMappings.mapIconSets;
import static com.android.wifitrackerlib.WifiEntry.CONNECTED_STATE_CONNECTED;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -176,6 +177,8 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    protected KeyguardStateController mKeyguardStateController;
    @VisibleForTesting
    protected boolean mHasEthernet = false;
    @VisibleForTesting
    protected ConnectedWifiInternetMonitor mConnectedWifiInternetMonitor;

    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
@@ -236,6 +239,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        mSignalDrawable = new SignalDrawable(mContext);
        mLocationController = locationController;
        mDialogLaunchAnimator = dialogLaunchAnimator;
        mConnectedWifiInternetMonitor = new ConnectedWifiInternetMonitor();
    }

    void onStart(@NonNull InternetDialogCallback callback, boolean canConfigWifi) {
@@ -276,6 +280,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        mAccessPointController.removeAccessPointCallback(this);
        mKeyguardUpdateMonitor.removeCallback(mKeyguardUpdateCallback);
        mConnectivityManager.unregisterNetworkCallback(mConnectivityManagerNetworkCallback);
        mConnectedWifiInternetMonitor.unregisterCallback();
    }

    @VisibleForTesting
@@ -881,8 +886,10 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        if (accessPointsSize > 0) {
            wifiEntries = new ArrayList<>();
            final int count = hasMoreWifiEntries ? MAX_WIFI_ENTRY_COUNT : accessPointsSize;
            mConnectedWifiInternetMonitor.unregisterCallback();
            for (int i = 0; i < count; i++) {
                WifiEntry entry = accessPoints.get(i);
                mConnectedWifiInternetMonitor.registerCallbackIfNeed(entry);
                if (connectedEntry == null && entry.isDefaultNetwork()
                        && entry.hasInternetAccess()) {
                    connectedEntry = entry;
@@ -970,6 +977,55 @@ public class InternetDialogController implements AccessPointController.AccessPoi
        }
    }

    /**
     * Helper class for monitoring the Internet access of the connected WifiEntry.
     */
    @VisibleForTesting
    protected class ConnectedWifiInternetMonitor implements WifiEntry.WifiEntryCallback {

        private WifiEntry mWifiEntry;

        public void registerCallbackIfNeed(WifiEntry entry) {
            if (entry == null || mWifiEntry != null) {
                return;
            }
            // If the Wi-Fi is not connected yet, or it's the connected Wi-Fi with Internet
            // access. Then we don't need to listen to the callback to update the Wi-Fi entries.
            if (entry.getConnectedState() != CONNECTED_STATE_CONNECTED
                    || (entry.isDefaultNetwork() && entry.hasInternetAccess())) {
                return;
            }
            mWifiEntry = entry;
            entry.setListener(this);
        }

        public void unregisterCallback() {
            if (mWifiEntry == null) {
                return;
            }
            mWifiEntry.setListener(null);
            mWifiEntry = null;
        }

        @MainThread
        @Override
        public void onUpdated() {
            if (mWifiEntry == null) {
                return;
            }
            WifiEntry entry = mWifiEntry;
            if (entry.getConnectedState() != CONNECTED_STATE_CONNECTED) {
                unregisterCallback();
                return;
            }
            if (entry.isDefaultNetwork() && entry.hasInternetAccess()) {
                unregisterCallback();
                // Trigger onAccessPointsChanged() to update the Wi-Fi entries.
                scanWifiAccessPoints();
            }
        }
    }

    /**
     * Return {@code true} If the Ethernet exists
     */
+31 −0
Original line number Diff line number Diff line
@@ -544,6 +544,37 @@ public class InternetDialogControllerTest extends SysuiTestCase {
                null /* connectedEntry */, false /* hasMoreEntry */);
    }

    @Test
    public void onAccessPointsChanged_connectedWifiNoInternetAccess_shouldSetListener() {
        reset(mWifiEntry1);
        mAccessPoints.clear();
        when(mWifiEntry1.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
        when(mWifiEntry1.isDefaultNetwork()).thenReturn(true);
        when(mWifiEntry1.hasInternetAccess()).thenReturn(false);
        mAccessPoints.add(mWifiEntry1);

        mInternetDialogController.onAccessPointsChanged(mAccessPoints);

        verify(mWifiEntry1).setListener(mInternetDialogController.mConnectedWifiInternetMonitor);
    }

    @Test
    public void onUpdated_connectedWifiHasInternetAccess_shouldScanWifiAccessPoints() {
        reset(mAccessPointController);
        when(mWifiEntry1.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
        when(mWifiEntry1.isDefaultNetwork()).thenReturn(true);
        when(mWifiEntry1.hasInternetAccess()).thenReturn(false);
        InternetDialogController.ConnectedWifiInternetMonitor mConnectedWifiInternetMonitor =
                mInternetDialogController.mConnectedWifiInternetMonitor;
        mConnectedWifiInternetMonitor.registerCallbackIfNeed(mWifiEntry1);

        // When the hasInternetAccess() changed to true, and call back the onUpdated() function.
        when(mWifiEntry1.hasInternetAccess()).thenReturn(true);
        mConnectedWifiInternetMonitor.onUpdated();

        verify(mAccessPointController).scanForAccessPoints();
    }

    @Test
    public void setMergedCarrierWifiEnabledIfNeed_carrierProvisionsEnabled_doNothing() {
        when(mCarrierConfigTracker.getCarrierProvisionsWifiMergedNetworksBool(SUB_ID))
+5 −0
Original line number Diff line number Diff line
@@ -312,6 +312,7 @@ public class InternetDialogTest extends SysuiTestCase {
        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
        // Show a blank block to fix the dialog height even if there is no WiFi list
        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        verify(mInternetAdapter).setMaxEntriesCount(3);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.INVISIBLE);
    }

@@ -326,6 +327,7 @@ public class InternetDialogTest extends SysuiTestCase {
        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
        // Show a blank block to fix the dialog height even if there is no WiFi list
        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        verify(mInternetAdapter).setMaxEntriesCount(3);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.INVISIBLE);
    }

@@ -339,6 +341,7 @@ public class InternetDialogTest extends SysuiTestCase {
        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.VISIBLE);
        // Show a blank block to fix the dialog height even if there is no WiFi list
        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        verify(mInternetAdapter).setMaxEntriesCount(2);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.INVISIBLE);
    }

@@ -353,6 +356,7 @@ public class InternetDialogTest extends SysuiTestCase {

        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        verify(mInternetAdapter).setMaxEntriesCount(3);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.VISIBLE);
    }

@@ -366,6 +370,7 @@ public class InternetDialogTest extends SysuiTestCase {

        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        verify(mInternetAdapter).setMaxEntriesCount(2);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.VISIBLE);
    }