!2213 AppAccountAuthenticatorSession SA多线程给authenticatorProxy_添加锁

Merge pull request !2213 from zhenghui/master
This commit is contained in:
openharmony_ci 2024-10-31 09:52:03 +00:00 committed by Gitee
commit d74b0526d1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 3 additions and 1 deletions

View File

@ -95,6 +95,7 @@ private:
int32_t OnAddAccountImplicitlyDone(const AAFwk::Want &result) const;
private:
std::mutex mutex_;
sptr<SessionConnection> conn_ = nullptr;
sptr<SessionClientDeathRecipient> clientDeathRecipient_ = nullptr;
sptr<SessionServerDeathRecipient> serverDeathRecipient_ = nullptr;

View File

@ -139,6 +139,7 @@ ErrCode AppAccountAuthenticatorSession::Open()
void AppAccountAuthenticatorSession::Close()
{
std::lock_guard<std::mutex> lock(mutex_);
if ((authenticatorProxy_ != nullptr) && (authenticatorProxy_->AsObject() != nullptr)) {
authenticatorProxy_->AsObject()->RemoveDeathRecipient(serverDeathRecipient_);
}
@ -174,11 +175,11 @@ ErrCode AppAccountAuthenticatorSession::AddClientDeathRecipient()
void AppAccountAuthenticatorSession::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode)
{
std::lock_guard<std::mutex> lock(mutex_);
isConnected_ = true;
AAFwk::Want errResult;
authenticatorProxy_ = iface_cast<IAppAccountAuthenticator>(remoteObject);
if ((!authenticatorProxy_) || (!authenticatorProxy_->AsObject())) {
ACCOUNT_LOGE("failed to cast app account authenticator proxy");
OnResult(ERR_JS_ACCOUNT_AUTHENTICATOR_SERVICE_EXCEPTION, errResult);
return;
}