From bb91da1ec5ea73855ecdb47b8d944ea52290b00b Mon Sep 17 00:00:00 2001 From: arunvoddu Date: Wed, 9 Oct 2024 07:51:20 +0000 Subject: [PATCH] VTS to verify set/get AllowedCarriers for HAL 2.2 Bug:333397050, 365568518 Test: atest VtsHalRadioTargetTest Change-Id: Iea8e771eb6d7982220a0f2b6522467397d87f2ce Merged-In: I940fd4ecdc70cb4e31802cefc1ae1d02436ffe90 Merged-In: Iea8e771eb6d7982220a0f2b6522467397d87f2ce --- .../compat/libradiocompat/sim/structs.cpp | 48 +++++++-- .../aidl/compat/libradiocompat/sim/structs.h | 1 + radio/aidl/vts/radio_sim_test.cpp | 98 +++++++++++++++---- 3 files changed, 119 insertions(+), 28 deletions(-) diff --git a/radio/aidl/compat/libradiocompat/sim/structs.cpp b/radio/aidl/compat/libradiocompat/sim/structs.cpp index 00db2b8718..27aca6049a 100644 --- a/radio/aidl/compat/libradiocompat/sim/structs.cpp +++ b/radio/aidl/compat/libradiocompat/sim/structs.cpp @@ -70,26 +70,60 @@ V1_0::Carrier toHidl(const aidl::Carrier& carrier) { }; } -aidl::CarrierRestrictions toAidl(const V1_0::CarrierRestrictions& cr) { +static aidl::CarrierInfo toCarrierInfo(const aidl::Carrier& carrier) { return { - .allowedCarriers = toAidl(cr.allowedCarriers), - .excludedCarriers = toAidl(cr.excludedCarriers), + .mcc = carrier.mcc, + .mnc = carrier.mnc, + }; +} + +static std::vector toCarrierInfos(const std::vector& carriers) { + std::vector infos(carriers.size()); + for (size_t i = 0; i < carriers.size(); i++) { + infos[i] = toCarrierInfo(carriers[i]); + } + return infos; +} + +V1_0::Carrier toHidl(const aidl::CarrierInfo& carrierInfo) { + return { + .mcc = carrierInfo.mcc, + .mnc = carrierInfo.mnc, + }; +} + +aidl::CarrierRestrictions toAidl(const V1_0::CarrierRestrictions& cr) { + auto allowedCarriers = toAidl(cr.allowedCarriers); + auto excludedCarriers = toAidl(cr.excludedCarriers); + return { + .allowedCarriers = allowedCarriers, + .excludedCarriers = excludedCarriers, .allowedCarriersPrioritized = true, + .allowedCarrierInfoList = toCarrierInfos(allowedCarriers), + .excludedCarrierInfoList = toCarrierInfos(excludedCarriers), }; } aidl::CarrierRestrictions toAidl(const V1_4::CarrierRestrictionsWithPriority& cr) { + auto allowedCarriers = toAidl(cr.allowedCarriers); + auto excludedCarriers = toAidl(cr.excludedCarriers); return { - .allowedCarriers = toAidl(cr.allowedCarriers), - .excludedCarriers = toAidl(cr.excludedCarriers), + .allowedCarriers = allowedCarriers, + .excludedCarriers = excludedCarriers, .allowedCarriersPrioritized = cr.allowedCarriersPrioritized, + .allowedCarrierInfoList = toCarrierInfos(allowedCarriers), + .excludedCarrierInfoList = toCarrierInfos(excludedCarriers), }; } V1_4::CarrierRestrictionsWithPriority toHidl(const aidl::CarrierRestrictions& cr) { return { - .allowedCarriers = toHidl(cr.allowedCarriers), - .excludedCarriers = toHidl(cr.excludedCarriers), + .allowedCarriers = (cr.allowedCarriers.size() > cr.allowedCarrierInfoList.size()) + ? toHidl(cr.allowedCarriers) + : toHidl(cr.allowedCarrierInfoList), + .excludedCarriers = (cr.excludedCarriers.size() > cr.excludedCarrierInfoList.size()) + ? toHidl(cr.excludedCarriers) + : toHidl(cr.excludedCarrierInfoList), .allowedCarriersPrioritized = cr.allowedCarriersPrioritized, }; } diff --git a/radio/aidl/compat/libradiocompat/sim/structs.h b/radio/aidl/compat/libradiocompat/sim/structs.h index 54099b7ca9..7774beee31 100644 --- a/radio/aidl/compat/libradiocompat/sim/structs.h +++ b/radio/aidl/compat/libradiocompat/sim/structs.h @@ -37,6 +37,7 @@ V1_0::SimApdu toHidl(const ::aidl::android::hardware::radio::sim::SimApdu& apdu) ::aidl::android::hardware::radio::sim::Carrier toAidl(const V1_0::Carrier& carrier); V1_0::Carrier toHidl(const ::aidl::android::hardware::radio::sim::Carrier& carrier); +V1_0::Carrier toHidl(const ::aidl::android::hardware::radio::sim::CarrierInfo& carrierInfo); ::aidl::android::hardware::radio::sim::CarrierRestrictions // toAidl(const V1_0::CarrierRestrictions& cr); diff --git a/radio/aidl/vts/radio_sim_test.cpp b/radio/aidl/vts/radio_sim_test.cpp index e9b68cc465..ec1facc085 100644 --- a/radio/aidl/vts/radio_sim_test.cpp +++ b/radio/aidl/vts/radio_sim_test.cpp @@ -460,14 +460,43 @@ TEST_P(RadioSimTest, setAllowedCarriers) { serial = GetRandomSerialNumber(); CarrierRestrictions carrierRestrictions; memset(&carrierRestrictions, 0, sizeof(carrierRestrictions)); - carrierRestrictions.allowedCarriers.resize(1); - carrierRestrictions.excludedCarriers.resize(0); - carrierRestrictions.allowedCarriers[0].mcc = std::string("123"); - carrierRestrictions.allowedCarriers[0].mnc = std::string("456"); - carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL; - carrierRestrictions.allowedCarriers[0].matchData = std::string(); - carrierRestrictions.allowedCarriersPrioritized = true; + int32_t aidl_version; + ndk::ScopedAStatus aidl_status = radio_sim->getInterfaceVersion(&aidl_version); + ASSERT_OK(aidl_status); + + // Changes start + SimLockMultiSimPolicy multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY; + ALOGI("VTSAllowedCarriers Current AIDL version is %d ", aidl_version); + if (aidl_version <= 2) { + ALOGI("VTSAllowedCarriers If aidl_version is below 3 then , it will consider old AIDLs"); + carrierRestrictions.allowedCarrierInfoList.resize(1); + if ((carrierRestrictions.allowedCarrierInfoList.size() > 0)) { + ALOGI("VTSAllowedCarriers If size of allowedCarrierInfoList is greater than 0"); + } + carrierRestrictions.allowedCarriers.resize(1); + carrierRestrictions.excludedCarriers.resize(0); + carrierRestrictions.allowedCarriers[0].mcc = std::string("123"); + carrierRestrictions.allowedCarriers[0].mnc = std::string("456"); + carrierRestrictions.allowedCarriers[0].matchType = Carrier::MATCH_TYPE_ALL; + carrierRestrictions.allowedCarriers[0].matchData = std::string(); + carrierRestrictions.allowedCarriersPrioritized = true; + multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY; + } else { + carrierRestrictions.allowedCarrierInfoList.resize(1); + carrierRestrictions.excludedCarrierInfoList.resize(0); + // TODO(b/365568518): change mcc/mnc to something else once CF fully supports + // setAllowedCarriers + carrierRestrictions.allowedCarrierInfoList[0].mcc = std::string("123"); + carrierRestrictions.allowedCarrierInfoList[0].mnc = std::string("456"); + carrierRestrictions.allowedCarrierInfoList[0].spn = std::string("TestNetwork"); + carrierRestrictions.allowedCarrierInfoList[0].gid1 = std::string("BAE000000000000"); + carrierRestrictions.allowedCarrierInfoList[0].gid2 = std::string("AE0000000000000"); + carrierRestrictions.allowedCarrierInfoList[0].imsiPrefix = std::string("9987"); + carrierRestrictions.allowedCarriersPrioritized = true; + carrierRestrictions.status = CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED; + multisimPolicy = SimLockMultiSimPolicy::NO_MULTISIM_POLICY; + } radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy); EXPECT_EQ(std::cv_status::no_timeout, wait()); @@ -490,7 +519,7 @@ TEST_P(RadioSimTest, setAllowedCarriers) { sleep(2); updateSimCardStatus(); } - // TODO: uncomment once CF fully supports setAllowedCarriers + // TODO(b/365568518): uncomment once CF fully supports setAllowedCarriers // EXPECT_EQ(CardStatus::STATE_RESTRICTED, cardStatus.cardState); } @@ -503,17 +532,38 @@ TEST_P(RadioSimTest, setAllowedCarriers) { EXPECT_EQ(serial, radioRsp_sim->rspInfo.serial); EXPECT_EQ(RadioError::NONE, radioRsp_sim->rspInfo.error); - EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size()); - EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size()); - ASSERT_TRUE(std::string("123") == - radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc); - ASSERT_TRUE(std::string("456") == - radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc); - EXPECT_EQ(Carrier::MATCH_TYPE_ALL, - radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType); - ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized); - EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp); + if (aidl_version <= 2) { + EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarriers.size()); + EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarriers.size()); + ASSERT_TRUE(std::string("123") == + radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mcc); + ASSERT_TRUE(std::string("456") == + radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].mnc); + EXPECT_EQ(Carrier::MATCH_TYPE_ALL, + radioRsp_sim->carrierRestrictionsResp.allowedCarriers[0].matchType); + ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized); + EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp); + } else { + EXPECT_EQ(1, radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList.size()); + EXPECT_EQ(0, radioRsp_sim->carrierRestrictionsResp.excludedCarrierInfoList.size()); + ASSERT_EQ(std::string("123"), + radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mcc); + ASSERT_EQ(std::string("456"), + radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].mnc); +#if 0 // TODO(b/365568518): enable once CF fully supports setAllowedCarriers + ASSERT_EQ(std::string("BAE000000000000"), + radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid1); + ASSERT_EQ(std::string("AE0000000000000"), + radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].gid2); + ASSERT_EQ(std::string("9987"), + radioRsp_sim->carrierRestrictionsResp.allowedCarrierInfoList[0].imsiPrefix); + EXPECT_EQ(CarrierRestrictions::CarrierRestrictionStatus::RESTRICTED, + radioRsp_sim->carrierRestrictionsResp.status); +#endif + ASSERT_TRUE(radioRsp_sim->carrierRestrictionsResp.allowedCarriersPrioritized); + EXPECT_EQ(SimLockMultiSimPolicy::NO_MULTISIM_POLICY, radioRsp_sim->multiSimPolicyResp); + } sleep(10); /** @@ -522,9 +572,15 @@ TEST_P(RadioSimTest, setAllowedCarriers) { * status for cardStatus. */ memset(&carrierRestrictions, 0, sizeof(carrierRestrictions)); - carrierRestrictions.allowedCarriers.resize(0); - carrierRestrictions.excludedCarriers.resize(0); - carrierRestrictions.allowedCarriersPrioritized = false; + if (aidl_version <= 2) { + carrierRestrictions.allowedCarriers.resize(0); + carrierRestrictions.excludedCarriers.resize(0); + carrierRestrictions.allowedCarriersPrioritized = false; + } else { + carrierRestrictions.allowedCarrierInfoList.resize(0); + carrierRestrictions.excludedCarrierInfoList.resize(0); + carrierRestrictions.allowedCarriersPrioritized = false; + } serial = GetRandomSerialNumber(); radio_sim->setAllowedCarriers(serial, carrierRestrictions, multisimPolicy);