1 /*
2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "bundle_common_event_mgr.h"
17
18 #include "account_helper.h"
19 #include "app_log_tag_wrapper.h"
20 #include "bundle_common_event.h"
21 #include "bundle_util.h"
22 #include "common_event_manager.h"
23 #include "common_event_support.h"
24 #include "ffrt.h"
25 #include "ipc_skeleton.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 constexpr const char* ACCESS_TOKEN_ID = "accessTokenId";
31 constexpr const char* IS_AGING_UNINSTALL = "isAgingUninstall";
32 constexpr const char* APP_ID = "appId";
33 constexpr const char* IS_MODULE_UPDATE = "isModuleUpdate";
34 constexpr const char* IS_ENABLE_DYNAMIC_ICON = "isEnableDynamicIcon";
35 constexpr const char* BUNDLE_RESOURCES_CHANGED = "usual.event.BUNDLE_RESOURCES_CHANGED";
36 constexpr const char* APP_IDENTIFIER = "appIdentifier";
37 constexpr const char* APP_DISTRIBUTION_TYPE = "appDistributionType";
38 constexpr const char* BUNDLE_TYPE = "bundleType";
39 constexpr const char* ATOMIC_SERVICE_MODULE_UPGRADE = "atomicServiceModuleUpgrade";
40 constexpr const char* UID = "uid";
41 constexpr const char* SANDBOX_APP_INDEX = "sandbox_app_index";
42 constexpr const char* BUNDLE_RESOURCE_CHANGE_TYPE = "bundleResourceChangeType";
43 constexpr const char* APP_INDEX = "appIndex";
44 constexpr const char* TYPE = "type";
45 constexpr const char* RESULT_CODE = "resultCode";
46 constexpr const char* IS_APP_UPDATE = "isAppUpdate";
47 constexpr const char* KEEP_DATA = "keepData";
48 constexpr const char* PERMISSION_GET_DISPOSED_STATUS = "ohos.permission.GET_DISPOSED_APP_STATUS";
49 constexpr const char* ASSET_ACCESS_GROUPS = "assetAccessGroups";
50 constexpr const char* DEVELOPERID = "developerId";
51 constexpr const char* CHANGE_DEFAULT_APPLICATION = "ohos.permission.CHANGE_DEFAULT_APPLICATION";
52 constexpr const char* UTD_IDS = "utdIds";
53 constexpr const char* BUNDLE_NAME = "bundleName";
54 constexpr const char* USER_ID = "userId";
55 constexpr const char* SHORTCUT_CHANGED = "usual.event.SHORTCUT_CHANGED";
56 constexpr const char* SHORTCUT_ID = "shortcutId";
57 constexpr const char* MANAGE_SHORTCUTS = "ohos.permission.MANAGE_SHORTCUTS";
58 constexpr const char* IS_BUNDLE_EXIST = "isBundleExist";
59 constexpr const char* CROSS_APP_SHARED_CONFIG = "crossAppSharedConfig";
60 constexpr const char* IS_RECOVER = "isRecover";
61 }
62
BundleCommonEventMgr()63 BundleCommonEventMgr::BundleCommonEventMgr()
64 {
65 APP_LOGI_NOFUNC("enter BundleCommonEventMgr");
66 Init();
67 }
68
Init()69 void BundleCommonEventMgr::Init()
70 {
71 commonEventMap_ = {
72 { NotifyType::INSTALL, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED },
73 { NotifyType::UNINSTALL_BUNDLE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED },
74 { NotifyType::UNINSTALL_MODULE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED },
75 { NotifyType::UPDATE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED },
76 { NotifyType::ABILITY_ENABLE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED },
77 { NotifyType::UNINSTALL_STATE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED },
78 { NotifyType::APPLICATION_ENABLE, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED },
79 { NotifyType::BUNDLE_DATA_CLEARED, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED },
80 { NotifyType::BUNDLE_CACHE_CLEARED, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CACHE_CLEARED },
81 { NotifyType::OVERLAY_INSTALL, OVERLAY_ADD_ACTION},
82 { NotifyType::OVERLAY_UPDATE, OVERLAY_CHANGED_ACTION},
83 { NotifyType::START_INSTALL, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_INSTALLATION_STARTED },
84 };
85 eventSet_ = {
86 EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED,
87 EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED,
88 EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED,
89 EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CACHE_CLEARED,
90 OVERLAY_ADD_ACTION,
91 OVERLAY_CHANGED_ACTION,
92 };
93 }
94
NotifyBundleStatus(const NotifyBundleEvents & installResult,const std::shared_ptr<BundleDataMgr> & dataMgr)95 void BundleCommonEventMgr::NotifyBundleStatus(const NotifyBundleEvents &installResult,
96 const std::shared_ptr<BundleDataMgr> &dataMgr)
97 {
98 APP_LOGD("notify type %{public}d with %{public}d for %{public}s-%{public}s in %{public}s",
99 static_cast<int32_t>(installResult.type), installResult.resultCode, installResult.modulePackage.c_str(),
100 installResult.abilityName.c_str(), installResult.bundleName.c_str());
101 OHOS::AAFwk::Want want;
102 SetNotifyWant(want, installResult);
103 EventFwk::CommonEventData commonData { want };
104 // trigger BundleEventCallback first
105 if (dataMgr != nullptr && !(want.GetAction() == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED &&
106 installResult.resultCode != ERR_OK)) {
107 LOG_I(BMS_TAG_DEFAULT, "eventBack begin");
108 dataMgr->NotifyBundleEventCallback(commonData);
109 LOG_I(BMS_TAG_DEFAULT, "eventBack end");
110 }
111
112 uint8_t installType = ((installResult.type == NotifyType::UNINSTALL_BUNDLE) ||
113 (installResult.type == NotifyType::UNINSTALL_MODULE)) ?
114 static_cast<uint8_t>(InstallType::UNINSTALL_CALLBACK) :
115 static_cast<uint8_t>(InstallType::INSTALL_CALLBACK);
116 int32_t bundleUserId = BundleUtil::GetUserIdByUid(installResult.uid);
117 int32_t publishUserId = (bundleUserId == Constants::DEFAULT_USERID || bundleUserId == Constants::U1) ?
118 AccountHelper::GetCurrentActiveUserId() : bundleUserId;
119
120 // trigger the status callback for status listening
121 if ((dataMgr != nullptr) && (installResult.type != NotifyType::START_INSTALL)) {
122 auto &callbackMutex = dataMgr->GetStatusCallbackMutex();
123 std::shared_lock<ffrt::shared_mutex> lock(callbackMutex);
124 auto callbackList = dataMgr->GetCallBackList();
125 for (const auto& callback : callbackList) {
126 int32_t callbackUserId = callback->GetUserId();
127 if (callbackUserId != Constants::UNSPECIFIED_USERID && callbackUserId != publishUserId) {
128 LOG_W(BMS_TAG_DEFAULT, "not callback userId %{public}d incorrect", callbackUserId);
129 continue;
130 }
131 if (callback->GetBundleName() == installResult.bundleName) {
132 // if the msg needed, it could convert in the proxy node
133 callback->OnBundleStateChanged(installType, installResult.resultCode, Constants::EMPTY_STRING,
134 installResult.bundleName);
135 }
136 }
137 }
138
139 if (installResult.resultCode != ERR_OK || installResult.isBmsExtensionUninstalled) {
140 APP_LOGI("install ret: %{public}d, extension: %{public}d",
141 installResult.resultCode, installResult.isBmsExtensionUninstalled);
142 return;
143 }
144
145 std::string identity = IPCSkeleton::ResetCallingIdentity();
146 (void)PublishCommonEvent(installResult.bundleName, want.GetAction(), publishUserId, commonData);
147 (void)ProcessBundleChangedEventForOtherUsers(dataMgr, installResult.bundleName,
148 want.GetAction(), publishUserId, commonData);
149 IPCSkeleton::SetCallingIdentity(identity);
150 }
151
PublishCommonEvent(const std::string & bundleName,const std::string & action,const int32_t publishUserId,const EventFwk::CommonEventData & commonData)152 bool BundleCommonEventMgr::PublishCommonEvent(
153 const std::string &bundleName,
154 const std::string &action,
155 const int32_t publishUserId,
156 const EventFwk::CommonEventData &commonData)
157 {
158 if (eventSet_.find(action) != eventSet_.end()) {
159 EventFwk::CommonEventPublishInfo publishInfo;
160 std::vector<std::string> permissionVec { Constants::LISTEN_BUNDLE_CHANGE };
161 publishInfo.SetSubscriberPermissions(permissionVec);
162 publishInfo.SetBundleName(bundleName);
163 publishInfo.SetSubscriberType(EventFwk::SubscriberType::SYSTEM_SUBSCRIBER_TYPE);
164 publishInfo.SetValidationRule(EventFwk::ValidationRule::OR);
165 if (!EventFwk::CommonEventManager::PublishCommonEventAsUser(commonData, publishInfo, publishUserId)) {
166 APP_LOGE("PublishCommonEventAsUser failed, userId:%{public}d", publishUserId);
167 return false;
168 }
169 } else {
170 if (!EventFwk::CommonEventManager::PublishCommonEventAsUser(commonData, publishUserId)) {
171 APP_LOGE("PublishCommonEventAsUser failed, userId:%{public}d", publishUserId);
172 return false;
173 }
174 }
175 return true;
176 }
ProcessBundleChangedEventForOtherUsers(const std::shared_ptr<BundleDataMgr> & dataMgr,const std::string & bundleName,const std::string & action,const int32_t publishUserId,const EventFwk::CommonEventData & commonData)177 bool BundleCommonEventMgr::ProcessBundleChangedEventForOtherUsers(
178 const std::shared_ptr<BundleDataMgr> &dataMgr,
179 const std::string &bundleName,
180 const std::string &action,
181 const int32_t publishUserId,
182 const EventFwk::CommonEventData &commonData)
183 {
184 if (action != EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) {
185 return false;
186 }
187 if (dataMgr == nullptr) {
188 APP_LOGE("dataMgr is nullptr -n %{public}s", bundleName.c_str());
189 return false;
190 }
191 auto userIds = dataMgr->GetUserIds(bundleName);
192 if (userIds.size() <= 1) {
193 APP_LOGD("-n %{public}s only has one user", bundleName.c_str());
194 return false;
195 }
196 EventFwk::CommonEventPublishInfo publishInfo;
197 std::vector<std::string> permissionVec { Constants::LISTEN_BUNDLE_CHANGE };
198 publishInfo.SetSubscriberPermissions(permissionVec);
199 for (const auto &userId : userIds) {
200 if (userId == publishUserId) {
201 continue;
202 }
203 APP_LOGI("-n %{public}s publish change event for -u %{public}d", bundleName.c_str(), userId);
204 if (!EventFwk::CommonEventManager::PublishCommonEventAsUser(commonData, publishInfo, userId)) {
205 APP_LOGE("PublishCommonEventAsUser failed, userId:%{public}d", userId);
206 }
207 }
208 return true;
209 }
210
SetNotifyWant(OHOS::AAFwk::Want & want,const NotifyBundleEvents & installResult)211 void BundleCommonEventMgr::SetNotifyWant(OHOS::AAFwk::Want& want, const NotifyBundleEvents &installResult)
212 {
213 std::string eventData = GetCommonEventData(installResult.type);
214 APP_LOGD("will send event data %{public}s", eventData.c_str());
215 want.SetAction(eventData);
216 ElementName element;
217 element.SetBundleName(installResult.bundleName);
218 element.SetModuleName(installResult.modulePackage);
219 element.SetAbilityName(installResult.abilityName);
220 want.SetElement(element);
221 want.SetParam(Constants::BUNDLE_NAME, installResult.bundleName);
222 want.SetParam(Constants::UID, installResult.uid);
223 want.SetParam(Constants::USER_ID, BundleUtil::GetUserIdByUid(installResult.uid));
224 want.SetParam(Constants::ABILITY_NAME, installResult.abilityName);
225 want.SetParam(ACCESS_TOKEN_ID, static_cast<int32_t>(installResult.accessTokenId));
226 want.SetParam(IS_AGING_UNINSTALL, installResult.isAgingUninstall);
227 want.SetParam(APP_ID, installResult.appId);
228 want.SetParam(IS_MODULE_UPDATE, installResult.isModuleUpdate);
229 want.SetParam(APP_IDENTIFIER, installResult.appIdentifier);
230 want.SetParam(APP_DISTRIBUTION_TYPE, installResult.appDistributionType);
231 want.SetParam(BUNDLE_TYPE, installResult.bundleType);
232 want.SetParam(ATOMIC_SERVICE_MODULE_UPGRADE, installResult.atomicServiceModuleUpgrade);
233 want.SetParam(APP_INDEX, installResult.appIndex);
234 want.SetParam(TYPE, static_cast<int32_t>(installResult.type));
235 want.SetParam(RESULT_CODE, installResult.resultCode);
236 want.SetParam(IS_APP_UPDATE, installResult.isAppUpdate);
237 want.SetParam(KEEP_DATA, installResult.keepData);
238 if (want.GetAction() == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED
239 && !installResult.assetAccessGroups.empty()) {
240 want.SetParam(ASSET_ACCESS_GROUPS, installResult.assetAccessGroups);
241 want.SetParam(DEVELOPERID, installResult.developerId);
242 }
243 want.SetParam(IS_BUNDLE_EXIST, installResult.isBundleExist);
244 want.SetParam(CROSS_APP_SHARED_CONFIG, installResult.crossAppSharedConfig);
245 want.SetParam(IS_RECOVER, installResult.isRecover);
246 }
247
NotifySandboxAppStatus(const InnerBundleInfo & info,int32_t uid,int32_t userId,const SandboxInstallType & type)248 ErrCode BundleCommonEventMgr::NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,
249 const SandboxInstallType &type)
250 {
251 OHOS::AAFwk::Want want;
252 if (type == SandboxInstallType::INSTALL) {
253 want.SetAction(COMMON_EVENT_SANDBOX_PACKAGE_ADDED);
254 } else if (type == SandboxInstallType::UNINSTALL) {
255 want.SetAction(COMMON_EVENT_SANDBOX_PACKAGE_REMOVED);
256 } else {
257 return ERR_APPEXECFWK_SANDBOX_INSTALL_UNKNOWN_INSTALL_TYPE;
258 }
259 ElementName element;
260 element.SetBundleName(info.GetBundleName());
261 element.SetAbilityName(info.GetMainAbility());
262 want.SetElement(element);
263 want.SetParam(UID, uid);
264 want.SetParam(Constants::USER_ID, userId);
265 want.SetParam(Constants::ABILITY_NAME, info.GetMainAbility());
266 want.SetParam(SANDBOX_APP_INDEX, info.GetAppIndex());
267 want.SetParam(ACCESS_TOKEN_ID, static_cast<int32_t>(info.GetAccessTokenId(userId)));
268 want.SetParam(APP_ID, info.GetAppId());
269 EventFwk::CommonEventData commonData { want };
270 EventFwk::CommonEventPublishInfo publishInfo;
271 std::vector<std::string> permissionVec { Constants::LISTEN_BUNDLE_CHANGE };
272 publishInfo.SetSubscriberPermissions(permissionVec);
273 std::string identity = IPCSkeleton::ResetCallingIdentity();
274 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
275 APP_LOGE("PublishCommonEvent failed");
276 }
277 IPCSkeleton::SetCallingIdentity(identity);
278 return ERR_OK;
279 }
280
NotifyOverlayModuleStateStatus(const std::string & bundleName,const std::string & moduleName,bool isEnabled,int32_t userId,int32_t uid)281 void BundleCommonEventMgr::NotifyOverlayModuleStateStatus(const std::string &bundleName,
282 const std::string &moduleName, bool isEnabled, int32_t userId, int32_t uid)
283 {
284 OHOS::AAFwk::Want want;
285 want.SetAction(OVERLAY_STATE_CHANGED);
286 ElementName element;
287 element.SetBundleName(bundleName);
288 element.SetModuleName(moduleName);
289 want.SetElement(element);
290 want.SetParam(UID, uid);
291 want.SetParam(Constants::USER_ID, userId);
292 want.SetParam(Constants::OVERLAY_STATE, isEnabled);
293 EventFwk::CommonEventData commonData { want };
294 EventFwk::CommonEventPublishInfo publishInfo;
295 std::vector<std::string> permissionVec { Constants::LISTEN_BUNDLE_CHANGE };
296 publishInfo.SetSubscriberPermissions(permissionVec);
297 std::string identity = IPCSkeleton::ResetCallingIdentity();
298 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
299 APP_LOGE("PublishCommonEvent failed");
300 }
301 IPCSkeleton::SetCallingIdentity(identity);
302 }
303
GetCommonEventData(const NotifyType & type)304 std::string BundleCommonEventMgr::GetCommonEventData(const NotifyType &type)
305 {
306 auto iter = commonEventMap_.find(type);
307 if (iter == commonEventMap_.end()) {
308 APP_LOGW("event type error");
309 return EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED;
310 }
311 return iter->second;
312 }
313
NotifySetDiposedRule(const std::string & appId,int32_t userId,const std::string & data,int32_t appIndex)314 void BundleCommonEventMgr::NotifySetDiposedRule(
315 const std::string &appId, int32_t userId, const std::string &data, int32_t appIndex)
316 {
317 OHOS::AAFwk::Want want;
318 want.SetAction(DISPOSED_RULE_ADDED);
319 want.SetParam(Constants::USER_ID, userId);
320 want.SetParam(APP_ID, appId);
321 want.SetParam(APP_INDEX, appIndex);
322 EventFwk::CommonEventData commonData { want };
323 commonData.SetData(data);
324 EventFwk::CommonEventPublishInfo publishInfo;
325 std::vector<std::string> permissionVec { PERMISSION_GET_DISPOSED_STATUS };
326 publishInfo.SetSubscriberPermissions(permissionVec);
327 std::string identity = IPCSkeleton::ResetCallingIdentity();
328 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
329 APP_LOGE("PublishCommonEvent failed");
330 }
331 IPCSkeleton::SetCallingIdentity(identity);
332 }
333
NotifyDeleteDiposedRule(const std::string & appId,int32_t userId,int32_t appIndex)334 void BundleCommonEventMgr::NotifyDeleteDiposedRule(const std::string &appId, int32_t userId, int32_t appIndex)
335 {
336 OHOS::AAFwk::Want want;
337 want.SetAction(DISPOSED_RULE_DELETED);
338 want.SetParam(Constants::USER_ID, userId);
339 want.SetParam(APP_ID, appId);
340 want.SetParam(APP_INDEX, appIndex);
341 EventFwk::CommonEventData commonData { want };
342 EventFwk::CommonEventPublishInfo publishInfo;
343 std::vector<std::string> permissionVec { PERMISSION_GET_DISPOSED_STATUS };
344 publishInfo.SetSubscriberPermissions(permissionVec);
345 std::string identity = IPCSkeleton::ResetCallingIdentity();
346 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
347 APP_LOGE("PublishCommonEvent failed");
348 }
349 IPCSkeleton::SetCallingIdentity(identity);
350 }
351
NotifyDynamicIconEvent(const std::string & bundleName,bool isEnableDynamicIcon,int32_t userId,int32_t appIndex)352 void BundleCommonEventMgr::NotifyDynamicIconEvent(
353 const std::string &bundleName, bool isEnableDynamicIcon, int32_t userId, int32_t appIndex)
354 {
355 APP_LOGI("NotifyDynamicIconEvent bundleName: %{public}s, %{public}d",
356 bundleName.c_str(), isEnableDynamicIcon);
357 OHOS::AAFwk::Want want;
358 want.SetAction(DYNAMIC_ICON_CHANGED);
359 ElementName element;
360 element.SetBundleName(bundleName);
361 want.SetElement(element);
362 want.SetParam(IS_ENABLE_DYNAMIC_ICON, isEnableDynamicIcon);
363 if ((userId != Constants::UNSPECIFIED_USERID) || (appIndex != Constants::DEFAULT_APP_INDEX)) {
364 want.SetParam(Constants::USER_ID, userId);
365 want.SetParam(Constants::APP_INDEX, appIndex);
366 }
367 EventFwk::CommonEventData commonData { want };
368 EventFwk::CommonEventPublishInfo publishInfo;
369 std::string identity = IPCSkeleton::ResetCallingIdentity();
370 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
371 APP_LOGE("PublishCommonEvent failed");
372 }
373 IPCSkeleton::SetCallingIdentity(identity);
374 }
375
NotifyBundleResourcesChanged(const int32_t userId,const uint32_t type)376 void BundleCommonEventMgr::NotifyBundleResourcesChanged(const int32_t userId, const uint32_t type)
377 {
378 OHOS::AAFwk::Want want;
379 want.SetAction(BUNDLE_RESOURCES_CHANGED);
380 want.SetParam(Constants::USER_ID, userId);
381 want.SetParam(BUNDLE_RESOURCE_CHANGE_TYPE, static_cast<int32_t>(type));
382 EventFwk::CommonEventData commonData { want };
383 EventFwk::CommonEventPublishInfo publishInfo;
384 std::vector<std::string> permissionVec { ServiceConstants::PERMISSION_GET_BUNDLE_RESOURCES };
385 publishInfo.SetSubscriberPermissions(permissionVec);
386 std::string identity = IPCSkeleton::ResetCallingIdentity();
387 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
388 APP_LOGE("PublishCommonEvent failed");
389 }
390 IPCSkeleton::SetCallingIdentity(identity);
391 }
392
NotifyDefaultAppChanged(const int32_t userId,std::vector<std::string> & utdIdVec)393 void BundleCommonEventMgr::NotifyDefaultAppChanged(const int32_t userId, std::vector<std::string> &utdIdVec)
394 {
395 OHOS::AAFwk::Want want;
396 want.SetAction(DEFAULT_APPLICATION_CHANGED);
397 want.SetParam(Constants::USER_ID, userId);
398 want.SetParam(UTD_IDS, utdIdVec);
399 EventFwk::CommonEventData commonData { want };
400 EventFwk::CommonEventPublishInfo publishInfo;
401 std::vector<std::string> permissionVec { CHANGE_DEFAULT_APPLICATION };
402 publishInfo.SetSubscriberPermissions(permissionVec);
403 std::string identity = IPCSkeleton::ResetCallingIdentity();
404 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
405 APP_LOGE("Publish defaultApp changed event failed");
406 }
407 IPCSkeleton::SetCallingIdentity(identity);
408 }
409
NotifyPluginEvents(const NotifyBundleEvents & event,const std::shared_ptr<BundleDataMgr> & dataMgr)410 void BundleCommonEventMgr::NotifyPluginEvents(const NotifyBundleEvents &event,
411 const std::shared_ptr<BundleDataMgr> &dataMgr)
412 {
413 OHOS::AAFwk::Want want;
414 std::string eventData = GetCommonEventData(event.type);
415 want.SetAction(eventData);
416 ElementName element;
417 element.SetBundleName(event.bundleName);
418 element.SetModuleName(event.modulePackage);
419 want.SetElement(element);
420 want.SetParam(Constants::BUNDLE_NAME, event.bundleName);
421 want.SetParam(BUNDLE_TYPE, event.bundleType);
422 want.SetParam(Constants::UID, event.uid);
423 EventFwk::CommonEventData commonData { want };
424 if (dataMgr != nullptr) {
425 LOG_I(BMS_TAG_DEFAULT, "pluginEventBack begin");
426 dataMgr->NotifyPluginEventCallback(commonData);
427 LOG_I(BMS_TAG_DEFAULT, "pluginEventBack end");
428 }
429 }
430
431
NotifyShortcutVisibleChanged(const std::string & bundlename,const std::string & id,int32_t userId,int32_t appIndex,bool visible)432 void BundleCommonEventMgr::NotifyShortcutVisibleChanged(
433 const std::string &bundlename, const std::string &id, int32_t userId, int32_t appIndex, bool visible)
434 {
435 OHOS::AAFwk::Want want;
436 want.SetAction(SHORTCUT_CHANGED);
437 ElementName element;
438 element.SetBundleName(bundlename);
439 want.SetElement(element);
440 want.SetParam(SHORTCUT_ID, id);
441 want.SetParam(USER_ID, userId);
442 want.SetParam(APP_INDEX, appIndex);
443 want.SetParam("visible", visible);
444 EventFwk::CommonEventData commonData { want };
445 EventFwk::CommonEventPublishInfo publishInfo;
446 std::vector<std::string> permissionVec { MANAGE_SHORTCUTS };
447 publishInfo.SetSubscriberPermissions(permissionVec);
448 std::string identity = IPCSkeleton::ResetCallingIdentity();
449 if (!EventFwk::CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
450 APP_LOGE("PublishCommonEvent failed");
451 }
452 IPCSkeleton::SetCallingIdentity(identity);
453 }
454 } // AppExecFwk
455 } // OHOS