Clear counters and delete tag data from NetworkStatsService.
Currently, NetworkStatsService deletes tag data by calling NetworkManagementSocketTagger, which then calls into libcutils "qtaguid" code. Instead, make NetworkStatsService call into libcutils directly and delete the NetworkManagementSocketTagger code. In the future, this will make it easier for NetworkStatsService to perform this operation by calling directly into BpfNetMaps. Because the unit test does not yet have working JNI code, provide an internal TagStatsDeleter interface that can be mocked out via the Dependencies class. This is a bit ugly but it will be deleted as soon as the code uses BpfNetMaps directly. Delete NetworkManagementSocketTagger#setKernelCounterSet since it was replaced in aosp/1958917. Also remove unused includes and make formatting changes suggested by clang-format. Test: m Test: atest NetworkStatsServiceTest Test: atest NetworkUsageStatsTest Test: atest TrafficStatsTest Test: stats deleted when CtsUsageStatsTestCases completes and test APK is uninstalled Change-Id: I62987000afc185199821580232bfb7668c8e301e
This commit is contained in:
@@ -59,7 +59,6 @@ import static android.text.format.DateUtils.SECOND_IN_MILLIS;
|
||||
|
||||
import static com.android.net.module.util.NetworkCapabilitiesUtils.getDisplayTransport;
|
||||
import static com.android.net.module.util.NetworkStatsUtils.LIMIT_GLOBAL_ALERT;
|
||||
import static com.android.server.NetworkManagementSocketTagger.resetKernelUidStats;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
@@ -121,6 +120,7 @@ import android.provider.Settings.Global;
|
||||
import android.service.NetworkInterfaceProto;
|
||||
import android.service.NetworkStatsServiceDumpProto;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.telephony.PhoneStateListener;
|
||||
import android.telephony.SubscriptionPlan;
|
||||
import android.text.TextUtils;
|
||||
@@ -546,6 +546,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public TagStatsDeleter getTagStatsDeleter() {
|
||||
return NetworkStatsService::nativeDeleteTagData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1801,7 +1805,10 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
|
||||
// Clear kernel stats associated with UID
|
||||
for (int uid : uids) {
|
||||
resetKernelUidStats(uid);
|
||||
final int ret = mDeps.getTagStatsDeleter().deleteTagData(uid);
|
||||
if (ret < 0) {
|
||||
Log.w(TAG, "problem clearing counters for uid " + uid + ": " + Os.strerror(-ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2380,4 +2387,12 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
||||
private static native long nativeGetTotalStat(int type);
|
||||
private static native long nativeGetIfaceStat(String iface, int type);
|
||||
private static native long nativeGetUidStat(int uid, int type);
|
||||
|
||||
// TODO: use BpfNetMaps to delete tag data and remove this.
|
||||
@VisibleForTesting
|
||||
interface TagStatsDeleter {
|
||||
int deleteTagData(int uid);
|
||||
}
|
||||
|
||||
private static native int nativeDeleteTagData(int uid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user