From fde640e59d18b780f5985529be447b70293581e6 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Mon, 29 Aug 2016 14:03:11 +0900 Subject: [PATCH] Don't notify on network switch if source network is validated. Sometimes we switch away from a network to another (e.g., wifi to cell data) not because the old network is unvalidated, but because the score is lowered by a low signal strength. In this case, don't notify the user of a network switch. Bug: 31132499 Change-Id: I996a6e00096f8cb864fa9b00b36921725a4edb53 --- .../core/java/com/android/server/ConnectivityService.java | 6 +++--- .../java/com/android/server/connectivity/LingerMonitor.java | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 14243c540f..86afe08ced 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -4699,9 +4699,6 @@ public class ConnectivityService extends IConnectivityManager.Stub if (VDBG) log(" accepting network in place of " + currentNetwork.name()); currentNetwork.removeRequest(nri.request.requestId); currentNetwork.lingerRequest(nri.request, now, mLingerDelayMs); - if (isDefaultRequest(nri)) { - mLingerMonitor.noteLingerDefaultNetwork(currentNetwork, newNetwork); - } affectedNetworks.add(currentNetwork); } else { if (VDBG) log(" accepting network in place of null"); @@ -4722,6 +4719,9 @@ public class ConnectivityService extends IConnectivityManager.Stub if (isDefaultRequest(nri)) { isNewDefault = true; oldDefaultNetwork = currentNetwork; + if (currentNetwork != null) { + mLingerMonitor.noteLingerDefaultNetwork(currentNetwork, newNetwork); + } } } } else if (newNetwork.isSatisfyingRequest(nri.request.requestId)) { diff --git a/services/core/java/com/android/server/connectivity/LingerMonitor.java b/services/core/java/com/android/server/connectivity/LingerMonitor.java index 4034877023..064a904853 100644 --- a/services/core/java/com/android/server/connectivity/LingerMonitor.java +++ b/services/core/java/com/android/server/connectivity/LingerMonitor.java @@ -242,6 +242,12 @@ public class LingerMonitor { return; } + // Only show the notification if we switched away because a network became unvalidated, not + // because its score changed. + // TODO: instead of just skipping notification, keep a note of it, and show it if it becomes + // unvalidated. + if (fromNai.lastValidated) return; + if (isNotificationEnabled(fromNai, toNai)) { notify(fromNai, toNai, forceToast); }