From 7a8868cb9a746f275d51e58102407586e299abc6 Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Thu, 6 Jul 2023 16:05:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=AD=BB=E4=BA=A1=E5=9B=9E=E8=B0=83=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../native/backup_kit_inner/src/b_session_backup.cpp | 1 + .../native/backup_kit_inner/src/b_session_restore.cpp | 1 + frameworks/native/backup_kit_inner/src/service_proxy.cpp | 7 +++++++ .../inner_api/native/backup_kit_inner/impl/service_proxy.h | 1 + tests/mock/backup_kit_inner/service_proxy_mock.cpp | 5 +++++ 5 files changed, 15 insertions(+) diff --git a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp index a798cd391..e3b4d3e93 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_backup.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_backup.cpp @@ -76,6 +76,7 @@ void BSessionBackup::RegisterBackupServiceDied(std::function functor) } auto callback = [functor](const wptr &obj) { + ServiceProxy::InvaildInstance(); HILOGI("Backup service died"); functor(); }; diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index f640d7abf..f6d917f3c 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -125,6 +125,7 @@ void BSessionRestore::RegisterBackupServiceDied(std::function functor) auto callback = [functor](const wptr &obj) { HILOGI("Backup service died"); + ServiceProxy::InvaildInstance(); functor(); }; deathRecipient_ = sptr(new SvcDeathRecipient(callback)); diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 707a5468a..6dbc42205 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -319,6 +319,13 @@ sptr ServiceProxy::GetInstance() return serviceProxy_; } +void ServiceProxy::InvaildInstance() +{ + HILOGI("invalid instance"); + unique_lock lock(proxyMutex_); + serviceProxy_ = nullptr; +} + void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr &remoteObject) { diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index 8033b7f10..4e9aaea6d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -46,6 +46,7 @@ public: public: static sptr GetInstance(); + static void InvaildInstance(); public: class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub { diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 6844d16bc..31536b973 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -110,6 +110,11 @@ sptr ServiceProxy::GetInstance() return serviceProxy_; } +void ServiceProxy::InvaildInstance() +{ + serviceProxy_ = nullptr; +} + void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilitySuccess(int32_t systemAbilityId, const OHOS::sptr &remoteObject) { -- Gitee