From e9332c4bdfdd4a65e79b8560fbe33fe2d3e4aea7 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 13 Sep 2022 20:46:19 +0900 Subject: [PATCH] Add the notification for actively prefer bad wifi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this patch and "config_activelyPreferBadWifi=1" (or SDK level >= U) and bad wifi avoidance turned off, when the device connects to a bad wifi, after 20 seconds of the wifi not validating the device will pop up a head-up notification with text " has no internet access". When tapped, the notification will bring up the existing Settings dialog : *Wifi not connected to the internet* You can switch to mobile whenever Wi-Fi is bad □ Never show again If the wifi validates and loses access again, the same notification/dialog are shown if Settings.Global. NETWORK_AVOID_BAD_WIFI=PROMPT ; if IGNORE, the device stays stuck on wifi. If AVOID, then bad wifi avoidance is turned on in the first place, so none of this happens. Behavior in other cases : - If config_activelyPreferBadWifi=0, then upon connecting to a wifi without internet, the behavior is unchanged : the device stays on mobile and after 8 seconds a notification pops up asking whether to stay connected. If the network validates, then loses access, the behavior depends on a few things : - If config_networkAvoidBadWifi is 0 and Settings.Global. NETWORK_AVOID_BAD_WIFI = IGNORE, then the device stays on wifi and says nothing. - If config_networkAvoidBadWifi is 0 and Settings.Global. NETWORK_AVOID_BAD_WIFI = PROMPT, then notification pops up asking whether to switch to mobile. - If config_networkAvoidBadWifi is 1 (regardless of the value of Settings.Global.NETWORK_AVOID_BAD_WIFI), or if Settings.Global.NETWORK_AVOID_BAD_WIFI = AVOID, then the device switches back to mobile. - If Mobile is not connected, all the above applies. This is not great for the messages including "switch to mobile" but this patch doesn't change it. Test: manual Change-Id: Idb05b6a6e5c085f5ef72435d462e14bfd1341f87 --- .../src/com/android/server/ConnectivityService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 35d94b0797..eb2674e20d 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -5238,6 +5238,16 @@ public class ConnectivityService extends IConnectivityManager.Stub // network was found not to have Internet access. nai.updateScoreForNetworkAgentUpdate(); rematchAllNetworksAndRequests(); + + // Also, if this is WiFi and it should be preferred actively, now is the time to + // prompt the user that they walked past and connected to a bad WiFi. + if (nai.networkCapabilities.hasTransport(TRANSPORT_WIFI) + && !avoidBadWifi() + && activelyPreferBadWifi()) { + // The notification will be removed if the network validates or disconnects. + showNetworkNotification(nai, NotificationType.LOST_INTERNET); + return; + } } if (!shouldPromptUnvalidated(nai)) return;