Merge "Add a lock to protect persistent stats snapshot" am: f31face531

am: 57f207b1c7

Change-Id: Ia91b71536447e65725a85ebf2ac4f411aebe86c8
This commit is contained in:
Chenbo Feng
2019-04-12 05:59:36 -07:00
committed by android-build-merger

View File

@@ -28,6 +28,7 @@ import android.net.NetworkStats;
import android.os.StrictMode;
import android.os.SystemClock;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ProcFileReader;
@@ -65,6 +66,7 @@ public class NetworkStatsFactory {
private boolean mUseBpfStats;
// A persistent Snapshot since device start for eBPF stats
@GuardedBy("mPersistSnapshot")
private final NetworkStats mPersistSnapshot;
// TODO: only do adjustments in NetworkStatsService and remove this.
@@ -284,6 +286,7 @@ public class NetworkStatsFactory {
stats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
}
if (mUseBpfStats) {
synchronized (mPersistSnapshot) {
if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
null, TAG_ALL, mUseBpfStats) != 0) {
throw new IOException("Failed to parse network stats");
@@ -293,6 +296,7 @@ public class NetworkStatsFactory {
NetworkStats result = mPersistSnapshot.clone();
result.filter(limitUid, limitIfaces, limitTag);
return result;
}
} else {
if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), limitUid,
limitIfaces, limitTag, mUseBpfStats) != 0) {