mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-23 18:19:51 +00:00
commit
5006b7ebc2
@ -222,6 +222,7 @@ public:
|
||||
public:
|
||||
int32_t userId_;
|
||||
uint64_t secureUid_ = 0;
|
||||
bool isCalled_ = false;
|
||||
std::mutex secureMtx_;
|
||||
std::condition_variable secureCv_;
|
||||
};
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const UserIam::UserAuth::Attributes &extraInfo) override;
|
||||
|
||||
public:
|
||||
bool isIdmOnResultCallBack_ = false;
|
||||
bool isCalled_ = false;
|
||||
int32_t resultCode_ = -1;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable onResultCondition_;
|
||||
|
@ -33,7 +33,8 @@ public:
|
||||
void OnStartUserDone(int userId, int errcode) override;
|
||||
|
||||
public:
|
||||
bool isReturnOk_ = false;
|
||||
bool isCalled_ = false;
|
||||
int32_t resultCode_ = -1;
|
||||
std::mutex mutex_;
|
||||
std::condition_variable onStartCondition_;
|
||||
std::condition_variable onStopCondition_;
|
||||
|
@ -402,16 +402,19 @@ void DelUserCallback::OnResult(int32_t result, const Attributes &extraInfo)
|
||||
}
|
||||
|
||||
auto eraseUserCallback = std::make_shared<OsAccountDeleteUserIdmCallback>();
|
||||
std::unique_lock<std::mutex> lock(eraseUserCallback->mutex_);
|
||||
errCode = UserIam::UserAuth::UserIdmClient::GetInstance().EraseUser(userId_, eraseUserCallback);
|
||||
if (errCode != ERR_OK) {
|
||||
ACCOUNT_LOGE("Fail to erase user, userId=%{public}d, errcode=%{public}d", userId_, errCode);
|
||||
return innerCallback_->OnResult(errCode, extraInfo);
|
||||
}
|
||||
eraseUserCallback->onResultCondition_.wait(lock);
|
||||
std::unique_lock<std::mutex> lock(eraseUserCallback->mutex_);
|
||||
eraseUserCallback->onResultCondition_.wait(lock, [eraseUserCallback] {
|
||||
return eraseUserCallback->isCalled_;
|
||||
});
|
||||
if (eraseUserCallback->resultCode_ != ERR_OK) {
|
||||
ACCOUNT_LOGE("Fail to erase user, userId=%{public}d, errcode=%{public}d", userId_, errCode);
|
||||
return innerCallback_->OnResult(errCode, extraInfo);
|
||||
ACCOUNT_LOGE("Fail to erase user, userId=%{public}d, errcode=%{public}d",
|
||||
userId_, eraseUserCallback->resultCode_);
|
||||
return innerCallback_->OnResult(eraseUserCallback->resultCode_, extraInfo);
|
||||
}
|
||||
(void)IInnerOsAccountManager::GetInstance().SetOsAccountCredentialId(userId_, 0);
|
||||
errCode = innerIamMgr_.UpdateStorageKeyContext(userId_);
|
||||
@ -588,6 +591,7 @@ void GetSecureUidCallback::OnSecUserInfo(const SecUserInfo &info)
|
||||
ACCOUNT_LOGI("SecUserInfo call back userId=%{public}d", userId_);
|
||||
std::unique_lock<std::mutex> lck(secureMtx_);
|
||||
this->secureUid_ = info.secureUid;
|
||||
isCalled_ = true;
|
||||
secureCv_.notify_all();
|
||||
}
|
||||
|
||||
|
@ -435,13 +435,15 @@ void InnerAccountIAMManager::HandleFileKeyException(int32_t userId, const std::v
|
||||
return;
|
||||
}
|
||||
auto callback = std::make_shared<GetSecureUidCallback>(userId);
|
||||
std::unique_lock<std::mutex> lck(callback->secureMtx_);
|
||||
ErrCode code = UserIDMClient::GetInstance().GetSecUserInfo(userId, callback);
|
||||
if (code != ERR_OK) {
|
||||
return;
|
||||
}
|
||||
auto status = callback->secureCv_.wait_for(lck, std::chrono::seconds(TIME_WAIT_TIME_OUT));
|
||||
if (status != std::cv_status::no_timeout) {
|
||||
std::unique_lock<std::mutex> lck(callback->secureMtx_);
|
||||
auto status = callback->secureCv_.wait_for(lck, std::chrono::seconds(TIME_WAIT_TIME_OUT), [callback] {
|
||||
return callback->isCalled_;
|
||||
});
|
||||
if (!status) {
|
||||
ACCOUNT_LOGE("GetSecureUidCallback time out");
|
||||
return;
|
||||
}
|
||||
|
@ -81,7 +81,6 @@ void AppAccountCommonEventObserver::OnReceiveEvent(const CommonEventData &data)
|
||||
{
|
||||
auto want = data.GetWant();
|
||||
std::string action = want.GetAction();
|
||||
ACCOUNT_LOGI("Receive event: %{public}s", action.c_str());
|
||||
if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED ||
|
||||
action == CommonEventSupport::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED) {
|
||||
DealWithRemoveEvent(want, action);
|
||||
|
@ -24,7 +24,7 @@ void OsAccountDeleteUserIdmCallback::OnResult(int32_t result, const UserIam::Use
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
ACCOUNT_LOGI("IAM OnResult callback! result %{public}d", result);
|
||||
isIdmOnResultCallBack_ = true;
|
||||
isCalled_ = true;
|
||||
resultCode_ = result;
|
||||
onResultCondition_.notify_one();
|
||||
}
|
||||
|
@ -80,7 +80,6 @@ ErrCode OsAccountInterface::SendToAMSAccountStart(OsAccountInfo &osAccountInfo)
|
||||
}
|
||||
StartTraceAdapter("AbilityManagerAdapter StartUser");
|
||||
|
||||
std::unique_lock<std::mutex> lock(osAccountStartUserCallback->mutex_);
|
||||
ErrCode code = AbilityManagerAdapter::GetInstance()->StartUser(osAccountInfo.GetLocalId(),
|
||||
osAccountStartUserCallback);
|
||||
if (code != ERR_OK) {
|
||||
@ -90,9 +89,12 @@ ErrCode OsAccountInterface::SendToAMSAccountStart(OsAccountInfo &osAccountInfo)
|
||||
FinishTraceAdapter();
|
||||
return code;
|
||||
}
|
||||
osAccountStartUserCallback->onStartCondition_.wait(lock);
|
||||
std::unique_lock<std::mutex> lock(osAccountStartUserCallback->mutex_);
|
||||
osAccountStartUserCallback->onStartCondition_.wait(lock, [osAccountStartUserCallback] {
|
||||
return osAccountStartUserCallback->isCalled_;
|
||||
});
|
||||
FinishTraceAdapter();
|
||||
if (!osAccountStartUserCallback->isReturnOk_) {
|
||||
if (osAccountStartUserCallback->resultCode_ != ERR_OK) {
|
||||
ACCOUNT_LOGE("failed to AbilityManagerService in call back");
|
||||
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_START, -1,
|
||||
"AbilityManagerService failed!");
|
||||
@ -114,7 +116,6 @@ ErrCode OsAccountInterface::SendToAMSAccountStop(OsAccountInfo &osAccountInfo)
|
||||
}
|
||||
StartTraceAdapter("AbilityManagerAdapter StopUser");
|
||||
|
||||
std::unique_lock<std::mutex> lock(osAccountStopUserCallback->mutex_);
|
||||
ErrCode code = AbilityManagerAdapter::GetInstance()->StopUser(osAccountInfo.GetLocalId(),
|
||||
osAccountStopUserCallback);
|
||||
if (code != ERR_OK) {
|
||||
@ -124,9 +125,12 @@ ErrCode OsAccountInterface::SendToAMSAccountStop(OsAccountInfo &osAccountInfo)
|
||||
FinishTraceAdapter();
|
||||
return code;
|
||||
}
|
||||
osAccountStopUserCallback->onStopCondition_.wait(lock);
|
||||
std::unique_lock<std::mutex> lock(osAccountStopUserCallback->mutex_);
|
||||
osAccountStopUserCallback->onStopCondition_.wait(lock, [osAccountStopUserCallback] {
|
||||
return osAccountStopUserCallback->isCalled_;
|
||||
});
|
||||
FinishTraceAdapter();
|
||||
if (!osAccountStopUserCallback->isReturnOk_) {
|
||||
if (osAccountStopUserCallback->resultCode_ != ERR_OK) {
|
||||
ACCOUNT_LOGE("failed to AbilityManagerService in call back");
|
||||
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_STOP, -1,
|
||||
"AbilityManagerService failed!");
|
||||
@ -214,11 +218,11 @@ ErrCode OsAccountInterface::SendToIDMAccountDelete(OsAccountInfo &osAccountInfo)
|
||||
OHOS::GetSystemCurrentTime(&startTime);
|
||||
OHOS::GetSystemCurrentTime(&nowTime);
|
||||
while (OHOS::GetSecondsBetween(startTime, nowTime) < Constants::TIME_WAIT_TIME_OUT &&
|
||||
!callback->isIdmOnResultCallBack_) {
|
||||
!callback->isCalled_) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(Constants::WAIT_ONE_TIME));
|
||||
OHOS::GetSystemCurrentTime(&nowTime);
|
||||
}
|
||||
if (!callback->isIdmOnResultCallBack_) {
|
||||
if (!callback->isCalled_) {
|
||||
ACCOUNT_LOGE("idm did not call back! timeout!");
|
||||
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_DELETE, -1,
|
||||
"UserIDMClient EnforceDelUser timeout!");
|
||||
|
@ -68,7 +68,8 @@ void OsAccountUserCallback::OnStopUserDone(int userId, int errcode)
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
ACCOUNT_LOGI("in call back account, OnStopUserDone id is %{public}d, errcode is %{public}d.",
|
||||
userId, errcode);
|
||||
isReturnOk_ = (errcode == 0);
|
||||
isCalled_ = true;
|
||||
resultCode_ = errcode;
|
||||
onStopCondition_.notify_one();
|
||||
}
|
||||
|
||||
@ -77,7 +78,8 @@ void OsAccountUserCallback::OnStartUserDone(int userId, int errcode)
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
ACCOUNT_LOGI("in call back account, OnStartUserDone id is %{public}d, errcode is %{public}d.",
|
||||
userId, errcode);
|
||||
isReturnOk_ = (errcode == 0);
|
||||
isCalled_ = true;
|
||||
resultCode_ = errcode;
|
||||
onStartCondition_.notify_one();
|
||||
}
|
||||
} // namespace AccountSA
|
||||
|
@ -72,7 +72,7 @@ HWTEST_F(OsAccountServiceTest, OnStopUserDone001, TestSize.Level1)
|
||||
ASSERT_NE(nullptr, osAccountStopUserCallback);
|
||||
int errCode = 0;
|
||||
osAccountStopUserCallback->OnStopUserDone(TEST_USER_ID, errCode);
|
||||
EXPECT_TRUE(osAccountStopUserCallback->isReturnOk_);
|
||||
EXPECT_EQ(osAccountStopUserCallback->resultCode_, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,7 +87,7 @@ HWTEST_F(OsAccountServiceTest, OnStartUserDone001, TestSize.Level1)
|
||||
ASSERT_NE(nullptr, osAccountStartUserCallback);
|
||||
int errCode = 0;
|
||||
osAccountStartUserCallback->OnStartUserDone(TEST_USER_ID, errCode);
|
||||
EXPECT_TRUE(osAccountStartUserCallback->isReturnOk_);
|
||||
EXPECT_EQ(osAccountStartUserCallback->resultCode_, ERR_OK);
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user