From f73c15c09008e7005f896845a9fcf157ff873a4c Mon Sep 17 00:00:00 2001 From: Jeff Davidson Date: Wed, 20 Jan 2016 11:35:38 -0800 Subject: [PATCH] Notify NetworkStatsService of roaming status changes. When the roaming status of the cell network changes, it is handled as follows: -DcActiveState gets an event (either EVENT_DATA_CONNECTION_ROAM_ON or EVENT_DATA_CONNECTION_ROAM_OFF) and calls NetworkAgent#sendNetworkInfo with updated NetworkInfo. -ConnectivityService then gets an EVENT_NETWORK_INFO_CHANGED and calls updateNetworkInfo with the new info. With the previous code, the NetworkAgent's NetworkInfo object would be updated internally, but because the state of the connection had not changed from CONNECTED, the change would be considered a duplicate and otherwise ignored. With the new code, we call notifyIfacesChanged() when the state is the same but the roaming status has changed. That should be all that is necessary, as roaming is not exposed as a link property or network capability today. Bug: 26545456 Change-Id: I33d32d1fa84ce41dbe01542e5b498eda4b744b74 --- .../android/server/ConnectivityService.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 2d1f96b0a7..3fd8b40dbc 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -33,7 +33,6 @@ import static android.net.NetworkPolicyManager.RULE_REJECT_ALL; import static android.net.NetworkPolicyManager.RULE_REJECT_METERED; import android.annotation.Nullable; -import android.app.AlarmManager; import android.app.BroadcastOptions; import android.app.Notification; import android.app.NotificationManager; @@ -88,7 +87,6 @@ import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; import android.os.ResultReceiver; -import android.os.SystemClock; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; @@ -115,7 +113,6 @@ import com.android.internal.net.NetworkStatsFactory; import com.android.internal.net.VpnConfig; import com.android.internal.net.VpnInfo; import com.android.internal.net.VpnProfile; -import com.android.internal.telephony.DctConstants; import com.android.internal.util.AsyncChannel; import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.XmlUtils; @@ -155,11 +152,9 @@ import java.util.HashMap; import java.util.HashSet; import java.util.SortedSet; import java.util.TreeSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; /** * @hide @@ -2186,7 +2181,7 @@ public class ConnectivityService extends IConnectivityManager.Stub if (wasDefault) { mDefaultInetConditionPublished = 0; } - notifyIfacesChanged(); + notifyIfacesChangedForNetworkStats(); // TODO - we shouldn't send CALLBACK_LOST to requests that can be satisfied // by other networks that are already connected. Perhaps that can be done by // sending all CALLBACK_LOST messages (for requests, not listens) at the end @@ -4095,7 +4090,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } // TODO - move this check to cover the whole function if (!Objects.equals(newLp, oldLp)) { - notifyIfacesChanged(); + notifyIfacesChangedForNetworkStats(); notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED); } @@ -4719,7 +4714,11 @@ public class ConnectivityService extends IConnectivityManager.Stub notifyLockdownVpn(networkAgent); if (oldInfo != null && oldInfo.getState() == state) { - if (VDBG) log("ignoring duplicate network state non-change"); + if (oldInfo.isRoaming() != newInfo.isRoaming()) { + if (VDBG) log("roaming status changed, notifying NetworkStatsService"); + notifyIfacesChangedForNetworkStats(); + } else if (VDBG) log("ignoring duplicate network state non-change"); + // In either case, no further work should be needed. return; } if (DBG) { @@ -4749,7 +4748,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } networkAgent.created = true; updateLinkProperties(networkAgent, null); - notifyIfacesChanged(); + notifyIfacesChangedForNetworkStats(); networkAgent.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_CONNECTED); scheduleUnvalidatedPrompt(networkAgent); @@ -4913,9 +4912,10 @@ public class ConnectivityService extends IConnectivityManager.Stub } /** - * Notify other system services that set of active ifaces has changed. + * Notify NetworkStatsService that the set of active ifaces has changed, or that one of the + * properties tracked by NetworkStatsService on an active iface has changed. */ - private void notifyIfacesChanged() { + private void notifyIfacesChangedForNetworkStats() { try { mStatsService.forceUpdateIfaces(); } catch (Exception ignored) { @@ -4949,7 +4949,7 @@ public class ConnectivityService extends IConnectivityManager.Stub success = mVpns.get(user).setUnderlyingNetworks(networks); } if (success) { - notifyIfacesChanged(); + notifyIfacesChangedForNetworkStats(); } return success; }