Clean up adb_trace_init.
Old code was a mess for splitting a string and then searching a list
when they really wanted a map.
To more closely match ANDROID_LOG_TAG, only use a space separated list
rather than space/colon/semi-colon/comma.
Change-Id: I915ff4968e42d5f8dec1b43b6eacc0c8d7b44d7b
diff --git a/adb/Android.mk b/adb/Android.mk
index f3a4822..94034c2 100644
--- a/adb/Android.mk
+++ b/adb/Android.mk
@@ -77,6 +77,10 @@
LOCAL_SHARED_LIBRARIES := libbase
+# Even though we're building a static library (and thus there's no link step for
+# this to take effect), this adds the includes to our path.
+LOCAL_STATIC_LIBRARIES := libbase
+
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
@@ -91,8 +95,8 @@
LOCAL_SHARED_LIBRARIES := libbase
# Even though we're building a static library (and thus there's no link step for
-# this to take effect), this adds the SSL includes to our path.
-LOCAL_STATIC_LIBRARIES := libcrypto_static
+# this to take effect), this adds the includes to our path.
+LOCAL_STATIC_LIBRARIES := libcrypto_static libbase
ifeq ($(HOST_OS),windows)
LOCAL_C_INCLUDES += development/host/windows/usb/api/
@@ -254,10 +258,10 @@
libbase \
libfs_mgr \
liblog \
- libcutils \
- libc \
libmincrypt \
libselinux \
libext4_utils_static \
+ libcutils \
+ libbase \
include $(BUILD_EXECUTABLE)
diff --git a/adb/adb.cpp b/adb/adb.cpp
index 3d1b7b4..0e14213 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -31,6 +31,8 @@
#include <time.h>
#include <string>
+#include <vector>
+#include <unordered_map>
#include <base/stringprintf.h>
#include <base/strings.h>
@@ -130,66 +132,46 @@
#endif
}
-// Split the comma/space/colum/semi-column separated list of tags from the trace
-// setting and build the trace mask from it. note that '1' and 'all' are special
-// cases to enable all tracing.
+// Split the space separated list of tags from the trace setting and build the
+// trace mask from it. note that '1' and 'all' are special cases to enable all
+// tracing.
//
// adb's trace setting comes from the ADB_TRACE environment variable, whereas
// adbd's comes from the system property persist.adb.trace_mask.
void adb_trace_init() {
const std::string trace_setting = get_trace_setting();
- static const struct {
- const char* tag;
- int flag;
- } tags[] = {
- { "1", 0 },
- { "all", 0 },
- { "adb", TRACE_ADB },
- { "sockets", TRACE_SOCKETS },
- { "packets", TRACE_PACKETS },
- { "rwx", TRACE_RWX },
- { "usb", TRACE_USB },
- { "sync", TRACE_SYNC },
- { "sysdeps", TRACE_SYSDEPS },
- { "transport", TRACE_TRANSPORT },
- { "jdwp", TRACE_JDWP },
- { "services", TRACE_SERVICES },
- { "auth", TRACE_AUTH },
- { NULL, 0 }
- };
+ std::unordered_map<std::string, int> trace_flags = {
+ {"1", 0},
+ {"all", 0},
+ {"adb", TRACE_ADB},
+ {"sockets", TRACE_SOCKETS},
+ {"packets", TRACE_PACKETS},
+ {"rwx", TRACE_RWX},
+ {"usb", TRACE_USB},
+ {"sync", TRACE_SYNC},
+ {"sysdeps", TRACE_SYSDEPS},
+ {"transport", TRACE_TRANSPORT},
+ {"jdwp", TRACE_JDWP},
+ {"services", TRACE_SERVICES},
+ {"auth", TRACE_AUTH}};
- if (trace_setting.empty()) {
- return;
- }
-
- // Use a comma/colon/semi-colon/space separated list
- const char* p = trace_setting.c_str();
- while (*p) {
- int len, tagn;
-
- const char* q = strpbrk(p, " ,:;");
- if (q == NULL) {
- q = p + strlen(p);
+ std::vector<std::string> elements = android::base::Split(trace_setting, " ");
+ for (const auto& elem : elements) {
+ const auto& flag = trace_flags.find(elem);
+ if (flag == trace_flags.end()) {
+ D("Unknown trace flag: %s", flag->first.c_str());
+ continue;
}
- len = q - p;
- for (tagn = 0; tags[tagn].tag != NULL; tagn++) {
- int taglen = strlen(tags[tagn].tag);
-
- if (len == taglen && !memcmp(tags[tagn].tag, p, len)) {
- int flag = tags[tagn].flag;
- if (flag == 0) {
- adb_trace_mask = ~0;
- return;
- }
- adb_trace_mask |= (1 << flag);
- break;
- }
+ if (flag->second == 0) {
+ // 0 is used for the special values "1" and "all" that enable all
+ // tracing.
+ adb_trace_mask = ~0;
+ return;
+ } else {
+ adb_trace_mask |= 1 << flag->second;
}
- p = q;
- if (*p)
- p++;
}
#if !ADB_HOST