From 3b9d8003adf3d6af2cc265e0b8b50fdce9e2cb52 Mon Sep 17 00:00:00 2001 From: liuleiminhw Date: Sat, 23 Aug 2025 16:58:11 +0800 Subject: [PATCH 1/4] data not release Signed-off-by: liuleiminhw --- .../js/napi/src/cellular_data_handler.cpp | 1 + .../js/napi/src/cellular_data_service.cpp | 34 +++++++++++++++ services/include/cellular_data_controller.h | 3 ++ services/include/cellular_data_service.h | 2 + services/src/cellular_data_controller.cpp | 10 +++++ test/cellular_data_handler_test.cpp | 16 ++++++++ test/cellular_data_service_test.cpp | 41 +++++++++++++++++++ 7 files changed, 107 insertions(+) diff --git a/frameworks/js/napi/src/cellular_data_handler.cpp b/frameworks/js/napi/src/cellular_data_handler.cpp index d117bb1c..24d45326 100644 --- a/frameworks/js/napi/src/cellular_data_handler.cpp +++ b/frameworks/js/napi/src/cellular_data_handler.cpp @@ -1653,6 +1653,7 @@ void CellularDataHandler::HandleSimAccountLoaded() } else { ClearAllConnections(DisConnectionReason::REASON_CLEAR_CONNECTION); } + DelayedRefSingleton::GetInstance().HandleSimAccountChanged(); } void CellularDataHandler::CreateApnItem() diff --git a/frameworks/js/napi/src/cellular_data_service.cpp b/frameworks/js/napi/src/cellular_data_service.cpp index d570cd67..a317e5f3 100644 --- a/frameworks/js/napi/src/cellular_data_service.cpp +++ b/frameworks/js/napi/src/cellular_data_service.cpp @@ -397,6 +397,9 @@ int32_t CellularDataService::ReleaseNet(const NetRequest &request) int32_t simId = std::stoi(requestIdent); int32_t slotId = CoreManagerInner::GetInstance().GetSlotId(simId); std::shared_ptr cellularDataController = GetCellularDataController(slotId); + if (cellularDataController == nullptr) { + cellularDataController = GetCellularDataControllerForce(simId); + } if (cellularDataController == nullptr) { return CELLULAR_DATA_INVALID_PARAM; } @@ -417,6 +420,9 @@ int32_t CellularDataService::RemoveUid(const NetRequest &request) int32_t simId = atoi(requestIdent.c_str()); int32_t slotId = CoreManagerInner::GetInstance().GetSlotId(simId); std::shared_ptr cellularDataController = GetCellularDataController(slotId); + if (cellularDataController == nullptr) { + cellularDataController = GetCellularDataControllerForce(simId); + } if (cellularDataController == nullptr) { return CELLULAR_DATA_INVALID_PARAM; } @@ -757,6 +763,23 @@ std::shared_ptr CellularDataService::GetCellularDataCont return item->second; } +std::shared_ptr CellularDataService::GetCellularDataControllerForce(int32_t simId) +{ + TELEPHONY_LOGI("GetCellularDataControllerForce, enter"); + if (!isInitSuccess_) { + return nullptr; + } + + std::lock_guard guard(mapLock_); + for(auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { + if (it->second != nullptr && it->second->GetSimId() == simId) { + TELEPHONY_LOGI("GetCellularDataControllerForce, simId=%{public}d", it->second->GetSimId()); + return it->second; + } + } + return nullptr; +} + int32_t CellularDataService::EstablishAllApnsIfConnectable(const int32_t slotId) { if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) { @@ -1020,5 +1043,16 @@ int32_t CellularDataService::GetActiveApnName(std::string &apnName) } return 0; } + +void CellularDataService::HandleSimAccountChanged() +{ + std::lock_guard guard(mapLock_); + for(auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { + if (it->second == nullptr) { + return; + } + it->second->UpdateSimIdInfo(); + } +} } // namespace Telephony } // namespace OHOS diff --git a/services/include/cellular_data_controller.h b/services/include/cellular_data_controller.h index d8429e70..c4a84201 100644 --- a/services/include/cellular_data_controller.h +++ b/services/include/cellular_data_controller.h @@ -62,6 +62,8 @@ public: bool IsSupportDunApn(); bool GetDefaultActReportInfo(ApnActivateReportInfo &info); bool GetInternalActReportInfo(ApnActivateReportInfo &info); + void UpdateSimIdInfo(); + int32_t GetSimId(); private: void RegisterEvents(); @@ -82,6 +84,7 @@ private: private: const int32_t slotId_; + int32_t simId_; std::shared_ptr handler_; }; }; diff --git a/services/include/cellular_data_service.h b/services/include/cellular_data_service.h index c18af7b7..373fb17f 100644 --- a/services/include/cellular_data_service.h +++ b/services/include/cellular_data_service.h @@ -104,6 +104,7 @@ public: int32_t GetNetworkSliceAllowedNssai(int32_t slotId, const std::vector& buffer) override; int32_t GetNetworkSliceEhplmn(int32_t slotId) override; int32_t GetActiveApnName(std::string &apnName) override; + void HandleSimAccountChanged(); private: bool Init(); @@ -113,6 +114,7 @@ private: void ClearCellularDataControllers(); void AddCellularDataControllers(int32_t slotId, std::shared_ptr cellularDataController); std::shared_ptr GetCellularDataController(int32_t slotId); + std::shared_ptr GetCellularDataControllerForce(int32_t simId); private: std::map> cellularDataControllers_; diff --git a/services/src/cellular_data_controller.cpp b/services/src/cellular_data_controller.cpp index a12aaffb..702aa960 100644 --- a/services/src/cellular_data_controller.cpp +++ b/services/src/cellular_data_controller.cpp @@ -529,5 +529,15 @@ bool CellularDataController::GetInternalActReportInfo(ApnActivateReportInfo &inf return true; } +void CellularDataController::UpdateSimIdInfo() +{ + simId_ = CoreManagerInner::GetInstance().GetSimId(slotId_); +} + +int32_t CellularDataController::GetSimId() +{ + return simId_; +} + } // namespace Telephony } // namespace OHOS diff --git a/test/cellular_data_handler_test.cpp b/test/cellular_data_handler_test.cpp index 0294f240..3fdc8496 100644 --- a/test/cellular_data_handler_test.cpp +++ b/test/cellular_data_handler_test.cpp @@ -1159,5 +1159,21 @@ HWTEST_F(CellularDataHandlerTest, IsCellularDataEnabledTest001, Function | Mediu cellularDataHandler->dataSwitchSettings_->lastQryRet_ = TELEPHONY_ERR_SUCCESS; EXPECT_EQ(cellularDataHandler->IsCellularDataEnabled(isDataEnabled), TELEPHONY_ERR_SUCCESS); } + +/** +@tc.number Telephony_HandleSimAccountLoaded001 +@tc.name HandleSimAccountLoaded +@tc.desc Function test +*/ +HWTEST_F(CellularDataHandlerTest, HandleSimAccountLoaded001, Function | MediumTest | Level1) +{ + int32_t slotId = 0; + EventFwk::MatchingSkills matchingSkills; + EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills); + auto cellularDataHandler = std::make_shared(subscriberInfo, slotId); + cellularDataHandler->Init(); + cellularDataHandler->HandleSimAccountLoaded(); + EXPECT_FALSE(cellularDataHandler->connectionManager_ == 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 ab8888f3..a77e2ec8 100644 --- a/test/cellular_data_service_test.cpp +++ b/test/cellular_data_service_test.cpp @@ -509,5 +509,46 @@ HWTEST_F(CellularDataServiceTest, ReleaseNet_001, TestSize.Level1) ASSERT_EQ(CELLULAR_DATA_INVALID_PARAM, service->RequestNet(request)); ASSERT_EQ(CELLULAR_DATA_INVALID_PARAM, service->ReleaseNet(request)); } + +/** + * @tc.number CellularDataService_ReleaseNet_001 + * @tc.name test function branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataServiceTest, CellularDataService_ReleaseNet_001, TestSize.Level1) +{ + DataAccessToken token; + service->OnStart(); + service->isInitSuccess_ = false; + NetRequest request; + request.ident = "simId2"; + ASSERT_NE(TELEPHONY_ERR_SUCCESS, service->ReleaseNet(request)); +} + +/** + * @tc.number CellularDataService_ReleaseNet_002 + * @tc.name test function branch + * @tc.desc Function test + */ +HWTEST_F(CellularDataServiceTest, CellularDataService_ReleaseNet_002, TestSize.Level1) +{ + DataAccessToken token; + service->OnStart(); + service->isInitSuccess_ = true; + service->cellularDataControllers_.clear(); + std::shared_ptr cellularDataController = std::make_shared(0); + service->cellularDataControllers_.insert( + std::pair>(0, cellularDataController)); + + service->HandleSimAccountChanged(); + auto it = service->cellularDataControllers_.begin(); + int32_t simId = it->second->GetSimId(); + + NetRequest request; + std::string str = "simId" + std::to_string(simId); + request.ident = str; + ASSERT_EQ(TELEPHONY_ERR_SUCCESS, service->ReleaseNet(request)); + service->cellularDataControllers_.clear(); +} } // namespace Telephony } // namespace OHOS \ No newline at end of file -- Gitee From 8bc13069a234d5412d00f4f19ef9a6dbffc66898 Mon Sep 17 00:00:00 2001 From: liuleimin_hw Date: Sat, 23 Aug 2025 09:13:54 +0000 Subject: [PATCH 2/4] update frameworks/js/napi/src/cellular_data_service.cpp. Signed-off-by: liuleimin_hw --- frameworks/js/napi/src/cellular_data_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/src/cellular_data_service.cpp b/frameworks/js/napi/src/cellular_data_service.cpp index a317e5f3..1cd1e3a9 100644 --- a/frameworks/js/napi/src/cellular_data_service.cpp +++ b/frameworks/js/napi/src/cellular_data_service.cpp @@ -1049,7 +1049,7 @@ void CellularDataService::HandleSimAccountChanged() std::lock_guard guard(mapLock_); for(auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { if (it->second == nullptr) { - return; + continue; } it->second->UpdateSimIdInfo(); } -- Gitee From 5378bce39809a962ba23a3fe6f9e0955e60ab2f5 Mon Sep 17 00:00:00 2001 From: liuleimin_hw Date: Sat, 23 Aug 2025 11:29:31 +0000 Subject: [PATCH 3/4] update frameworks/js/napi/src/cellular_data_service.cpp. Signed-off-by: liuleimin_hw --- frameworks/js/napi/src/cellular_data_service.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/src/cellular_data_service.cpp b/frameworks/js/napi/src/cellular_data_service.cpp index 1cd1e3a9..04039548 100644 --- a/frameworks/js/napi/src/cellular_data_service.cpp +++ b/frameworks/js/napi/src/cellular_data_service.cpp @@ -771,7 +771,7 @@ std::shared_ptr CellularDataService::GetCellularDataCont } std::lock_guard guard(mapLock_); - for(auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { + for (auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { if (it->second != nullptr && it->second->GetSimId() == simId) { TELEPHONY_LOGI("GetCellularDataControllerForce, simId=%{public}d", it->second->GetSimId()); return it->second; @@ -1047,7 +1047,7 @@ int32_t CellularDataService::GetActiveApnName(std::string &apnName) void CellularDataService::HandleSimAccountChanged() { std::lock_guard guard(mapLock_); - for(auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { + for (auto it = cellularDataControllers_.begin(); it != cellularDataControllers_.end(); ++it) { if (it->second == nullptr) { continue; } -- Gitee From 87a6d66dd2e337493ebdb5e048d272131bec7785 Mon Sep 17 00:00:00 2001 From: liuleimin_hw Date: Sat, 23 Aug 2025 11:56:19 +0000 Subject: [PATCH 4/4] update services/include/cellular_data_controller.h. Signed-off-by: liuleimin_hw --- services/include/cellular_data_controller.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/include/cellular_data_controller.h b/services/include/cellular_data_controller.h index c4a84201..b21b1381 100644 --- a/services/include/cellular_data_controller.h +++ b/services/include/cellular_data_controller.h @@ -73,6 +73,7 @@ private: std::shared_ptr cellularDataHandler_; sptr systemAbilityListener_ = nullptr; const int32_t slotId_; + int32_t simId_; private: class SystemAbilityStatusChangeListener : public OHOS::SystemAbilityStatusChangeStub { @@ -84,7 +85,6 @@ private: private: const int32_t slotId_; - int32_t simId_; std::shared_ptr handler_; }; }; -- Gitee