From 551043d3e4c50a0018fa590234f4e185a8e1343d Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 30 May 2019 04:10:30 -0700 Subject: [PATCH] Replace limited connectivity notification after detecting it No internet notification may be prompted before partial connectivity being detected. Partial connectivity status will be set into NAI and prompted in the Setting. Behavior is not aligned between Setting and notification. Thus, update notification again if partial connectivity is detected. Also, sliently show the updated notification if no internet notification has already been shown to user to prevent alerting user in short time. Bug: 130683832 Test: Verified with simulated partial connectivity Test: atest FrameworksNetTests Change-Id: Ie16a8ce6e0fa437048e8c1eea240314ca30e9520 Merged-In: I004e78a33689e2208918d4316bcf9a8f50a0bac3 Merged-In: I14385a39d99a45c4a6a50a665f456f589c2f4da3 (cherry picked from commit a5c68348d89f256cb5f42283d983d05834c7e36c) --- .../connectivity/NetworkNotificationManager.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java index 0910dac273..f6735d9834 100644 --- a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java +++ b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java @@ -237,9 +237,15 @@ public class NetworkNotificationManager { + getTransportName(transportType)); return; } - - final String channelId = highPriority ? SystemNotificationChannels.NETWORK_ALERTS : - SystemNotificationChannels.NETWORK_STATUS; + // When replacing an existing notification for a given network, don't alert, just silently + // update the existing notification. Note that setOnlyAlertOnce() will only work for the + // same id, and the id used here is the NotificationType which is different in every type of + // notification. This is required because the notification metrics only track the ID but not + // the tag. + final boolean hasPreviousNotification = previousNotifyType != null; + final String channelId = (highPriority && !hasPreviousNotification) + ? SystemNotificationChannels.NETWORK_ALERTS + : SystemNotificationChannels.NETWORK_STATUS; Notification.Builder builder = new Notification.Builder(mContext, channelId) .setWhen(System.currentTimeMillis()) .setShowWhen(notifyType == NotificationType.NETWORK_SWITCH)