Prevent native_init from starting TrafficController
TrafficController is currently still started by netd, and this should
not happen in two places. Instead, native_init should init (open) the
maps.
Test: atest FrameworksNetTests
Change-Id: Ifd6be50aa5f62e59a5b1c5c0a97550389fd0e7e1
diff --git a/service/jni/com_android_server_BpfNetMaps.cpp b/service/jni/com_android_server_BpfNetMaps.cpp
index 113c449..bde52a5 100644
--- a/service/jni/com_android_server_BpfNetMaps.cpp
+++ b/service/jni/com_android_server_BpfNetMaps.cpp
@@ -39,7 +39,8 @@
namespace android {
static void native_init(JNIEnv* env, jobject clazz) {
- Status status = mTc.start();
+ // start is still being called by netd
+ Status status = mTc.initMaps();
if (!isOk(status)) {
ALOGE("%s failed", __func__);
}
diff --git a/service/native/include/TrafficController.h b/service/native/include/TrafficController.h
index ddcf445..2d89344 100644
--- a/service/native/include/TrafficController.h
+++ b/service/native/include/TrafficController.h
@@ -32,14 +32,22 @@
using netdutils::StatusOr;
class TrafficController {
- public:
- static constexpr char DUMP_KEYWORD[] = "trafficcontroller";
-
+ // TODO: marking this private for right now, as start is already called by
+ // netd. start() calls initMaps(), initPrograms(), and sets up the socket
+ // destroy listener. Both initPrograms() and setting up the socket destroy
+ // listener should only be done once.
/*
* Initialize the whole controller
*/
netdutils::Status start();
+ public:
+ static constexpr char DUMP_KEYWORD[] = "trafficcontroller";
+
+ // TODO: marking this public for right now, as start() is already called by
+ // netd.
+ netdutils::Status initMaps() EXCLUDES(mMutex);
+
int setCounterSet(int counterSetNum, uid_t uid, uid_t callingUid) EXCLUDES(mMutex);
/*
@@ -187,8 +195,6 @@
std::mutex mMutex;
- netdutils::Status initMaps() EXCLUDES(mMutex);
-
// Keep track of uids that have permission UPDATE_DEVICE_STATS so we don't
// need to call back to system server for permission check.
std::set<uid_t> mPrivilegedUser GUARDED_BY(mMutex);