Loading flags/uicc.aconfig +8 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,13 @@ flag { flag { name: "carrier_restriction_status" namespace: "telephony" description: "This flag control the visibility of the getCarrierRestrictionStatus in carrierRestrictionRules class." description: "This flag controls the visibility of the getCarrierRestrictionStatus in carrierRestrictionRules class." bug:"313553044" } flag { name: "carrier_restriction_rules_enhancement" namespace: "telephony" description: "This flag controls the new enhancements to the existing carrier restrictions rules" bug:"317226653" } No newline at end of file src/java/com/android/internal/telephony/RILUtils.java +83 −0 Original line number Diff line number Diff line Loading @@ -305,6 +305,7 @@ import android.net.LinkAddress; import android.net.LinkProperties; import android.os.SystemClock; import android.service.carrier.CarrierIdentifier; import android.telephony.CarrierInfo; import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.BarringInfo; Loading Loading @@ -4039,6 +4040,9 @@ public class RILUtils { public static List<CarrierIdentifier> convertHalCarrierList( android.hardware.radio.sim.Carrier[] carrierList) { List<CarrierIdentifier> ret = new ArrayList<>(); if (carrierList == null) { return ret; } for (int i = 0; i < carrierList.length; i++) { String mcc = carrierList[i].mcc; String mnc = carrierList[i].mnc; Loading @@ -4059,6 +4063,85 @@ public class RILUtils { return ret; } /** * Convert an array of CarrierInfo defined in * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl to a list of CarrierInfo * defined in android/service/carrier/CarrierInfo.java * * @param carrierInfos array of CarrierInfo defined in * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl * @return The converted list of CarrierInfo */ public static List<CarrierInfo> convertAidlCarrierInfoList( android.hardware.radio.sim.CarrierInfo[] carrierInfos) { List<CarrierInfo> carrierInfoList = new ArrayList<>(); if (carrierInfos == null) { loge("convertAidlCarrierInfoList received NULL carrierInfos"); return carrierInfoList; } for (int index = 0; index < carrierInfos.length; index++) { String mcc = carrierInfos[index].mcc; String mnc = carrierInfos[index].mnc; String spn = carrierInfos[index].spn; String gid1 = carrierInfos[index].gid1; String gid2 = carrierInfos[index].gid2; String imsi = carrierInfos[index].imsiPrefix; String iccid = carrierInfos[index].iccid; String impi = carrierInfos[index].impi; List<android.hardware.radio.sim.Plmn> halEhplmn = carrierInfos[index].ehplmn; List<String> eHplmnList = new ArrayList<>(); if (halEhplmn != null) { for (int plmnIndex = 0; plmnIndex < halEhplmn.size(); plmnIndex++) { String ehplmnMcc = halEhplmn.get(plmnIndex).mcc; String ehplmnMnc = halEhplmn.get(plmnIndex).mnc; eHplmnList.add(ehplmnMcc + "," + ehplmnMnc); } } else { loge("convertAidlCarrierInfoList ehplmList is NULL"); } CarrierInfo carrierInfo = new CarrierInfo(mcc, mnc, spn, gid1, gid2, imsi, iccid, impi, eHplmnList); carrierInfoList.add(carrierInfo); } return carrierInfoList; } /** * Convert the sim policy defined in * radio/aidl/android/hardware/radio/sim/SimLockMultiSimPolicy.aidl to the equivalent sim * policy defined in android.telephony/CarrierRestrictionRules.MultiSimPolicy * * @param multiSimPolicy of type defined in SimLockMultiSimPolicy.aidl * @return int of type CarrierRestrictionRules.MultiSimPolicy */ public static @CarrierRestrictionRules.MultiSimPolicy int convertAidlSimLockMultiSimPolicy( int multiSimPolicy) { switch (multiSimPolicy) { case android.hardware.radio.sim.SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT: return CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ALL_SLOTS: return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ALL_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ONLY_SLOT_1: return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ONLY_SLOT_1; case android.hardware.radio.sim.SimLockMultiSimPolicy.VALID_SIM_MUST_PRESENT_ON_SLOT_1: return CarrierRestrictionRules.MULTISIM_POLICY_VALID_SIM_MUST_PRESENT_ON_SLOT_1; case android.hardware.radio.sim.SimLockMultiSimPolicy. ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS: return CarrierRestrictionRules. MULTISIM_POLICY_ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy. ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS: return CarrierRestrictionRules. MULTISIM_POLICY_ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy.ALL_SIMS_MUST_BE_VALID: return CarrierRestrictionRules.MULTISIM_POLICY_ALL_SIMS_MUST_BE_VALID; case android.hardware.radio.sim.SimLockMultiSimPolicy.SLOT_POLICY_OTHER: return CarrierRestrictionRules.MULTISIM_POLICY_SLOT_POLICY_OTHER; default: return CarrierRestrictionRules.MULTISIM_POLICY_NONE; } } /** * Convert CardStatus defined in radio/1.0, 1.5/types.hal to IccCardStatus * @param cardStatus CardStatus defined in radio/1.0, 1.5/types.hal Loading src/java/com/android/internal/telephony/SimResponse.java +12 −17 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.telephony.TelephonyManager.HAL_SERVICE_SIM; import android.hardware.radio.RadioError; import android.hardware.radio.RadioResponseInfo; import android.hardware.radio.sim.CarrierRestrictions; import android.hardware.radio.sim.IRadioSimResponse; import android.telephony.CarrierRestrictionRules; import android.telephony.TelephonyManager; Loading Loading @@ -116,28 +115,24 @@ public class SimResponse extends IRadioSimResponse.Stub { if (rr == null) { return; } CarrierRestrictionRules ret; int policy = CarrierRestrictionRules.MULTISIM_POLICY_NONE; if (multiSimPolicy == android.hardware.radio.sim.SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT) { policy = CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; } int policy = RILUtils.convertAidlSimLockMultiSimPolicy(multiSimPolicy); int carrierRestrictionDefault = CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED; if (!carrierRestrictions.allowedCarriersPrioritized) { carrierRestrictionDefault = CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED; } ret = CarrierRestrictionRules.newBuilder() .setAllowedCarriers(RILUtils.convertHalCarrierList( carrierRestrictions.allowedCarriers)) .setExcludedCarriers(RILUtils.convertHalCarrierList( carrierRestrictions.excludedCarriers)) .setDefaultCarrierRestriction(carrierRestrictionDefault) .setMultiSimPolicy(policy) .setCarrierRestrictionStatus(carrierRestrictions.status) .build(); CarrierRestrictionRules ret = CarrierRestrictionRules.newBuilder().setAllowedCarriers( RILUtils.convertHalCarrierList( carrierRestrictions.allowedCarriers)).setExcludedCarriers( RILUtils.convertHalCarrierList( carrierRestrictions.excludedCarriers)).setDefaultCarrierRestriction( carrierRestrictionDefault).setMultiSimPolicy(policy).setCarrierRestrictionStatus( carrierRestrictions.status).setAllowedCarrierInfo( RILUtils.convertAidlCarrierInfoList( carrierRestrictions.allowedCarrierInfoList)).setExcludedCarrierInfo( RILUtils.convertAidlCarrierInfoList( carrierRestrictions.excludedCarrierInfoList)).build(); if (responseInfo.error == RadioError.NONE) { RadioResponse.sendMessageResponse(rr.mResult, ret); } Loading tests/telephonytests/src/com/android/internal/telephony/CarrierRestrictionRulesTest.java +101 −0 Original line number Diff line number Diff line Loading @@ -16,13 +16,17 @@ package com.android.internal.telephony; import static android.telephony.CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; import android.os.Parcel; import android.service.carrier.CarrierIdentifier; import android.telephony.CarrierInfo; import android.telephony.CarrierRestrictionRules; import android.test.AndroidTestCase; import androidx.test.filters.SmallTest; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; Loading Loading @@ -341,4 +345,101 @@ public class CarrierRestrictionRulesTest extends AndroidTestCase { List<Boolean> expected = Arrays.asList(false, false, false); assertTrue(result.equals(expected)); } @Test public void testBuilderAllowedAndExcludedCarrierInfos() { List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, null)); allowedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, null, null, null, null, null)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithEplmn() { List<String> plmns = new ArrayList<>(); plmns.add("**1" + "," + "123"); plmns.add("2*1" + "," + "1*3"); List<String> plmns2 = new ArrayList<>(); plmns2.add("**1" + "," + "123"); plmns2.add("2*1" + "," + "1*3"); plmns2.add("2**" + "," + "*"); List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, plmns)); allowedCarriers.add( new CarrierInfo(MCC2, MNC2, null, null, null, null, null, null, plmns2)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertTrue(rules.getAllowedCarriersInfoList().get(0).getEhplmn().equals(plmns)); assertTrue(rules.getAllowedCarriersInfoList().get(1).getEhplmn().equals(plmns2)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithNullEplmn() { List<String> plmns = new ArrayList<>(); List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, plmns)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertTrue(rules.getAllowedCarriersInfoList().get(0).getEhplmn().equals(plmns)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithSimPolicy() { List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, null)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder(). setAllowedCarrierInfo(allowedCarriers). setExcludedCarrierInfo(excludedCarriers). setDefaultCarrierRestriction( CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED). setMultiSimPolicy(MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT).build(); assertEquals(true, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertEquals(MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT, rules.getMultiSimPolicy()); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED, rules.getDefaultCarrierRestriction()); } } Loading
flags/uicc.aconfig +8 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,13 @@ flag { flag { name: "carrier_restriction_status" namespace: "telephony" description: "This flag control the visibility of the getCarrierRestrictionStatus in carrierRestrictionRules class." description: "This flag controls the visibility of the getCarrierRestrictionStatus in carrierRestrictionRules class." bug:"313553044" } flag { name: "carrier_restriction_rules_enhancement" namespace: "telephony" description: "This flag controls the new enhancements to the existing carrier restrictions rules" bug:"317226653" } No newline at end of file
src/java/com/android/internal/telephony/RILUtils.java +83 −0 Original line number Diff line number Diff line Loading @@ -305,6 +305,7 @@ import android.net.LinkAddress; import android.net.LinkProperties; import android.os.SystemClock; import android.service.carrier.CarrierIdentifier; import android.telephony.CarrierInfo; import android.telephony.AccessNetworkConstants; import android.telephony.Annotation; import android.telephony.BarringInfo; Loading Loading @@ -4039,6 +4040,9 @@ public class RILUtils { public static List<CarrierIdentifier> convertHalCarrierList( android.hardware.radio.sim.Carrier[] carrierList) { List<CarrierIdentifier> ret = new ArrayList<>(); if (carrierList == null) { return ret; } for (int i = 0; i < carrierList.length; i++) { String mcc = carrierList[i].mcc; String mnc = carrierList[i].mnc; Loading @@ -4059,6 +4063,85 @@ public class RILUtils { return ret; } /** * Convert an array of CarrierInfo defined in * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl to a list of CarrierInfo * defined in android/service/carrier/CarrierInfo.java * * @param carrierInfos array of CarrierInfo defined in * radio/aidl/android/hardware/radio/sim/CarrierInfo.aidl * @return The converted list of CarrierInfo */ public static List<CarrierInfo> convertAidlCarrierInfoList( android.hardware.radio.sim.CarrierInfo[] carrierInfos) { List<CarrierInfo> carrierInfoList = new ArrayList<>(); if (carrierInfos == null) { loge("convertAidlCarrierInfoList received NULL carrierInfos"); return carrierInfoList; } for (int index = 0; index < carrierInfos.length; index++) { String mcc = carrierInfos[index].mcc; String mnc = carrierInfos[index].mnc; String spn = carrierInfos[index].spn; String gid1 = carrierInfos[index].gid1; String gid2 = carrierInfos[index].gid2; String imsi = carrierInfos[index].imsiPrefix; String iccid = carrierInfos[index].iccid; String impi = carrierInfos[index].impi; List<android.hardware.radio.sim.Plmn> halEhplmn = carrierInfos[index].ehplmn; List<String> eHplmnList = new ArrayList<>(); if (halEhplmn != null) { for (int plmnIndex = 0; plmnIndex < halEhplmn.size(); plmnIndex++) { String ehplmnMcc = halEhplmn.get(plmnIndex).mcc; String ehplmnMnc = halEhplmn.get(plmnIndex).mnc; eHplmnList.add(ehplmnMcc + "," + ehplmnMnc); } } else { loge("convertAidlCarrierInfoList ehplmList is NULL"); } CarrierInfo carrierInfo = new CarrierInfo(mcc, mnc, spn, gid1, gid2, imsi, iccid, impi, eHplmnList); carrierInfoList.add(carrierInfo); } return carrierInfoList; } /** * Convert the sim policy defined in * radio/aidl/android/hardware/radio/sim/SimLockMultiSimPolicy.aidl to the equivalent sim * policy defined in android.telephony/CarrierRestrictionRules.MultiSimPolicy * * @param multiSimPolicy of type defined in SimLockMultiSimPolicy.aidl * @return int of type CarrierRestrictionRules.MultiSimPolicy */ public static @CarrierRestrictionRules.MultiSimPolicy int convertAidlSimLockMultiSimPolicy( int multiSimPolicy) { switch (multiSimPolicy) { case android.hardware.radio.sim.SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT: return CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ALL_SLOTS: return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ALL_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy.APPLY_TO_ONLY_SLOT_1: return CarrierRestrictionRules.MULTISIM_POLICY_APPLY_TO_ONLY_SLOT_1; case android.hardware.radio.sim.SimLockMultiSimPolicy.VALID_SIM_MUST_PRESENT_ON_SLOT_1: return CarrierRestrictionRules.MULTISIM_POLICY_VALID_SIM_MUST_PRESENT_ON_SLOT_1; case android.hardware.radio.sim.SimLockMultiSimPolicy. ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS: return CarrierRestrictionRules. MULTISIM_POLICY_ACTIVE_SERVICE_ON_SLOT_1_TO_UNBLOCK_OTHER_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy. ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS: return CarrierRestrictionRules. MULTISIM_POLICY_ACTIVE_SERVICE_ON_ANY_SLOT_TO_UNBLOCK_OTHER_SLOTS; case android.hardware.radio.sim.SimLockMultiSimPolicy.ALL_SIMS_MUST_BE_VALID: return CarrierRestrictionRules.MULTISIM_POLICY_ALL_SIMS_MUST_BE_VALID; case android.hardware.radio.sim.SimLockMultiSimPolicy.SLOT_POLICY_OTHER: return CarrierRestrictionRules.MULTISIM_POLICY_SLOT_POLICY_OTHER; default: return CarrierRestrictionRules.MULTISIM_POLICY_NONE; } } /** * Convert CardStatus defined in radio/1.0, 1.5/types.hal to IccCardStatus * @param cardStatus CardStatus defined in radio/1.0, 1.5/types.hal Loading
src/java/com/android/internal/telephony/SimResponse.java +12 −17 Original line number Diff line number Diff line Loading @@ -20,7 +20,6 @@ import static android.telephony.TelephonyManager.HAL_SERVICE_SIM; import android.hardware.radio.RadioError; import android.hardware.radio.RadioResponseInfo; import android.hardware.radio.sim.CarrierRestrictions; import android.hardware.radio.sim.IRadioSimResponse; import android.telephony.CarrierRestrictionRules; import android.telephony.TelephonyManager; Loading Loading @@ -116,28 +115,24 @@ public class SimResponse extends IRadioSimResponse.Stub { if (rr == null) { return; } CarrierRestrictionRules ret; int policy = CarrierRestrictionRules.MULTISIM_POLICY_NONE; if (multiSimPolicy == android.hardware.radio.sim.SimLockMultiSimPolicy.ONE_VALID_SIM_MUST_BE_PRESENT) { policy = CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; } int policy = RILUtils.convertAidlSimLockMultiSimPolicy(multiSimPolicy); int carrierRestrictionDefault = CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED; if (!carrierRestrictions.allowedCarriersPrioritized) { carrierRestrictionDefault = CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED; } ret = CarrierRestrictionRules.newBuilder() .setAllowedCarriers(RILUtils.convertHalCarrierList( carrierRestrictions.allowedCarriers)) .setExcludedCarriers(RILUtils.convertHalCarrierList( carrierRestrictions.excludedCarriers)) .setDefaultCarrierRestriction(carrierRestrictionDefault) .setMultiSimPolicy(policy) .setCarrierRestrictionStatus(carrierRestrictions.status) .build(); CarrierRestrictionRules ret = CarrierRestrictionRules.newBuilder().setAllowedCarriers( RILUtils.convertHalCarrierList( carrierRestrictions.allowedCarriers)).setExcludedCarriers( RILUtils.convertHalCarrierList( carrierRestrictions.excludedCarriers)).setDefaultCarrierRestriction( carrierRestrictionDefault).setMultiSimPolicy(policy).setCarrierRestrictionStatus( carrierRestrictions.status).setAllowedCarrierInfo( RILUtils.convertAidlCarrierInfoList( carrierRestrictions.allowedCarrierInfoList)).setExcludedCarrierInfo( RILUtils.convertAidlCarrierInfoList( carrierRestrictions.excludedCarrierInfoList)).build(); if (responseInfo.error == RadioError.NONE) { RadioResponse.sendMessageResponse(rr.mResult, ret); } Loading
tests/telephonytests/src/com/android/internal/telephony/CarrierRestrictionRulesTest.java +101 −0 Original line number Diff line number Diff line Loading @@ -16,13 +16,17 @@ package com.android.internal.telephony; import static android.telephony.CarrierRestrictionRules.MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT; import android.os.Parcel; import android.service.carrier.CarrierIdentifier; import android.telephony.CarrierInfo; import android.telephony.CarrierRestrictionRules; import android.test.AndroidTestCase; import androidx.test.filters.SmallTest; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; Loading Loading @@ -341,4 +345,101 @@ public class CarrierRestrictionRulesTest extends AndroidTestCase { List<Boolean> expected = Arrays.asList(false, false, false); assertTrue(result.equals(expected)); } @Test public void testBuilderAllowedAndExcludedCarrierInfos() { List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, null)); allowedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, null, null, null, null, null)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithEplmn() { List<String> plmns = new ArrayList<>(); plmns.add("**1" + "," + "123"); plmns.add("2*1" + "," + "1*3"); List<String> plmns2 = new ArrayList<>(); plmns2.add("**1" + "," + "123"); plmns2.add("2*1" + "," + "1*3"); plmns2.add("2**" + "," + "*"); List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, plmns)); allowedCarriers.add( new CarrierInfo(MCC2, MNC2, null, null, null, null, null, null, plmns2)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertTrue(rules.getAllowedCarriersInfoList().get(0).getEhplmn().equals(plmns)); assertTrue(rules.getAllowedCarriersInfoList().get(1).getEhplmn().equals(plmns2)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithNullEplmn() { List<String> plmns = new ArrayList<>(); List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, plmns)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder().setAllowedCarrierInfo( allowedCarriers).setExcludedCarrierInfo(excludedCarriers).build(); assertEquals(false, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertTrue(rules.getAllowedCarriersInfoList().get(0).getEhplmn().equals(plmns)); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_NOT_ALLOWED, rules.getDefaultCarrierRestriction()); } @Test public void testBuilderAllowedAndExcludedCarrierInfoWithSimPolicy() { List<CarrierInfo> allowedCarriers = new ArrayList<>(); allowedCarriers.add(new CarrierInfo(MCC1, MNC1, null, null, null, null, null, null, null)); List<CarrierInfo> excludedCarriers = new ArrayList<>(); excludedCarriers.add(new CarrierInfo(MCC2, MNC2, null, null, GID1, null, null, null, null)); CarrierRestrictionRules rules = CarrierRestrictionRules.newBuilder(). setAllowedCarrierInfo(allowedCarriers). setExcludedCarrierInfo(excludedCarriers). setDefaultCarrierRestriction( CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED). setMultiSimPolicy(MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT).build(); assertEquals(true, rules.isAllCarriersAllowed()); assertTrue(rules.getAllowedCarriersInfoList().equals(allowedCarriers)); assertTrue(rules.getExcludedCarriersInfoList().equals(excludedCarriers)); assertEquals(MULTISIM_POLICY_ONE_VALID_SIM_MUST_BE_PRESENT, rules.getMultiSimPolicy()); assertEquals(CarrierRestrictionRules.CARRIER_RESTRICTION_DEFAULT_ALLOWED, rules.getDefaultCarrierRestriction()); } }