mirror of
https://gitee.com/openharmony/telephony_core_service
synced 2024-11-27 02:00:45 +00:00
!2465 Bugfix for CoreServiceClient lifecyle.
Merge pull request !2465 from harrey/work
This commit is contained in:
commit
7f4ab30c77
@ -31,6 +31,9 @@ CoreServiceClient::CoreServiceClient() = default;
|
||||
CoreServiceClient::~CoreServiceClient()
|
||||
{
|
||||
RemoveDeathRecipient(nullptr, false);
|
||||
if (deathRecipient_ != nullptr) {
|
||||
reinterpret_cast<CoreServiceDeathRecipient*>(deathRecipient_.GetRefPtr())->SetValid(false);
|
||||
}
|
||||
}
|
||||
|
||||
sptr<ICoreService> CoreServiceClient::GetProxy()
|
||||
|
@ -16,6 +16,7 @@
|
||||
#ifndef CORE_SERVICE_CLIENT_H
|
||||
#define CORE_SERVICE_CLIENT_H
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <iremote_object.h>
|
||||
#include <singleton.h>
|
||||
@ -1212,15 +1213,23 @@ private:
|
||||
void RemoveDeathRecipient(const wptr<IRemoteObject> &remote, bool isRemoteDied);
|
||||
class CoreServiceDeathRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
explicit CoreServiceDeathRecipient(CoreServiceClient &client) : client_(client) {}
|
||||
explicit CoreServiceDeathRecipient(CoreServiceClient &client) : client_(client), isValid_(true) {}
|
||||
~CoreServiceDeathRecipient() override = default;
|
||||
__attribute__((no_sanitize("cfi"))) void OnRemoteDied(const wptr<IRemoteObject> &remote) override
|
||||
{
|
||||
if (isValid_.load()) {
|
||||
client_.OnRemoteDied(remote);
|
||||
}
|
||||
}
|
||||
|
||||
void SetValid(bool isValid)
|
||||
{
|
||||
isValid_.store(isValid);
|
||||
}
|
||||
|
||||
private:
|
||||
CoreServiceClient &client_;
|
||||
std::atomic_bool isValid_;
|
||||
};
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user