summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/gd/Android.bp2
-rw-r--r--system/gd/shim/dumpsys.cc14
-rw-r--r--system/main/shim/dumpsys.cc38
-rw-r--r--system/main/shim/shim.h2
4 files changed, 45 insertions, 11 deletions
diff --git a/system/gd/Android.bp b/system/gd/Android.bp
index bd2b148120..3126b09673 100644
--- a/system/gd/Android.bp
+++ b/system/gd/Android.bp
@@ -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",
diff --git a/system/gd/shim/dumpsys.cc b/system/gd/shim/dumpsys.cc
index 61b284f174..f12c0bbd5b 100644
--- a/system/gd/shim/dumpsys.cc
+++ b/system/gd/shim/dumpsys.cc
@@ -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) {
- DumpWithArgsAsync(fd, args);
+ 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) {
diff --git a/system/main/shim/dumpsys.cc b/system/main/shim/dumpsys.cc
index 7c80cb27db..52e82d33d4 100644
--- a/system/main/shim/dumpsys.cc
+++ b/system/main/shim/dumpsys.cc
@@ -18,6 +18,8 @@
#include "main/shim/dumpsys.h"
+#include <android_bluetooth_flags.h>
+
#include <unordered_map>
#include "include/check.h"
@@ -55,16 +57,32 @@ void bluetooth::shim::Dump(int fd, const char** args) {
dumpsys.second(fd);
}
}
- bluetooth::shim::Stack::GetInstance()->LockForDumpsys([=]() {
- if (bluetooth::shim::is_gd_stack_started_up()) {
- if (bluetooth::shim::is_gd_dumpsys_module_started()) {
- bluetooth::shim::GetDumpsys()->Dump(fd, args);
- } else {
- dprintf(fd, "%s NOTE: gd dumpsys module not loaded or started\n",
- kModuleName);
- }
+ 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 gd stack is enabled but not started\n", kModuleName);
+ 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()) {
+ bluetooth::shim::GetDumpsys()->Dump(fd, args);
+ } else {
+ dprintf(fd, "%s NOTE: gd dumpsys module not loaded or started\n",
+ kModuleName);
+ }
+ } else {
+ dprintf(fd, "%s gd stack is enabled but not started\n", kModuleName);
+ }
+ });
+ }
}
diff --git a/system/main/shim/shim.h b/system/main/shim/shim.h
index 8fa166b603..d297b91b07 100644
--- a/system/main/shim/shim.h
+++ b/system/main/shim/shim.h
@@ -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();