From d977c2b13a8f2a671c8a869b78c1a5a14526dd41 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 13 Jun 2019 02:50:16 -0700 Subject: [PATCH 1/2] Suppress the wtf log for notifications that are expected PARTIAL and NO_INTERNET may happen in the real world for those transport types that provide internet. These two notification types should be reasonable notificaitons, not a terrible failure as the log. For Q, it may be too risky to display more notifications with other information instead of SSID. Thus, suppress the wtf log for these two notifications. Bug: 135043192 Test: atest FrameworksNetTests Change-Id: I35f3718fa93b403858587d918f0bc596f6c92f3e Merged-In: I91b92249dc7905aadbc59df50c3bc6da30a8590e Merged-In: Ia1c2a765b0fb0cc8d440c02533bdc15774a5a3ef (cherry picked from commit ed0a54bd07ea1c9072459bafeaf796eaa4dad4c5) --- .../NetworkNotificationManager.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java index f6735d9834661..bcf5a71344b06 100644 --- a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java +++ b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java @@ -178,15 +178,31 @@ public class NetworkNotificationManager { CharSequence title; CharSequence details; int icon = getIcon(transportType, notifyType); - if (notifyType == NotificationType.NO_INTERNET && transportType == TRANSPORT_WIFI) { - title = r.getString(R.string.wifi_no_internet, - WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); - details = r.getString(R.string.wifi_no_internet_detailed); - } else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY - && transportType == TRANSPORT_WIFI) { - title = r.getString(R.string.network_partial_connectivity, - WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); - details = r.getString(R.string.network_partial_connectivity_detailed); + if (notifyType == NotificationType.NO_INTERNET) { + switch (transportType) { + case TRANSPORT_WIFI: + title = r.getString(R.string.wifi_no_internet, + WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); + details = r.getString(R.string.wifi_no_internet_detailed); + break; + default: + // TODO: Display notifications for those networks that provide internet. + // except VPN. + return; + } + + } else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY) { + switch (transportType) { + case TRANSPORT_WIFI: + title = r.getString(R.string.network_partial_connectivity, + WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); + details = r.getString(R.string.network_partial_connectivity_detailed); + break; + default: + // TODO: Display notifications for those networks that provide internet. + // except VPN. + return; + } } else if (notifyType == NotificationType.LOST_INTERNET && transportType == TRANSPORT_WIFI) { title = r.getString(R.string.wifi_no_internet, From accf7105b65ae99dc86d78bb22ae1d2b973ca886 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Mon, 17 Jun 2019 04:42:04 -0700 Subject: [PATCH 2/2] Simplification of code to prevent a Log.wtf in expected cases. This mostly serves to unindent code to make it locally more readable. It is a functional no-op. Bug: 135043192 Test: atest FrameworksNetTests Merged-In: Iad0e9a28670e96a3c953518a0d0ccd77e2f2fa80 Change-Id: I80bebcd04c277f6e4b0665fe1253b2309e3bc535 (cherry picked from commit e1f5759319a4559b3cf89029449878dc56f92bb7) --- .../NetworkNotificationManager.java | 39 +++++++------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java index bcf5a71344b06..077c4057a3a09 100644 --- a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java +++ b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java @@ -178,31 +178,15 @@ public class NetworkNotificationManager { CharSequence title; CharSequence details; int icon = getIcon(transportType, notifyType); - if (notifyType == NotificationType.NO_INTERNET) { - switch (transportType) { - case TRANSPORT_WIFI: - title = r.getString(R.string.wifi_no_internet, - WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); - details = r.getString(R.string.wifi_no_internet_detailed); - break; - default: - // TODO: Display notifications for those networks that provide internet. - // except VPN. - return; - } - - } else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY) { - switch (transportType) { - case TRANSPORT_WIFI: - title = r.getString(R.string.network_partial_connectivity, - WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); - details = r.getString(R.string.network_partial_connectivity_detailed); - break; - default: - // TODO: Display notifications for those networks that provide internet. - // except VPN. - return; - } + if (notifyType == NotificationType.NO_INTERNET && transportType == TRANSPORT_WIFI) { + title = r.getString(R.string.wifi_no_internet, + WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); + details = r.getString(R.string.wifi_no_internet_detailed); + } else if (notifyType == NotificationType.PARTIAL_CONNECTIVITY + && transportType == TRANSPORT_WIFI) { + title = r.getString(R.string.network_partial_connectivity, + WifiInfo.removeDoubleQuotes(nai.networkCapabilities.getSSID())); + details = r.getString(R.string.network_partial_connectivity_detailed); } else if (notifyType == NotificationType.LOST_INTERNET && transportType == TRANSPORT_WIFI) { title = r.getString(R.string.wifi_no_internet, @@ -248,6 +232,11 @@ public class NetworkNotificationManager { title = r.getString(R.string.network_switch_metered, toTransport); details = r.getString(R.string.network_switch_metered_detail, toTransport, fromTransport); + } else if (notifyType == NotificationType.NO_INTERNET + || notifyType == NotificationType.PARTIAL_CONNECTIVITY) { + // NO_INTERNET and PARTIAL_CONNECTIVITY notification for non-WiFi networks + // are sent, but they are not implemented yet. + return; } else { Slog.wtf(TAG, "Unknown notification type " + notifyType + " on network transport " + getTransportName(transportType));