From 97089b03b1d1c25bd07a4c35096c2d443a1675ad Mon Sep 17 00:00:00 2001
From: h00854973
Date: Thu, 4 Jul 2024 12:32:42 +0800
Subject: [PATCH] =?UTF-8?q?TicketNo:DTS2024062210582=20Description:SIM?=
=?UTF-8?q?=E7=8A=B6=E6=80=81=E5=8F=98=E5=8C=96=E9=80=BB=E8=BE=91=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Team:PDU_PTL
Feature or Bugfix:Bugfix
Binary Source:No
PrivateCode(Yes/No):No
Change-Id: I11d7c75c0e859eb12f01a76e6772d523814ff62d
---
services/include/cellular_data_handler.h | 5 +-
.../include/common/cellular_data_constant.h | 3 +-
services/src/cellular_data_controller.cpp | 2 -
services/src/cellular_data_handler.cpp | 50 ++++++++-----------
services/src/cellular_data_service.cpp | 8 ++-
services/src/traffic_management.cpp | 3 +-
.../src/utils/cellular_data_net_agent.cpp | 21 ++------
test/zero_branch_test.cpp | 18 +++----
8 files changed, 40 insertions(+), 70 deletions(-)
diff --git a/services/include/cellular_data_handler.h b/services/include/cellular_data_handler.h
index 2d1921d5..ea339c62 100644
--- a/services/include/cellular_data_handler.h
+++ b/services/include/cellular_data_handler.h
@@ -99,9 +99,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);
@@ -165,7 +165,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_;
@@ -192,7 +192,6 @@ private:
{ RadioEvent::RADIO_DSDS_MODE_CHANGED, &CellularDataHandler::HandleDsdsModeChanged },
{ RadioEvent::RADIO_SIM_STATE_CHANGE, &CellularDataHandler::HandleSimStateOrRecordsChanged },
{ RadioEvent::RADIO_SIM_RECORDS_LOADED, &CellularDataHandler::HandleSimStateOrRecordsChanged },
- { RadioEvent::RADIO_SIM_ACCOUNT_LOADED, &CellularDataHandler::HandleSimAccountLoaded },
{ RadioEvent::RADIO_PS_RAT_CHANGED, &CellularDataHandler::PsDataRatChanged },
{ CellularDataEventCode::MSG_APN_CHANGED, &CellularDataHandler::HandleApnChanged },
{ CellularDataEventCode::MSG_SET_RIL_ATTACH_APN, &CellularDataHandler::SetRilAttachApnResponse },
diff --git a/services/include/common/cellular_data_constant.h b/services/include/common/cellular_data_constant.h
index edc31fe9..0464cf22 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 63dd1e2f..5fb3a728 100644
--- a/services/src/cellular_data_controller.cpp
+++ b/services/src/cellular_data_controller.cpp
@@ -206,7 +206,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);
@@ -242,7 +241,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 8a79770e..8f41acf8 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)
@@ -1164,7 +1164,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_);
@@ -1194,25 +1194,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:
@@ -1220,16 +1203,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 3a00663b..b006bddc 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 d21215a1..27de0ab8 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 b16cfe09..36cec92b 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 1f38da1f..c67f6da6 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);
@@ -311,7 +310,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);
@@ -381,7 +380,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);
@@ -515,9 +513,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));
@@ -557,9 +555,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));
@@ -616,9 +614,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));
--
Gitee