aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Zhang <marvinz@motorola.com>2023-04-15 17:27:22 -0500
committerMarvin Zhang <marvinz@motorola.com>2023-04-15 17:27:22 -0500
commitcf546634b7b12d697fd1ff4b5a03a0fa141d0d7c (patch)
tree53a5565a52e2ee903caf5840cdb6569b722e2223
parent5a721606c1194cf042f8b8eb6ba322d13071761d (diff)
downloadcarrier_settings-cf546634b7b12d697fd1ff4b5a03a0fa141d0d7c.tar.gz
Add "unique_rule_id" and "following" attributes to carrier_config
The new attributes are to explicit define the inheritance. 1. Add "unique_rule_id" attribute as the id for parent configuration. 2. Add the "following" attribute to indicate the inheritance from specific unique_rule_id. 3. The "unique_rule_id" attribute is limited in vendor.xml. AOSP Assets should NOT have carrier_config with unique_rule_id. 4. The unique_rule_id must be unique to one carrier_config. If there are more than one carrier_config that have the same unique_rule_id the carrier config convert tool will stop and report an error. 5. If one carrier_config has more than one "unique_rule_id", only the first one will take effect. 6. If one carrier_config has more than one "following", only the first one will take effect. 7. General carrier_config can NOT have "unique_rule_id" or "following". 8. The carrier_config has "unique_rule_id" can be before or after the carrier_config has "following". The order in vendor.xml won't break the inheritance. Bug: 217591523 Change-Id: Iddb3004e6f7e9f1ec0a347e52edd3effa66537b8
-rw-r--r--java/CarrierConfigConverterV2.java61
1 files changed, 60 insertions, 1 deletions
diff --git a/java/CarrierConfigConverterV2.java b/java/CarrierConfigConverterV2.java
index 8f180db..feceabf 100644
--- a/java/CarrierConfigConverterV2.java
+++ b/java/CarrierConfigConverterV2.java
@@ -269,6 +269,7 @@ public final class CarrierConfigConverterV2 {
}
// 3. For each CarrierId, build its carrier configs, following AOSP DefaultCarrierConfigService.
+ loadUniqueRulesFromVendorXml(vendorXmls);
for (CarrierId carrier : carriers) {
Map<String, CarrierConfig.Config> config = ImmutableMap.of();
@@ -596,13 +597,19 @@ public final class CarrierConfigConverterV2 {
* @return a map, key being the carrier config key, value being a {@link CarrierConfig.Config}
* with one of the value set.
*/
- private static HashMap<String, CarrierConfig.Config> parseCarrierConfigFromVendorXml(
+ private HashMap<String, CarrierConfig.Config> parseCarrierConfigFromVendorXml(
Document xmlDoc, CarrierIdentifier carrier) throws IOException {
HashMap<String, CarrierConfig.Config> configMap = new HashMap<>();
for (Element element : getElementsByTagName(xmlDoc, TAG_CARRIER_CONFIG)) {
if (carrier != null && !checkFilters(element, carrier)) {
continue;
}
+
+ Element parent_config = findParentConfigByUniqueRuleId(element);
+ if (parent_config != null) {
+ configMap.putAll(parseCarrierConfigToMap(parent_config));
+ }
+
configMap.putAll(parseCarrierConfigToMap(element));
}
return configMap;
@@ -786,6 +793,8 @@ public final class CarrierConfigConverterV2 {
break;
case "name":
// name is used together with cid for readability. ignore for filter.
+ case "unique_rule_id":
+ case "following":
break;
default:
System.err.println("Unsupported attribute " + attribute + "=" + value);
@@ -974,4 +983,54 @@ public final class CarrierConfigConverterV2 {
}
}
private CarrierConfigConverterV2() {}
+
+ // The hash map to store all the configs with attribute "unique_rule_id".
+ // The config entry with attribute "following" can inherit from the config
+ // with matching "unique_rule_id".
+ // Both "unique_rule_id" and "following" attributes can only appear in vendor xml.
+ private HashMap<String, Element> mUniqueRules = new HashMap<>();
+
+ private void loadUniqueRulesFromVendorXml(List<Document> vendorXmls)
+ throws IOException {
+ for (Document vendorXml : vendorXmls) {
+ for (Element element : getElementsByTagName(vendorXml, TAG_CARRIER_CONFIG)) {
+ NamedNodeMap attributes = element.getAttributes();
+ boolean uniqueRuleIdSeen = false;
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String attribute = attributes.item(i).getNodeName();
+ String value = attributes.item(i).getNodeValue();
+ switch (attribute) {
+ case "unique_rule_id":
+ if (mUniqueRules.containsKey(value)) {
+ throw new IOException("The carrier_config has duplicated unique_rule_id: " + attributes);
+ } else if (uniqueRuleIdSeen) {
+ throw new IOException("The carrier_config has more than 1 unique_rule_id: " + attributes);
+ }
+ mUniqueRules.put(value, element);
+ uniqueRuleIdSeen = true;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private Element findParentConfigByUniqueRuleId(Element childElement) {
+ NamedNodeMap attributes = childElement.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String attribute = attributes.item(i).getNodeName();
+ String value = attributes.item(i).getNodeValue();
+ switch (attribute) {
+ case "following":
+ return mUniqueRules.get(value);
+ //break;
+ default:
+ break;
+ }
+ }
+ return null;
+ }
+
}