Remove ConnectivityManager swapActiveStatsMap API
swapActiveStatsMap is temporary added for the NetworkStatsFactory to
call BpfNetMaps#swapActiveStatsMap in tethering mainline module. Now
NetworkStatsFactory already be mainlined, calling BpfNetMaps#swapActiveStatsMap
directly.
Bug: 218494448
Test: atest ConnectivityCoverageTests
atest FrameworksNetTests
Change-Id: I25618020c078c7de3f0036c48d06d7816a431f62
This commit is contained in:
@@ -25,9 +25,9 @@ import static android.net.NetworkStats.UID_ALL;
|
|||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkStats;
|
import android.net.NetworkStats;
|
||||||
import android.net.UnderlyingNetworkInfo;
|
import android.net.UnderlyingNetworkInfo;
|
||||||
|
import android.os.ServiceSpecificException;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@ import com.android.internal.annotations.GuardedBy;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.util.ProcFileReader;
|
import com.android.internal.util.ProcFileReader;
|
||||||
import com.android.net.module.util.CollectionUtils;
|
import com.android.net.module.util.CollectionUtils;
|
||||||
|
import com.android.server.BpfNetMaps;
|
||||||
|
|
||||||
import libcore.io.IoUtils;
|
import libcore.io.IoUtils;
|
||||||
|
|
||||||
@@ -74,6 +75,8 @@ public class NetworkStatsFactory {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final BpfNetMaps mBpfNetMaps;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Guards persistent data access in this class
|
* Guards persistent data access in this class
|
||||||
*
|
*
|
||||||
@@ -170,6 +173,7 @@ public class NetworkStatsFactory {
|
|||||||
mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");
|
mStatsXtIfaceFmt = new File(procRoot, "net/xt_qtaguid/iface_stat_fmt");
|
||||||
mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats");
|
mStatsXtUid = new File(procRoot, "net/xt_qtaguid/stats");
|
||||||
mUseBpfStats = useBpfStats;
|
mUseBpfStats = useBpfStats;
|
||||||
|
mBpfNetMaps = new BpfNetMaps();
|
||||||
synchronized (mPersistentDataLock) {
|
synchronized (mPersistentDataLock) {
|
||||||
mPersistSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), -1);
|
mPersistSnapshot = new NetworkStats(SystemClock.elapsedRealtime(), -1);
|
||||||
mTunAnd464xlatAdjustedStats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
|
mTunAnd464xlatAdjustedStats = new NetworkStats(SystemClock.elapsedRealtime(), -1);
|
||||||
@@ -297,12 +301,14 @@ public class NetworkStatsFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GuardedBy("mPersistentDataLock")
|
@GuardedBy("mPersistentDataLock")
|
||||||
private void requestSwapActiveStatsMapLocked() {
|
private void requestSwapActiveStatsMapLocked() throws IOException {
|
||||||
// Do a active map stats swap. When the binder call successfully returns,
|
try {
|
||||||
// the system server should be able to safely read and clean the inactive map
|
// Do a active map stats swap. Once the swap completes, this code
|
||||||
// without race problem.
|
// can read and clean the inactive map without races.
|
||||||
final ConnectivityManager cm = mContext.getSystemService(ConnectivityManager.class);
|
mBpfNetMaps.swapActiveStatsMap();
|
||||||
cm.swapActiveStatsMap();
|
} catch (ServiceSpecificException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -328,11 +334,7 @@ public class NetworkStatsFactory {
|
|||||||
final NetworkStats stats =
|
final NetworkStats stats =
|
||||||
new NetworkStats(SystemClock.elapsedRealtime(), 0 /* initialSize */);
|
new NetworkStats(SystemClock.elapsedRealtime(), 0 /* initialSize */);
|
||||||
if (mUseBpfStats) {
|
if (mUseBpfStats) {
|
||||||
try {
|
|
||||||
requestSwapActiveStatsMapLocked();
|
requestSwapActiveStatsMapLocked();
|
||||||
} catch (RuntimeException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
// Stats are always read from the inactive map, so they must be read after the
|
// Stats are always read from the inactive map, so they must be read after the
|
||||||
// swap
|
// swap
|
||||||
if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
|
if (nativeReadNetworkStatsDetail(stats, mStatsXtUid.getAbsolutePath(), UID_ALL,
|
||||||
|
|||||||
Reference in New Issue
Block a user