diff --git a/services/include/cellular_data_handler.h b/services/include/cellular_data_handler.h index b5392b1cbd4586c710e63e442fba148ec30b4185..1d912f47b000e1a9b08a50692a265f6464aa0506 100644 --- a/services/include/cellular_data_handler.h +++ b/services/include/cellular_data_handler.h @@ -98,9 +98,9 @@ private: void HandleVoiceCallChanged(int32_t state); void HandleDefaultDataSubscriptionChanged(); void HandleSimStateChanged(); + void HandleSimRecordsLoaded(int32_t slotId); void HandleDsdsModeChanged(const AppExecFwk::InnerEvent::Pointer &event); void HandleSimStateOrRecordsChanged(const AppExecFwk::InnerEvent::Pointer &event); - void HandleSimAccountLoaded(const AppExecFwk::InnerEvent::Pointer &event); void HandleRadioStateChanged(const AppExecFwk::InnerEvent::Pointer &event); void PsDataRatChanged(const AppExecFwk::InnerEvent::Pointer &event); void SetRilAttachApnResponse(const AppExecFwk::InnerEvent::Pointer &event); @@ -166,7 +166,7 @@ private: bool physicalConnectionActiveState_ = false; bool multipleConnectionsEnabled_ = false; bool defaultDataRoamingEnable_ = false; - bool isSimAccountLoaded_ = false; + bool isSimLoaded_ = false; std::vector upLinkThresholds_; std::vector downLinkThresholds_; sptr settingObserver_; @@ -207,8 +207,6 @@ private: [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimStateOrRecordsChanged(event); } }, { RadioEvent::RADIO_SIM_RECORDS_LOADED, [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimStateOrRecordsChanged(event); } }, - { RadioEvent::RADIO_SIM_ACCOUNT_LOADED, - [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimAccountLoaded(event); } }, { RadioEvent::RADIO_PS_RAT_CHANGED, [this](const AppExecFwk::InnerEvent::Pointer &event) { PsDataRatChanged(event); } }, { CellularDataEventCode::MSG_APN_CHANGED, diff --git a/services/include/common/cellular_data_constant.h b/services/include/common/cellular_data_constant.h index edc31fe904ecd4d8daef2808382532495fb781ae..0464cf229f33c0d81d53177545d81c8f3064cc0b 100644 --- a/services/include/common/cellular_data_constant.h +++ b/services/include/common/cellular_data_constant.h @@ -57,7 +57,6 @@ struct NetSupplier { uint32_t supplierId = 0; uint64_t capability = 0; int32_t slotId = 0; - int32_t simId = 0; }; enum RegisterType { UNKOWN, @@ -188,7 +187,7 @@ static constexpr const char *DATA_METERED_CONTEXT_ROLES = "default"; static constexpr const char *IS_CELLULAR_DATA_ENABLE = "isCellularDataEnable"; static constexpr const char *IS_ROAMING = "isRoaming"; static constexpr const char *SETTING_SWITCH = "settingSwitch"; -static constexpr const char *IDENT_PREFIX = "simId"; +static constexpr const char *IDENT_PREFIX = "slotId"; static constexpr const char *DEFAULT_HOSTNAME = ""; static constexpr const char *DEFAULT_MASK = ""; static constexpr const char *CELLULAR_DATA_RDB_URI = "datashare:///com.ohos.pdpprofileability"; diff --git a/services/src/cellular_data_controller.cpp b/services/src/cellular_data_controller.cpp index 9906ef6754099b4dc41020683e4e03fffd5f7d79..0bb10c5e89b25da3bfa26d9bfa33e737dc69aa1e 100644 --- a/services/src/cellular_data_controller.cpp +++ b/services/src/cellular_data_controller.cpp @@ -208,7 +208,6 @@ void CellularDataController::RegisterEvents() CoreManagerInner &coreInner = CoreManagerInner::GetInstance(); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_RECORDS_LOADED, nullptr); - coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_ACCOUNT_LOADED, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_ATTACHED, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_DETACHED, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_OPEN, nullptr); @@ -244,7 +243,6 @@ void CellularDataController::UnRegisterEvents() CoreManagerInner &coreInner = CoreManagerInner::GetInstance(); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_STATE_CHANGE); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_RECORDS_LOADED); - coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_SIM_ACCOUNT_LOADED); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_ATTACHED); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_CONNECTION_DETACHED); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_PS_ROAMING_OPEN); diff --git a/services/src/cellular_data_handler.cpp b/services/src/cellular_data_handler.cpp index dbec11893d947fd83d46afec8e95de254a260f2b..67e04b64038ea0d93b18b3e034c691aea4b07320 100644 --- a/services/src/cellular_data_handler.cpp +++ b/services/src/cellular_data_handler.cpp @@ -524,8 +524,8 @@ bool CellularDataHandler::CheckAttachAndSimState(sptr &apnHolder) bool attached = coreInner.GetPsRegState(slotId_) == (int32_t)RegServiceState::REG_STATE_IN_SERVICE; SimState simState = SimState::SIM_STATE_UNKNOWN; coreInner.GetSimState(slotId_, simState); - TELEPHONY_LOGD("Slot%{public}d: attached: %{public}d simState: %{public}d isSimAccountLoaded: %{public}d", - slotId_, attached, simState, isSimAccountLoaded_); + TELEPHONY_LOGD("Slot%{public}d: attached: %{public}d simState: %{public}d isSimLoaded: %{public}d", + slotId_, attached, simState, isSimLoaded_); bool isMmsApn = apnHolder->IsMmsType(); if (isMmsApn && (simState == SimState::SIM_STATE_READY)) { if (SetDataPermittedForMms(true) && !attached) { @@ -543,7 +543,7 @@ bool CellularDataHandler::CheckAttachAndSimState(sptr &apnHolder) CellularDataErrorCode::DATA_ERROR_SIM_NOT_READY, "It is not emergencyApn and sim not ready"); return false; } - return isEmergencyApn || isSimAccountLoaded_; + return isEmergencyApn || isSimLoaded_; } bool CellularDataHandler::CheckRoamingState(sptr &apnHolder) @@ -1183,7 +1183,7 @@ void CellularDataHandler::HandleSimStateChanged() CoreManagerInner::GetInstance().GetSimState(slotId_, simState); TELEPHONY_LOGI("Slot%{public}d: sim state is :%{public}d", slotId_, simState); if (simState != SimState::SIM_STATE_READY) { - isSimAccountLoaded_ = false; + isSimLoaded_ = false; ClearAllConnections(DisConnectionReason::REASON_CLEAR_CONNECTION); if (simState == SimState::SIM_STATE_NOT_PRESENT) { CellularDataNetAgent::GetInstance().UnregisterNetSupplierForSimUpdate(slotId_); @@ -1213,25 +1213,8 @@ void CellularDataHandler::HandleSimStateOrRecordsChanged(const AppExecFwk::Inner break; } case RadioEvent::RADIO_SIM_RECORDS_LOADED: { - std::u16string iccId; - CoreManagerInner::GetInstance().GetSimIccId(slotId_, iccId); - SimState simState = SimState::SIM_STATE_UNKNOWN; - CoreManagerInner::GetInstance().GetSimState(slotId_, simState); - TELEPHONY_LOGI("Slot%{public}d: sim records loaded state is :%{public}d", slotId_, simState); - if (simState != SimState::SIM_STATE_READY || iccId == u"") { - TELEPHONY_LOGI("sim state error or iccId nullptr"); - break; - } - if (iccId != lastIccId_) { - if (dataSwitchSettings_ != nullptr) { - dataSwitchSettings_->SetPolicyDataOn(true); - } - lastIccId_ = iccId; - } else if (lastIccId_ == iccId) { - TELEPHONY_LOGI("Slot%{public}d: sim state changed, but iccId not changed.", slotId_); - // the sim card status has changed to ready, so try to connect - EstablishAllApnsIfConnectable(); - } + auto slotId = event->GetParam(); + HandleSimRecordsLoaded(slotId); break; } default: @@ -1239,16 +1222,25 @@ void CellularDataHandler::HandleSimStateOrRecordsChanged(const AppExecFwk::Inner } } -void CellularDataHandler::HandleSimAccountLoaded(const InnerEvent::Pointer &event) +void CellularDataHandler::HandleSimRecordsLoaded(int32_t slotId) { - if (event == nullptr) { - TELEPHONY_LOGE("Slot%{public}d: event is null", slotId_); + TELEPHONY_LOGI("SlotId_ %{public}d, current Slot%{public}d", slotId_, slotId); + std::u16string iccId; + CoreManagerInner::GetInstance().GetSimIccId(slotId_, iccId); + SimState simState = SimState::SIM_STATE_UNKNOWN; + CoreManagerInner::GetInstance().GetSimState(slotId_, simState); + if (simState != SimState::SIM_STATE_READY || iccId == u"") { + TELEPHONY_LOGI("sim state error or iccId nullptr"); return; } - TELEPHONY_LOGI("Slot%{public}d", slotId_); - auto slotId = event->GetParam(); + if (iccId != lastIccId_) { + if (dataSwitchSettings_ != nullptr) { + dataSwitchSettings_->SetPolicyDataOn(true); + } + lastIccId_ = iccId; + } if (slotId == slotId_) { - isSimAccountLoaded_ = true; + isSimLoaded_ = true; ReleaseAllNetworkRequest(); ClearAllConnections(DisConnectionReason::REASON_CHANGE_CONNECTION); CellularDataNetAgent::GetInstance().UnregisterNetSupplierForSimUpdate(slotId_); diff --git a/services/src/cellular_data_service.cpp b/services/src/cellular_data_service.cpp index 3a00663b4f2ec9f79c91893d1abb5a5d83fff34c..b006bddca1f1ae79486f1ca6fbc98c780dbbc2a9 100644 --- a/services/src/cellular_data_service.cpp +++ b/services/src/cellular_data_service.cpp @@ -305,7 +305,6 @@ void CellularDataService::AddNetSupplier(int32_t slotId, CellularDataNetAgent &n NetSupplier netSupplier = { 0 }; netSupplier.supplierId = 0; netSupplier.slotId = slotId; - netSupplier.simId = INVALID_SIM_ID; netSupplier.capability = capability; netAgent.AddNetSupplier(netSupplier); } @@ -345,8 +344,7 @@ int32_t CellularDataService::ReleaseNet(const NetRequest &request) if (!IsValidDecValue(requestIdent)) { return CELLULAR_DATA_INVALID_PARAM; } - int32_t simId = std::stoi(requestIdent); - int32_t slotId = CoreManagerInner::GetInstance().GetSlotId(simId); + int32_t slotId = std::stoi(requestIdent); if (!CheckParamValid(slotId)) { return CELLULAR_DATA_INVALID_PARAM; } @@ -360,12 +358,12 @@ int32_t CellularDataService::RequestNet(const NetRequest &request) if (!IsValidDecValue(requestIdent)) { return CELLULAR_DATA_INVALID_PARAM; } - int32_t simId = std::stoi(requestIdent); + int32_t slotId = std::stoi(requestIdent); + int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId); if (TELEPHONY_EXT_WRAPPER.isCardAllowData_ && !TELEPHONY_EXT_WRAPPER.isCardAllowData_(simId, request.capability)) { return static_cast(RequestNetCode::REQUEST_FAILED); } - int32_t slotId = CoreManagerInner::GetInstance().GetSlotId(simId); if (!CheckParamValid(slotId)) { return CELLULAR_DATA_INVALID_PARAM; } diff --git a/services/src/traffic_management.cpp b/services/src/traffic_management.cpp index d21215a1c5cb3936bf460be132df1f787c7a4835..27de0ab8dfcfe1625f9fdf85b5acb9956d30aa5b 100644 --- a/services/src/traffic_management.cpp +++ b/services/src/traffic_management.cpp @@ -47,9 +47,8 @@ void TrafficManagement::UpdatePacketData() std::string TrafficManagement::GetIfaceName() { std::string ifaceName = ""; - int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId_); std::list netIdList; - int32_t ret = NetConnClient::GetInstance().GetNetIdByIdentifier(IDENT_PREFIX + std::to_string(simId), netIdList); + int32_t ret = NetConnClient::GetInstance().GetNetIdByIdentifier(IDENT_PREFIX + std::to_string(slotId_), netIdList); if (ret != NETMANAGER_SUCCESS) { TELEPHONY_LOGE("Slot%{public}d: get netIdList by identifier failed, ret = %{public}d", slotId_, ret); return ifaceName; diff --git a/services/src/utils/cellular_data_net_agent.cpp b/services/src/utils/cellular_data_net_agent.cpp index b16cfe09eb1c4db0e1af6a1cbfe0b26e42c8ba85..36cec92b2879686fe7dcf8bddc0298cb04accddc 100644 --- a/services/src/utils/cellular_data_net_agent.cpp +++ b/services/src/utils/cellular_data_net_agent.cpp @@ -50,21 +50,16 @@ bool CellularDataNetAgent::RegisterNetSupplier(const int32_t slotId) TELEPHONY_LOGE("capabilities(%{public}" PRIu64 ") not support", netSupplier.capability); continue; } - int32_t simId = CoreManagerInner::GetInstance().GetSimId(netSupplier.slotId); - if (simId <= INVALID_SIM_ID) { - TELEPHONY_LOGE("Slot%{public}d Invalid simId: %{public}d", slotId, simId); - continue; - } std::set netCap { static_cast(netSupplier.capability) }; uint32_t supplierId = 0; int32_t result = netManager.RegisterNetSupplier( - NetBearType::BEARER_CELLULAR, std::string(IDENT_PREFIX) + std::to_string(simId), netCap, supplierId); + NetBearType::BEARER_CELLULAR, std::string(IDENT_PREFIX) + std::to_string(netSupplier.slotId), + netCap, supplierId); TELEPHONY_LOGI( "Slot%{public}d Register network supplierId: %{public}d,result:%{public}d", slotId, supplierId, result); if (result == NETMANAGER_SUCCESS) { flag = true; netSupplier.supplierId = supplierId; - netSupplier.simId = simId; int32_t regCallback = netManager.RegisterNetSupplierCallback(netSupplier.supplierId, callBack_); TELEPHONY_LOGI("Register supplier callback(%{public}d)", regCallback); sptr netSupplierInfo = new (std::nothrow) NetSupplierInfo(); @@ -85,13 +80,8 @@ bool CellularDataNetAgent::RegisterNetSupplier(const int32_t slotId) void CellularDataNetAgent::UnregisterNetSupplier(const int32_t slotId) { - int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId); - if (simId <= INVALID_SIM_ID) { - TELEPHONY_LOGE("Slot%{public}d Invalid simId: %{public}d", slotId, simId); - return; - } for (const NetSupplier &netSupplier : netSuppliers_) { - if (netSupplier.simId != simId) { + if (netSupplier.slotId != slotId) { continue; } auto& netManager = NetConnClient::GetInstance(); @@ -103,15 +93,12 @@ void CellularDataNetAgent::UnregisterNetSupplier(const int32_t slotId) void CellularDataNetAgent::UnregisterNetSupplierForSimUpdate(const int32_t slotId) { for (NetSupplier &netSupplier : netSuppliers_) { - if (netSupplier.slotId != slotId || netSupplier.simId <= INVALID_SIM_ID) { + if (netSupplier.slotId != slotId) { continue; } auto& netManager = NetConnClient::GetInstance(); int32_t result = netManager.UnregisterNetSupplier(netSupplier.supplierId); TELEPHONY_LOGI("Slot%{public}d unregister network result:%{public}d", slotId, result); - if (result == NETMANAGER_SUCCESS) { - netSupplier.simId = INVALID_SIM_ID; - } } } diff --git a/test/zero_branch_test.cpp b/test/zero_branch_test.cpp index ece24917eaafe90e644508f15ceb9abb9eae5694..3463ea10021fe8fb53c063a17ca47933596d11b0 100644 --- a/test/zero_branch_test.cpp +++ b/test/zero_branch_test.cpp @@ -152,7 +152,7 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_001, Function | MediumTest | matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); CellularDataHandler cellularDataHandler { subscriberInfo, 0 }; - NetRequest request { 0, "simId1" }; + NetRequest request { 0, "slotId1" }; cellularDataHandler.HandleSimStateChanged(); cellularDataHandler.ReleaseAllNetworkRequest(); cellularDataHandler.CreateApnItem(); @@ -226,7 +226,6 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_002, Function | MediumTest | cellularDataHandler.HandleImsCallChanged(0); cellularDataHandler.HandleVoiceCallChanged(0); cellularDataHandler.HandleSimStateOrRecordsChanged(event); - cellularDataHandler.HandleSimAccountLoaded(event); cellularDataHandler.HandleRadioStateChanged(event); cellularDataHandler.HandleDsdsModeChanged(event); cellularDataHandler.SetRilAttachApnResponse(event); @@ -310,7 +309,7 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_004, Function | MediumTest | CellularDataController controller { 0 }; controller.Init(); ASSERT_FALSE(controller.cellularDataHandler_ == nullptr); - NetRequest request { 0, "simId1" }; + NetRequest request { 0, "slotId1" }; controller.cellularDataHandler_->ReleaseNet(request); controller.cellularDataHandler_->RequestNet(request); auto event = AppExecFwk::InnerEvent::Get(0); @@ -380,7 +379,6 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_005, Function | MediumTest | controller.cellularDataHandler_->HandleImsCallChanged(0); controller.cellularDataHandler_->HandleVoiceCallChanged(0); controller.cellularDataHandler_->HandleSimStateOrRecordsChanged(event); - controller.cellularDataHandler_->HandleSimAccountLoaded(event); controller.cellularDataHandler_->HandleRadioStateChanged(event); controller.cellularDataHandler_->HandleDsdsModeChanged(event); controller.cellularDataHandler_->SetRilAttachApnResponse(event); @@ -513,9 +511,9 @@ HWTEST_F(BranchTest, Telephony_CellularDataService_001, Function | MediumTest | ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.StrategySwitch(INVALID_SLOTID, false)); ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.StrategySwitch(DEFAULT_SIM_SLOT_ID, false)); NetRequest request; - request.ident = "simId12"; + request.ident = "slotId12"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.RequestNet(request)); - request.ident = "simId2"; + request.ident = "slotId2"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ReleaseNet(request)); ASSERT_TRUE(service.CheckParamValid(DEFAULT_SIM_SLOT_ID)); ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID)); @@ -555,9 +553,9 @@ HWTEST_F(BranchTest, Telephony_CellularDataService_002, Function | MediumTest | ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ChangeConnectionForDsds(INVALID_SLOTID, false)); ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.StrategySwitch(INVALID_SLOTID, false)); NetRequest request; - request.ident = "simId12"; + request.ident = "slotId12"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.RequestNet(request)); - request.ident = "simId2"; + request.ident = "slotId2"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ReleaseNet(request)); ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID)); ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID_TWO)); @@ -614,9 +612,9 @@ HWTEST_F(BranchTest, Telephony_CellularDataService_003, Function | MediumTest | ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ChangeConnectionForDsds(DEFAULT_SIM_SLOT_ID, false)); ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ChangeConnectionForDsds(DEFAULT_SIM_SLOT_ID, true)); NetRequest request; - request.ident = "simId12"; + request.ident = "slotId12"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.RequestNet(request)); - request.ident = "simId2"; + request.ident = "slotId2"; ASSERT_NE(TELEPHONY_ERR_SUCCESS, service.ReleaseNet(request)); ASSERT_FALSE(service.CheckParamValid(DEFAULT_SIM_SLOT_ID)); ASSERT_FALSE(service.CheckParamValid(INVALID_SLOTID));