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 a798cd391e4e599edd295420b9216de9f476986c..e3b4d3e93a9f77948fd1ec22e835fb03eec3af43 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 f640d7abf6320dec4c101480a05843acea9154ab..f6d917f3caba3a3b16a0615ba9a074006203a172 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 707a5468a6e857190c45a1eedd4d750571162e36..6dbc42205ce8d7aa54891d0666dd686b1691f657 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 8033b7f10e2c0304f6400db97e24818d8babb043..4e9aaea6d821b8d29993ddf111bda1ba8416167c 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 6844d16bc5b7d9168a973de6d51c9b16f149957e..31536b973b1d54b1d5c214988e4461a5b51ccb35 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) {