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

Commit 25243b4e authored by Chenbo Feng's avatar Chenbo Feng Committed by android-build-merger
Browse files

Merge "Add a lock to protect persistent stats snapshot"

am: 84f5f1b8

Change-Id: I73851336452110afb74d6dd1ca5e50047d5b3d4a
parents bea65fa4 84f5f1b8
Loading
Loading
Loading
Loading
+12 −8
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.NetworkStats;
import android.os.StrictMode;
import android.os.StrictMode;
import android.os.SystemClock;
import android.os.SystemClock;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ProcFileReader;
import com.android.internal.util.ProcFileReader;
@@ -65,6 +66,7 @@ public class NetworkStatsFactory {
    private boolean mUseBpfStats;
    private boolean mUseBpfStats;


    // A persistent Snapshot since device start for eBPF stats
    // A persistent Snapshot since device start for eBPF stats
    @GuardedBy("mPersistSnapshot")
    private final NetworkStats mPersistSnapshot;
    private final NetworkStats mPersistSnapshot;


    // TODO: only do adjustments in NetworkStatsService and remove this.
    // TODO: only do adjustments in NetworkStatsService and remove this.
@@ -289,6 +291,7 @@ public class NetworkStatsFactory {
                stats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
                stats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
            }
            }
            if (mUseBpfStats) {
            if (mUseBpfStats) {
                synchronized (mPersistSnapshot) {
                    if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
                    if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
                            null, TAG_ALL, mUseBpfStats) != 0) {
                            null, TAG_ALL, mUseBpfStats) != 0) {
                        throw new IOException("Failed to parse network stats");
                        throw new IOException("Failed to parse network stats");
@@ -298,6 +301,7 @@ public class NetworkStatsFactory {
                    NetworkStats result = mPersistSnapshot.clone();
                    NetworkStats result = mPersistSnapshot.clone();
                    result.filter(limitUid, limitIfaces, limitTag);
                    result.filter(limitUid, limitIfaces, limitTag);
                    return result;
                    return result;
                }
            } else {
            } else {
                if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), limitUid,
                if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), limitUid,
                        limitIfaces, limitTag, mUseBpfStats) != 0) {
                        limitIfaces, limitTag, mUseBpfStats) != 0) {