NetworkStatsService - add void nativeRegisterIface(iface)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8dd893d09fd5b01676b08fb87f0e01b5d2ab9efd
This commit is contained in:
Maciej Żenczykowski 2024-01-24 12:20:44 -08:00
commit bfb3a3c5b4
2 changed files with 11 additions and 0 deletions

View file

@ -38,6 +38,9 @@ using android::bpf::NetworkTraceHandler;
namespace android {
static void nativeRegisterIface(JNIEnv* env, jclass clazz, jstring iface) {
}
static jobject statsValueToEntry(JNIEnv* env, StatsValue* stats) {
// Find the Java class that represents the structure
jclass gEntryClass = env->FindClass("android/net/NetworkStats$Entry");
@ -100,6 +103,11 @@ static void nativeInitNetworkTracing(JNIEnv* env, jclass clazz) {
}
static const JNINativeMethod gMethods[] = {
{
"nativeRegisterIface",
"(Ljava/lang/String;)V",
(void*)nativeRegisterIface
},
{
"nativeGetTotalStat",
"()Landroid/net/NetworkStats$Entry;",

View file

@ -2211,6 +2211,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// both total usage and UID details.
final String baseIface = snapshot.getLinkProperties().getInterfaceName();
if (baseIface != null) {
nativeRegisterIface(baseIface);
findOrCreateNetworkIdentitySet(mActiveIfaces, baseIface).add(ident);
findOrCreateNetworkIdentitySet(mActiveUidIfaces, baseIface).add(ident);
@ -2282,6 +2283,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// baseIface has been handled, so ignore it.
if (TextUtils.equals(baseIface, iface)) continue;
if (iface != null) {
nativeRegisterIface(iface);
findOrCreateNetworkIdentitySet(mActiveIfaces, iface).add(ident);
findOrCreateNetworkIdentitySet(mActiveUidIfaces, iface).add(ident);
if (isMobile) {
@ -3415,6 +3417,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
}
// TODO: Read stats by using BpfNetMapsReader.
private static native void nativeRegisterIface(String iface);
@Nullable
private static native NetworkStats.Entry nativeGetTotalStat();
@Nullable