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

Commit b398d107 authored by Weng Su's avatar Weng Su Committed by Zoey Chen
Browse files

[Provider Model] Should not show Wi-Fi entries under lockscreen

- If the Internet Panel is showing under lockscreen
  - Show "Unlock to view networks" subtitle
    - Highlight Wi-Fi toggle if the default network is Wi-Fi
    - Hide Wi-Fi entries
    - Hide "See all" item

- If the Wi-Fi entries is empty
  - Hide Wi-Fi entries
  - Hide "See all" item

Bug: 194872708
Bug: 194873442
Bug: 195088254
Test: manual test
atest -c InternetDialogControllerTest \
         InternetDialogTest

Change-Id: I40ff3ed0b38d590c0171c654ceaa433ceb0fac59
Merged-In: I40ff3ed0b38d590c0171c654ceaa433ceb0fac59
(cherry picked from commit 08c3dbec)
parent 007eb0da
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -3021,6 +3021,8 @@
    <string name="pref_title_network_details" msgid="7329759534269363308">"Network details"</string>
    <!-- Provider Model: Panel subtitle for tapping a network to connect to internet. [CHAR LIMIT=60] -->
    <string name="tap_a_network_to_connect">Tap a network to connect</string>
    <!-- Provider Model: Panel subtitle for unlocking screen to view networks. [CHAR LIMIT=60] -->
    <string name="unlock_to_view_networks">Unlock to view networks</string>
    <!-- Provider Model: Wi-Fi settings. text displayed when Wi-Fi is on and network list is empty [CHAR LIMIT=50]-->
    <string name="wifi_empty_list_wifi_on">Searching for networks\u2026</string>
    <!-- Provider Model: Failure notification for connect -->
+26 −11
Original line number Diff line number Diff line
@@ -287,14 +287,22 @@ public class InternetDialog extends SystemUIDialog implements
        }
        showProgressBar();
        setMobileDataLayout(mInternetDialogController.activeNetworkIsCellular());
        setConnectedWifiLayout();
        boolean isWifiEnabled = mWifiManager.isWifiEnabled();
        mWiFiToggle.setChecked(isWifiEnabled);
        int visible = isWifiEnabled ? View.VISIBLE : View.GONE;
        mWifiRecyclerView.setVisibility(visible);

        final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked();
        final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
        updateWifiToggle(isWifiEnabled, isDeviceLocked);
        updateConnectedWifi(isWifiEnabled, isDeviceLocked);

        List<WifiEntry> wifiEntryList = mInternetDialogController.getWifiEntryList();
        final int wifiListVisibility =
                (isDeviceLocked || wifiEntryList == null || wifiEntryList.size() <= 0)
                        ? View.GONE : View.VISIBLE;
        mWifiRecyclerView.setVisibility(wifiListVisibility);
        if (wifiListVisibility == View.VISIBLE) {
            mAdapter.notifyDataSetChanged();
        mSeeAllLayout.setVisibility(visible);
        mSpace.setVisibility(isWifiEnabled ? View.GONE : View.VISIBLE);
        }
        mSeeAllLayout.setVisibility(wifiListVisibility);
        mSpace.setVisibility(wifiListVisibility == View.VISIBLE ? View.GONE : View.VISIBLE);
    }

    private void setOnClickListener() {
@@ -358,8 +366,14 @@ public class InternetDialog extends SystemUIDialog implements
        }
    }

    private void setConnectedWifiLayout() {
        if (!mWifiManager.isWifiEnabled() || mConnectedWifiEntry == null) {
    private void updateWifiToggle(boolean isWifiEnabled, boolean isDeviceLocked) {
        mWiFiToggle.setChecked(isWifiEnabled);
        mTurnWifiOnLayout.setBackground(
                (isDeviceLocked && mConnectedWifiEntry != null) ? mBackgroundOn : null);
    }

    private void updateConnectedWifi(boolean isWifiEnabled, boolean isDeviceLocked) {
        if (!isWifiEnabled || mConnectedWifiEntry == null || isDeviceLocked) {
            mConnectedWifListLayout.setBackground(null);
            mConnectedWifListLayout.setVisibility(View.GONE);
            return;
@@ -418,7 +432,8 @@ public class InternetDialog extends SystemUIDialog implements
    }

    protected void showProgressBar() {
        if (mWifiManager == null || !mWifiManager.isWifiEnabled()) {
        if (mWifiManager == null || !mWifiManager.isWifiEnabled()
                || mInternetDialogController.isDeviceLocked()) {
            setProgressBarVisible(false);
            return;
        }
+21 −1
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.systemui.R;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
import com.android.systemui.util.settings.GlobalSettings;
@@ -97,6 +98,8 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
    private static final int SUBTITLE_TEXT_WIFI_IS_OFF = R.string.wifi_is_off;
    private static final int SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT =
            R.string.tap_a_network_to_connect;
    private static final int SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS =
            R.string.unlock_to_view_networks;
    private static final int SUBTITLE_TEXT_SEARCHING_FOR_NETWORKS =
            R.string.wifi_empty_list_wifi_on;
    private static final int SUBTITLE_TEXT_NON_CARRIER_NETWORK_UNAVAILABLE =
@@ -137,6 +140,9 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
    @VisibleForTesting
    protected WifiUtils.InternetIconInjector mWifiIconInjector;

    @VisibleForTesting
    KeyguardStateController mKeyguardStateController;

    private final KeyguardUpdateMonitorCallback mKeyguardUpdateCallback =
            new KeyguardUpdateMonitorCallback() {
                @Override
@@ -161,7 +167,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
            @Nullable WifiManager wifiManager, ConnectivityManager connectivityManager,
            @Main Handler handler, @Main Executor mainExecutor,
            BroadcastDispatcher broadcastDispatcher, KeyguardUpdateMonitor keyguardUpdateMonitor,
            GlobalSettings globalSettings) {
            GlobalSettings globalSettings, KeyguardStateController keyguardStateController) {
        if (DEBUG) {
            Log.d(TAG, "Init InternetDialogController");
        }
@@ -175,6 +181,7 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
        mSubscriptionManager = subscriptionManager;
        mBroadcastDispatcher = broadcastDispatcher;
        mKeyguardUpdateMonitor = keyguardUpdateMonitor;
        mKeyguardStateController = keyguardStateController;
        mConnectionStateFilter = new IntentFilter();
        mConnectionStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
        mConnectionStateFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
@@ -272,6 +279,15 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
            return mContext.getText(SUBTITLE_TEXT_WIFI_IS_OFF);
        }

        if (isDeviceLocked()) {
            // When the device is locked.
            //   Sub-Title: Unlock to view networks
            if (DEBUG) {
                Log.d(TAG, "The device is locked.");
            }
            return mContext.getText(SUBTITLE_TEXT_UNLOCK_TO_VIEW_NETWORKS);
        }

        final List<ScanResult> wifiList = mWifiManager.getScanResults();
        if (wifiList != null && wifiList.size() != 0) {
            return mContext.getText(SUBTITLE_TEXT_TAP_A_NETWORK_TO_CONNECT);
@@ -683,6 +699,10 @@ public class InternetDialogController implements WifiEntry.DisconnectCallback,
                && serviceState.getState() == serviceState.STATE_IN_SERVICE;
    }

    public boolean isDeviceLocked() {
        return !mKeyguardStateController.isUnlocked();
    }

    boolean activeNetworkIsCellular() {
        if (mConnectivityManager == null) {
            if (DEBUG) {
+33 −6
Original line number Diff line number Diff line
@@ -33,13 +33,13 @@ import androidx.test.filters.SmallTest;

import com.android.internal.logging.UiEventLogger;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.settingslib.Utils;
import com.android.settingslib.wifi.WifiUtils;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.statusbar.policy.NetworkController;
import com.android.systemui.statusbar.policy.NetworkController.AccessPointController;
import com.android.systemui.util.concurrency.FakeExecutor;
@@ -79,7 +79,7 @@ public class InternetDialogControllerTest extends SysuiTestCase {
    @Mock
    private GlobalSettings mGlobalSettings;
    @Mock
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private KeyguardStateController mKeyguardStateController;
    @Mock
    private NetworkController.AccessPointController mAccessPointController;
    @Mock
@@ -99,15 +99,16 @@ public class InternetDialogControllerTest extends SysuiTestCase {
    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
        doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
        when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo);
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);
        when(mConnectedEntry.isDefaultNetwork()).thenReturn(true);

        mInternetDialogController = new MockInternetDialogController(mContext,
                mock(UiEventLogger.class), mock(ActivityStarter.class), mAccessPointController,
                mSubscriptionManager, mTelephonyManager, mWifiManager,
                mock(ConnectivityManager.class), mHandler, mExecutor, mBroadcastDispatcher,
                mKeyguardUpdateMonitor, mGlobalSettings);
                mock(KeyguardUpdateMonitor.class), mGlobalSettings, mKeyguardStateController);
        mSubscriptionManager.addOnSubscriptionsChangedListener(mExecutor,
                mInternetDialogController.mOnSubscriptionsChangedListener);
        mInternetDialogController.onStart(
@@ -173,6 +174,16 @@ public class InternetDialogControllerTest extends SysuiTestCase {
                getResourcesString("tap_a_network_to_connect")));
    }

    @Test
    public void getSubtitleText_deviceLockedWithWifiOn_returnUnlockToViewNetworks() {
        mInternetDialogController.setAirplaneModeEnabled(false);
        when(mWifiManager.isWifiEnabled()).thenReturn(true);
        when(mKeyguardStateController.isUnlocked()).thenReturn(false);

        assertTrue(TextUtils.equals(mInternetDialogController.getSubtitleText(false),
                getResourcesString("unlock_to_view_networks")));
    }

    @Test
    public void getSubtitleText_withNoService_returnNoNetworksAvailable() {
        mInternetDialogController.setAirplaneModeEnabled(false);
@@ -311,6 +322,20 @@ public class InternetDialogControllerTest extends SysuiTestCase {
        verify(mActivityStarter).postStartActivityDismissingKeyguard(any(Intent.class), anyInt());
    }

    @Test
    public void isDeviceLocked_keyguardIsUnlocked_returnFalse() {
        when(mKeyguardStateController.isUnlocked()).thenReturn(true);

        assertThat(mInternetDialogController.isDeviceLocked()).isFalse();
    }

    @Test
    public void isDeviceLocked_keyguardIsLocked_returnTrue() {
        when(mKeyguardStateController.isUnlocked()).thenReturn(false);

        assertThat(mInternetDialogController.isDeviceLocked()).isTrue();
    }

    private String getResourcesString(String name) {
        return mContext.getResources().getString(getResourcesId(name));
    }
@@ -331,10 +356,12 @@ public class InternetDialogControllerTest extends SysuiTestCase {
                @Nullable WifiManager wifiManager, ConnectivityManager connectivityManager,
                @Main Handler handler, @Main Executor mainExecutor,
                BroadcastDispatcher broadcastDispatcher,
                KeyguardUpdateMonitor keyguardUpdateMonitor, GlobalSettings globalSettings) {
                KeyguardUpdateMonitor keyguardUpdateMonitor, GlobalSettings globalSettings,
                KeyguardStateController keyguardStateController) {
            super(context, uiEventLogger, starter, accessPointController, subscriptionManager,
                    telephonyManager, wifiManager, connectivityManager, handler, mainExecutor,
                    broadcastDispatcher, keyguardUpdateMonitor, globalSettings);
                    broadcastDispatcher, keyguardUpdateMonitor, globalSettings,
                    keyguardStateController);
            mGlobalSettings = globalSettings;
        }

+102 −31
Original line number Diff line number Diff line
@@ -59,24 +59,31 @@ public class InternetDialogTest extends SysuiTestCase {
    private static final String WIFI_TITLE = "Connected Wi-Fi Title";
    private static final String WIFI_SUMMARY = "Connected Wi-Fi Summary";

    private final UiEventLogger mUiEventLogger = mock(UiEventLogger.class);

    private InternetDialogFactory mInternetDialogFactory = mock(InternetDialogFactory.class);
    private InternetAdapter mInternetAdapter = mock(InternetAdapter.class);
    private InternetDialogController mInternetDialogController = mock(
            InternetDialogController.class);
    private InternetDialogController.InternetDialogCallback mCallback =
            mock(InternetDialogController.InternetDialogCallback.class);
    private MockInternetDialog mInternetDialog;
    private WifiReceiver mWifiReceiver = null;
    private WifiManager mMockWifiManager = mock(WifiManager.class);
    private TelephonyManager mTelephonyManager = mock(TelephonyManager.class);
    @Mock
    private WifiEntry mWifiEntry = mock(WifiEntry.class);
    private InternetDialogFactory mInternetDialogFactory;
    @Mock
    private WifiInfo mWifiInfo;
    private InternetDialogController mInternetDialogController;
    @Mock
    private UiEventLogger mUiEventLogger;
    @Mock
    private Handler mHandler;
    @Mock
    private TelephonyManager mTelephonyManager;
    @Mock
    private InternetAdapter mInternetAdapter;
    @Mock
    private WifiManager mMockWifiManager;
    @Mock
    private WifiEntry mWifiEntry;
    @Mock
    private WifiInfo mWifiInfo;

    private MockInternetDialog mInternetDialog;
    private WifiReceiver mWifiReceiver;
    private LinearLayout mWifiToggle;
    private LinearLayout mConnectedWifi;
    private RecyclerView mWifiList;
    private LinearLayout mSeeAll;

    @Before
    public void setUp() {
@@ -99,6 +106,10 @@ public class InternetDialogTest extends SysuiTestCase {
        when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
        when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
        when(mInternetDialogController.getWifiEntryList()).thenReturn(Arrays.asList(mWifiEntry));
        mWifiToggle = mInternetDialog.mDialogView.requireViewById(R.id.turn_on_wifi_layout);
        mConnectedWifi = mInternetDialog.mDialogView.requireViewById(R.id.wifi_connected_layout);
        mWifiList = mInternetDialog.mDialogView.requireViewById(R.id.wifi_list_layout);
        mSeeAll = mInternetDialog.mDialogView.requireViewById(R.id.see_all_layout);
    }

    @After
@@ -137,7 +148,7 @@ public class InternetDialogTest extends SysuiTestCase {
    }

    @Test
    public void updateDialog_withWifiOnAndHasConnectedWifi_connectedWifiLayoutVisible() {
    public void updateDialog_wifiOnAndHasConnectedWifi_showConnectedWifi() {
        doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();
        when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
        when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
@@ -147,36 +158,85 @@ public class InternetDialogTest extends SysuiTestCase {

        mInternetDialog.updateDialog();

        final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
                R.id.wifi_connected_layout);
        assertThat(linearLayout.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void updateDialog_withWifiOnAndNoConnectedWifi_connectedWifiLayoutGone() {
    public void updateDialog_wifiOnAndNoConnectedWifi_hideConnectedWifi() {
        doReturn(false).when(mInternetDialogController).activeNetworkIsCellular();

        mInternetDialog.updateDialog();
        final LinearLayout linearLayout = mInternetDialog.mDialogView.requireViewById(
                R.id.wifi_connected_layout);

        assertThat(linearLayout.getVisibility()).isEqualTo(View.GONE);
        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void updateDialog_withWifiOff_WifiRecycleViewGone() {
        when(mMockWifiManager.isWifiEnabled()).thenReturn(false);
    public void updateDialog_wifiOnAndNoWifiList_hideWifiListAndSeeAll() {
        when(mInternetDialogController.getWifiEntryList()).thenReturn(null);

        mInternetDialog.updateDialog();
        final RecyclerView view = mInternetDialog.mDialogView.requireViewById(
                R.id.wifi_list_layout);

        assertThat(view.getVisibility()).isEqualTo(View.GONE);
        assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void updateDialog_wifiOnAndHasWifiList_showWifiListAndSeeAll() {
        List<WifiEntry> wifiEntries = new ArrayList<WifiEntry>();
        wifiEntries.add(mWifiEntry);
        when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries);

        mInternetDialog.updateDialog();

        assertThat(mWifiList.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void onClickSeeMoreButton_clickSeeMore_verifyLaunchNetworkSetting() {
        final LinearLayout seeAllLayout = mInternetDialog.mDialogView.requireViewById(
                R.id.see_all_layout);
        seeAllLayout.performClick();
    public void updateDialog_deviceLockedAndHasConnectedWifi_showHighlightWifiToggle() {
        when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
        when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
        when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
        when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
        when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
        mInternetDialog.mConnectedWifiEntry = mWifiEntry;

        mInternetDialog.updateDialog();

        assertThat(mWifiToggle.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mWifiToggle.getBackground()).isNotNull();
    }

    @Test
    public void updateDialog_deviceLockedAndHasConnectedWifi_hideConnectedWifi() {
        when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
        when(mWifiEntry.getTitle()).thenReturn(WIFI_TITLE);
        when(mWifiEntry.getSummary(false)).thenReturn(WIFI_SUMMARY);
        when(mWifiEntry.getConnectedState()).thenReturn(WifiEntry.CONNECTED_STATE_CONNECTED);
        when(mWifiEntry.isDefaultNetwork()).thenReturn(true);
        mInternetDialog.mConnectedWifiEntry = mWifiEntry;

        mInternetDialog.updateDialog();

        assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void updateDialog_deviceLockedAndHasWifiList_hideWifiListAndSeeAll() {
        when(mInternetDialogController.isDeviceLocked()).thenReturn(true);
        List<WifiEntry> wifiEntries = new ArrayList<WifiEntry>();
        wifiEntries.add(mWifiEntry);
        when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries);

        mInternetDialog.updateDialog();

        assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE);
        assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void onClickSeeMoreButton_clickSeeAll_verifyLaunchNetworkSetting() {
        mSeeAll.performClick();

        verify(mInternetDialogController).launchNetworkSetting();
    }
@@ -192,6 +252,17 @@ public class InternetDialogTest extends SysuiTestCase {
        verify(mHandler, never()).postDelayed(any(Runnable.class), anyLong());
    }

    @Test
    public void showProgressBar_deviceLocked_hideProgressBar() {
        Mockito.reset(mHandler);
        when(mInternetDialogController.isDeviceLocked()).thenReturn(true);

        mInternetDialog.showProgressBar();

        assertThat(mInternetDialog.mIsProgressBarVisible).isFalse();
        verify(mHandler, never()).postDelayed(any(Runnable.class), anyLong());
    }

    @Test
    public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() {
        Mockito.reset(mHandler);