From d7efd7ba07760f5de4d05d9f9566b6087bacc9c6 Mon Sep 17 00:00:00 2001 From: junyulai Date: Fri, 6 Dec 2019 18:50:41 +0800 Subject: [PATCH] Update interface quota limit when network stats updated In previous design, interface quota limit does not changed when network stats are updated. However, this is incorrect today since there are some offloaded traffic that cannot be seen by kernel. If the limit is not updated, the offloaded traffic might still be able to use whole quota as if there is no embedded traffic. This change also removes the re-arm global alert after advising persist threshold if not changed, given that it will cause an additional alert while updating interface quota limit. Bug: 145792619 Test: 1. atest NetworkStatsServiceTest 2. atest NetworkPolicyManagerServiceTest 3. manual test: run speedtest, check dumpsys netd Change-Id: I8d2203e713730d536430a234b1aa8b2468badee3 --- .../java/com/android/server/net/NetworkStatsService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index 16424f2fef..a943e77284 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -873,6 +873,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { + mPersistThreshold); } + final long oldGlobalAlertBytes = mGlobalAlertBytes; + // update and persist if beyond new thresholds final long currentTime = mClock.millis(); synchronized (mStatsLock) { @@ -886,8 +888,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mUidTagRecorder.maybePersistLocked(currentTime); } - // re-arm global alert - registerGlobalAlert(); + if (oldGlobalAlertBytes != mGlobalAlertBytes) { + registerGlobalAlert(); + } } @Override