diff options
author | Oscar Wei <oscarwei@microsoft.com> | 2022-12-08 04:13:58 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-12-08 04:13:58 +0000 |
commit | 5b7cd399ce961057e747830dfc7010edf0d6762a (patch) | |
tree | 5c35ba65fef2732ea2ad566adf0b75586509d435 | |
parent | 1638caca8b7ca0291b909823e2caa952bf16ab6c (diff) | |
parent | 3abba56ce236db37bf4179d5e721cf8e0eb3f355 (diff) | |
download | carrier_settings-5b7cd399ce961057e747830dfc7010edf0d6762a.tar.gz |
Letting parsing tool can use parent_canonical_id am: 722a6018b7 am: b3956c1c4e am: 3abba56ce2
Original change: https://android-review.googlesource.com/c/platform/tools/carrier_settings/+/2161938
Change-Id: I15fac85a419d79a1b0fcef0de0cab751260cd1db
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | java/CarrierConfigConverterV2.java | 97 |
1 files changed, 86 insertions, 11 deletions
diff --git a/java/CarrierConfigConverterV2.java b/java/CarrierConfigConverterV2.java index 2ba11a7..8f180db 100644 --- a/java/CarrierConfigConverterV2.java +++ b/java/CarrierConfigConverterV2.java @@ -102,6 +102,9 @@ public final class CarrierConfigConverterV2 { @Parameter(names = "--version", description = "The version number for all output textpb.") private long version = 1L; + @Parameter(names = "--consider_parent_canonical_id", arity = 1, description = "To consider parent_canonical_id") + private static boolean considerParentCanonicalId = false; + private static final String MCCMNC_FOR_DEFAULT_SETTINGS = "000000"; // Resource file path to the AOSP carrier list file @@ -125,13 +128,14 @@ public final class CarrierConfigConverterV2 { /** Entry point when invoked from other Java code, eg. the server side conversion tool. */ public static void convert( - String vendorXmlFile, String assetsDirName, String outputDir, long version) + String vendorXmlFile, String assetsDirName, String outputDir, long version, boolean considerParentCanonicalId) throws IOException { CarrierConfigConverterV2 converter = new CarrierConfigConverterV2(); converter.vendorXmlFiles = ImmutableList.of(vendorXmlFile); converter.assetsDirName = assetsDirName; converter.outputDir = outputDir; converter.version = version; + converter.considerParentCanonicalId = considerParentCanonicalId; converter.convert(); } @@ -147,6 +151,7 @@ public final class CarrierConfigConverterV2 { DocumentBuilder xmlDocBuilder = getDocumentBuilder(); Multimap<Integer, CarrierId> aospCarrierList = loadAospCarrierList(); Multimap<CarrierId, Integer> reverseAospCarrierList = reverseAospCarrierList(aospCarrierList); + Multimap<CarrierId, Integer> reverseAospCarrierListPerParentCanonicalId = reverseAospCarrierListPerParentCanonicalId(); /* * High-level flow: @@ -267,7 +272,7 @@ public final class CarrierConfigConverterV2 { for (CarrierId carrier : carriers) { Map<String, CarrierConfig.Config> config = ImmutableMap.of(); - CarrierIdentifier id = getCid(carrier, reverseAospCarrierList); + CarrierIdentifier id = getCid(carrier, reverseAospCarrierList, reverseAospCarrierListPerParentCanonicalId); if (id.getCarrierId() != -1) { HashMap<String, CarrierConfig.Config> configBySpecificCarrierId = parseCarrierConfigFromXml( @@ -407,6 +412,31 @@ public final class CarrierConfigConverterV2 { MultimapBuilder.linkedHashKeys().arrayListValues()::build)); } + private static Multimap<CarrierId, Integer> reverseAospCarrierListPerParentCanonicalId() throws IOException { + + com.android.providers.telephony.CarrierIdProto.CarrierList.Builder aospCarrierList = + com.android.providers.telephony.CarrierIdProto.CarrierList.newBuilder(); + try (InputStream textpb = + CarrierConfigConverterV2.class.getResourceAsStream(RESOURCE_CARRIER_LIST); + BufferedReader textpbReader = new BufferedReader(new InputStreamReader(textpb, UTF_8))) { + TextFormat.getParser().merge(textpbReader, aospCarrierList); + } + Multimap<Integer, CarrierId> res = aospCarrierList.getCarrierIdList().stream() + .filter(cid -> cid.getParentCanonicalId() > 0) + .collect( + flatteningToMultimap( + cid -> cid.getParentCanonicalId(), + cid -> carrierAttributeToCarrierId(cid.getCarrierAttributeList()).stream(), + MultimapBuilder.linkedHashKeys().arrayListValues()::build)); + + return res.entries().stream() + .collect( + toMultimap( + entry -> entry.getValue(), + entry -> entry.getKey(), + MultimapBuilder.linkedHashKeys().arrayListValues()::build)); + } + // Convert `CarrierAttribute`s to `CarrierId`s. // A CarrierAttribute message with fields not supported by CarrierSettings, like preferred_apn, // is ignored. @@ -871,32 +901,77 @@ public final class CarrierConfigConverterV2 { } private static CarrierIdentifier getCid( - CarrierId carrierId, Multimap<CarrierId, Integer> reverseAospCarrierList) { + CarrierId carrierId, Multimap<CarrierId, Integer> reverseAospCarrierList, + Multimap<CarrierId, Integer> reverseAospCarrierListPerParentCanonicalId) { // Mimic TelephonyManager#getCarrierIdFromMccMnc, which is implemented by // CarrierResolver#getCarrierIdFromMccMnc. CarrierId mccMnc = CarrierId.newBuilder().setMccMnc(carrierId.getMccMnc()).build(); int mccMncCarrierId = reverseAospCarrierList.get(mccMnc).stream().findFirst().orElse(-1); - List<Integer> cids = ImmutableList.copyOf(reverseAospCarrierList.get(carrierId)); + int parentCanonicalId = getParentCanonicalId(carrierId, cids, reverseAospCarrierListPerParentCanonicalId); // No match: use -1 if (cids.isEmpty()) { - return CarrierIdentifier.create(carrierId, -1, -1, mccMncCarrierId); + if (considerParentCanonicalId) { + return CarrierIdentifier.create(carrierId, parentCanonicalId, -1, mccMncCarrierId); + } else { + return CarrierIdentifier.create(carrierId, -1, -1, mccMncCarrierId); + } } // One match: use as both carrierId and specificCarrierId if (cids.size() == 1) { - return CarrierIdentifier.create(carrierId, cids.get(0), cids.get(0), mccMncCarrierId); + if (considerParentCanonicalId) { + return CarrierIdentifier.create(carrierId, parentCanonicalId, cids.get(0), mccMncCarrierId); + } else { + return CarrierIdentifier.create(carrierId, cids.get(0), cids.get(0), mccMncCarrierId); + } } // Two matches: specificCarrierId is always bigger than carrierId if (cids.size() == 2) { - return CarrierIdentifier.create( - carrierId, - Math.min(cids.get(0), cids.get(1)), - Math.max(cids.get(0), cids.get(1)), - mccMncCarrierId); + if (considerParentCanonicalId) { + return CarrierIdentifier.create( + carrierId, + parentCanonicalId, + Math.max(cids.get(0), cids.get(1)), + mccMncCarrierId); + } else { + return CarrierIdentifier.create( + carrierId, + Math.min(cids.get(0), cids.get(1)), + Math.max(cids.get(0), cids.get(1)), + mccMncCarrierId); + } } // Cannot be more than 2 matches. throw new IllegalStateException("More than two cid's found for " + carrierId + ": " + cids); } + private static int getParentCanonicalId( + CarrierId carrierId, + List<Integer> cids, + Multimap<CarrierId, Integer> reverseAospCarrierListPerParentCanonicalId) { + + List<Integer> parentCids = ImmutableList.copyOf(reverseAospCarrierListPerParentCanonicalId.get(carrierId)); + if (cids.isEmpty()) { + if (parentCids.isEmpty()) { + return -1; + } else { + return parentCids.get(0); + } + } else if (cids.size() == 1) { + if (parentCids.isEmpty()) { + return cids.get(0); + } else { + return parentCids.get(0); + } + } else if (cids.size() == 2) { + if (parentCids.isEmpty()) { + return Math.min(cids.get(0), cids.get(1)); + } else { + return parentCids.get(0); + } + } else { + return -1; + } + } private CarrierConfigConverterV2() {} } |