diff options
author | Tom Cherry | 2017-12-19 17:46:07 -0600 |
---|---|---|
committer | Tom Cherry | 2017-12-19 18:47:21 -0600 |
commit | f5ed661f729079b4231f9ea1d836b4eb474c5629 (patch) | |
tree | 6b1a9706257d896d83871d227b9f6cf57b23b818 /property_service | |
parent | e1d9e7c343ac4577450b96d4de19da6f099eb154 (diff) | |
download | platform-system-core-f5ed661f729079b4231f9ea1d836b4eb474c5629.tar.gz platform-system-core-f5ed661f729079b4231f9ea1d836b4eb474c5629.tar.xz platform-system-core-f5ed661f729079b4231f9ea1d836b4eb474c5629.zip |
Only apply match if there is something to apply
It is possible for a match to only contain a context and not a schema,
or vice versa and in this case, the previously matched values should
continue to be used. The serializer already handles this case by
setting the index of the match to ~0u if there is not one, so this
change simply has the parser skip these values.
Bug: 70858511
Test: unit tests, including new ones
Change-Id: Ibc65bd8d637e39f3b1ce7bcc2b88189b75173f88
Diffstat (limited to 'property_service')
-rw-r--r-- | property_service/libpropertyinfoparser/property_info_parser.cpp | 24 | ||||
-rw-r--r-- | property_service/libpropertyinfoserializer/property_info_serializer_test.cpp | 42 |
2 files changed, 62 insertions, 4 deletions
diff --git a/property_service/libpropertyinfoparser/property_info_parser.cpp b/property_service/libpropertyinfoparser/property_info_parser.cpp index e53c6253e..a8f663624 100644 --- a/property_service/libpropertyinfoparser/property_info_parser.cpp +++ b/property_service/libpropertyinfoparser/property_info_parser.cpp | |||
@@ -96,8 +96,12 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo | |||
96 | if (prefix_len > remaining_name_size) continue; | 96 | if (prefix_len > remaining_name_size) continue; |
97 | 97 | ||
98 | if (!strncmp(c_string(trie_node.prefix(i)->name_offset), remaining_name, prefix_len)) { | 98 | if (!strncmp(c_string(trie_node.prefix(i)->name_offset), remaining_name, prefix_len)) { |
99 | *context_index = trie_node.prefix(i)->context_index; | 99 | if (trie_node.prefix(i)->context_index != ~0u) { |
100 | *schema_index = trie_node.prefix(i)->schema_index; | 100 | *context_index = trie_node.prefix(i)->context_index; |
101 | } | ||
102 | if (trie_node.prefix(i)->schema_index != ~0u) { | ||
103 | *schema_index = trie_node.prefix(i)->schema_index; | ||
104 | } | ||
101 | return; | 105 | return; |
102 | } | 106 | } |
103 | } | 107 | } |
@@ -142,8 +146,20 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex | |||
142 | // Check exact matches | 146 | // Check exact matches |
143 | for (uint32_t i = 0; i < trie_node.num_exact_matches(); ++i) { | 147 | for (uint32_t i = 0; i < trie_node.num_exact_matches(); ++i) { |
144 | if (!strcmp(c_string(trie_node.exact_match(i)->name_offset), remaining_name)) { | 148 | if (!strcmp(c_string(trie_node.exact_match(i)->name_offset), remaining_name)) { |
145 | if (context_index != nullptr) *context_index = trie_node.exact_match(i)->context_index; | 149 | if (context_index != nullptr) { |
146 | if (schema_index != nullptr) *schema_index = trie_node.exact_match(i)->schema_index; | 150 | if (trie_node.exact_match(i)->context_index != ~0u) { |
151 | *context_index = trie_node.exact_match(i)->context_index; | ||
152 | } else { | ||
153 | *context_index = return_context_index; | ||
154 | } | ||
155 | } | ||
156 | if (schema_index != nullptr) { | ||
157 | if (trie_node.exact_match(i)->schema_index != ~0u) { | ||
158 | *schema_index = trie_node.exact_match(i)->schema_index; | ||
159 | } else { | ||
160 | *schema_index = return_schema_index; | ||
161 | } | ||
162 | } | ||
147 | return; | 163 | return; |
148 | } | 164 | } |
149 | } | 165 | } |
diff --git a/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp b/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp index b3fae268e..46c2d06ef 100644 --- a/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp +++ b/property_service/libpropertyinfoserializer/property_info_serializer_test.cpp | |||
@@ -844,5 +844,47 @@ TEST(propertyinfoserializer, GetPropertyInfo_prefix_with_dot_vs_without) { | |||
844 | EXPECT_STREQ("3rd", schema); | 844 | EXPECT_STREQ("3rd", schema); |
845 | } | 845 | } |
846 | 846 | ||
847 | TEST(propertyinfoserializer, GetPropertyInfo_empty_context_and_schema) { | ||
848 | auto property_info = std::vector<PropertyInfoEntry>{ | ||
849 | {"persist.", "1st", "", false}, | ||
850 | {"persist.dot_prefix.", "2nd", "", false}, | ||
851 | {"persist.non_dot_prefix", "3rd", "", false}, | ||
852 | {"persist.exact_match", "", "", true}, | ||
853 | {"persist.dot_prefix2.", "", "4th", false}, | ||
854 | {"persist.non_dot_prefix2", "", "5th", false}, | ||
855 | }; | ||
856 | |||
857 | auto serialized_trie = std::string(); | ||
858 | auto build_trie_error = std::string(); | ||
859 | ASSERT_TRUE(BuildTrie(property_info, "default", "default", &serialized_trie, &build_trie_error)) | ||
860 | << build_trie_error; | ||
861 | |||
862 | auto property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_trie.data()); | ||
863 | |||
864 | const char* context; | ||
865 | const char* schema; | ||
866 | property_info_area->GetPropertyInfo("notpersist.radio.something", &context, &schema); | ||
867 | EXPECT_STREQ("default", context); | ||
868 | EXPECT_STREQ("default", schema); | ||
869 | property_info_area->GetPropertyInfo("persist.nomatch", &context, &schema); | ||
870 | EXPECT_STREQ("1st", context); | ||
871 | EXPECT_STREQ("default", schema); | ||
872 | property_info_area->GetPropertyInfo("persist.dot_prefix.something", &context, &schema); | ||
873 | EXPECT_STREQ("2nd", context); | ||
874 | EXPECT_STREQ("default", schema); | ||
875 | property_info_area->GetPropertyInfo("persist.non_dot_prefix.something", &context, &schema); | ||
876 | EXPECT_STREQ("3rd", context); | ||
877 | EXPECT_STREQ("default", schema); | ||
878 | property_info_area->GetPropertyInfo("persist.exact_match", &context, &schema); | ||
879 | EXPECT_STREQ("1st", context); | ||
880 | EXPECT_STREQ("default", schema); | ||
881 | property_info_area->GetPropertyInfo("persist.dot_prefix2.something", &context, &schema); | ||
882 | EXPECT_STREQ("1st", context); | ||
883 | EXPECT_STREQ("4th", schema); | ||
884 | property_info_area->GetPropertyInfo("persist.non_dot_prefix2.something", &context, &schema); | ||
885 | EXPECT_STREQ("1st", context); | ||
886 | EXPECT_STREQ("5th", schema); | ||
887 | } | ||
888 | |||
847 | } // namespace properties | 889 | } // namespace properties |
848 | } // namespace android | 890 | } // namespace android |