Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bff0fb4e authored by Chenbo Feng's avatar Chenbo Feng
Browse files

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
Merged-In: I872ae18fb3e9631a4e6c4d773fefbba32e60a03b
parent 6ca9d3d9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -179,6 +179,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub {

    private final PowerManager.WakeLock mWakeLock;

    private final boolean mUseBpfTrafficStats;

    private IConnectivityManager mConnManager;

    @VisibleForTesting
@@ -328,6 +330,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();
    }

    @VisibleForTesting
@@ -916,7 +919,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
    }

    private boolean checkBpfStatsEnable() {
        return new File("/sys/fs/bpf/traffic_uid_stats_map").exists();
        return mUseBpfTrafficStats;
    }

    /**