From c067c87672ca7c5e683f37090f57a42e3e2bf809 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Thu, 28 Oct 2021 16:31:37 +0800 Subject: [PATCH] Notify NetworkStatsService if TEMPORARILY_NOT_METERED changed Currently 5G usage includes both metered and unmetered usage. To support 5G unmetered usage metrics, unmetered usage should be separated from the 5G usage. Thus, ConnectivityService needs to inform NetworkStatsService if TEMPORARILY_NOT_METERED has changed. Then NSS will count temporarily not metered usage as unmetered. Bug: 222339311 Bug: 183776809 Test: FrameworksNetTests:ConnectivityServiceTest Change-Id: I0c7e1eb98925184f36e322e09b4d3d8c6f056fa6 --- service/src/com/android/server/ConnectivityService.java | 7 ++++++- .../java/com/android/server/ConnectivityServiceTest.java | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 9b1fa45cde..e9cf37ca1c 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -75,6 +75,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PAID; import static android.net.NetworkCapabilities.NET_CAPABILITY_OEM_PRIVATE; import static android.net.NetworkCapabilities.NET_CAPABILITY_PARTIAL_CONNECTIVITY; +import static android.net.NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED; import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED; import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1; import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_5; @@ -8049,6 +8050,10 @@ public class ConnectivityService extends IConnectivityManager.Stub final boolean oldMetered = prevNc.isMetered(); final boolean newMetered = newNc.isMetered(); final boolean meteredChanged = oldMetered != newMetered; + final boolean oldTempMetered = prevNc.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED); + final boolean newTempMetered = newNc.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED); + final boolean tempMeteredChanged = oldTempMetered != newTempMetered; + if (meteredChanged) { maybeNotifyNetworkBlocked(nai, oldMetered, newMetered, @@ -8059,7 +8064,7 @@ public class ConnectivityService extends IConnectivityManager.Stub != newNc.hasCapability(NET_CAPABILITY_NOT_ROAMING); // Report changes that are interesting for network statistics tracking. - if (meteredChanged || roamingChanged) { + if (meteredChanged || roamingChanged || tempMeteredChanged) { notifyIfacesChangedForNetworkStats(); } diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index e8e3ae8949..3a36136132 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -7326,9 +7326,15 @@ public class ConnectivityServiceTest { expectNotifyNetworkStatus(onlyCell(), onlyCell(), MOBILE_IFNAME); reset(mStatsManager); - // Temp metered change shouldn't update ifaces + // Temp metered change should update ifaces mCellNetworkAgent.addCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED); waitForIdle(); + expectNotifyNetworkStatus(onlyCell(), onlyCell(), MOBILE_IFNAME); + reset(mStatsManager); + + // Congested change shouldn't update ifaces + mCellNetworkAgent.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED); + waitForIdle(); verify(mStatsManager, never()).notifyNetworkStatus(eq(onlyCell()), any(List.class), eq(MOBILE_IFNAME), any(List.class)); reset(mStatsManager);