Merge changes I044d0363,I0be3b802,Ib584ea57,I92291023
* changes:
bpf is required so /sys/fs/bpf/map_netd_app_uid_stats_map always exists
bpf is required - remove mUseBpfTrafficStats field
bpf is required - remove checkBpfStatsEnable()
remove qtaguid parsing
diff --git a/services/core/java/com/android/server/net/NetworkStatsFactory.java b/services/core/java/com/android/server/net/NetworkStatsFactory.java
index 431b009..e6433db 100644
--- a/services/core/java/com/android/server/net/NetworkStatsFactory.java
+++ b/services/core/java/com/android/server/net/NetworkStatsFactory.java
@@ -159,7 +159,7 @@
}
public NetworkStatsFactory() {
- this(new File("/proc/"), new File("/sys/fs/bpf/map_netd_app_uid_stats_map").exists());
+ this(new File("/proc/"), true);
}
@VisibleForTesting
diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java
index 097b071..f4b72a1 100644
--- a/services/core/java/com/android/server/net/NetworkStatsService.java
+++ b/services/core/java/com/android/server/net/NetworkStatsService.java
@@ -215,8 +215,6 @@
private final PowerManager.WakeLock mWakeLock;
- private final boolean mUseBpfTrafficStats;
-
private final ContentObserver mContentObserver;
private final ContentResolver mContentResolver;
@@ -438,7 +436,6 @@
mStatsObservers = Objects.requireNonNull(statsObservers, "missing NetworkStatsObservers");
mSystemDir = Objects.requireNonNull(systemDir, "missing systemDir");
mBaseDir = Objects.requireNonNull(baseDir, "missing baseDir");
- mUseBpfTrafficStats = new File("/sys/fs/bpf/map_netd_app_uid_stats_map").exists();
mDeps = Objects.requireNonNull(deps, "missing Dependencies");
final HandlerThread handlerThread = mDeps.makeHandlerThread();
@@ -1084,13 +1081,13 @@
if (callingUid != android.os.Process.SYSTEM_UID && callingUid != uid) {
return UNSUPPORTED;
}
- return nativeGetUidStat(uid, type, checkBpfStatsEnable());
+ return nativeGetUidStat(uid, type);
}
@Override
public long getIfaceStats(@NonNull String iface, int type) {
Objects.requireNonNull(iface);
- long nativeIfaceStats = nativeGetIfaceStat(iface, type, checkBpfStatsEnable());
+ long nativeIfaceStats = nativeGetIfaceStat(iface, type);
if (nativeIfaceStats == -1) {
return nativeIfaceStats;
} else {
@@ -1104,7 +1101,7 @@
@Override
public long getTotalStats(int type) {
- long nativeTotalStats = nativeGetTotalStat(type, checkBpfStatsEnable());
+ long nativeTotalStats = nativeGetTotalStat(type);
if (nativeTotalStats == -1) {
return nativeTotalStats;
} else {
@@ -1137,10 +1134,6 @@
}
}
- private boolean checkBpfStatsEnable() {
- return mUseBpfTrafficStats;
- }
-
/**
* Update {@link NetworkStatsRecorder} and {@link #mGlobalAlertBytes} to
* reflect current {@link #mPersistThreshold} value. Always defers to
@@ -2249,7 +2242,7 @@
}
}
- private static native long nativeGetTotalStat(int type, boolean useBpfStats);
- private static native long nativeGetIfaceStat(String iface, int type, boolean useBpfStats);
- private static native long nativeGetUidStat(int uid, int type, boolean useBpfStats);
+ 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);
}
diff --git a/services/core/jni/com_android_server_net_NetworkStatsService.cpp b/services/core/jni/com_android_server_net_NetworkStatsService.cpp
index 10b248a..5178132 100644
--- a/services/core/jni/com_android_server_net_NetworkStatsService.cpp
+++ b/services/core/jni/com_android_server_net_NetworkStatsService.cpp
@@ -38,9 +38,6 @@
namespace android {
-static const char* QTAGUID_IFACE_STATS = "/proc/net/xt_qtaguid/iface_stat_fmt";
-static const char* QTAGUID_UID_STATS = "/proc/net/xt_qtaguid/stats";
-
// NOTE: keep these in sync with TrafficStats.java
static const uint64_t UNKNOWN = -1;
@@ -72,102 +69,17 @@
}
}
-static int parseIfaceStats(const char* iface, Stats* stats) {
- FILE *fp = fopen(QTAGUID_IFACE_STATS, "r");
- if (fp == NULL) {
- return -1;
- }
-
- char buffer[384];
- char cur_iface[32];
- bool foundTcp = false;
- uint64_t rxBytes, rxPackets, txBytes, txPackets, tcpRxPackets, tcpTxPackets;
-
- while (fgets(buffer, sizeof(buffer), fp) != NULL) {
- int matched = sscanf(buffer, "%31s %" SCNu64 " %" SCNu64 " %" SCNu64
- " %" SCNu64 " " "%*u %" SCNu64 " %*u %*u %*u %*u "
- "%*u %" SCNu64 " %*u %*u %*u %*u", cur_iface, &rxBytes,
- &rxPackets, &txBytes, &txPackets, &tcpRxPackets, &tcpTxPackets);
- if (matched >= 5) {
- if (matched == 7) {
- foundTcp = true;
- }
- if (!iface || !strcmp(iface, cur_iface)) {
- stats->rxBytes += rxBytes;
- stats->rxPackets += rxPackets;
- stats->txBytes += txBytes;
- stats->txPackets += txPackets;
- if (matched == 7) {
- stats->tcpRxPackets += tcpRxPackets;
- stats->tcpTxPackets += tcpTxPackets;
- }
- }
- }
- }
-
- if (!foundTcp) {
- stats->tcpRxPackets = UNKNOWN;
- stats->tcpTxPackets = UNKNOWN;
- }
-
- if (fclose(fp) != 0) {
- return -1;
- }
- return 0;
-}
-
-static int parseUidStats(const uint32_t uid, Stats* stats) {
- FILE *fp = fopen(QTAGUID_UID_STATS, "r");
- if (fp == NULL) {
- return -1;
- }
-
- char buffer[384];
- char iface[32];
- uint32_t idx, cur_uid, set;
- uint64_t tag, rxBytes, rxPackets, txBytes, txPackets;
-
- while (fgets(buffer, sizeof(buffer), fp) != NULL) {
- if (sscanf(buffer,
- "%" SCNu32 " %31s 0x%" SCNx64 " %u %u %" SCNu64 " %" SCNu64
- " %" SCNu64 " %" SCNu64 "",
- &idx, iface, &tag, &cur_uid, &set, &rxBytes, &rxPackets,
- &txBytes, &txPackets) == 9) {
- if (uid == cur_uid && tag == 0L) {
- stats->rxBytes += rxBytes;
- stats->rxPackets += rxPackets;
- stats->txBytes += txBytes;
- stats->txPackets += txPackets;
- }
- }
- }
-
- if (fclose(fp) != 0) {
- return -1;
- }
- return 0;
-}
-
-static jlong getTotalStat(JNIEnv* env, jclass clazz, jint type, jboolean useBpfStats) {
+static jlong getTotalStat(JNIEnv* env, jclass clazz, jint type) {
Stats stats = {};
- if (useBpfStats) {
- if (bpfGetIfaceStats(NULL, &stats) == 0) {
- return getStatsType(&stats, (StatsType) type);
- } else {
- return UNKNOWN;
- }
- }
-
- if (parseIfaceStats(NULL, &stats) == 0) {
+ if (bpfGetIfaceStats(NULL, &stats) == 0) {
return getStatsType(&stats, (StatsType) type);
} else {
return UNKNOWN;
}
}
-static jlong getIfaceStat(JNIEnv* env, jclass clazz, jstring iface, jint type,
- jboolean useBpfStats) {
+static jlong getIfaceStat(JNIEnv* env, jclass clazz, jstring iface, jint type) {
ScopedUtfChars iface8(env, iface);
if (iface8.c_str() == NULL) {
return UNKNOWN;
@@ -175,33 +87,17 @@
Stats stats = {};
- if (useBpfStats) {
- if (bpfGetIfaceStats(iface8.c_str(), &stats) == 0) {
- return getStatsType(&stats, (StatsType) type);
- } else {
- return UNKNOWN;
- }
- }
-
- if (parseIfaceStats(iface8.c_str(), &stats) == 0) {
+ if (bpfGetIfaceStats(iface8.c_str(), &stats) == 0) {
return getStatsType(&stats, (StatsType) type);
} else {
return UNKNOWN;
}
}
-static jlong getUidStat(JNIEnv* env, jclass clazz, jint uid, jint type, jboolean useBpfStats) {
+static jlong getUidStat(JNIEnv* env, jclass clazz, jint uid, jint type) {
Stats stats = {};
- if (useBpfStats) {
- if (bpfGetUidStats(uid, &stats) == 0) {
- return getStatsType(&stats, (StatsType) type);
- } else {
- return UNKNOWN;
- }
- }
-
- if (parseUidStats(uid, &stats) == 0) {
+ if (bpfGetUidStats(uid, &stats) == 0) {
return getStatsType(&stats, (StatsType) type);
} else {
return UNKNOWN;
@@ -209,9 +105,9 @@
}
static const JNINativeMethod gMethods[] = {
- {"nativeGetTotalStat", "(IZ)J", (void*) getTotalStat},
- {"nativeGetIfaceStat", "(Ljava/lang/String;IZ)J", (void*) getIfaceStat},
- {"nativeGetUidStat", "(IIZ)J", (void*) getUidStat},
+ {"nativeGetTotalStat", "(I)J", (void*)getTotalStat},
+ {"nativeGetIfaceStat", "(Ljava/lang/String;I)J", (void*)getIfaceStat},
+ {"nativeGetUidStat", "(II)J", (void*)getUidStat},
};
int register_android_server_net_NetworkStatsService(JNIEnv* env) {