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() void DomainAccountClient::RestoreListenerRecords()
{ {
std::lock_guard<std::mutex> lock(recordMutex_);
if (listenerManager_ == nullptr) { if (listenerManager_ == nullptr) {
ACCOUNT_LOGI("listenerManager_ is nullptr"); ACCOUNT_LOGI("listenerManager_ is nullptr");
return; return;

View File

@ -35,7 +35,7 @@ class InnerDomainAccountManager {
public: public:
static InnerDomainAccountManager &GetInstance(); static InnerDomainAccountManager &GetInstance();
ErrCode RegisterPlugin(const sptr<IDomainAccountPlugin> &plugin); ErrCode RegisterPlugin(const sptr<IDomainAccountPlugin> &plugin);
void UnregisterPlugin(); ErrCode UnregisterPlugin();
ErrCode Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password, ErrCode Auth(const DomainAccountInfo &info, const std::vector<uint8_t> &password,
const sptr<IDomainAccountCallback> &callback); const sptr<IDomainAccountCallback> &callback);
ErrCode AuthUser(int32_t userId, const std::vector<uint8_t> &password, 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() ErrCode DomainAccountManagerService::UnregisterPlugin()
{ {
InnerDomainAccountManager::GetInstance().UnregisterPlugin(); return InnerDomainAccountManager::GetInstance().UnregisterPlugin();
return ERR_OK;
} }
ErrCode DomainAccountManagerService::HasDomainAccount( ErrCode DomainAccountManagerService::HasDomainAccount(

View File

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

View File

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