Add initial dump() method to NetdNativeService
This is called by "dumpsys netd".
Bug: 27239233
Change-Id: I27fb308f8067243ff241a6f8fd6a83f406087d2a
diff --git a/server/Network.cpp b/server/Network.cpp
index 0ca6247..f33cd88 100644
--- a/server/Network.cpp
+++ b/server/Network.cpp
@@ -19,6 +19,9 @@
#define LOG_TAG "Netd"
#include "log/log.h"
+#include <android-base/strings.h>
+#include <sstream>
+
Network::~Network() {
if (!mInterfaces.empty()) {
ALOGE("deleting network with netId %u without clearing its interfaces", mNetId);
@@ -49,5 +52,37 @@
return 0;
}
+std::string Network::toString() const {
+ const char kSeparator[] = " ";
+ std::stringstream repr;
+
+ repr << mNetId;
+
+ repr << kSeparator;
+ switch (getType()) {
+ case DUMMY:
+ repr << "DUMMY";
+ break;
+ case LOCAL:
+ repr << "LOCAL";
+ break;
+ case PHYSICAL:
+ repr << "PHYSICAL";
+ break;
+ case VIRTUAL:
+ repr << "VIRTUAL";
+ break;
+ default:
+ repr << "unknown";
+ }
+
+ if (mInterfaces.size() > 0) {
+ repr << kSeparator << android::base::Join(mInterfaces, ",");
+ }
+
+ return repr.str();
+}
+
+
Network::Network(unsigned netId) : mNetId(netId) {
}