From a545c35fa4fa81dd9920b33f6036aa34e8023f68 Mon Sep 17 00:00:00 2001 From: junyulai Date: Fri, 6 Nov 2020 19:19:31 +0800 Subject: [PATCH] Remove unused variables From aosp/537809, variables that used to fetch realtime stats are defined in NetworkStatsService. These varialbles are filled by JNI in boot up stage in order to keep definitions sync with native layer. However, there is still a copy in TrafficStats.java, and this copy cannot be filled in boot-up stage since it is in app process. Besides, making a binder call to fetch these constants from service is considered an overkill. Thus, since there is no caller to these variables and callers should use definitions in TrafficStats, remove these variables. Test: atest FrameworksNetTests Bug: 16229221 Change-Id: I6a48d4dbb1b824cfc6c4a47395b2a76aa28cf5c9 --- .../android/server/net/NetworkStatsService.java | 9 --------- ...com_android_server_net_NetworkStatsService.cpp | 15 --------------- 2 files changed, 24 deletions(-) diff --git a/services/core/java/com/android/server/net/NetworkStatsService.java b/services/core/java/com/android/server/net/NetworkStatsService.java index bfd0211f18..81a6641de8 100644 --- a/services/core/java/com/android/server/net/NetworkStatsService.java +++ b/services/core/java/com/android/server/net/NetworkStatsService.java @@ -2214,15 +2214,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub { } } - // TODO: Remove unused definitions after removing JNI that fills these variables. - // See {@code com_android_server_net_NetworkStatsService.cpp}. - private static int TYPE_RX_BYTES; - private static int TYPE_RX_PACKETS; - private static int TYPE_TX_BYTES; - private static int TYPE_TX_PACKETS; - private static int TYPE_TCP_RX_PACKETS; - private static int TYPE_TCP_TX_PACKETS; - 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); diff --git a/services/core/jni/com_android_server_net_NetworkStatsService.cpp b/services/core/jni/com_android_server_net_NetworkStatsService.cpp index 0275f3ea32..10b248a70e 100644 --- a/services/core/jni/com_android_server_net_NetworkStatsService.cpp +++ b/services/core/jni/com_android_server_net_NetworkStatsService.cpp @@ -215,21 +215,6 @@ static const JNINativeMethod gMethods[] = { }; int register_android_server_net_NetworkStatsService(JNIEnv* env) { - jclass netStatsService = env->FindClass("com/android/server/net/NetworkStatsService"); - jfieldID rxBytesId = env->GetStaticFieldID(netStatsService, "TYPE_RX_BYTES", "I"); - jfieldID rxPacketsId = env->GetStaticFieldID(netStatsService, "TYPE_RX_PACKETS", "I"); - jfieldID txBytesId = env->GetStaticFieldID(netStatsService, "TYPE_TX_BYTES", "I"); - jfieldID txPacketsId = env->GetStaticFieldID(netStatsService, "TYPE_TX_PACKETS", "I"); - jfieldID tcpRxPacketsId = env->GetStaticFieldID(netStatsService, "TYPE_TCP_RX_PACKETS", "I"); - jfieldID tcpTxPacketsId = env->GetStaticFieldID(netStatsService, "TYPE_TCP_TX_PACKETS", "I"); - - env->SetStaticIntField(netStatsService, rxBytesId, RX_BYTES); - env->SetStaticIntField(netStatsService, rxPacketsId, RX_PACKETS); - env->SetStaticIntField(netStatsService, txBytesId, TX_BYTES); - env->SetStaticIntField(netStatsService, txPacketsId, TX_PACKETS); - env->SetStaticIntField(netStatsService, tcpRxPacketsId, TCP_RX_PACKETS); - env->SetStaticIntField(netStatsService, tcpTxPacketsId, TCP_TX_PACKETS); - return jniRegisterNativeMethods(env, "com/android/server/net/NetworkStatsService", gMethods, NELEM(gMethods)); }