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 64fb1958d8a9bea9787725b0caafefedd632664b..4a70e670f0702d801617ba30e8a4b7c1dc65f772 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 ab5eafb814d5d51f2003036360b0d9ef5177dab0..deb855590590804fe15d36ca2a5c8d06cd094ddd 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))();