From b398d107adf989c8106c1455503ba41398c0868f Mon Sep 17 00:00:00 2001 From: Weng Su Date: Tue, 3 Aug 2021 02:13:18 +0800 Subject: [PATCH 1/5] [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 08c3dbec3206172b6da3fec8488d60a183d2000e) --- 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 584eb511154b6..a180cc1b5af0b 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -3021,6 +3021,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); From 151d93fdbcd06746279bdf13e6620627982b7809 Mon Sep 17 00:00:00 2001 From: Weng Su Date: Sat, 7 Aug 2021 23:08:12 +0800 Subject: [PATCH 2/5] [Provider Model] Correct the connected Wi-Fi UI - Highlight the connected Wi-Fi with both default network and internet access attributes - Show Wi-Fi icon with exclamation mark if the connected Wi-Fi has no the internet access (e.g. Printer/GoPro cases). Bug: 195379439 Bug: 195728184 Test: manual test atest -c InternetAdapterTest \ InternetDialogControllerTest \ InternetDialogTest Change-Id: Ic80ed7f819ffb9f5821df244a3a4f7b2e5ac0379 Merged-In: Ic80ed7f819ffb9f5821df244a3a4f7b2e5ac0379 (cherry picked from commit 194264a941d808f61fb8414f9c5e2f7c94bf55ab) --- .../qs/tiles/dialog/InternetAdapter.java | 17 +- .../qs/tiles/dialog/InternetDialog.java | 14 +- .../dialog/InternetDialogController.java | 27 +-- .../qs/tiles/dialog/InternetAdapterTest.java | 30 ++- .../dialog/InternetDialogControllerTest.java | 50 ++--- .../qs/tiles/dialog/InternetDialogTest.java | 176 ++++-------------- 6 files changed, 114 insertions(+), 200 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java index e346044e746de..91c81bc506c29 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/dialog/InternetAdapter.java @@ -97,7 +97,8 @@ public class InternetAdapter extends RecyclerView.Adapter !wifiEntry.isDefaultNetwork()) + .filter(wifiEntry -> (!wifiEntry.isDefaultNetwork() + || !wifiEntry.hasInternetAccess())) .limit(getItemCount()) .collect(Collectors.toList()); } @@ -107,21 +108,21 @@ public class InternetAdapter extends RecyclerView.Adapter wifiEntries = new ArrayList(); - wifiEntries.add(mWifiEntry); - when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries); + // The preconditions WiFi ON and WiFi entries are already in setUp() mInternetDialog.updateDialog(); @@ -193,13 +181,9 @@ public class InternetDialogTest extends SysuiTestCase { } @Test - public void updateDialog_deviceLockedAndHasConnectedWifi_showHighlightWifiToggle() { + public void updateDialog_deviceLockedAndHasInternetWifi_showHighlightWifiToggle() { + // The preconditions WiFi ON and Internet WiFi are already in setUp() 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(); @@ -208,13 +192,9 @@ public class InternetDialogTest extends SysuiTestCase { } @Test - public void updateDialog_deviceLockedAndHasConnectedWifi_hideConnectedWifi() { + public void updateDialog_deviceLockedAndHasInternetWifi_hideConnectedWifi() { + // The preconditions WiFi ON and Internet WiFi are already in setUp() 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(); @@ -223,10 +203,8 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void updateDialog_deviceLockedAndHasWifiList_hideWifiListAndSeeAll() { + // The preconditions WiFi entries are already in setUp() when(mInternetDialogController.isDeviceLocked()).thenReturn(true); - List wifiEntries = new ArrayList(); - wifiEntries.add(mWifiEntry); - when(mInternetDialogController.getWifiEntryList()).thenReturn(wifiEntries); mInternetDialog.updateDialog(); @@ -244,7 +222,7 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void showProgressBar_wifiDisabled_hideProgressBar() { Mockito.reset(mHandler); - when(mMockWifiManager.isWifiEnabled()).thenReturn(false); + when(mWifiManager.isWifiEnabled()).thenReturn(false); mInternetDialog.showProgressBar(); @@ -266,10 +244,10 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void showProgressBar_wifiEnabledWithWifiEntry_showProgressBarThenHide() { Mockito.reset(mHandler); - when(mMockWifiManager.isWifiEnabled()).thenReturn(true); + when(mWifiManager.isWifiEnabled()).thenReturn(true); List wifiScanResults = mock(ArrayList.class); when(wifiScanResults.size()).thenReturn(1); - when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults); + when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); mInternetDialog.showProgressBar(); @@ -288,10 +266,10 @@ public class InternetDialogTest extends SysuiTestCase { @Test public void showProgressBar_wifiEnabledWithoutWifiScanResults_showProgressBarThenHideSearch() { Mockito.reset(mHandler); - when(mMockWifiManager.isWifiEnabled()).thenReturn(true); + when(mWifiManager.isWifiEnabled()).thenReturn(true); List wifiScanResults = mock(ArrayList.class); when(wifiScanResults.size()).thenReturn(0); - when(mMockWifiManager.getScanResults()).thenReturn(wifiScanResults); + when(mWifiManager.getScanResults()).thenReturn(wifiScanResults); mInternetDialog.showProgressBar(); @@ -307,78 +285,4 @@ public class InternetDialogTest extends SysuiTestCase { assertThat(mInternetDialog.mIsProgressBarVisible).isTrue(); assertThat(mInternetDialog.mIsSearchingHidden).isTrue(); } - - private class MockInternetDialog extends InternetDialog { - - private String mMobileNetworkTitle; - private String mMobileNetworkSummary; - private String mConnectedWifiTitle; - private String mConnectedWifiSummary; - - MockInternetDialog(Context context, InternetDialogFactory internetDialogFactory, - InternetDialogController internetDialogController, boolean canConfigMobileData, - boolean aboveStatusBar, UiEventLogger uiEventLogger, @Main Handler handler) { - super(context, internetDialogFactory, internetDialogController, canConfigMobileData, - aboveStatusBar, uiEventLogger, handler); - mAdapter = mInternetAdapter; - mWifiManager = mMockWifiManager; - } - - @Override - String getMobileNetworkTitle() { - return mMobileNetworkTitle; - } - - @Override - String getMobileNetworkSummary() { - return mMobileNetworkSummary; - } - - void setMobileNetworkTitle(String title) { - mMobileNetworkTitle = title; - } - - void setMobileNetworkSummary(String summary) { - mMobileNetworkSummary = summary; - } - - @Override - String getConnectedWifiTitle() { - return mConnectedWifiTitle; - } - - @Override - String getConnectedWifiSummary() { - return mConnectedWifiSummary; - } - - void setConnectedWifiTitle(String title) { - mConnectedWifiTitle = title; - } - - void setConnectedWifiSummary(String summary) { - mConnectedWifiSummary = summary; - } - - @Override - public void onWifiStateReceived(Context context, Intent intent) { - setMobileNetworkTitle(MOBILE_NETWORK_TITLE); - setMobileNetworkSummary(MOBILE_NETWORK_SUMMARY); - } - } - - private class WifiReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (action.equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { - return; - } - - if (action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { - mInternetDialog.updateDialog(); - } - } - } - } From b17c58a73293bfe6ae8df7c3e1e70ed59800062b Mon Sep 17 00:00:00 2001 From: Zoey Chen Date: Wed, 11 Aug 2021 00:14:58 +0800 Subject: [PATCH 3/5] [Provider Model] Fix the toggle's size and dialog's width Bug: 196019329 Test: manuak Change-Id: Ifb79e402540b4aef58f829312e836b4f11114a5d Merged-In: Ifb79e402540b4aef58f829312e836b4f11114a5d (cherry picked from commit 3f4bddc36dd56441861f7d72e91c9be309916ec7) --- .../res/drawable/settingslib_thumb_off.xml | 2 - .../res/drawable/settingslib_thumb_on.xml | 2 - .../settingslib_track_off_background.xml | 2 + .../settingslib_track_on_background.xml | 2 + .../layout/internet_connectivity_dialog.xml | 76 +++++++++---------- packages/SystemUI/res/values/dimens.xml | 20 +++-- .../qs/tiles/dialog/InternetDialog.java | 9 +-- 7 files changed, 59 insertions(+), 54 deletions(-) diff --git a/packages/SystemUI/res/drawable/settingslib_thumb_off.xml b/packages/SystemUI/res/drawable/settingslib_thumb_off.xml index 8b69ad1b2493b..87d4aeaac84fb 100644 --- a/packages/SystemUI/res/drawable/settingslib_thumb_off.xml +++ b/packages/SystemUI/res/drawable/settingslib_thumb_off.xml @@ -18,8 +18,6 @@ + diff --git a/packages/SystemUI/res/drawable/settingslib_track_on_background.xml b/packages/SystemUI/res/drawable/settingslib_track_on_background.xml index c12d012a0508a..1d9dacd6c0f98 100644 --- a/packages/SystemUI/res/drawable/settingslib_track_on_background.xml +++ b/packages/SystemUI/res/drawable/settingslib_track_on_background.xml @@ -19,6 +19,8 @@ android:shape="rectangle" android:width="@dimen/settingslib_switch_track_width" android:height="@dimen/settingslib_switch_track_height"> + diff --git a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml index f23085a66903f..5b58fe8c0b582 100644 --- a/packages/SystemUI/res/layout/internet_connectivity_dialog.xml +++ b/packages/SystemUI/res/layout/internet_connectivity_dialog.xml @@ -19,18 +19,18 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:androidprv="http://schemas.android.com/apk/prv/res/android" android:id="@+id/internet_connectivity_dialog" - android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_width="@dimen/internet_dialog_list_max_width" + android:layout_height="@dimen/internet_dialog_list_max_height" android:background="@drawable/internet_dialog_rounded_top_corner_background" android:orientation="vertical"> - - - + android:layout_marginBottom="16dp" + android:orientation="vertical"> + + + + + @@ -148,14 +154,15 @@ @@ -195,15 +202,16 @@ @@ -343,31 +351,23 @@ - - - + android:layout_marginBottom="40dp">