codecheck part1 lock

Signed-off-by: xuqian <xuqian65@huawei.com>
This commit is contained in:
xuqian 2024-11-16 16:50:52 +08:00
parent e790409f51
commit 9cd395aeae
5 changed files with 32 additions and 27 deletions

View File

@ -362,6 +362,7 @@ ErrCode DomainAccountClient::GetAccountServerConfig(const DomainAccountInfo &inf
void DomainAccountClient::RestoreListenerRecords()
{
std::lock_guard<std::mutex> lock(recordMutex_);
if (listenerManager_ == nullptr) {
ACCOUNT_LOGI("listenerManager_ is nullptr");
return;

View File

@ -35,7 +35,7 @@ class InnerDomainAccountManager {
public:
static InnerDomainAccountManager &GetInstance();
ErrCode RegisterPlugin(const sptr<IDomainAccountPlugin> &plugin);
void UnregisterPlugin();
ErrCode UnregisterPlugin();
ErrCode Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password,
const sptr<IDomainAccountCallback> &callback);
ErrCode AuthUser(int32_t userId, const std::vector<uint8_t> &password,

View File

@ -39,8 +39,7 @@ ErrCode DomainAccountManagerService::RegisterPlugin(const sptr<IDomainAccountPlu
ErrCode DomainAccountManagerService::UnregisterPlugin()
{
InnerDomainAccountManager::GetInstance().UnregisterPlugin();
return ERR_OK;
return InnerDomainAccountManager::GetInstance().UnregisterPlugin();
}
ErrCode DomainAccountManagerService::HasDomainAccount(

View File

@ -119,10 +119,15 @@ InnerDomainAuthCallback::~InnerDomainAuthCallback()
void InnerDomainAuthCallback::OnResult(const int32_t errCode, Parcel &parcel)
{
if (callback_ == nullptr) {
ACCOUNT_LOGI("callback_ is nullptr");
return;
}
Parcel resultParcel;
std::shared_ptr<DomainAuthResult> authResult(DomainAuthResult::Unmarshalling(parcel));
if (authResult == nullptr) {
ACCOUNT_LOGE("authResult is nullptr");
return;
return callback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, resultParcel);
}
if ((errCode == ERR_OK) && (userId_ != 0)) {
InnerDomainAccountManager::GetInstance().InsertTokenToMap(userId_, (*authResult).token);
@ -137,16 +142,12 @@ void InnerDomainAuthCallback::OnResult(const int32_t errCode, Parcel &parcel)
}
(void)memset_s(authResult->token.data(), authResult->token.size(), 0, authResult->token.size());
authResult->token.clear();
Parcel resultParcel;
if (!(*authResult).Marshalling(resultParcel)) {
ACCOUNT_LOGE("authResult Marshalling failed");
return;
return callback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, resultParcel);
}
AccountInfoReport::ReportSecurityInfo("", userId_, ReportEvent::EVENT_LOGIN, errCode);
if (callback_ == nullptr) {
ACCOUNT_LOGI("callback_ is nullptr");
return;
}
return callback_->OnResult(errCode, resultParcel);
}
@ -172,15 +173,21 @@ ErrCode InnerDomainAccountManager::RegisterPlugin(const sptr<IDomainAccountPlugi
return ERR_OK;
}
void InnerDomainAccountManager::UnregisterPlugin()
ErrCode InnerDomainAccountManager::UnregisterPlugin()
{
std::lock_guard<std::mutex> lock(mutex_);
if (callingUid_ != IPCSkeleton::GetCallingUid()) {
ACCOUNT_LOGE("Failed to check callingUid, register callingUid=%{public}d, unregister callingUid=%{public}d.",
callingUid_, IPCSkeleton::GetCallingUid());
return ERR_ACCOUNT_COMMON_PERMISSION_DENIED;
}
if ((plugin_ != nullptr) && (plugin_->AsObject() != nullptr)) {
plugin_->AsObject()->RemoveDeathRecipient(deathRecipient_);
}
plugin_ = nullptr;
callingUid_ = -1;
deathRecipient_ = nullptr;
return ERR_OK;
}
ErrCode InnerDomainAccountManager::StartAuth(const sptr<IDomainAccountPlugin> &plugin, const DomainAccountInfo &info,
@ -1789,7 +1796,7 @@ ErrCode InnerDomainAccountManager::UpdateAccountInfo(
}
}
}
// update local info
return IInnerOsAccountManager::GetInstance().UpdateAccountInfoByDomainAccountInfo(
userId, newDomainAccountInfo);

View File

@ -214,22 +214,20 @@ ErrCode OsAccountInterface::SendToIDMAccountDelete(OsAccountInfo &osAccountInfo)
}
// wait callback
struct tm startTime = {0};
struct tm nowTime = {0};
OHOS::GetSystemCurrentTime(&startTime);
OHOS::GetSystemCurrentTime(&nowTime);
while (OHOS::GetSecondsBetween(startTime, nowTime) < Constants::TIME_WAIT_TIME_OUT &&
!callback->isCalled_) {
std::this_thread::sleep_for(std::chrono::milliseconds(Constants::WAIT_ONE_TIME));
OHOS::GetSystemCurrentTime(&nowTime);
}
if (!callback->isCalled_) {
ACCOUNT_LOGE("idm did not call back! timeout!");
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_REMOVE, -1,
"UserIDM erase user timeout");
FinishTraceAdapter();
return ERR_OK; // do not return fail
{
std::unique_lock<std::mutex> lck(callback->mutex_);
if (!callback->isCalled_) {
callback->onResultCondition_.wait_for(lck, std::chrono::seconds(Constants::TIME_WAIT_TIME_OUT));
}
if (!callback->isCalled_) {
ACCOUNT_LOGE("idm did not call back! timeout!");
ReportOsAccountOperationFail(osAccountInfo.GetLocalId(), Constants::OPERATION_REMOVE, -1,
"UserIDM erase user timeout");
FinishTraceAdapter();
return ERR_OK; // do not return fail
}
}
ACCOUNT_LOGI("send to idm account delete and get callback succeed!");
FinishTraceAdapter();
return ERR_OK;