diff options
| author | 2021-12-14 03:46:20 +0800 | |
|---|---|---|
| committer | 2021-12-14 17:46:33 +0000 | |
| commit | 995b8190038c06353be94e30882a21b1210db9db (patch) | |
| tree | 4f9e4cf1a68be63425b29bf1a4cca22e4ff2633b | |
| parent | c5d0caf274926b7fc1e6ea82f12162517968ce1f (diff) | |
[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
4 files changed, 93 insertions, 1 deletions
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 d894c96dfa28..41ff56a0e733 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 @@ -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); 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 e01918ec717a..0d064af9c17d 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 @@ -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; @@ -971,6 +978,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 */ @MainThread 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 42a4b7f4b01d..0d6554103dac 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 @@ -545,6 +545,37 @@ public class InternetDialogControllerTest extends SysuiTestCase { } @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)) .thenReturn(true); 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 562d31907635..c20e88708f40 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 @@ -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); } |