Merge "Clear counters and delete tag data from NetworkStatsService." am: d2e67f24d0 am: 67105844ab
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1962922 Change-Id: Iaa0ddbb9d6b291cfe7b2ca6396dc2aeaf5617bf1
This commit is contained in:
@@ -61,27 +61,9 @@ static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) {
|
||||
return (jint)res;
|
||||
}
|
||||
|
||||
static jint setCounterSet(JNIEnv* env, jclass, jint setNum, jint uid) {
|
||||
int res = qtaguid_setCounterSet(setNum, uid);
|
||||
if (res < 0) {
|
||||
return (jint)-errno;
|
||||
}
|
||||
return (jint)res;
|
||||
}
|
||||
|
||||
static jint deleteTagData(JNIEnv* env, jclass, jint tagNum, jint uid) {
|
||||
int res = qtaguid_deleteTagData(tagNum, uid);
|
||||
if (res < 0) {
|
||||
return (jint)-errno;
|
||||
}
|
||||
return (jint)res;
|
||||
}
|
||||
|
||||
static const JNINativeMethod gQTagUidMethods[] = {
|
||||
{ "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*)tagSocketFd},
|
||||
{ "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*)untagSocketFd},
|
||||
{ "native_setCounterSet", "(II)I", (void*)setCounterSet},
|
||||
{ "native_deleteTagData", "(II)I", (void*)deleteTagData},
|
||||
};
|
||||
|
||||
int register_android_server_NetworkManagementSocketTagger(JNIEnv* env) {
|
||||
|
||||
@@ -111,21 +111,6 @@ public final class NetworkManagementSocketTagger extends SocketTagger {
|
||||
public int statsUid = -1;
|
||||
}
|
||||
|
||||
public static void setKernelCounterSet(int uid, int counterSet) {
|
||||
final int errno = native_setCounterSet(counterSet, uid);
|
||||
if (errno < 0) {
|
||||
Log.w(TAG, "setKernelCountSet(" + uid + ", " + counterSet + ") failed with errno "
|
||||
+ errno);
|
||||
}
|
||||
}
|
||||
|
||||
public static void resetKernelUidStats(int uid) {
|
||||
int errno = native_deleteTagData(0, uid);
|
||||
if (errno < 0) {
|
||||
Log.w(TAG, "problem clearing counters for uid " + uid + " : errno " + errno);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert {@code /proc/} tag format to {@link Integer}. Assumes incoming
|
||||
* format like {@code 0x7fffffff00000000}.
|
||||
@@ -141,6 +126,4 @@ public final class NetworkManagementSocketTagger extends SocketTagger {
|
||||
|
||||
private static native int native_tagSocketFd(FileDescriptor fd, int tag, int uid);
|
||||
private static native int native_untagSocketFd(FileDescriptor fd);
|
||||
private static native int native_setCounterSet(int uid, int counterSetNum);
|
||||
private static native int native_deleteTagData(int tag, int uid);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -16,20 +16,18 @@
|
||||
|
||||
#define LOG_TAG "NetworkStatsNative"
|
||||
|
||||
#include <cutils/qtaguid.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "core_jni_helpers.h"
|
||||
#include <jni.h>
|
||||
#include <nativehelper/ScopedUtfChars.h>
|
||||
#include <utils/misc.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <utils/Log.h>
|
||||
#include <utils/misc.h>
|
||||
|
||||
#include "android-base/unique_fd.h"
|
||||
#include "bpf/BpfUtils.h"
|
||||
#include "netdbpf/BpfNetworkStats.h"
|
||||
|
||||
@@ -104,10 +102,15 @@ static jlong getUidStat(JNIEnv* env, jclass clazz, jint uid, jint type) {
|
||||
}
|
||||
}
|
||||
|
||||
static int deleteTagData(JNIEnv* /* env */, jclass /* clazz */, jint uid) {
|
||||
return qtaguid_deleteTagData(0, uid);
|
||||
}
|
||||
|
||||
static const JNINativeMethod gMethods[] = {
|
||||
{"nativeGetTotalStat", "(I)J", (void*)getTotalStat},
|
||||
{"nativeGetIfaceStat", "(Ljava/lang/String;I)J", (void*)getIfaceStat},
|
||||
{"nativeGetUidStat", "(II)J", (void*)getUidStat},
|
||||
{"nativeDeleteTagData", "(I)I", (void*)deleteTagData},
|
||||
};
|
||||
|
||||
int register_android_server_net_NetworkStatsService(JNIEnv* env) {
|
||||
|
||||
Reference in New Issue
Block a user