Loading system/gd/dumpsys_data.fbs +2 −0 Original line number Diff line number Diff line // Top level module dumpsys data schema include "module_unittest.fbs"; include "shim/dumpsys.fbs"; namespace bluetooth; Loading @@ -7,6 +8,7 @@ attribute "privacy"; table DumpsysData { title:string; shim_dumpsys_data:bluetooth.shim.DumpsysModuleData (privacy:"Any"); module_unittest_data:bluetooth.ModuleUnitTestData; // private } Loading system/gd/shim/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ filegroup { filegroup { name: "BluetoothShimTestSources", srcs: [ "dumpsys_test.cc", "l2cap_test.cc", ], } Loading system/gd/shim/dumpsys.cc +101 −26 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <utility> #include "bundler_generated.h" #include "dumpsys_generated.h" #include "dumpsys_module_schema_data.h" #include "flatbuffers/idl.h" #include "flatbuffers/reflection_generated.h" #include "module.h" Loading Loading @@ -71,42 +73,89 @@ struct Dumpsys::impl { public: void DumpWithArgs(int fd, const char** args, std::promise<void> promise); impl(const Dumpsys& dumpsys_module); impl(const Dumpsys& dumpsys_module, const std::string& bundled_schema_data); ~impl() = default; int GetNumberOfBundledSchemas() const; protected: void FilterAsUser(std::string* output); void FilterAsDeveloper(std::string* output); std::string PrintAsJson(std::string* output) const; void FilterAsUser(std::string* dumpsys_data); void FilterAsDeveloper(std::string* dumpsys_data); std::string PrintAsJson(std::string* dumpsys_data) const; private: const reflection::Schema* FindBundledSchema( const dumpsys::BundledSchema& bundled_schema, const std::string& name) const; const reflection::Schema* FindInBundledSchema(const std::string& name) const; const dumpsys::BundledSchema* GetBundledSchema() const; const Dumpsys& dumpsys_module_; const std::string pre_bundled_schema_; }; const ModuleFactory Dumpsys::Factory = ModuleFactory([]() { return new Dumpsys(); }); const ModuleFactory Dumpsys::Factory = ModuleFactory([]() { return new Dumpsys(bluetooth::dumpsys::GetBundledSchemaData()); }); Dumpsys::impl::impl(const Dumpsys& dumpsys_module, const std::string& pre_bundled_schema) : dumpsys_module_(dumpsys_module), pre_bundled_schema_(pre_bundled_schema) {} Dumpsys::impl::impl(const Dumpsys& dumpsys_module) : dumpsys_module_(dumpsys_module) {} int Dumpsys::impl::GetNumberOfBundledSchemas() const { return GetBundledSchema()->map()->size(); } void Dumpsys::impl::FilterAsDeveloper(std::string* output) { ASSERT(output != nullptr); const dumpsys::BundledSchema* Dumpsys::impl::GetBundledSchema() const { const dumpsys::BundledSchema* bundled_schema = flatbuffers::GetRoot<dumpsys::BundledSchema>(pre_bundled_schema_.data()); ASSERT(bundled_schema != nullptr); return bundled_schema; } const reflection::Schema* Dumpsys::impl::FindInBundledSchema(const std::string& name) const { const flatbuffers::Vector<flatbuffers::Offset<dumpsys::BundledSchemaMap>>* map = GetBundledSchema()->map(); for (auto it = map->cbegin(); it != map->cend(); ++it) { if (it->name()->str() == name) { flatbuffers::Verifier verifier(reinterpret_cast<const uint8_t*>(it->data()->Data()), it->data()->size()); if (!reflection::VerifySchemaBuffer(verifier)) { LOG_WARN("Unable to verify schema buffer name:%s", name.c_str()); return nullptr; } return reflection::GetSchema(it->data()->Data()); } } LOG_WARN("Unable to find bundled schema name:%s", name.c_str()); LOG_WARN(" title:%s root_name:%s", GetBundledSchema()->title()->c_str(), GetBundledSchema()->root_name()->c_str()); for (auto it = map->cbegin(); it != map->cend(); ++it) { LOG_WARN(" schema:%s", it->name()->c_str()); } return nullptr; } void Dumpsys::impl::FilterAsDeveloper(std::string* dumpsys_data) { ASSERT(dumpsys_data != nullptr); LOG_INFO("%s UNIMPLEMENTED", __func__); } void Dumpsys::impl::FilterAsUser(std::string* output) { ASSERT(output != nullptr); void Dumpsys::impl::FilterAsUser(std::string* dumpsys_data) { ASSERT(dumpsys_data != nullptr); LOG_INFO("%s UNIMPLEMENTED", __func__); } const reflection::Schema* Dumpsys::impl::FindBundledSchema( const dumpsys::BundledSchema& bundled_schema, const std::string& name) const { // TODO(cmanton) Return proper schema given schema container and name to index return nullptr; std::string Dumpsys::impl::PrintAsJson(std::string* dumpsys_data) const { ASSERT(dumpsys_data != nullptr); const flatbuffers::String* root_name = GetBundledSchema()->root_name(); if (root_name == nullptr) { char buf[255]; snprintf(buf, sizeof(buf), "ERROR: Unable to find root name in prebundled schema\n"); return std::string(buf); } std::string Dumpsys::impl::PrintAsJson(std::string* output) const { return std::string("UNIMPLEMENTED"); const reflection::Schema* schema = FindInBundledSchema(root_name->str()); if (schema == nullptr) { char buf[255]; snprintf(buf, sizeof(buf), "ERROR: Unable to find schema root name:%s\n", root_name->c_str()); return std::string(buf); } return std::string("UNIMPLEMENTED\n"); } void Dumpsys::impl::DumpWithArgs(int fd, const char** args, std::promise<void> promise) { Loading @@ -114,20 +163,23 @@ void Dumpsys::impl::DumpWithArgs(int fd, const char** args, std::promise<void> p const auto registry = dumpsys_module_.GetModuleRegistry(); ModuleDumper dumper(*registry, kDumpsysTitle); std::string output; // Get the dumpstate into out string dumper.DumpState(&output); std::string dumpsys_data; dumper.DumpState(&dumpsys_data); if (parsed_dumpsys_args.IsDeveloper()) { FilterAsDeveloper(&output); dprintf(fd, " ----- Filtering as Developer -----\n"); FilterAsDeveloper(&dumpsys_data); } else { FilterAsUser(&output); dprintf(fd, " ----- Filtering as User -----\n"); FilterAsUser(&dumpsys_data); } dprintf(fd, "%s", PrintAsJson(&output).c_str()); dprintf(fd, "%s", PrintAsJson(&dumpsys_data).c_str()); promise.set_value(); } Dumpsys::Dumpsys(const std::string& pre_bundled_schema) : pre_bundled_schema_(pre_bundled_schema) {} void Dumpsys::Dump(int fd, const char** args) { std::promise<void> promise; auto future = promise.get_future(); Loading @@ -145,13 +197,36 @@ os::Handler* Dumpsys::GetGdShimHandler() { void Dumpsys::ListDependencies(ModuleList* list) {} void Dumpsys::Start() { pimpl_ = std::make_unique<impl>(*this); pimpl_ = std::make_unique<impl>(*this, pre_bundled_schema_); } void Dumpsys::Stop() { pimpl_.reset(); } DumpsysDataFinisher Dumpsys::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) const { auto name = fb_builder->CreateString("----- Shim Dumpsys -----"); auto example_piecemeal_string = fb_builder->CreateString("Example Piecemeal String"); auto example_instant_string = fb_builder->CreateString("Example Instant String"); ExamplePiecemealTableBuilder example_piecemeal_table_builder(*fb_builder); example_piecemeal_table_builder.add_example_string(example_piecemeal_string); example_piecemeal_table_builder.add_example_int(123); example_piecemeal_table_builder.add_example_float(1.23); auto example_piecemeal_table = example_piecemeal_table_builder.Finish(); auto example_instant_table = CreateExampleInstantTable(*fb_builder, example_instant_string, 246, 2.46); DumpsysModuleDataBuilder builder(*fb_builder); builder.add_title(name); builder.add_number_of_bundled_schemas(pimpl_->GetNumberOfBundledSchemas()); builder.add_example_piecemeal_table(example_piecemeal_table); builder.add_example_instant_table(example_instant_table); auto dumpsys_data = builder.Finish(); return [dumpsys_data](DumpsysDataBuilder* builder) { builder->add_shim_dumpsys_data(dumpsys_data); }; } std::string Dumpsys::ToString() const { return kModuleName; } Loading system/gd/shim/dumpsys.fbs +15 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,23 @@ namespace bluetooth.shim; attribute "privacy"; table ExamplePiecemealTable { example_string:string (privacy:"Any"); example_int:int (privacy:"Any"); example_float:float (privacy:"Any"); } table ExampleInstantTable { example_string:string (privacy:"Any"); example_int:int (privacy:"Any"); example_float:float (privacy:"Any"); } table DumpsysModuleData { title:string (privacy:"Any"); number_of_bundled_schemas:int (privacy:"Any"); example_piecemeal_table:ExamplePiecemealTable (privacy:"Any"); example_instant_table:ExampleInstantTable (privacy:"Any"); } root_type DumpsysModuleData; system/gd/shim/dumpsys.h +3 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ class Dumpsys : public bluetooth::Module { // Convenience thread used by shim layer for task execution os::Handler* GetGdShimHandler(); Dumpsys() = default; Dumpsys(const std::string& pre_bundled_schema); ~Dumpsys() = default; static const ModuleFactory Factory; Loading @@ -40,10 +40,12 @@ class Dumpsys : public bluetooth::Module { void Start() override; // Module void Stop() override; // Module std::string ToString() const override; // Module DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override; // Module private: struct impl; std::unique_ptr<impl> pimpl_; const std::string& pre_bundled_schema_; DISALLOW_COPY_AND_ASSIGN(Dumpsys); }; Loading Loading
system/gd/dumpsys_data.fbs +2 −0 Original line number Diff line number Diff line // Top level module dumpsys data schema include "module_unittest.fbs"; include "shim/dumpsys.fbs"; namespace bluetooth; Loading @@ -7,6 +8,7 @@ attribute "privacy"; table DumpsysData { title:string; shim_dumpsys_data:bluetooth.shim.DumpsysModuleData (privacy:"Any"); module_unittest_data:bluetooth.ModuleUnitTestData; // private } Loading
system/gd/shim/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -10,6 +10,7 @@ filegroup { filegroup { name: "BluetoothShimTestSources", srcs: [ "dumpsys_test.cc", "l2cap_test.cc", ], } Loading
system/gd/shim/dumpsys.cc +101 −26 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ #include <utility> #include "bundler_generated.h" #include "dumpsys_generated.h" #include "dumpsys_module_schema_data.h" #include "flatbuffers/idl.h" #include "flatbuffers/reflection_generated.h" #include "module.h" Loading Loading @@ -71,42 +73,89 @@ struct Dumpsys::impl { public: void DumpWithArgs(int fd, const char** args, std::promise<void> promise); impl(const Dumpsys& dumpsys_module); impl(const Dumpsys& dumpsys_module, const std::string& bundled_schema_data); ~impl() = default; int GetNumberOfBundledSchemas() const; protected: void FilterAsUser(std::string* output); void FilterAsDeveloper(std::string* output); std::string PrintAsJson(std::string* output) const; void FilterAsUser(std::string* dumpsys_data); void FilterAsDeveloper(std::string* dumpsys_data); std::string PrintAsJson(std::string* dumpsys_data) const; private: const reflection::Schema* FindBundledSchema( const dumpsys::BundledSchema& bundled_schema, const std::string& name) const; const reflection::Schema* FindInBundledSchema(const std::string& name) const; const dumpsys::BundledSchema* GetBundledSchema() const; const Dumpsys& dumpsys_module_; const std::string pre_bundled_schema_; }; const ModuleFactory Dumpsys::Factory = ModuleFactory([]() { return new Dumpsys(); }); const ModuleFactory Dumpsys::Factory = ModuleFactory([]() { return new Dumpsys(bluetooth::dumpsys::GetBundledSchemaData()); }); Dumpsys::impl::impl(const Dumpsys& dumpsys_module, const std::string& pre_bundled_schema) : dumpsys_module_(dumpsys_module), pre_bundled_schema_(pre_bundled_schema) {} Dumpsys::impl::impl(const Dumpsys& dumpsys_module) : dumpsys_module_(dumpsys_module) {} int Dumpsys::impl::GetNumberOfBundledSchemas() const { return GetBundledSchema()->map()->size(); } void Dumpsys::impl::FilterAsDeveloper(std::string* output) { ASSERT(output != nullptr); const dumpsys::BundledSchema* Dumpsys::impl::GetBundledSchema() const { const dumpsys::BundledSchema* bundled_schema = flatbuffers::GetRoot<dumpsys::BundledSchema>(pre_bundled_schema_.data()); ASSERT(bundled_schema != nullptr); return bundled_schema; } const reflection::Schema* Dumpsys::impl::FindInBundledSchema(const std::string& name) const { const flatbuffers::Vector<flatbuffers::Offset<dumpsys::BundledSchemaMap>>* map = GetBundledSchema()->map(); for (auto it = map->cbegin(); it != map->cend(); ++it) { if (it->name()->str() == name) { flatbuffers::Verifier verifier(reinterpret_cast<const uint8_t*>(it->data()->Data()), it->data()->size()); if (!reflection::VerifySchemaBuffer(verifier)) { LOG_WARN("Unable to verify schema buffer name:%s", name.c_str()); return nullptr; } return reflection::GetSchema(it->data()->Data()); } } LOG_WARN("Unable to find bundled schema name:%s", name.c_str()); LOG_WARN(" title:%s root_name:%s", GetBundledSchema()->title()->c_str(), GetBundledSchema()->root_name()->c_str()); for (auto it = map->cbegin(); it != map->cend(); ++it) { LOG_WARN(" schema:%s", it->name()->c_str()); } return nullptr; } void Dumpsys::impl::FilterAsDeveloper(std::string* dumpsys_data) { ASSERT(dumpsys_data != nullptr); LOG_INFO("%s UNIMPLEMENTED", __func__); } void Dumpsys::impl::FilterAsUser(std::string* output) { ASSERT(output != nullptr); void Dumpsys::impl::FilterAsUser(std::string* dumpsys_data) { ASSERT(dumpsys_data != nullptr); LOG_INFO("%s UNIMPLEMENTED", __func__); } const reflection::Schema* Dumpsys::impl::FindBundledSchema( const dumpsys::BundledSchema& bundled_schema, const std::string& name) const { // TODO(cmanton) Return proper schema given schema container and name to index return nullptr; std::string Dumpsys::impl::PrintAsJson(std::string* dumpsys_data) const { ASSERT(dumpsys_data != nullptr); const flatbuffers::String* root_name = GetBundledSchema()->root_name(); if (root_name == nullptr) { char buf[255]; snprintf(buf, sizeof(buf), "ERROR: Unable to find root name in prebundled schema\n"); return std::string(buf); } std::string Dumpsys::impl::PrintAsJson(std::string* output) const { return std::string("UNIMPLEMENTED"); const reflection::Schema* schema = FindInBundledSchema(root_name->str()); if (schema == nullptr) { char buf[255]; snprintf(buf, sizeof(buf), "ERROR: Unable to find schema root name:%s\n", root_name->c_str()); return std::string(buf); } return std::string("UNIMPLEMENTED\n"); } void Dumpsys::impl::DumpWithArgs(int fd, const char** args, std::promise<void> promise) { Loading @@ -114,20 +163,23 @@ void Dumpsys::impl::DumpWithArgs(int fd, const char** args, std::promise<void> p const auto registry = dumpsys_module_.GetModuleRegistry(); ModuleDumper dumper(*registry, kDumpsysTitle); std::string output; // Get the dumpstate into out string dumper.DumpState(&output); std::string dumpsys_data; dumper.DumpState(&dumpsys_data); if (parsed_dumpsys_args.IsDeveloper()) { FilterAsDeveloper(&output); dprintf(fd, " ----- Filtering as Developer -----\n"); FilterAsDeveloper(&dumpsys_data); } else { FilterAsUser(&output); dprintf(fd, " ----- Filtering as User -----\n"); FilterAsUser(&dumpsys_data); } dprintf(fd, "%s", PrintAsJson(&output).c_str()); dprintf(fd, "%s", PrintAsJson(&dumpsys_data).c_str()); promise.set_value(); } Dumpsys::Dumpsys(const std::string& pre_bundled_schema) : pre_bundled_schema_(pre_bundled_schema) {} void Dumpsys::Dump(int fd, const char** args) { std::promise<void> promise; auto future = promise.get_future(); Loading @@ -145,13 +197,36 @@ os::Handler* Dumpsys::GetGdShimHandler() { void Dumpsys::ListDependencies(ModuleList* list) {} void Dumpsys::Start() { pimpl_ = std::make_unique<impl>(*this); pimpl_ = std::make_unique<impl>(*this, pre_bundled_schema_); } void Dumpsys::Stop() { pimpl_.reset(); } DumpsysDataFinisher Dumpsys::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) const { auto name = fb_builder->CreateString("----- Shim Dumpsys -----"); auto example_piecemeal_string = fb_builder->CreateString("Example Piecemeal String"); auto example_instant_string = fb_builder->CreateString("Example Instant String"); ExamplePiecemealTableBuilder example_piecemeal_table_builder(*fb_builder); example_piecemeal_table_builder.add_example_string(example_piecemeal_string); example_piecemeal_table_builder.add_example_int(123); example_piecemeal_table_builder.add_example_float(1.23); auto example_piecemeal_table = example_piecemeal_table_builder.Finish(); auto example_instant_table = CreateExampleInstantTable(*fb_builder, example_instant_string, 246, 2.46); DumpsysModuleDataBuilder builder(*fb_builder); builder.add_title(name); builder.add_number_of_bundled_schemas(pimpl_->GetNumberOfBundledSchemas()); builder.add_example_piecemeal_table(example_piecemeal_table); builder.add_example_instant_table(example_instant_table); auto dumpsys_data = builder.Finish(); return [dumpsys_data](DumpsysDataBuilder* builder) { builder->add_shim_dumpsys_data(dumpsys_data); }; } std::string Dumpsys::ToString() const { return kModuleName; } Loading
system/gd/shim/dumpsys.fbs +15 −0 Original line number Diff line number Diff line Loading @@ -3,8 +3,23 @@ namespace bluetooth.shim; attribute "privacy"; table ExamplePiecemealTable { example_string:string (privacy:"Any"); example_int:int (privacy:"Any"); example_float:float (privacy:"Any"); } table ExampleInstantTable { example_string:string (privacy:"Any"); example_int:int (privacy:"Any"); example_float:float (privacy:"Any"); } table DumpsysModuleData { title:string (privacy:"Any"); number_of_bundled_schemas:int (privacy:"Any"); example_piecemeal_table:ExamplePiecemealTable (privacy:"Any"); example_instant_table:ExampleInstantTable (privacy:"Any"); } root_type DumpsysModuleData;
system/gd/shim/dumpsys.h +3 −1 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ class Dumpsys : public bluetooth::Module { // Convenience thread used by shim layer for task execution os::Handler* GetGdShimHandler(); Dumpsys() = default; Dumpsys(const std::string& pre_bundled_schema); ~Dumpsys() = default; static const ModuleFactory Factory; Loading @@ -40,10 +40,12 @@ class Dumpsys : public bluetooth::Module { void Start() override; // Module void Stop() override; // Module std::string ToString() const override; // Module DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override; // Module private: struct impl; std::unique_ptr<impl> pimpl_; const std::string& pre_bundled_schema_; DISALLOW_COPY_AND_ASSIGN(Dumpsys); }; Loading