Check for bpf support at NetworkStatsService start
The current implementation check for bpf map existance whenever a
NetworkStats request comes in. The check is not efficient and may
require additional permission for threads. So a member variable is added
to NetworkStatsService to store the bpf configuration status and is
initialized when NetworkStatsService start.
Test: -m CtsNetTestCases -t android.net.cts.TrafficStatsTest
-m CtsUsageStatsTestCases -t android.app.usage.cts.NetworkUsageStatsTest
Bug: 79994577
Change-Id: I872ae18fb3e9631a4e6c4d773fefbba32e60a03b
This commit is contained in:
@@ -184,6 +184,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
|
||||
private final PowerManager.WakeLock mWakeLock;
|
||||
|
||||
private final boolean mUseBpfTrafficStats;
|
||||
|
||||
private IConnectivityManager mConnManager;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -347,6 +349,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
mStatsObservers = checkNotNull(statsObservers, "missing NetworkStatsObservers");
|
||||
mSystemDir = checkNotNull(systemDir, "missing systemDir");
|
||||
mBaseDir = checkNotNull(baseDir, "missing baseDir");
|
||||
mUseBpfTrafficStats = new File("/sys/fs/bpf/traffic_uid_stats_map").exists();
|
||||
|
||||
LocalServices.addService(NetworkStatsManagerInternal.class,
|
||||
new NetworkStatsManagerInternalImpl());
|
||||
@@ -947,7 +950,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
}
|
||||
|
||||
private boolean checkBpfStatsEnable() {
|
||||
return new File("/sys/fs/bpf/traffic_uid_stats_map").exists();
|
||||
return mUseBpfTrafficStats;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user