From 9a0b0d41568717b4aed8a17d4901ead3d4a73cd8 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Tue, 26 Aug 2025 03:05:26 -0700 Subject: [PATCH] Don't set setPollOnOpen in SatelliteCoarseUsageMetricsCollector. This is not safe to do in system server because it affects all system server callers of NetworkStatsManager, including ones that frequently call into NetworkStatsService, such as NetworkPolicyManagerService. Also, setPollOnOpen is unnecessary because data usage is only collected when processing the `onLost` callback, which is triggered after ConnectivityService forces a poll. Fix: 427909947 Flag: EXEMPT BUGFIX Test: covered by existing tests Change-Id: I2fb25f4529d46dfc14b00b0aa69c5145317ca9dd --- .../metrics/SatelliteCoarseUsageMetricsCollector.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/service/src/com/android/metrics/SatelliteCoarseUsageMetricsCollector.java b/service/src/com/android/metrics/SatelliteCoarseUsageMetricsCollector.java index 7e8e463389..0dea382f4c 100644 --- a/service/src/com/android/metrics/SatelliteCoarseUsageMetricsCollector.java +++ b/service/src/com/android/metrics/SatelliteCoarseUsageMetricsCollector.java @@ -299,12 +299,11 @@ public class SatelliteCoarseUsageMetricsCollector { private void handleStartMonitoring() { // Note that in the constructor it is too early to get the managers. mCm = mContext.getSystemService(ConnectivityManager.class); + // Note: there is no need to call setPollOnOpen(true) to obtain accurate data. This class + // collects data usage only when processing the onLost callback, and ConnectivityService + // calls onLost only after it calls notifyIfacesChangedForNetworkStats, which forces a poll. + // Also, it is not safe to call setPollOnOpen(true) inside system server. b/427909947 . mNsm = mContext.getSystemService(NetworkStatsManager.class); - // Note: This might create heavy workload on NetworkStatsService if queried with high - // frequency, as the calling UID is system. Each query made with this manager - // updates usage stored in files before returning the newest result. - // This behavior is not rate-limited because the calling uid is the system UID. - mNsm.setPollOnOpen(true); // Get the first baseline. updateStartTimestamp(); mSatelliteBaseline = mDeps.getSummary(mNsm, mStartTime);