From 82eba2565a7cfc3c0758da2c698704b49660cff6 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 7 Jun 2022 18:17:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B9=B6=E5=8F=91=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=97=B6client=20core=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/include/bundle_active_client.h | 3 +++ interfaces/innerkits/src/bundle_active_client.cpp | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index c7668f2..c396903 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -16,6 +16,8 @@ #ifndef BUNDLE_ACTIVE_CLIENT_H #define BUNDLE_ACTIVE_CLIENT_H +#include + #include "ibundle_active_service.h" #include "bundle_active_package_stats.h" #include "bundle_active_event.h" @@ -135,6 +137,7 @@ public: private: bool GetBundleActiveProxy(); sptr bundleActiveProxy_; + std::mutex mutex_; }; } // namespace DeviceUsageStats } // namespace OHOS diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index efaf269..c29ff3b 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -30,6 +30,10 @@ BundleActiveClient& BundleActiveClient::GetInstance() bool BundleActiveClient::GetBundleActiveProxy() { + if (bundleActiveProxy_ != nullptr) { + return true; + } + std::lock_guard lock(mutex_); sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); @@ -44,7 +48,7 @@ bool BundleActiveClient::GetBundleActiveProxy() bundleActiveProxy_ = iface_cast(object); if (!bundleActiveProxy_) { - BUNDLE_ACTIVE_LOGE("Failed to get BundleActiveClient."); + BUNDLE_ACTIVE_LOGE("Failed to get BundleActiveProxy."); return false; } return true; -- Gitee