OSDN Git Service

gd_shim: Skip legacy dumpsys if no registrants
authorChris Manton <cmanton@google.com>
Sun, 6 Dec 2020 17:23:18 +0000 (09:23 -0800)
committerChris Manton <cmanton@google.com>
Sat, 12 Dec 2020 17:07:23 +0000 (17:07 +0000)
Test: dumpsys on live system
Bug: 173755948
Tag: #refactor

Change-Id: I658e091c7f4fcd3977baea7534b8bc6d33a736cb

main/shim/dumpsys.cc

index 2cd8597..f01baf4 100644 (file)
@@ -25,7 +25,7 @@
 namespace {
 constexpr char kModuleName[] = "shim::legacy::dumpsys";
 static std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>*
-    dumpsys_functions_;
+    dumpsys_functions_{nullptr};
 }  // namespace
 
 void bluetooth::shim::RegisterDumpsysFunction(const void* token,
@@ -42,10 +42,14 @@ void bluetooth::shim::UnregisterDumpsysFunction(const void* token) {
 }
 
 void bluetooth::shim::Dump(int fd, const char** args) {
-  dprintf(fd, "%s Dumping shim legacy targets:%zd\n", kModuleName,
-          dumpsys_functions_->size());
-  for (auto& dumpsys : *dumpsys_functions_) {
-    dumpsys.second(fd);
+  if (dumpsys_functions_ == nullptr) {
+    dprintf(fd, "%s No registered dumpsys shim legacy targets\n", kModuleName);
+  } else {
+    dprintf(fd, "%s Dumping shim legacy targets:%zd\n", kModuleName,
+            dumpsys_functions_->size());
+    for (auto& dumpsys : *dumpsys_functions_) {
+      dumpsys.second(fd);
+    }
   }
   if (bluetooth::shim::is_gd_stack_started_up()) {
     bluetooth::shim::GetDumpsys()->Dump(fd, args);