From b82586f581d449766c7203e4027a40046c33bdd0 Mon Sep 17 00:00:00 2001 From: Cuiziyuan Date: Tue, 8 Jul 2025 22:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cuiziyuan --- .../data_share/data_share_service_impl.cpp | 1 + .../data_share/sys_event_subscriber.cpp | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp index 64fb1958d..4a70e670f 100644 --- a/services/distributeddataservice/service/data_share/data_share_service_impl.cpp +++ b/services/distributeddataservice/service/data_share/data_share_service_impl.cpp @@ -1243,6 +1243,7 @@ void DataShareServiceImpl::InitSubEvent() EventFwk::MatchingSkills matchingSkills; matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED); matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON); diff --git a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp index ab5eafb81..deb855590 100644 --- a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp +++ b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp @@ -42,20 +42,22 @@ void SysEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& event) { EventFwk::Want want = event.GetWant(); std::string action = want.GetAction(); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED || - action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { + auto installEvent = installCallbacks_.find(action); + if (installEvent != installCallbacks_.end()) { std::string bundleName = want.GetElement().GetBundleName(); int32_t userId = want.GetIntParam(USER_ID, -1); int32_t appIndex = want.GetIntParam(APP_INDEX, 0); - auto tokenId = want.GetIntParam(ACCESS_TOKEN_ID, -1); - bool isCrossAppSharedConfig = want.GetBoolParam(CROSS_APP_SHARED_CONFIG, false); - ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d, isCrossAppSharedConfig:%{public}d", - bundleName.c_str(), userId, appIndex, isCrossAppSharedConfig); - auto installEvent = installCallbacks_.find(action); - if (installEvent != installCallbacks_.end()) { - (this->*(installEvent->second))(bundleName, userId, appIndex, tokenId, isCrossAppSharedConfig); + int32_t tokenId = want.GetIntParam(ACCESS_TOKEN_ID, -1); + // when application updated, the tokenId in event's want is 0, so use other way to get tokenId + if (tokenId == 0) { + tokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, appIndex); } + bool isCrossAppSharedConfig = want.GetBoolParam(CROSS_APP_SHARED_CONFIG, false); + ZLOGI("bundleName:%{public}s, user:%{public}d, appIndex:%{public}d, tokenId:%{public}d, " + "isCrossAppSharedConfig:%{public}d", bundleName.c_str(), userId, appIndex, tokenId, isCrossAppSharedConfig); + (this->*(installEvent->second))(bundleName, userId, appIndex, tokenId, isCrossAppSharedConfig); } + auto it = callbacks_.find(action); if (it != callbacks_.end()) { (this->*(it->second))(); -- Gitee