From 4094e5ee2eacc11ce7f062ceb9bb9df9028f492f Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 11 Jan 2018 16:26:10 -0800 Subject: [PATCH] Rename property 'schema' to 'type' Bug: 70858511 Test: boot Change-Id: I8e17596ddd8393f245c7e02ff72765c84d3bb208 --- .../property_info_parser.h | 31 ++- .../property_info_parser.cpp | 52 ++-- .../property_info_serializer.h | 8 +- .../property_info_file.cpp | 4 +- .../property_info_serializer.cpp | 8 +- .../property_info_serializer_test.cpp | 231 +++++++++--------- .../trie_builder.cpp | 22 +- .../libpropertyinfoserializer/trie_builder.h | 31 ++- .../trie_builder_test.cpp | 46 ++-- .../trie_serializer.cpp | 14 +- 10 files changed, 222 insertions(+), 225 deletions(-) diff --git a/property_service/libpropertyinfoparser/include/property_info_parser/property_info_parser.h b/property_service/libpropertyinfoparser/include/property_info_parser/property_info_parser.h index 2ee816124..054802197 100644 --- a/property_service/libpropertyinfoparser/include/property_info_parser/property_info_parser.h +++ b/property_service/libpropertyinfoparser/include/property_info_parser/property_info_parser.h @@ -32,8 +32,8 @@ struct PropertyEntry { // This is the context match for this node_; ~0u if it doesn't correspond to any. uint32_t context_index; - // This is the schema for this node_; ~0u if it doesn't correspond to any. - uint32_t schema_index; + // This is the type for this node_; ~0u if it doesn't correspond to any. + uint32_t type_index; }; struct TrieNodeInternal { @@ -61,7 +61,7 @@ struct PropertyInfoAreaHeader { uint32_t minimum_supported_version; uint32_t size; uint32_t contexts_offset; - uint32_t schemas_offset; + uint32_t types_offset; uint32_t root_offset; }; @@ -103,7 +103,7 @@ class TrieNode { } uint32_t context_index() const { return node_property_entry()->context_index; } - uint32_t schema_index() const { return node_property_entry()->schema_index; } + uint32_t type_index() const { return node_property_entry()->type_index; } uint32_t num_child_nodes() const { return trie_node_base_->num_child_nodes; } TrieNode child_node(int n) const { @@ -143,12 +143,11 @@ class TrieNode { class PropertyInfoArea : private SerializedData { public: - void GetPropertyInfoIndexes(const char* name, uint32_t* context_index, - uint32_t* schema_index) const; - void GetPropertyInfo(const char* property, const char** context, const char** schema) const; + void GetPropertyInfoIndexes(const char* name, uint32_t* context_index, uint32_t* type_index) const; + void GetPropertyInfo(const char* property, const char** context, const char** type) const; int FindContextIndex(const char* context) const; - int FindSchemaIndex(const char* schema) const; + int FindTypeIndex(const char* type) const; const char* context(uint32_t index) const { uint32_t context_array_size_offset = contexts_offset(); @@ -156,10 +155,10 @@ class PropertyInfoArea : private SerializedData { return data_base() + context_array[index]; } - const char* schema(uint32_t index) const { - uint32_t schema_array_size_offset = schemas_offset(); - const uint32_t* schema_array = uint32_array(schema_array_size_offset + sizeof(uint32_t)); - return data_base() + schema_array[index]; + const char* type(uint32_t index) const { + uint32_t type_array_size_offset = types_offset(); + const uint32_t* type_array = uint32_array(type_array_size_offset + sizeof(uint32_t)); + return data_base() + type_array[index]; } uint32_t current_version() const { return header()->current_version; } @@ -168,21 +167,21 @@ class PropertyInfoArea : private SerializedData { uint32_t size() const { return SerializedData::size(); } uint32_t num_contexts() const { return uint32_array(contexts_offset())[0]; } - uint32_t num_schemas() const { return uint32_array(schemas_offset())[0]; } + uint32_t num_types() const { return uint32_array(types_offset())[0]; } TrieNode root_node() const { return trie(header()->root_offset); } private: void CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node, - uint32_t* context_index, uint32_t* schema_index) const; + uint32_t* context_index, uint32_t* type_index) const; const PropertyInfoAreaHeader* header() const { return reinterpret_cast(data_base()); } uint32_t contexts_offset() const { return header()->contexts_offset; } uint32_t contexts_array_offset() const { return contexts_offset() + sizeof(uint32_t); } - uint32_t schemas_offset() const { return header()->schemas_offset; } - uint32_t schemas_array_offset() const { return schemas_offset() + sizeof(uint32_t); } + uint32_t types_offset() const { return header()->types_offset; } + uint32_t types_array_offset() const { return types_offset() + sizeof(uint32_t); } TrieNode trie(uint32_t offset) const { if (offset != 0 && offset > size()) return TrieNode(); diff --git a/property_service/libpropertyinfoparser/property_info_parser.cpp b/property_service/libpropertyinfoparser/property_info_parser.cpp index a8f663624..489d81a67 100644 --- a/property_service/libpropertyinfoparser/property_info_parser.cpp +++ b/property_service/libpropertyinfoparser/property_info_parser.cpp @@ -56,12 +56,12 @@ int PropertyInfoArea::FindContextIndex(const char* context) const { }); } -// Binary search the list of schemas to find the index of a given schema string. +// Binary search the list of types to find the index of a given type string. // Only should be used for TrieSerializer to construct the Trie. -int PropertyInfoArea::FindSchemaIndex(const char* schema) const { - return Find(num_schemas(), [this, schema](auto array_offset) { - auto string_offset = uint32_array(schemas_array_offset())[array_offset]; - return strcmp(c_string(string_offset), schema); +int PropertyInfoArea::FindTypeIndex(const char* type) const { + return Find(num_types(), [this, type](auto array_offset) { + auto string_offset = uint32_array(types_array_offset())[array_offset]; + return strcmp(c_string(string_offset), type); }); } @@ -89,7 +89,7 @@ bool TrieNode::FindChildForString(const char* name, uint32_t namelen, TrieNode* } void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node, - uint32_t* context_index, uint32_t* schema_index) const { + uint32_t* context_index, uint32_t* type_index) const { const uint32_t remaining_name_size = strlen(remaining_name); for (uint32_t i = 0; i < trie_node.num_prefixes(); ++i) { auto prefix_len = trie_node.prefix(i)->namelen; @@ -99,8 +99,8 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo if (trie_node.prefix(i)->context_index != ~0u) { *context_index = trie_node.prefix(i)->context_index; } - if (trie_node.prefix(i)->schema_index != ~0u) { - *schema_index = trie_node.prefix(i)->schema_index; + if (trie_node.prefix(i)->type_index != ~0u) { + *type_index = trie_node.prefix(i)->type_index; } return; } @@ -108,9 +108,9 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo } void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* context_index, - uint32_t* schema_index) const { + uint32_t* type_index) const { uint32_t return_context_index = ~0u; - uint32_t return_schema_index = ~0u; + uint32_t return_type_index = ~0u; const char* remaining_name = name; auto trie_node = root_node(); while (true) { @@ -120,13 +120,13 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex if (trie_node.context_index() != ~0u) { return_context_index = trie_node.context_index(); } - if (trie_node.schema_index() != ~0u) { - return_schema_index = trie_node.schema_index(); + if (trie_node.type_index() != ~0u) { + return_type_index = trie_node.type_index(); } // Check prefixes at this node. This comes after the node check since these prefixes are by // definition longer than the node itself. - CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index); + CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index); if (sep == nullptr) { break; @@ -153,29 +153,29 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex *context_index = return_context_index; } } - if (schema_index != nullptr) { - if (trie_node.exact_match(i)->schema_index != ~0u) { - *schema_index = trie_node.exact_match(i)->schema_index; + if (type_index != nullptr) { + if (trie_node.exact_match(i)->type_index != ~0u) { + *type_index = trie_node.exact_match(i)->type_index; } else { - *schema_index = return_schema_index; + *type_index = return_type_index; } } return; } } // Check prefix matches for prefixes not deliminated with '.' - CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index); + CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index); // Return previously found prefix match. if (context_index != nullptr) *context_index = return_context_index; - if (schema_index != nullptr) *schema_index = return_schema_index; + if (type_index != nullptr) *type_index = return_type_index; return; } void PropertyInfoArea::GetPropertyInfo(const char* property, const char** context, - const char** schema) const { + const char** type) const { uint32_t context_index; - uint32_t schema_index; - GetPropertyInfoIndexes(property, &context_index, &schema_index); + uint32_t type_index; + GetPropertyInfoIndexes(property, &context_index, &type_index); if (context != nullptr) { if (context_index == ~0u) { *context = nullptr; @@ -183,11 +183,11 @@ void PropertyInfoArea::GetPropertyInfo(const char* property, const char** contex *context = this->context(context_index); } } - if (schema != nullptr) { - if (schema_index == ~0u) { - *schema = nullptr; + if (type != nullptr) { + if (type_index == ~0u) { + *type = nullptr; } else { - *schema = this->schema(schema_index); + *type = this->type(type_index); } } } diff --git a/property_service/libpropertyinfoserializer/include/property_info_serializer/property_info_serializer.h b/property_service/libpropertyinfoserializer/include/property_info_serializer/property_info_serializer.h index d2ec385d4..439813d12 100644 --- a/property_service/libpropertyinfoserializer/include/property_info_serializer/property_info_serializer.h +++ b/property_service/libpropertyinfoserializer/include/property_info_serializer/property_info_serializer.h @@ -26,19 +26,19 @@ namespace properties { struct PropertyInfoEntry { PropertyInfoEntry() {} template - PropertyInfoEntry(T&& name, U&& context, V&& schema, bool exact_match) + PropertyInfoEntry(T&& name, U&& context, V&& type, bool exact_match) : name(std::forward(name)), context(std::forward(context)), - schema(std::forward(schema)), + type(std::forward(type)), exact_match(exact_match) {} std::string name; std::string context; - std::string schema; + std::string type; bool exact_match; }; bool BuildTrie(const std::vector& property_info, - const std::string& default_context, const std::string& default_schema, + const std::string& default_context, const std::string& default_type, std::string* serialized_trie, std::string* error); void ParsePropertyInfoFile(const std::string& file_contents, diff --git a/property_service/libpropertyinfoserializer/property_info_file.cpp b/property_service/libpropertyinfoserializer/property_info_file.cpp index 702f219d8..bf96d88bf 100644 --- a/property_service/libpropertyinfoserializer/property_info_file.cpp +++ b/property_service/libpropertyinfoserializer/property_info_file.cpp @@ -28,9 +28,9 @@ bool ParsePropertyInfoLine(const std::string& line, PropertyInfoEntry* out, std: // It is not an error to not find these, as older files will not contain them. auto exact_match = tokenizer.GetNext(); - auto schema = tokenizer.GetRemaining(); + auto type = tokenizer.GetRemaining(); - *out = {property, context, schema, exact_match == "exact"}; + *out = {property, context, type, exact_match == "exact"}; return true; } diff --git a/property_service/libpropertyinfoserializer/property_info_serializer.cpp b/property_service/libpropertyinfoserializer/property_info_serializer.cpp index 656c96e33..803657ab8 100644 --- a/property_service/libpropertyinfoserializer/property_info_serializer.cpp +++ b/property_service/libpropertyinfoserializer/property_info_serializer.cpp @@ -27,13 +27,13 @@ namespace android { namespace properties { bool BuildTrie(const std::vector& property_info, - const std::string& default_context, const std::string& default_schema, + const std::string& default_context, const std::string& default_type, std::string* serialized_trie, std::string* error) { // Check that names are legal first - auto trie_builder = TrieBuilder(default_context, default_schema); + auto trie_builder = TrieBuilder(default_context, default_type); - for (const auto& [name, context, schema, is_exact] : property_info) { - if (!trie_builder.AddToTrie(name, context, schema, is_exact, error)) { + for (const auto& [name, context, type, is_exact] : property_info) { + if (!trie_builder.AddToTrie(name, context, type, is_exact, error)) { return false; } } diff --git a/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp b/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp index 46c2d06ef..f4845505c 100644 --- a/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp +++ b/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp @@ -46,7 +46,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) { auto root_node = property_info_area->root_node(); EXPECT_STREQ("root", root_node.name()); EXPECT_STREQ("default", property_info_area->context(root_node.context_index())); - EXPECT_STREQ("default", property_info_area->schema(root_node.schema_index())); + EXPECT_STREQ("default", property_info_area->type(root_node.type_index())); EXPECT_EQ(0U, root_node.num_prefixes()); EXPECT_EQ(0U, root_node.num_exact_matches()); @@ -59,7 +59,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) { EXPECT_STREQ("test", test_node.name()); EXPECT_STREQ("1st", property_info_area->context(test_node.context_index())); - EXPECT_STREQ("1st", property_info_area->schema(test_node.schema_index())); + EXPECT_STREQ("1st", property_info_area->type(test_node.type_index())); EXPECT_EQ(0U, test_node.num_child_nodes()); @@ -69,7 +69,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) { EXPECT_STREQ("test", serialized_trie.data() + prefix->name_offset); EXPECT_EQ(4U, prefix->namelen); EXPECT_STREQ("2nd", property_info_area->context(prefix->context_index)); - EXPECT_STREQ("2nd", property_info_area->schema(prefix->schema_index)); + EXPECT_STREQ("2nd", property_info_area->type(prefix->type_index)); } EXPECT_EQ(3U, test_node.num_exact_matches()); @@ -85,9 +85,9 @@ TEST(propertyinfoserializer, TrieNodeCheck) { EXPECT_STREQ("3rd", property_info_area->context(match2->context_index)); EXPECT_STREQ("3rd", property_info_area->context(match3->context_index)); - EXPECT_STREQ("3rd", property_info_area->schema(match1->schema_index)); - EXPECT_STREQ("3rd", property_info_area->schema(match2->schema_index)); - EXPECT_STREQ("3rd", property_info_area->schema(match3->schema_index)); + EXPECT_STREQ("3rd", property_info_area->type(match1->type_index)); + EXPECT_STREQ("3rd", property_info_area->type(match2->type_index)); + EXPECT_STREQ("3rd", property_info_area->type(match3->type_index)); } // Check the long string node @@ -120,7 +120,7 @@ TEST(propertyinfoserializer, TrieNodeCheck) { auto final_match = long_string_node.exact_match(0); EXPECT_STREQ("string", serialized_trie.data() + final_match->name_offset); EXPECT_STREQ("4th", property_info_area->context(final_match->context_index)); - EXPECT_STREQ("4th", property_info_area->schema(final_match->schema_index)); + EXPECT_STREQ("4th", property_info_area->type(final_match->type_index)); } TEST(propertyinfoserializer, GetPropertyInfo) { @@ -143,109 +143,109 @@ TEST(propertyinfoserializer, GetPropertyInfo) { auto root_node = property_info_area->root_node(); EXPECT_STREQ("root", root_node.name()); EXPECT_STREQ("default", property_info_area->context(root_node.context_index())); - EXPECT_STREQ("default", property_info_area->schema(root_node.schema_index())); + EXPECT_STREQ("default", property_info_area->type(root_node.type_index())); const char* context; - const char* schema; - property_info_area->GetPropertyInfo("abc", &context, &schema); + const char* type; + property_info_area->GetPropertyInfo("abc", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("abc.abc", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("abc.abc", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("123.abc", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("123.abc", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); + EXPECT_STREQ("default", type); - property_info_area->GetPropertyInfo("test.a", &context, &schema); + property_info_area->GetPropertyInfo("test.a", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("test.b", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("test.b", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("test.c", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("test.c", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); + EXPECT_STREQ("1st", type); - property_info_area->GetPropertyInfo("test.test", &context, &schema); + property_info_area->GetPropertyInfo("test.test", &context, &type); EXPECT_STREQ("5th", context); - EXPECT_STREQ("5th", schema); - property_info_area->GetPropertyInfo("test.testa", &context, &schema); + EXPECT_STREQ("5th", type); + property_info_area->GetPropertyInfo("test.testa", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.testb", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.testb", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.testc", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.testc", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); + EXPECT_STREQ("2nd", type); - property_info_area->GetPropertyInfo("test.test.a", &context, &schema); + property_info_area->GetPropertyInfo("test.test.a", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.test.b", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.test.b", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.test.c", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.test.c", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); + EXPECT_STREQ("2nd", type); - property_info_area->GetPropertyInfo("test.test1", &context, &schema); + property_info_area->GetPropertyInfo("test.test1", &context, &type); EXPECT_STREQ("3rd", context); - EXPECT_STREQ("3rd", schema); - property_info_area->GetPropertyInfo("test.test2", &context, &schema); + EXPECT_STREQ("3rd", type); + property_info_area->GetPropertyInfo("test.test2", &context, &type); EXPECT_STREQ("7th", context); - EXPECT_STREQ("7th", schema); - property_info_area->GetPropertyInfo("test.test3", &context, &schema); + EXPECT_STREQ("7th", type); + property_info_area->GetPropertyInfo("test.test3", &context, &type); EXPECT_STREQ("3rd", context); - EXPECT_STREQ("3rd", schema); + EXPECT_STREQ("3rd", type); - property_info_area->GetPropertyInfo("test.test11", &context, &schema); + property_info_area->GetPropertyInfo("test.test11", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.test22", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.test22", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("test.test33", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("test.test33", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); + EXPECT_STREQ("2nd", type); - property_info_area->GetPropertyInfo("this.is.a.long.string", &context, &schema); + property_info_area->GetPropertyInfo("this.is.a.long.string", &context, &type); EXPECT_STREQ("4th", context); - EXPECT_STREQ("4th", schema); + EXPECT_STREQ("4th", type); - property_info_area->GetPropertyInfo("this.is.a.long", &context, &schema); + property_info_area->GetPropertyInfo("this.is.a.long", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("this.is.a", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("this.is.a", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("this.is", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("this.is", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("this", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("this", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); + EXPECT_STREQ("default", type); - property_info_area->GetPropertyInfo("test.test2.a", &context, &schema); + property_info_area->GetPropertyInfo("test.test2.a", &context, &type); EXPECT_STREQ("6th", context); - EXPECT_STREQ("6th", schema); + EXPECT_STREQ("6th", type); - property_info_area->GetPropertyInfo("testoneword", &context, &schema); + property_info_area->GetPropertyInfo("testoneword", &context, &type); EXPECT_STREQ("8th", context); - EXPECT_STREQ("8th", schema); + EXPECT_STREQ("8th", type); - property_info_area->GetPropertyInfo("testwordprefix", &context, &schema); + property_info_area->GetPropertyInfo("testwordprefix", &context, &type); EXPECT_STREQ("9th", context); - EXPECT_STREQ("9th", schema); + EXPECT_STREQ("9th", type); - property_info_area->GetPropertyInfo("testwordprefixblah", &context, &schema); + property_info_area->GetPropertyInfo("testwordprefixblah", &context, &type); EXPECT_STREQ("9th", context); - EXPECT_STREQ("9th", schema); + EXPECT_STREQ("9th", type); - property_info_area->GetPropertyInfo("testwordprefix.blah", &context, &schema); + property_info_area->GetPropertyInfo("testwordprefix.blah", &context, &type); EXPECT_STREQ("9th", context); - EXPECT_STREQ("9th", schema); + EXPECT_STREQ("9th", type); } TEST(propertyinfoserializer, RealProperties) { @@ -777,35 +777,34 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_without_dot) { auto property_info_area = reinterpret_cast(serialized_trie.data()); const char* context; - const char* schema; - property_info_area->GetPropertyInfo("persist.radio", &context, &schema); + const char* type; + property_info_area->GetPropertyInfo("persist.radio", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radiowords", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radiowords", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radio.long.long.long.sub.property", &context, - &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radio.long.long.long.sub.property", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radio.something.else.here", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radio.something.else.here", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.something.else.here2", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.something.else.here2", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.something.else.here.after", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.something.else.here.after", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.something.else.nothere", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.something.else.nothere", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radio.something.else", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radio.something.else", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); + EXPECT_STREQ("1st", type); } TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) { @@ -823,28 +822,28 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) { auto property_info_area = reinterpret_cast(serialized_trie.data()); const char* context; - const char* schema; - property_info_area->GetPropertyInfo("persist.notradio", &context, &schema); + const char* type; + property_info_area->GetPropertyInfo("persist.notradio", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("1st", schema); - property_info_area->GetPropertyInfo("persist.radio", &context, &schema); + EXPECT_STREQ("1st", type); + property_info_area->GetPropertyInfo("persist.radio", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.subproperty", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radiowords", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radiowords", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.long.property.prefix.match", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.long.property.prefix.match", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("2nd", schema); - property_info_area->GetPropertyInfo("persist.radio.long.property.exact.match", &context, &schema); + EXPECT_STREQ("2nd", type); + property_info_area->GetPropertyInfo("persist.radio.long.property.exact.match", &context, &type); EXPECT_STREQ("3rd", context); - EXPECT_STREQ("3rd", schema); + EXPECT_STREQ("3rd", type); } -TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) { +TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_type) { auto property_info = std::vector{ {"persist.", "1st", "", false}, {"persist.dot_prefix.", "2nd", "", false}, @@ -862,28 +861,28 @@ TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) { auto property_info_area = reinterpret_cast(serialized_trie.data()); const char* context; - const char* schema; - property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &schema); + const char* type; + property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &type); EXPECT_STREQ("default", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("persist.nomatch", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("persist.nomatch", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &type); EXPECT_STREQ("2nd", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &type); EXPECT_STREQ("3rd", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("persist.exact_match", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("persist.exact_match", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("default", schema); - property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &schema); + EXPECT_STREQ("default", type); + property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("4th", schema); - property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &schema); + EXPECT_STREQ("4th", type); + property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &type); EXPECT_STREQ("1st", context); - EXPECT_STREQ("5th", schema); + EXPECT_STREQ("5th", type); } } // namespace properties diff --git a/property_service/libpropertyinfoserializer/trie_builder.cpp b/property_service/libpropertyinfoserializer/trie_builder.cpp index feb753be7..8c5ce8495 100644 --- a/property_service/libpropertyinfoserializer/trie_builder.cpp +++ b/property_service/libpropertyinfoserializer/trie_builder.cpp @@ -23,23 +23,23 @@ using android::base::Split; namespace android { namespace properties { -TrieBuilder::TrieBuilder(const std::string& default_context, const std::string& default_schema) +TrieBuilder::TrieBuilder(const std::string& default_context, const std::string& default_type) : builder_root_("root") { auto* context_pointer = StringPointerFromContainer(default_context, &contexts_); builder_root_.set_context(context_pointer); - auto* schema_pointer = StringPointerFromContainer(default_schema, &schemas_); - builder_root_.set_schema(schema_pointer); + auto* type_pointer = StringPointerFromContainer(default_type, &types_); + builder_root_.set_type(type_pointer); } bool TrieBuilder::AddToTrie(const std::string& name, const std::string& context, - const std::string& schema, bool exact, std::string* error) { + const std::string& type, bool exact, std::string* error) { auto* context_pointer = StringPointerFromContainer(context, &contexts_); - auto* schema_pointer = StringPointerFromContainer(schema, &schemas_); - return AddToTrie(name, context_pointer, schema_pointer, exact, error); + auto* type_pointer = StringPointerFromContainer(type, &types_); + return AddToTrie(name, context_pointer, type_pointer, exact, error); } bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context, - const std::string* schema, bool exact, std::string* error) { + const std::string* type, bool exact, std::string* error) { TrieBuilderNode* current_node = &builder_root_; auto name_pieces = Split(name, "."); @@ -66,12 +66,12 @@ bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context, // Store our context based on what type of match it is. if (exact) { - if (!current_node->AddExactMatchContext(name_pieces.front(), context, schema)) { + if (!current_node->AddExactMatchContext(name_pieces.front(), context, type)) { *error = "Duplicate exact match detected for '" + name + "'"; return false; } } else if (!ends_with_dot) { - if (!current_node->AddPrefixContext(name_pieces.front(), context, schema)) { + if (!current_node->AddPrefixContext(name_pieces.front(), context, type)) { *error = "Duplicate prefix match detected for '" + name + "'"; return false; } @@ -84,12 +84,12 @@ bool TrieBuilder::AddToTrie(const std::string& name, const std::string* context, *error = "Unable to allocate Trie node"; return false; } - if (child->context() != nullptr || child->schema() != nullptr) { + if (child->context() != nullptr || child->type() != nullptr) { *error = "Duplicate prefix match detected for '" + name + "'"; return false; } child->set_context(context); - child->set_schema(schema); + child->set_type(type); } return true; } diff --git a/property_service/libpropertyinfoserializer/trie_builder.h b/property_service/libpropertyinfoserializer/trie_builder.h index f928e764f..b971589fe 100644 --- a/property_service/libpropertyinfoserializer/trie_builder.h +++ b/property_service/libpropertyinfoserializer/trie_builder.h @@ -26,13 +26,12 @@ namespace android { namespace properties { struct PropertyEntryBuilder { - PropertyEntryBuilder() : context(nullptr), schema(nullptr) {} - PropertyEntryBuilder(const std::string& name, const std::string* context, - const std::string* schema) - : name(name), context(context), schema(schema) {} + PropertyEntryBuilder() : context(nullptr), type(nullptr) {} + PropertyEntryBuilder(const std::string& name, const std::string* context, const std::string* type) + : name(name), context(context), type(type) {} std::string name; const std::string* context; - const std::string* schema; + const std::string* type; }; class TrieBuilderNode { @@ -56,33 +55,33 @@ class TrieBuilderNode { TrieBuilderNode* AddChild(const std::string& name) { return &children_.emplace_back(name); } bool AddPrefixContext(const std::string& prefix, const std::string* context, - const std::string* schema) { + const std::string* type) { if (std::find_if(prefixes_.begin(), prefixes_.end(), [&prefix](const auto& t) { return t.name == prefix; }) != prefixes_.end()) { return false; } - prefixes_.emplace_back(prefix, context, schema); + prefixes_.emplace_back(prefix, context, type); return true; } bool AddExactMatchContext(const std::string& exact_match, const std::string* context, - const std::string* schema) { + const std::string* type) { if (std::find_if(exact_matches_.begin(), exact_matches_.end(), [&exact_match](const auto& t) { return t.name == exact_match; }) != exact_matches_.end()) { return false; } - exact_matches_.emplace_back(exact_match, context, schema); + exact_matches_.emplace_back(exact_match, context, type); return true; } const std::string& name() const { return property_entry_.name; } const std::string* context() const { return property_entry_.context; } void set_context(const std::string* context) { property_entry_.context = context; } - const std::string* schema() const { return property_entry_.schema; } - void set_schema(const std::string* schema) { property_entry_.schema = schema; } + const std::string* type() const { return property_entry_.type; } + void set_type(const std::string* type) { property_entry_.type = type; } const PropertyEntryBuilder property_entry() const { return property_entry_; } @@ -99,23 +98,23 @@ class TrieBuilderNode { class TrieBuilder { public: - TrieBuilder(const std::string& default_context, const std::string& default_schema); - bool AddToTrie(const std::string& name, const std::string& context, const std::string& schema, + TrieBuilder(const std::string& default_context, const std::string& default_type); + bool AddToTrie(const std::string& name, const std::string& context, const std::string& type, bool exact, std::string* error); const TrieBuilderNode builder_root() const { return builder_root_; } const std::set& contexts() const { return contexts_; } - const std::set& schemas() const { return schemas_; } + const std::set& types() const { return types_; } private: - bool AddToTrie(const std::string& name, const std::string* context, const std::string* schema, + bool AddToTrie(const std::string& name, const std::string* context, const std::string* type, bool exact, std::string* error); const std::string* StringPointerFromContainer(const std::string& string, std::set* container); TrieBuilderNode builder_root_; std::set contexts_; - std::set schemas_; + std::set types_; }; } // namespace properties diff --git a/property_service/libpropertyinfoserializer/trie_builder_test.cpp b/property_service/libpropertyinfoserializer/trie_builder_test.cpp index 2b948f3b0..50788108d 100644 --- a/property_service/libpropertyinfoserializer/trie_builder_test.cpp +++ b/property_service/libpropertyinfoserializer/trie_builder_test.cpp @@ -22,19 +22,19 @@ namespace android { namespace properties { TEST(propertyinfoserializer, BuildTrie_Simple) { - auto trie_builder = TrieBuilder("default", "default_schema"); + auto trie_builder = TrieBuilder("default", "default_type"); // Add test data to tree auto error = std::string(); - EXPECT_TRUE(trie_builder.AddToTrie("test.", "1st", "1st_schema", false, &error)); - EXPECT_TRUE(trie_builder.AddToTrie("test.test", "2nd", "2nd_schema", false, &error)); - EXPECT_TRUE(trie_builder.AddToTrie("test.test1", "3rd", "3rd_schema", true, &error)); - EXPECT_TRUE(trie_builder.AddToTrie("test.test2", "3rd", "3rd_schema", true, &error)); - EXPECT_TRUE(trie_builder.AddToTrie("test.test3", "3rd", "3rd_schema", true, &error)); - EXPECT_TRUE(trie_builder.AddToTrie("this.is.a.long.string", "4th", "4th_schema", true, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("test.", "1st", "1st_type", false, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("test.test", "2nd", "2nd_type", false, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("test.test1", "3rd", "3rd_type", true, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("test.test2", "3rd", "3rd_type", true, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("test.test3", "3rd", "3rd_type", true, &error)); + EXPECT_TRUE(trie_builder.AddToTrie("this.is.a.long.string", "4th", "4th_type", true, &error)); ASSERT_EQ(5U, trie_builder.contexts().size()); - ASSERT_EQ(5U, trie_builder.schemas().size()); + ASSERT_EQ(5U, trie_builder.types().size()); auto& builder_root = trie_builder.builder_root(); @@ -42,8 +42,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) { EXPECT_EQ("root", builder_root.name()); ASSERT_NE(nullptr, builder_root.context()); EXPECT_EQ("default", *builder_root.context()); - ASSERT_NE(nullptr, builder_root.schema()); - EXPECT_EQ("default_schema", *builder_root.schema()); + ASSERT_NE(nullptr, builder_root.type()); + EXPECT_EQ("default_type", *builder_root.type()); EXPECT_EQ(0U, builder_root.prefixes().size()); EXPECT_EQ(0U, builder_root.exact_matches().size()); @@ -55,8 +55,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) { EXPECT_EQ("test", test_node->name()); ASSERT_NE(nullptr, test_node->context()); EXPECT_EQ("1st", *test_node->context()); - ASSERT_NE(nullptr, test_node->schema()); - EXPECT_EQ("1st_schema", *test_node->schema()); + ASSERT_NE(nullptr, test_node->type()); + EXPECT_EQ("1st_type", *test_node->type()); EXPECT_EQ(0U, test_node->children().size()); EXPECT_EQ(1U, test_node->prefixes().size()); @@ -65,8 +65,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) { EXPECT_EQ("test", property_entry.name); ASSERT_NE(nullptr, property_entry.context); EXPECT_EQ("2nd", *property_entry.context); - ASSERT_NE(nullptr, property_entry.schema); - EXPECT_EQ("2nd_schema", *property_entry.schema); + ASSERT_NE(nullptr, property_entry.type); + EXPECT_EQ("2nd_type", *property_entry.type); } EXPECT_EQ(3U, test_node->exact_matches().size()); EXPECT_EQ("test1", test_node->exact_matches()[0].name); @@ -80,18 +80,18 @@ TEST(propertyinfoserializer, BuildTrie_Simple) { EXPECT_EQ("3rd", *test_node->exact_matches()[1].context); EXPECT_EQ("3rd", *test_node->exact_matches()[2].context); - ASSERT_NE(nullptr, test_node->exact_matches()[0].schema); - ASSERT_NE(nullptr, test_node->exact_matches()[1].schema); - ASSERT_NE(nullptr, test_node->exact_matches()[2].schema); - EXPECT_EQ("3rd_schema", *test_node->exact_matches()[0].schema); - EXPECT_EQ("3rd_schema", *test_node->exact_matches()[1].schema); - EXPECT_EQ("3rd_schema", *test_node->exact_matches()[2].schema); + ASSERT_NE(nullptr, test_node->exact_matches()[0].type); + ASSERT_NE(nullptr, test_node->exact_matches()[1].type); + ASSERT_NE(nullptr, test_node->exact_matches()[2].type); + EXPECT_EQ("3rd_type", *test_node->exact_matches()[0].type); + EXPECT_EQ("3rd_type", *test_node->exact_matches()[1].type); + EXPECT_EQ("3rd_type", *test_node->exact_matches()[2].type); // Check the long string node auto expect_empty_one_child = [](auto* node) { ASSERT_NE(nullptr, node); EXPECT_EQ(nullptr, node->context()); - EXPECT_EQ(nullptr, node->schema()); + EXPECT_EQ(nullptr, node->type()); EXPECT_EQ(0U, node->prefixes().size()); EXPECT_EQ(0U, node->exact_matches().size()); EXPECT_EQ(1U, node->children().size()); @@ -120,8 +120,8 @@ TEST(propertyinfoserializer, BuildTrie_Simple) { EXPECT_EQ("string", property_entry.name); ASSERT_NE(nullptr, property_entry.context); EXPECT_EQ("4th", *property_entry.context); - ASSERT_NE(nullptr, property_entry.schema); - EXPECT_EQ("4th_schema", *property_entry.schema); + ASSERT_NE(nullptr, property_entry.type); + EXPECT_EQ("4th_type", *property_entry.type); } } diff --git a/property_service/libpropertyinfoserializer/trie_serializer.cpp b/property_service/libpropertyinfoserializer/trie_serializer.cpp index 5326537f4..adeed1bf7 100644 --- a/property_service/libpropertyinfoserializer/trie_serializer.cpp +++ b/property_service/libpropertyinfoserializer/trie_serializer.cpp @@ -43,15 +43,15 @@ uint32_t TrieSerializer::WritePropertyEntry(const PropertyEntryBuilder& property uint32_t context_index = property_entry.context != nullptr && !property_entry.context->empty() ? serialized_info()->FindContextIndex(property_entry.context->c_str()) : ~0u; - uint32_t schema_index = property_entry.schema != nullptr && !property_entry.schema->empty() - ? serialized_info()->FindSchemaIndex(property_entry.schema->c_str()) - : ~0u; + uint32_t type_index = property_entry.type != nullptr && !property_entry.type->empty() + ? serialized_info()->FindTypeIndex(property_entry.type->c_str()) + : ~0u; uint32_t offset; auto serialized_property_entry = arena_->AllocateObject(&offset); serialized_property_entry->name_offset = arena_->AllocateAndWriteString(property_entry.name); serialized_property_entry->namelen = property_entry.name.size(); serialized_property_entry->context_index = context_index; - serialized_property_entry->schema_index = schema_index; + serialized_property_entry->type_index = type_index; return offset; } @@ -122,9 +122,9 @@ std::string TrieSerializer::SerializeTrie(const TrieBuilder& trie_builder) { header->contexts_offset = arena_->size(); SerializeStrings(trie_builder.contexts()); - // Store where we're about to write the schemas. - header->schemas_offset = arena_->size(); - SerializeStrings(trie_builder.schemas()); + // Store where we're about to write the types. + header->types_offset = arena_->size(); + SerializeStrings(trie_builder.types()); // We need to store size() up to this point now for Find*Offset() to work. header->size = arena_->size();