diff --git a/frameworks/native/src/core_manager_inner.cpp b/frameworks/native/src/core_manager_inner.cpp index bf712005..b546387e 100644 --- a/frameworks/native/src/core_manager_inner.cpp +++ b/frameworks/native/src/core_manager_inner.cpp @@ -2212,6 +2212,15 @@ int32_t CoreManagerInner::GetSimState(int32_t slotId, SimState &simState) return simManager_->GetSimState(slotId, simState); } +int32_t CoreManagerInner::GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) +{ + if (simManager_ == nullptr) { + TELEPHONY_LOGE("simManager_ is null!"); + return TELEPHONY_ERR_LOCAL_PTR_NULL; + } + return simManager_->GetSimIccStatus(slotId, iccStatus); +} + int32_t CoreManagerInner::GetCardType(int32_t slotId, CardType &cardType) { if (simManager_ == nullptr) { diff --git a/interfaces/innerkits/include/core_manager_inner.h b/interfaces/innerkits/include/core_manager_inner.h index 337d96bc..df07487e 100644 --- a/interfaces/innerkits/include/core_manager_inner.h +++ b/interfaces/innerkits/include/core_manager_inner.h @@ -247,6 +247,7 @@ public: int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response); int32_t HasSimCard(int32_t slotId, bool &hasSimCard); int32_t GetSimState(int32_t slotId, SimState &simState); + int32_t GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus); int32_t GetCardType(int32_t slotId, CardType &cardType); int32_t SetModemInit(int32_t slotId, bool state); int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response); diff --git a/interfaces/innerkits/include/i_sim_manager.h b/interfaces/innerkits/include/i_sim_manager.h index 29de0bff..3d815cb1 100644 --- a/interfaces/innerkits/include/i_sim_manager.h +++ b/interfaces/innerkits/include/i_sim_manager.h @@ -33,6 +33,7 @@ public: // SimState virtual int32_t HasSimCard(int32_t slotId, bool &hasSimCard) = 0; virtual int32_t GetSimState(int32_t slotId, SimState &simState) = 0; + virtual int32_t GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) = 0; virtual int32_t GetCardType(int32_t slotId, CardType &cardType) = 0; virtual int32_t SetModemInit(int32_t slotId, bool state) = 0; virtual int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) = 0; diff --git a/interfaces/innerkits/include/sim_state_type.h b/interfaces/innerkits/include/sim_state_type.h index e0de4ce9..2d81a820 100755 --- a/interfaces/innerkits/include/sim_state_type.h +++ b/interfaces/innerkits/include/sim_state_type.h @@ -225,6 +225,25 @@ enum class LockState { LOCK_ERROR, }; +/** + * @brief icc sim status + */ +enum class IccSimStatus { + ICC_CONTENT_UNKNOWN = -1, + ICC_CARD_ABSENT = 0, + ICC_CONTENT_READY, + ICC_CONTENT_PIN, + ICC_CONTENT_PUK, + ICC_CONTENT_PIN2, + ICC_CONTENT_PUK2, + ICC_CONTENT_PH_NET_PIN, + ICC_CONTENT_PH_NET_PUK, + ICC_CONTENT_PH_NET_SUB_PIN, + ICC_CONTENT_PH_NET_SUB_PUK, + ICC_CONTENT_PH_SP_PIN, + ICC_CONTENT_PH_SP_PUK, +}; + /** * @brief Lock information */ diff --git a/services/sim/include/sim_manager.h b/services/sim/include/sim_manager.h index a72965de..d875c8dd 100644 --- a/services/sim/include/sim_manager.h +++ b/services/sim/include/sim_manager.h @@ -47,6 +47,7 @@ public: // SimState int32_t HasSimCard(int32_t slotId, bool &hasSimCard) override; int32_t GetSimState(int32_t slotId, SimState &simState) override; + int32_t GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) override; int32_t GetCardType(int32_t slotId, CardType &cardType) override; int32_t SetModemInit(int32_t slotId, bool state) override; int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) override; diff --git a/services/sim/include/sim_state_handle.h b/services/sim/include/sim_state_handle.h index 16f30973..e7e51ba3 100644 --- a/services/sim/include/sim_state_handle.h +++ b/services/sim/include/sim_state_handle.h @@ -111,6 +111,7 @@ public: void Init(int32_t slotId); void UnInit(); SimState GetSimState(); + IccSimStatus GetSimIccStatus(); CardType GetCardType(); std::string GetIccid(); bool HasSimCard(); diff --git a/services/sim/include/sim_state_manager.h b/services/sim/include/sim_state_manager.h index 67786f14..794afd07 100644 --- a/services/sim/include/sim_state_manager.h +++ b/services/sim/include/sim_state_manager.h @@ -33,6 +33,7 @@ public: void Init(int32_t slotId); bool HasSimCard(); SimState GetSimState(); + IccSimStatus GetSimIccStatus(); CardType GetCardType(); std::string GetIccid(); int32_t SetModemInit(bool state); diff --git a/services/sim/src/sim_manager.cpp b/services/sim/src/sim_manager.cpp index 1376c2a8..96c8ce93 100644 --- a/services/sim/src/sim_manager.cpp +++ b/services/sim/src/sim_manager.cpp @@ -163,6 +163,16 @@ int32_t SimManager::GetSimState(int32_t slotId, SimState &simState) return TELEPHONY_ERR_SUCCESS; } +int32_t SimManager::GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) +{ + if (!HasSimCardInner(slotId)) { + iccStatus = IccSimStatus::ICC_CARD_ABSENT; + return TELEPHONY_ERR_SUCCESS; + } + iccStatus = simStateManager_[slotId]->GetSimIccStatus(); + return TELEPHONY_ERR_SUCCESS; +} + int32_t SimManager::GetCardType(int32_t slotId, CardType &cardType) { if (!HasSimCardInner(slotId)) { diff --git a/services/sim/src/sim_state_handle.cpp b/services/sim/src/sim_state_handle.cpp index c59d984b..5c8e9e0d 100644 --- a/services/sim/src/sim_state_handle.cpp +++ b/services/sim/src/sim_state_handle.cpp @@ -151,6 +151,11 @@ SimState SimStateHandle::GetSimState() return externalState_; } +IccSimStatus SimStateHandle::GetSimIccStatus() +{ + return static_cast(oldSimStatus_); +} + CardType SimStateHandle::GetCardType() { TELEPHONY_LOGD("SimStateHandle::GetCardType() externalType_=%{public}d", static_cast(externalType_)); diff --git a/services/sim/src/sim_state_manager.cpp b/services/sim/src/sim_state_manager.cpp index c773e4c0..68a93796 100644 --- a/services/sim/src/sim_state_manager.cpp +++ b/services/sim/src/sim_state_manager.cpp @@ -97,6 +97,17 @@ SimState SimStateManager::GetSimState() return ret; } +IccSimStatus SimStateManager::GetSimIccStatus() +{ + IccSimStatus ret = IccSimStatus::ICC_CONTENT_UNKNOWN; + if (simStateHandle_ != nullptr) { + std::lock_guard lck(mtx_); + TELEPHONY_LOGD("SimStateManager::GetSimIccStatus()"); + ret = simStateHandle_->GetSimIccStatus(); + } + return ret; +} + bool SimStateManager::IfModemInitDone() { if (simStateHandle_ != nullptr) { diff --git a/test/unittest/core_service_gtest/zero_branch_test.cpp b/test/unittest/core_service_gtest/zero_branch_test.cpp index 6366395a..83fc9828 100644 --- a/test/unittest/core_service_gtest/zero_branch_test.cpp +++ b/test/unittest/core_service_gtest/zero_branch_test.cpp @@ -948,6 +948,12 @@ HWTEST_F(BranchTest, Telephony_CoreManagerInner_002, Function | MediumTest | Lev EXPECT_GT(mInner.GetOperatorInfo(0, 0, nullptr), TELEPHONY_ERR_SUCCESS); EXPECT_GT(mInner.GetCellInfoList(0, 0, nullptr), TELEPHONY_ERR_SUCCESS); EXPECT_GT(mInner.GetCurrentCellInfo(0, 0, nullptr), TELEPHONY_ERR_SUCCESS); + IccSimStatus iccStatus = IccSimStatus::ICC_CARD_ABSENT; + auto telRilManager = std::make_shared(); + mInner.simManager_ = std::make_shared(telRilManager); + EXPECT_GT(mInner.GetSimIccStatus(0, iccStatus), TELEPHONY_ERR_SUCCESS); + mInner.simManager_ = nullptr; + EXPECT_GT(mInner.GetSimIccStatus(0, iccStatus), TELEPHONY_ERR_SUCCESS); } /** @@ -1444,6 +1450,9 @@ HWTEST_F(BranchTest, Telephony_SimManager_001, Function | MediumTest | Level1) EXPECT_NE(simManager->GetLockState(INVALID_SLOTID, mLockType, lockState), TELEPHONY_ERR_SUCCESS); EXPECT_NE(simManager->RefreshSimState(0), TELEPHONY_ERR_SUCCESS); EXPECT_NE(simManager->RefreshSimState(INVALID_SLOTID), TELEPHONY_ERR_SUCCESS); + IccSimStatus iccStatus = IccSimStatus::ICC_CARD_ABSENT; + EXPECT_EQ(simManager->GetSimIccStatus(3, iccStatus), TELEPHONY_ERR_SUCCESS); + EXPECT_EQ(simManager->GetSimIccStatus(0, iccStatus), TELEPHONY_ERR_SUCCESS); } /** @@ -1679,6 +1688,12 @@ HWTEST_F(BranchTest, Telephony_SimStateManager_001, Function | MediumTest | Leve simStateManager->simStateHandle_ = std::make_shared(simStateManagerTwo); EXPECT_GE(simStateManager->GetCardType(), CardType::UNKNOWN_CARD); EXPECT_GT(simStateManager->UnlockSimLock(0, mPersoLockInfo, mLockStatusResponse), TELEPHONY_ERR_SUCCESS); + simStateManager->simStateHandle_->GetSimIccStatus(); + auto ret = simStateManager->GetSimIccStatus(); + EXPECT_EQ(static_cast(ret), -1); + simStateManager->simStateHandle_ = nullptr; + ret = simStateManager->GetSimIccStatus(); + EXPECT_EQ(static_cast(ret), -1); } /**