From 821d1b7100144762c64fa7eca196aa130abed5aa Mon Sep 17 00:00:00 2001 From: l00635678 Date: Wed, 14 Aug 2024 20:27:59 +0800 Subject: [PATCH] =?UTF-8?q?PLR=E5=86=85=E7=BD=91=E5=8D=A1ril-crash?= =?UTF-8?q?=E4=B9=8B=E5=90=8E=E6=95=B0=E6=8D=AE=E4=B8=9A=E5=8A=A1=E6=9C=AA?= =?UTF-8?q?=E6=BF=80=E6=B4=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: l00635678 --- services/include/apn_manager/apn_manager.h | 1 - services/include/cellular_data_handler.h | 22 +- services/src/apn_manager/apn_manager.cpp | 42 ---- services/src/cellular_data_controller.cpp | 3 + services/src/cellular_data_handler.cpp | 236 ++++++++++++--------- test/cellular_data_handler_test.cpp | 142 +++++++++++++ test/cellular_data_service_test.cpp | 1 - test/zero_branch_test.cpp | 10 +- 8 files changed, 294 insertions(+), 163 deletions(-) diff --git a/services/include/apn_manager/apn_manager.h b/services/include/apn_manager/apn_manager.h index c0c4e23f..5cbde7fa 100644 --- a/services/include/apn_manager/apn_manager.h +++ b/services/include/apn_manager/apn_manager.h @@ -34,7 +34,6 @@ public: sptr GetApnHolder(const std::string &apnType) const; std::vector> GetAllApnHolder() const; std::vector> GetSortApnHolder() const; - void CreateAllApnItem(); std::vector> FilterMatchedApns(const std::string &requestApnType, const int32_t slotId); void InitApnHolders(); sptr FindApnHolderById(const int32_t id) const; diff --git a/services/include/cellular_data_handler.h b/services/include/cellular_data_handler.h index 73769722..fc7104b2 100644 --- a/services/include/cellular_data_handler.h +++ b/services/include/cellular_data_handler.h @@ -36,6 +36,7 @@ #include "tel_event_handler.h" #include "tel_profile_util.h" #include "tel_ril_data_parcel.h" +#include "telephony_types.h" namespace OHOS { namespace Telephony { class CellularDataHandler : public TelEventHandler, public EventFwk::CommonEventSubscriber { @@ -57,6 +58,7 @@ public: void ClearConnection(const sptr &apnHolder, DisConnectionReason reason); void EstablishAllApnsIfConnectable(); void ClearAllConnections(DisConnectionReason reason); + void ClearConnectionsOnUpdateApns(const DataProfile &dataProfile, DisConnectionReason reason); bool ChangeConnectionForDsds(bool enable); int32_t GetSlotId() const; bool HandleApnChanged(); @@ -69,7 +71,7 @@ public: void GetDataConnApnAttr(ApnItem::Attribute &apnAttr) const; std::string GetDataConnIpType() const; int32_t GetDataRecoveryState(); - void SetRilAttachApn(); + void SetRilAttachApn(DataProfile &dataProfile); void IsNeedDoRecovery(bool needDoRecovery) const; void RegisterDataSettingObserver(); void UnRegisterDataSettingObserver(); @@ -99,9 +101,11 @@ private: void HandleVoiceCallChanged(int32_t state); void HandleDefaultDataSubscriptionChanged(); void HandleSimStateChanged(); + void HandleRecordsChanged(); + void HandleRadioNvRefreshFinished(); void HandleDsdsModeChanged(const AppExecFwk::InnerEvent::Pointer &event); - void HandleSimStateOrRecordsChanged(const AppExecFwk::InnerEvent::Pointer &event); - void HandleSimAccountLoaded(const AppExecFwk::InnerEvent::Pointer &event); + void HandleSimEvent(const AppExecFwk::InnerEvent::Pointer &event); + void HandleSimAccountLoaded(); void HandleRadioStateChanged(const AppExecFwk::InnerEvent::Pointer &event); void PsDataRatChanged(const AppExecFwk::InnerEvent::Pointer &event); void SetRilAttachApnResponse(const AppExecFwk::InnerEvent::Pointer &event); @@ -131,7 +135,6 @@ private: void ClearConnectionIfRequired(); void ReleaseAllNetworkRequest(); bool GetEsmFlagFromOpCfg(); - void SetInitApnWithNullDp(); void GetSinglePdpEnabledFromOpCfg(); bool IsSingleConnectionEnabled(int32_t radioTech); void OnRilAdapterHostDied(const AppExecFwk::InnerEvent::Pointer &event); @@ -149,6 +152,7 @@ private: #endif void SetNetRequest(NetRequest &request, const std::unique_ptr &netRequest); void SendEstablishDataConnectionEvent(int32_t id); + bool IsSimStateReadyOrLoaded(); private: sptr apnManager_; @@ -171,6 +175,7 @@ private: bool multipleConnectionsEnabled_ = false; bool defaultDataRoamingEnable_ = false; bool isSimAccountLoaded_ = false; + bool isRilApnAttached_ = false; std::vector upLinkThresholds_; std::vector downLinkThresholds_; sptr settingObserver_; @@ -178,6 +183,7 @@ private: sptr incallObserver_; sptr cellularDataRdbObserver_; std::shared_ptr incallDataStateMachine_; + DataProfile lastDataProfile_; using Fun = std::function; std::map eventIdMap_ { @@ -208,11 +214,11 @@ private: { RadioEvent::RADIO_DSDS_MODE_CHANGED, [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleDsdsModeChanged(event); } }, { RadioEvent::RADIO_SIM_STATE_CHANGE, - [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimStateOrRecordsChanged(event); } }, + [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimEvent(event); } }, { RadioEvent::RADIO_SIM_RECORDS_LOADED, - [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimStateOrRecordsChanged(event); } }, + [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimEvent(event); } }, { RadioEvent::RADIO_SIM_ACCOUNT_LOADED, - [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimAccountLoaded(event); } }, + [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimEvent(event); } }, { RadioEvent::RADIO_PS_RAT_CHANGED, [this](const AppExecFwk::InnerEvent::Pointer &event) { PsDataRatChanged(event); } }, { CellularDataEventCode::MSG_APN_CHANGED, @@ -239,6 +245,8 @@ private: [this](const AppExecFwk::InnerEvent::Pointer &event) { OnCleanAllDataConnectionsDone(event); } }, { CellularDataEventCode::MSG_DATA_CALL_LIST_CHANGED, [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleUpdateNetInfo(event); } }, + { RadioEvent::RADIO_NV_REFRESH_FINISHED, + [this](const AppExecFwk::InnerEvent::Pointer &event) { HandleSimEvent(event); } }, }; }; } // namespace Telephony diff --git a/services/src/apn_manager/apn_manager.cpp b/services/src/apn_manager/apn_manager.cpp index 3186f87d..212c6d3c 100644 --- a/services/src/apn_manager/apn_manager.cpp +++ b/services/src/apn_manager/apn_manager.cpp @@ -227,48 +227,6 @@ std::vector> ApnManager::GetSortApnHolder() const return sortedApnHolders_; } -void ApnManager::CreateAllApnItem() -{ - std::lock_guard lock(mutex_); - allApnItem_.clear(); - sptr defaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DEFAULT); - if (defaultApnItem != nullptr) { - allApnItem_.push_back(defaultApnItem); - } - sptr mmsApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_MMS); - if (mmsApnItem != nullptr) { - allApnItem_.push_back(mmsApnItem); - } - sptr suplApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_SUPL); - if (suplApnItem != nullptr) { - allApnItem_.push_back(suplApnItem); - } - sptr dunApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_DUN); - if (dunApnItem != nullptr) { - allApnItem_.push_back(dunApnItem); - } - sptr imsApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_IMS); - if (imsApnItem != nullptr) { - allApnItem_.push_back(imsApnItem); - } - sptr iaApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_IA); - if (iaApnItem != nullptr) { - allApnItem_.push_back(iaApnItem); - } - sptr emergencyApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_EMERGENCY); - if (emergencyApnItem != nullptr) { - allApnItem_.push_back(emergencyApnItem); - } - auto internalDefaultApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_INTERNAL_DEFAULT); - if (internalDefaultApnItem != nullptr) { - allApnItem_.push_back(internalDefaultApnItem); - } - auto xcapApnItem = ApnItem::MakeDefaultApn(DATA_CONTEXT_ROLE_XCAP); - if (xcapApnItem != nullptr) { - allApnItem_.push_back(xcapApnItem); - } -} - int32_t ApnManager::CreateAllApnItemByDatabase(int32_t slotId) { int32_t count = 0; diff --git a/services/src/cellular_data_controller.cpp b/services/src/cellular_data_controller.cpp index 1a268d37..985d6f4e 100644 --- a/services/src/cellular_data_controller.cpp +++ b/services/src/cellular_data_controller.cpp @@ -224,6 +224,8 @@ void CellularDataController::RegisterEvents() coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_FREQUENCY_CHANGED, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED, nullptr); coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_FACTORY_RESET, nullptr); + coreInner.RegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NV_REFRESH_FINISHED, nullptr); + if (slotId_ == 0) { sptr networkSearchCallback = std::make_unique().release(); if (networkSearchCallback != nullptr) { @@ -260,6 +262,7 @@ void CellularDataController::UnRegisterEvents() coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NR_FREQUENCY_CHANGED); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_RIL_ADAPTER_HOST_DIED); coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_FACTORY_RESET); + coreInner.UnRegisterCoreNotify(slotId_, cellularDataHandler_, RadioEvent::RADIO_NV_REFRESH_FINISHED); TELEPHONY_LOGI("Slot%{public}d: end", slotId_); } diff --git a/services/src/cellular_data_handler.cpp b/services/src/cellular_data_handler.cpp index 0e3a4c08..3fa92418 100644 --- a/services/src/cellular_data_handler.cpp +++ b/services/src/cellular_data_handler.cpp @@ -33,7 +33,6 @@ #include "str_convert.h" #include "string_ex.h" #include "telephony_log_wrapper.h" -#include "telephony_types.h" #include "telephony_ext_wrapper.h" #include "telephony_permission.h" #include "ipc_skeleton.h" @@ -67,7 +66,6 @@ void CellularDataHandler::Init() } connectionManager_->Init(); apnManager_->InitApnHolders(); - apnManager_->CreateAllApnItem(); dataSwitchSettings_->LoadSwitchValue(); GetConfigurationFor5G(); SetRilLinkBandwidths(); @@ -257,6 +255,21 @@ void CellularDataHandler::ClearAllConnections(DisConnectionReason reason) ResetDataFlowType(); } +void CellularDataHandler::ClearConnectionsOnUpdateApns(const DataProfile &dataProfile, DisConnectionReason reason) +{ + bool isDataProfileSame = (dataProfile.profileId == lastDataProfile_.profileId + && dataProfile.apn == lastDataProfile_.apn + && dataProfile.protocol == lastDataProfile_.protocol + && dataProfile.verType == lastDataProfile_.verType + && dataProfile.userName == lastDataProfile_.userName + && dataProfile.password == lastDataProfile_.password + && dataProfile.roamingProtocol == lastDataProfile_.roamingProtocol); + if (!isDataProfileSame) { + ClearAllConnections(reason); + lastDataProfile_ = dataProfile; + } +} + void CellularDataHandler::ResetDataFlowType() { if (dataSwitchSettings_ == nullptr) { @@ -514,12 +527,12 @@ bool CellularDataHandler::CheckAttachAndSimState(sptr &apnHolder) } CoreManagerInner &coreInner = CoreManagerInner::GetInstance(); 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_); + bool isSimStateReadyOrLoaded = IsSimStateReadyOrLoaded(); + TELEPHONY_LOGD("Slot%{public}d: attached: %{public}d simState: %{public}d isSimAccountLoaded: %{public}d " + "isRilApnAttached: %{public}d", slotId_, attached, isSimStateReadyOrLoaded, isSimAccountLoaded_, + isRilApnAttached_); bool isMmsApn = apnHolder->IsMmsType(); - if (isMmsApn && (simState == SimState::SIM_STATE_READY)) { + if (isMmsApn && isSimStateReadyOrLoaded) { if (!attached) { return false; } @@ -530,7 +543,7 @@ bool CellularDataHandler::CheckAttachAndSimState(sptr &apnHolder) CellularDataErrorCode::DATA_ERROR_PS_NOT_ATTACH, "It is not emergencyApn and not attached"); return false; } - if (!isEmergencyApn && (simState != SimState::SIM_STATE_READY)) { + if (!isEmergencyApn && !isSimStateReadyOrLoaded) { CellularDataHiSysEvent::WriteDataActivateFaultEvent(slotId_, SWITCH_ON, CellularDataErrorCode::DATA_ERROR_SIM_NOT_READY, "It is not emergencyApn and sim not ready"); return false; @@ -1049,6 +1062,14 @@ void CellularDataHandler::HandleScreenStateChanged(bool isScreenOn) const connectionManager_->HandleScreenStateChanged(isScreenOn); } +bool CellularDataHandler::IsSimStateReadyOrLoaded() +{ + SimState simState = SimState::SIM_STATE_UNKNOWN; + CoreManagerInner &coreInner = CoreManagerInner::GetInstance(); + coreInner.GetSimState(slotId_, simState); + return (simState == SimState::SIM_STATE_READY || simState == SimState::SIM_STATE_LOADED); +} + void CellularDataHandler::HandleSettingSwitchChanged(const InnerEvent::Pointer &event) { if (event == nullptr) { @@ -1213,93 +1234,111 @@ void CellularDataHandler::HandleSimStateChanged() SimState simState = SimState::SIM_STATE_UNKNOWN; CoreManagerInner::GetInstance().GetSimState(slotId_, simState); TELEPHONY_LOGI("Slot%{public}d: sim state is :%{public}d", slotId_, simState); - if (simState != SimState::SIM_STATE_READY) { + if (simState == SimState::SIM_STATE_READY) { + std::u16string iccId; + CoreManagerInner::GetInstance().GetSimIccId(slotId_, iccId); + if (lastIccId_ != u"" && lastIccId_ == iccId) { + EstablishAllApnsIfConnectable(); + } + } else if (simState != SimState::SIM_STATE_LOADED) { isSimAccountLoaded_ = false; + isRilApnAttached_ = false; ClearAllConnections(DisConnectionReason::REASON_CLEAR_CONNECTION); if (simState == SimState::SIM_STATE_NOT_PRESENT) { CellularDataNetAgent::GetInstance().UnregisterNetSupplierForSimUpdate(slotId_); ReleaseAllNetworkRequest(); UnRegisterDataSettingObserver(); } - } else { - std::u16string iccId; - CoreManagerInner::GetInstance().GetSimIccId(slotId_, iccId); - if (lastIccId_ != u"" && lastIccId_ == iccId) { - EstablishAllApnsIfConnectable(); + } +} + +void CellularDataHandler::HandleRecordsChanged() +{ + std::u16string iccId; + CoreManagerInner::GetInstance().GetSimIccId(slotId_, iccId); + if (iccId == u"") { + TELEPHONY_LOGI("iccId nullptr"); + return; + } + if (iccId != lastIccId_) { + if (dataSwitchSettings_ != nullptr) { + dataSwitchSettings_->SetPolicyDataOn(true); } + lastIccId_ = iccId; + } + GetConfigurationFor5G(); + CreateApnItem(); + DataProfile dataProfile; + SetRilAttachApn(dataProfile); + ClearConnectionsOnUpdateApns(dataProfile, DisConnectionReason::REASON_CHANGE_CONNECTION); + EstablishAllApnsIfConnectable(); +} + +void CellularDataHandler::HandleRadioNvRefreshFinished() +{ + if (isRilApnAttached_) { + TELEPHONY_LOGI("Apn is alread attached"); + return; } + GetConfigurationFor5G(); + CreateApnItem(); + DataProfile dataProfile; + SetRilAttachApn(dataProfile); + ClearConnectionsOnUpdateApns(dataProfile, DisConnectionReason::REASON_CHANGE_CONNECTION); + EstablishAllApnsIfConnectable(); } -void CellularDataHandler::HandleSimStateOrRecordsChanged(const AppExecFwk::InnerEvent::Pointer &event) +void CellularDataHandler::HandleSimEvent(const AppExecFwk::InnerEvent::Pointer &event) { if (event == nullptr) { return; } + auto slotId = event->GetParam(); + if (slotId != slotId_) { + return; + } if (dataSwitchSettings_ != nullptr) { dataSwitchSettings_->LoadSwitchValue(); } - switch (event->GetInnerEventId()) { - case RadioEvent::RADIO_SIM_STATE_CHANGE: { + auto eventId = event->GetInnerEventId(); + TELEPHONY_LOGI("Slot%{public}d, event:%{public}d", slotId_, eventId); + switch (eventId) { + case RadioEvent::RADIO_SIM_STATE_CHANGE: HandleSimStateChanged(); 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); - 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(); - } + case RadioEvent::RADIO_SIM_RECORDS_LOADED: + HandleRecordsChanged(); + break; + case RadioEvent::RADIO_NV_REFRESH_FINISHED: + HandleRadioNvRefreshFinished(); + break; + case RadioEvent::RADIO_SIM_ACCOUNT_LOADED: + HandleSimAccountLoaded(); break; - } default: break; } } -void CellularDataHandler::HandleSimAccountLoaded(const InnerEvent::Pointer &event) +void CellularDataHandler::HandleSimAccountLoaded() { - if (event == nullptr) { - TELEPHONY_LOGE("Slot%{public}d: event is null", slotId_); - return; - } - TELEPHONY_LOGI("Slot%{public}d", slotId_); if (isSimAccountLoaded_) { TELEPHONY_LOGE("Slot%{public}d has already loaded", slotId_); return; } - auto slotId = event->GetParam(); - if (slotId == slotId_) { - isSimAccountLoaded_ = true; - ReleaseAllNetworkRequest(); - ClearAllConnections(DisConnectionReason::REASON_CHANGE_CONNECTION); - CellularDataNetAgent::GetInstance().UnregisterNetSupplierForSimUpdate(slotId_); - if (!CellularDataNetAgent::GetInstance().RegisterNetSupplier(slotId_)) { - TELEPHONY_LOGE("Slot%{public}d register supplierid fail", slotId_); - isSimAccountLoaded_ = false; - } - if (slotId_ == 0) { - CellularDataNetAgent::GetInstance().UnregisterPolicyCallback(); - CellularDataNetAgent::GetInstance().RegisterPolicyCallback(); - } - RegisterDataSettingObserver(); - if (dataSwitchSettings_ != nullptr) { - dataSwitchSettings_->LoadSwitchValue(); - } - GetConfigurationFor5G(); - CreateApnItem(); + isSimAccountLoaded_ = true; + CellularDataNetAgent::GetInstance().UnregisterNetSupplierForSimUpdate(slotId_); + if (!CellularDataNetAgent::GetInstance().RegisterNetSupplier(slotId_)) { + TELEPHONY_LOGE("Slot%{public}d register supplierid fail", slotId_); + isSimAccountLoaded_ = false; + } + if (slotId_ == 0) { + CellularDataNetAgent::GetInstance().UnregisterPolicyCallback(); + CellularDataNetAgent::GetInstance().RegisterPolicyCallback(); + } + RegisterDataSettingObserver(); + if (dataSwitchSettings_ != nullptr) { + dataSwitchSettings_->LoadSwitchValue(); } CoreManagerInner &coreInner = CoreManagerInner::GetInstance(); const int32_t defSlotId = coreInner.GetDefaultCellularDataSlotId(); @@ -1323,12 +1362,6 @@ void CellularDataHandler::CreateApnItem() break; } } - if (result == 0) { - apnManager_->CreateAllApnItem(); - } - if (result != 0) { - SetRilAttachApn(); - } } bool CellularDataHandler::HandleApnChanged() @@ -1356,10 +1389,9 @@ void CellularDataHandler::HandleApnChanged(const InnerEvent::Pointer &event) return; } CreateApnItem(); - ApnProfileState apnState = apnManager_->GetOverallApnState(); - if (apnState == ApnProfileState::PROFILE_STATE_CONNECTING || apnState == ApnProfileState::PROFILE_STATE_CONNECTED) { - ClearAllConnections(DisConnectionReason::REASON_RETRY_CONNECTION); - } + DataProfile dataProfile; + SetRilAttachApn(dataProfile); + ClearConnectionsOnUpdateApns(dataProfile, DisConnectionReason::REASON_RETRY_CONNECTION); for (const sptr &apnHolder : apnManager_->GetAllApnHolder()) { if (apnHolder == nullptr) { continue; @@ -1599,41 +1631,31 @@ bool CellularDataHandler::GetEsmFlagFromOpCfg() return (esmFlagFromOpCfg != 0); } -void CellularDataHandler::SetInitApnWithNullDp() -{ - DataProfile dataProfile; - dataProfile.profileId = 0; - dataProfile.apn = ""; - dataProfile.protocol = ""; - dataProfile.verType = 0; - dataProfile.userName = ""; - dataProfile.password = ""; - dataProfile.roamingProtocol = ""; - CoreManagerInner::GetInstance().SetInitApnInfo( - slotId_, CellularDataEventCode::MSG_SET_RIL_ATTACH_APN, dataProfile, shared_from_this()); - return; -} - -void CellularDataHandler::SetRilAttachApn() +void CellularDataHandler::SetRilAttachApn(DataProfile &dataProfile) { - sptr attachApn = apnManager_->GetRilAttachApn(); - if (attachApn == nullptr) { - TELEPHONY_LOGE("Slot%{public}d: attachApn is null", slotId_); - return; - } if (!GetEsmFlagFromOpCfg()) { - SetInitApnWithNullDp(); - return; + dataProfile.profileId = 0; + dataProfile.apn = ""; + dataProfile.protocol = ""; + dataProfile.verType = 0; + dataProfile.userName = ""; + dataProfile.password = ""; + dataProfile.roamingProtocol = ""; + } else { + sptr attachApn = apnManager_->GetRilAttachApn(); + if (attachApn == nullptr) { + TELEPHONY_LOGE("Slot%{public}d: attachApn is null", slotId_); + return; + } + dataProfile.profileId = attachApn->attr_.profileId_; + dataProfile.apn = attachApn->attr_.apn_; + dataProfile.protocol = attachApn->attr_.protocol_; + dataProfile.verType = attachApn->attr_.authType_; + dataProfile.userName = attachApn->attr_.user_; + dataProfile.password = attachApn->attr_.password_; + dataProfile.roamingProtocol = attachApn->attr_.roamingProtocol_; } - DataProfile dataProfile; - dataProfile.profileId = attachApn->attr_.profileId_; - dataProfile.apn = attachApn->attr_.apn_; - dataProfile.protocol = attachApn->attr_.protocol_; - dataProfile.verType = attachApn->attr_.authType_; - dataProfile.userName = attachApn->attr_.user_; - dataProfile.password = attachApn->attr_.password_; - dataProfile.roamingProtocol = attachApn->attr_.roamingProtocol_; - TELEPHONY_LOGI("DataProfile profileId = %{public}d", dataProfile.profileId); + TELEPHONY_LOGI("Slot%{public}d: DataProfile profileId = %{public}d", slotId_, dataProfile.profileId); CoreManagerInner::GetInstance().SetInitApnInfo( slotId_, CellularDataEventCode::MSG_SET_RIL_ATTACH_APN, dataProfile, shared_from_this()); } @@ -1652,6 +1674,8 @@ void CellularDataHandler::SetRilAttachApnResponse(const AppExecFwk::InnerEvent:: if (rilInfo->errorNo != 0) { TELEPHONY_LOGE("Slot%{public}d: SetRilAttachApn error", slotId_); } + isRilApnAttached_ = (rilInfo->errorNo == 0); + TELEPHONY_LOGI("Slot%{public}d: isRilApnAttached_ = %{public}d", slotId_, isRilApnAttached_); } bool CellularDataHandler::HasAnyHigherPriorityConnection(const sptr &apnHolder) diff --git a/test/cellular_data_handler_test.cpp b/test/cellular_data_handler_test.cpp index 154dedbd..466e35d1 100644 --- a/test/cellular_data_handler_test.cpp +++ b/test/cellular_data_handler_test.cpp @@ -215,5 +215,147 @@ HWTEST_F(CellularDataHandlerTest, HandleRoamingOff_002, Function | MediumTest | auto event = AppExecFwk::InnerEvent::Get(0); cellularDataHandler->RoamingStateOff(event); } + +/** + * @tc.number HandleSimEvent_001 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_001, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + AppExecFwk::InnerEvent::Pointer nullEvent(nullptr, nullptr); + cellularDataHandler->HandleSimEvent(nullEvent); + auto event = AppExecFwk::InnerEvent::Get(CellularDataEventCode::MSG_DATA_CALL_LIST_CHANGED, 0); + cellularDataHandler->HandleSimEvent(event); + EXPECT_NE(cellularDataHandler->connectionManager_, nullptr); + EXPECT_NE(cellularDataHandler->apnManager_, nullptr); +} + +/** + * @tc.number HandleSimEvent_002 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_002, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_STATE_CHANGE, 1); + cellularDataHandler->HandleSimEvent(event); + EXPECT_NE(cellularDataHandler->slotId_, event->GetParam()); +} + +/** + * @tc.number HandleSimEvent_003 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_003, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_STATE_CHANGE, 0); + cellularDataHandler->HandleSimEvent(event); + EXPECT_EQ(event->GetInnerEventId(), RadioEvent::RADIO_SIM_STATE_CHANGE); +} + +/** + * @tc.number HandleSimEvent_004 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_004, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_RECORDS_LOADED, 0); + cellularDataHandler->HandleSimEvent(event); + EXPECT_EQ(event->GetInnerEventId(), RadioEvent::RADIO_SIM_RECORDS_LOADED); +} + +/** + * @tc.number HandleSimEvent_005 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_005, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_NV_REFRESH_FINISHED, 0); + cellularDataHandler->HandleSimEvent(event); + EXPECT_EQ(event->GetInnerEventId(), RadioEvent::RADIO_NV_REFRESH_FINISHED); +} + +/** + * @tc.number HandleSimEvent_006 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, HandleSimEvent_006, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SIM_ACCOUNT_LOADED, 0); + cellularDataHandler->HandleSimEvent(event); + EXPECT_EQ(event->GetInnerEventId(), RadioEvent::RADIO_SIM_ACCOUNT_LOADED); +} + +/** + * @tc.number ClearConnectionsOnUpdateApns_001 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, ClearConnectionsOnUpdateApns_001, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + DataProfile dataProfile; + cellularDataHandler->ClearConnectionsOnUpdateApns(dataProfile, DisConnectionReason::REASON_RETRY_CONNECTION); + EXPECT_NE(cellularDataHandler->connectionManager_, nullptr); + EXPECT_NE(cellularDataHandler->apnManager_, nullptr); +} + +/** + * @tc.number ClearConnectionsOnUpdateApns_002 + * @tc.name test error branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataHandlerTest, ClearConnectionsOnUpdateApns_002, Function | MediumTest | Level3) +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_CALL_STATE_CHANGED); + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, 0); + cellularDataHandler->Init(); + DataProfile dataProfile; + dataProfile.profileId = 1; + cellularDataHandler->ClearConnectionsOnUpdateApns(dataProfile, DisConnectionReason::REASON_RETRY_CONNECTION); + EXPECT_NE(cellularDataHandler->connectionManager_, nullptr); + EXPECT_NE(cellularDataHandler->apnManager_, nullptr); +} } // namespace Telephony } // namespace OHOS \ No newline at end of file diff --git a/test/cellular_data_service_test.cpp b/test/cellular_data_service_test.cpp index 9168e616..beb858f2 100644 --- a/test/cellular_data_service_test.cpp +++ b/test/cellular_data_service_test.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace Telephony { using namespace testing::ext; -const int32_t DEFAULT_SIM_SLOT_ID = 0; class CellularDataServiceTest : public testing::Test { public: diff --git a/test/zero_branch_test.cpp b/test/zero_branch_test.cpp index 3c66542c..500cd71f 100644 --- a/test/zero_branch_test.cpp +++ b/test/zero_branch_test.cpp @@ -64,7 +64,6 @@ const int32_t INVALID_SLOTID = -1; const int32_t INVALID_SLOTID_TWO = 5; const int32_t INVALID_CID = -1; const int32_t INVALID_FD = -1; -const int32_t DEFAULT_SIM_SLOT_ID = 0; const int32_t SLEEP_TIME_SECONDS = 3; const std::string ADDRESS = "127.0.0.1"; const std::string FLAG = "."; @@ -222,8 +221,8 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_002, Function | MediumTest | cellularDataHandler.HandleCallChanged(0); cellularDataHandler.HandleImsCallChanged(0); cellularDataHandler.HandleVoiceCallChanged(0); - cellularDataHandler.HandleSimStateOrRecordsChanged(event); - cellularDataHandler.HandleSimAccountLoaded(event); + cellularDataHandler.HandleSimEvent(event); + cellularDataHandler.HandleSimAccountLoaded(); cellularDataHandler.HandleRadioStateChanged(event); cellularDataHandler.HandleDsdsModeChanged(event); cellularDataHandler.SetRilAttachApnResponse(event); @@ -372,8 +371,8 @@ HWTEST_F(BranchTest, Telephony_CellularDataHandler_005, Function | MediumTest | controller.cellularDataHandler_->HandleCallChanged(0); controller.cellularDataHandler_->HandleImsCallChanged(0); controller.cellularDataHandler_->HandleVoiceCallChanged(0); - controller.cellularDataHandler_->HandleSimStateOrRecordsChanged(event); - controller.cellularDataHandler_->HandleSimAccountLoaded(event); + controller.cellularDataHandler_->HandleSimEvent(event); + controller.cellularDataHandler_->HandleSimAccountLoaded(); controller.cellularDataHandler_->HandleRadioStateChanged(event); controller.cellularDataHandler_->HandleDsdsModeChanged(event); controller.cellularDataHandler_->SetRilAttachApnResponse(event); @@ -1416,7 +1415,6 @@ HWTEST_F(BranchTest, Default_Test_01, Function | MediumTest | Level3) HWTEST_F(BranchTest, ApnManager_Test_01, Function | MediumTest | Level3) { auto apnManager = std::make_shared(); - apnManager->CreateAllApnItem(); EXPECT_GE(apnManager->CreateAllApnItemByDatabase(0), 0); EXPECT_EQ(apnManager->CreateAllApnItemByDatabase(0), 0); apnManager->ResetApns(0); -- Gitee