!2450 unlockpin 单独加锁

Merge pull request !2450 from 刘峻朋/master
This commit is contained in:
openharmony_ci 2024-11-15 09:39:50 +00:00 committed by Gitee
commit 867e93072c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 22 additions and 7 deletions

View File

@ -61,14 +61,18 @@ public:
int32_t GetSimIO(int32_t slotId, SimIoRequestInfo requestInfo, SimAuthenticationResponse &response);
void SyncCmdResponse();
void SyncSimMatchResponse();
void SyncUnlockPinResponse();
public:
bool responseReady_ = false;
bool responseSimMatchReady_ = false;
bool responseUnlockPinReady_ = false;
std::mutex ctx_;
std::mutex stx_;
std::mutex unlockPinCtx_;
std::condition_variable cv_;
std::condition_variable sv_;
std::condition_variable unlockPinCv_;
private:
void RequestUnlock(UnlockCmd type);

View File

@ -707,6 +707,8 @@ void SimStateHandle::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
}
if (eventId == MSG_SIM_SEND_NCFG_OPER_INFO_DONE) {
simStateManager->SyncSimMatchResponse();
} else if (eventId == MSG_SIM_UNLOCK_PIN_DONE) {
simStateManager->SyncUnlockPinResponse();
} else {
simStateManager->SyncCmdResponse();
}

View File

@ -168,28 +168,37 @@ void SimStateManager::SyncSimMatchResponse()
{
std::unique_lock<std::mutex> lck(stx_);
responseSimMatchReady_ = true;
TELEPHONY_LOGI(
"SimStateManager::SyncSimMatchResponse(), responseSimMatchReady = %{public}d", responseSimMatchReady_);
TELEPHONY_LOGI("SimStateManager::SyncSimMatchResponse(), responseSimMatchReady = %{public}d",
responseSimMatchReady_);
sv_.notify_one();
}
void SimStateManager::SyncUnlockPinResponse()
{
std::unique_lock<std::mutex> lck(unlockPinCtx_);
responseUnlockPinReady_ = true;
TELEPHONY_LOGI("SimStateManager::SyncUnlockPinResponse(), responseUnlockPinReady = %{public}d",
responseUnlockPinReady_);
unlockPinCv_.notify_one();
}
int32_t SimStateManager::UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response)
{
if (simStateHandle_ == nullptr) {
TELEPHONY_LOGE("simStateHandle_ is nullptr");
return TELEPHONY_ERR_LOCAL_PTR_NULL;
}
std::unique_lock<std::mutex> lck(ctx_);
std::unique_lock<std::mutex> lck(unlockPinCtx_);
TELEPHONY_LOGD("SimStateManager::UnlockPin slotId = %{public}d", slotId);
responseReady_ = false;
responseUnlockPinReady_ = false;
simStateHandle_->UnlockPin(slotId, pin);
while (!responseReady_) {
while (!responseUnlockPinReady_) {
TELEPHONY_LOGI("UnlockPin::wait(), response = false");
if (cv_.wait_for(lck, std::chrono::seconds(WAIT_TIME_LONG_SECOND)) == std::cv_status::timeout) {
if (unlockPinCv_.wait_for(lck, std::chrono::seconds(WAIT_TIME_LONG_SECOND)) == std::cv_status::timeout) {
break;
}
}
if (!responseReady_) {
if (!responseUnlockPinReady_) {
TELEPHONY_LOGE("unlock pin sim update failed");
return CORE_ERR_SIM_CARD_UPDATE_FAILED;
}