From 08c3dbec3206172b6da3fec8488d60a183d2000e Mon Sep 17 00:00:00 2001 From: Weng Su Date: Tue, 3 Aug 2021 02:13:18 +0800 Subject: [PATCH] [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 --- packages/SystemUI/res/values/strings.xml | 2 + .../qs/tiles/dialog/InternetDialog.java | 37 +++-- .../dialog/InternetDialogController.java | 22 ++- .../dialog/InternetDialogControllerTest.java | 39 ++++- .../qs/tiles/dialog/InternetDialogTest.java | 137 +++++++++++++----- 5 files changed, 186 insertions(+), 51 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index a8812bf4a293a..83a4f1bc46197 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -3012,6 +3012,8 @@ "Network details" Tap a network to connect + + Unlock to view networks Searching for networks\u2026 diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java index a63d1f80f3947..e338750faadb6 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialog.java @@ -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); - mAdapter.notifyDataSetChanged(); - mSeeAllLayout.setVisibility(visible); - mSpace.setVisibility(isWifiEnabled ? View.GONE : View.VISIBLE); + + final boolean isDeviceLocked = mInternetDialogController.isDeviceLocked(); + final boolean isWifiEnabled = mWifiManager.isWifiEnabled(); + updateWifiToggle(isWifiEnabled, isDeviceLocked); + updateConnectedWifi(isWifiEnabled, isDeviceLocked); + + List 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(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; } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java index 890dcfd46f78b..80a93d6c4a7c0 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetDialogController.java @@ -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 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) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java index f876a43f75d40..2b3624e89538c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogControllerTest.java @@ -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; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java index 856e3a1281939..de2c7e32d37c3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/dialog/InternetDialogTest.java @@ -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); + mInternetDialog.updateDialog(); + + assertThat(mConnectedWifi.getVisibility()).isEqualTo(View.GONE); } @Test - public void updateDialog_withWifiOff_WifiRecycleViewGone() { - when(mMockWifiManager.isWifiEnabled()).thenReturn(false); - mInternetDialog.updateDialog(); - final RecyclerView view = mInternetDialog.mDialogView.requireViewById( - R.id.wifi_list_layout); + public void updateDialog_wifiOnAndNoWifiList_hideWifiListAndSeeAll() { + when(mInternetDialogController.getWifiEntryList()).thenReturn(null); - assertThat(view.getVisibility()).isEqualTo(View.GONE); + mInternetDialog.updateDialog(); + + assertThat(mWifiList.getVisibility()).isEqualTo(View.GONE); + assertThat(mSeeAll.getVisibility()).isEqualTo(View.GONE); } @Test - public void onClickSeeMoreButton_clickSeeMore_verifyLaunchNetworkSetting() { - final LinearLayout seeAllLayout = mInternetDialog.mDialogView.requireViewById( - R.id.see_all_layout); - seeAllLayout.performClick(); + public void updateDialog_wifiOnAndHasWifiList_showWifiListAndSeeAll() { + List wifiEntries = new ArrayList(); + 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 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 wifiEntries = new ArrayList(); + 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);