[a11y] Add Max file size for log file.
Use the new constructor of Pseudo File since older one is getting
deprecated. New constructor has max file size support.
Testing:
* Builds: Passed
* Installed on device
MI4-2038 #commit
Change-Id: Idca55e00ac0a2b9b5ce2d6f1b36c0107eb2277df
diff --git a/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.cc b/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.cc
index 8db7854..0264a3b 100644
--- a/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.cc
+++ b/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.cc
@@ -11,6 +11,8 @@
#include "third_party/abseil-cpp/absl/strings/str_cat.h"
namespace a11y_manager {
+// Max file size of semantic tree log file is 1MB.
+constexpr size_t kMaxDebugFileSize = 1024 * 1024;
const std::string kNewLine = "\n";
const std::string::size_type kIndentSize = 4;
const int kRootNode = 0;
@@ -214,4 +216,28 @@
}
}
+void SemanticTreeImpl::InitializeDebugEntry(vfs::PseudoDir* debug_dir) {
+ if (debug_dir_) {
+ // Add Semantic Tree log file in Hub-Debug directory.
+ debug_dir_->AddEntry(
+ std::to_string(GetKoid(view_ref_)),
+ std::make_unique<vfs::PseudoFile>(
+ kMaxDebugFileSize,
+ [this](std::vector<uint8_t>* output, size_t max_file_size) {
+ std::string buffer = LogSemanticTree();
+ size_t len = buffer.length();
+ if (len > max_file_size) {
+ FX_LOGS(WARNING)
+ << "Semantic Tree log file ("
+ << std::to_string(GetKoid(view_ref_)) << ") size is:" << len
+ << " which is more than max size:" << kMaxDebugFileSize;
+ len = kMaxDebugFileSize;
+ }
+ output->resize(len);
+ std::copy(buffer.begin(), buffer.begin() + len, output->begin());
+ return ZX_OK;
+ }));
+ }
+}
+
} // namespace a11y_manager
diff --git a/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.h b/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.h
index 765b91e..84e12e4 100644
--- a/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.h
+++ b/garnet/bin/a11y/a11y_manager/semantics/semantic_tree_impl.h
@@ -31,18 +31,7 @@
: view_ref_(std::move(view_ref)),
client_action_listener_(std::move(client_action_listener)),
debug_dir_(debug_dir) {
- if (debug_dir_) {
- // Add Semantic Tree log file in Hub-Debug directory.
- debug_dir_->AddEntry(std::to_string(GetKoid(view_ref_)),
- std::make_unique<vfs::PseudoFile>(
- [this](std::vector<uint8_t>* output) {
- std::string buffer = LogSemanticTree();
- output->resize(buffer.length());
- std::copy(buffer.begin(), buffer.end(),
- output->begin());
- return ZX_OK;
- }));
- }
+ InitializeDebugEntry(debug_dir_);
}
~SemanticTreeImpl() override = default;
@@ -110,6 +99,10 @@
bool BoxContainsPoint(const fuchsia::ui::gfx::BoundingBox& box,
const escher::vec2& point) const;
+ // Function to create per view Log files under debug directory for debugging
+ // semantic tree.
+ void InitializeDebugEntry(vfs::PseudoDir* debug_dir);
+
// List of committed, cached nodes for each front-end. We represent semantics
// tree as a map of local node ids to the actual node objects. All query
// operations should use the node information from these trees.