Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14b95b68 authored by Chris Manton's avatar Chris Manton
Browse files

dumpsys: Acquire stack manager lock upon execution

Previously acquired lock before queuing on main loop

Bug: 329685247
Bug: 329682970
Test: atest net_test_main_dumpsys
Flag: dumpsys_acquire_stack_when_executing
Change-Id: If1310cbb705b7ec5a67bd173c8e1ba6e2577ca09
parent fb0d2313
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -289,6 +289,7 @@ cc_binary {
        ":BluetoothFacade_neighbor",
        ":BluetoothFacade_security_layer",
        ":BluetoothFacade_shim_layer",
        ":TestMockMainShimStack",
        "facade/facade_main.cc",
        "facade/grpc_root_server.cc",
        "facade/read_only_property_server.cc",
@@ -529,6 +530,7 @@ cc_test {
        ":BluetoothDumpsysTestSources",
        ":BluetoothShimTestSources",
        ":TestCommonMockFunctions",
        ":TestMockMainShimStack",
        "module_gdx_unittest.cc",
        "module_jniloop_unittest.cc",
        "module_mainloop_unittest.cc",
+13 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@

#include "dumpsys/filter.h"
#include "dumpsys_data_generated.h"
#include "main/shim/stack.h"
#include "module.h"
#include "module_dumper.h"
#include "os/log.h"
@@ -156,13 +157,23 @@ void Dumpsys::impl::DumpWithArgsAsync(int fd, const char** args) const {
}

void Dumpsys::impl::DumpWithArgsSync(int fd, const char** args, std::promise<void> promise) {
  if (IS_FLAG_ENABLED(dumpsys_acquire_stack_when_executing)) {
    if (bluetooth::shim::Stack::GetInstance()->LockForDumpsys(
            [=, *this]() { this->DumpWithArgsAsync(fd, args); })) {
      log::info("Successful dumpsys procedure");
    } else {
      log::info("Failed dumpsys procedure as stack was not longer active");
    }
  } else {
    DumpWithArgsAsync(fd, args);
  }
  promise.set_value();
}

Dumpsys::Dumpsys(const std::string& pre_bundled_schema)
    : reflection_schema_(dumpsys::ReflectionSchema(pre_bundled_schema)) {}

// DEPRECATED Flag: dumpsys_acquire_stack_when_executing
void Dumpsys::Dump(int fd, const char** args) {
  if (fd <= 0) {
    return;
@@ -172,6 +183,7 @@ void Dumpsys::Dump(int fd, const char** args) {
  CallOn(pimpl_.get(), &Dumpsys::impl::DumpWithArgsSync, fd, args, std::move(promise));
  future.get();
}
// !DEPRECATED Flag: dumpsys_acquire_stack_when_executing

void Dumpsys::Dump(int fd, const char** args, std::promise<void> promise) {
  if (fd <= 0) {
+28 −10
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include "main/shim/dumpsys.h"

#include <android_bluetooth_flags.h>

#include <unordered_map>

#include "include/check.h"
@@ -55,6 +57,21 @@ void bluetooth::shim::Dump(int fd, const char** args) {
      dumpsys.second(fd);
    }
  }
  if (IS_FLAG_ENABLED(dumpsys_acquire_stack_when_executing)) {
    std::promise<void> promise;
    std::future future = promise.get_future();
    if (bluetooth::shim::Stack::GetInstance()->CallOnModule<shim::Dumpsys>(
            [&promise, fd, args](shim::Dumpsys* mod) {
              mod->Dump(fd, args, std::move(promise));
            })) {
      log::assert_that(
          future.wait_for(std::chrono::seconds(1)) == std::future_status::ready,
          "Timed out waiting for dumpsys to complete");
    } else {
      dprintf(fd, "%s NOTE: gd dumpsys module not loaded or started\n",
              kModuleName);
    }
  } else {  // !FLAG(dumpsys_acquire_stack_when_executing)
    bluetooth::shim::Stack::GetInstance()->LockForDumpsys([=]() {
      if (bluetooth::shim::is_gd_stack_started_up()) {
        if (bluetooth::shim::is_gd_dumpsys_module_started()) {
@@ -68,3 +85,4 @@ void bluetooth::shim::Dump(int fd, const char** args) {
      }
    });
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ bool is_gd_stack_started_up();
/**
 * Checks if the dumpsys module has been started.
 *
 * DEPRECATED Flag:dumpsys_acquire_stack_when_executing
 *
 * @return true if specified module has started, false otherwise.
 */
bool is_gd_dumpsys_module_started();