Signed-off-by: xuchenghua <xuchenghua09@huawei.com>
Change-Id: Iaec481e163d55c6c2737b34332153cc698ff3f6f
This commit is contained in:
xuchenghua 2022-05-23 19:46:07 +08:00
parent e9e1f2c4d4
commit 47744b278a
2 changed files with 17 additions and 5 deletions

View File

@ -94,8 +94,14 @@ void DataAbilityHelper::AddDataAbilityDeathRecipient(const sptr<IRemoteObject> &
token->RemoveDeathRecipient(callerDeathRecipient_);
}
if (callerDeathRecipient_ == nullptr) {
std::weak_ptr<DataAbilityHelper> thisWeakPtr(shared_from_this());
callerDeathRecipient_ =
new DataAbilityDeathRecipient(std::bind(&DataAbilityHelper::OnSchedulerDied, this, std::placeholders::_1));
new DataAbilityDeathRecipient([thisWeakPtr](const wptr<IRemoteObject> &remote) {
auto dataAbilityHelper = thisWeakPtr.lock();
if (dataAbilityHelper) {
dataAbilityHelper->OnSchedulerDied(remote);
}
});
}
if (token != nullptr) {
HILOG_INFO("token AddDeathRecipient.");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@ -184,10 +184,16 @@ void DataObsMgrInner::AddObsDeathRecipient(const sptr<IDataAbilityObserver> &dat
HILOG_ERROR("%{public}s this death recipient has been added.", __func__);
return;
} else {
std::weak_ptr<DataObsMgrInner> thisWeakPtr(shared_from_this());
sptr<IRemoteObject::DeathRecipient> deathRecipient =
new DataObsCallbackRecipient(std::bind(&DataObsMgrInner::OnCallBackDied, this, std::placeholders::_1));
dataObserver->AsObject()->AddDeathRecipient(deathRecipient);
recipientMap_.emplace(dataObserver->AsObject(), deathRecipient);
new DataObsCallbackRecipient([thisWeakPtr](const wptr<IRemoteObject> &remote) {
auto dataObsMgrInner = thisWeakPtr.lock();
if (dataObsMgrInner) {
dataObsMgrInner->OnCallBackDied(remote);
}
});
dataObserver->AsObject()->AddDeathRecipient(deathRecipient);
recipientMap_.emplace(dataObserver->AsObject(), deathRecipient);
}
}