• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H
18 
19 #include <functional>
20 #include <unordered_map>
21 
22 #include "appexecfwk_errors.h"
23 #include "bundle_data_mgr.h"
24 #include "disposed_rule.h"
25 #include "inner_bundle_info.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 enum class NotifyType : uint8_t {
30     INSTALL = 1,
31     UPDATE,
32     UNINSTALL_BUNDLE,
33     UNINSTALL_MODULE,
34     ABILITY_ENABLE,
35     APPLICATION_ENABLE,
36     BUNDLE_DATA_CLEARED,
37     BUNDLE_CACHE_CLEARED,
38     OVERLAY_INSTALL,
39     OVERLAY_UPDATE,
40     OVERLAY_STATE_CHANGED,
41     DISPOSED_RULE_ADDED,
42     DISPOSED_RULE_DELETED,
43     START_INSTALL,
44     UNINSTALL_STATE,
45 };
46 
47 enum class SandboxInstallType : uint8_t {
48     INSTALL = 0,
49     UNINSTALL,
50 };
51 
52 struct NotifyBundleEvents {
53     bool isAgingUninstall = false;
54     bool isBmsExtensionUninstalled = false;
55     bool isModuleUpdate = false;
56     bool isAppUpdate = false;
57     NotifyType type = NotifyType::INSTALL;
58     ErrCode resultCode = ERR_OK;
59     uint32_t accessTokenId = 0;
60     int32_t uid = 0;
61     int32_t bundleType = 0;
62     int32_t atomicServiceModuleUpgrade = 0;
63     int32_t appIndex = 0;
64     std::string bundleName = "";
65     std::string modulePackage = "";
66     std::string abilityName = "";
67     std::string appId;
68     std::string appIdentifier;
69     std::string appDistributionType;
70     std::string developerId;
71     std::string assetAccessGroups;
72     bool keepData = false;
73     bool isBundleExist = false;
74     bool crossAppSharedConfig = false;
75     bool isRecover = false;
76 };
77 
78 class BundleCommonEventMgr {
79 public:
80     BundleCommonEventMgr();
81     virtual ~BundleCommonEventMgr() = default;
82     void NotifyBundleStatus(const NotifyBundleEvents &installResult,
83         const std::shared_ptr<BundleDataMgr> &dataMgr);
84     ErrCode NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,
85         const SandboxInstallType &type);
86     void NotifyOverlayModuleStateStatus(const std::string &bundleName, const std::string &moduleName, bool isEnabled,
87         int32_t userId, int32_t uid);
88     void NotifySetDiposedRule(const std::string &appId, int32_t userId, const std::string &data, int32_t appIndex);
89     void NotifyDeleteDiposedRule(const std::string &appId, int32_t userId, int32_t appIndex);
90     void NotifyDynamicIconEvent(
91         const std::string &bundleName, bool isEnableDynamicIcon, int32_t userId, int32_t appIndex);
92     void NotifyBundleResourcesChanged(const int32_t userId, const uint32_t type);
93     void NotifyDefaultAppChanged(const int32_t userId, std::vector<std::string> &utdIdVec);
94     void NotifyPluginEvents(const NotifyBundleEvents &event, const std::shared_ptr<BundleDataMgr> &dataMgr);
95     void NotifyShortcutVisibleChanged(
96         const std::string &bundlename, const std::string &id, int32_t userId, int32_t appIndex, bool visible);
97 private:
98     std::string GetCommonEventData(const NotifyType &type);
99     void SetNotifyWant(OHOS::AAFwk::Want& want, const NotifyBundleEvents &installResult);
100     bool PublishCommonEvent(const std::string &bundleName, const std::string &action,
101         const int32_t publishUserId, const EventFwk::CommonEventData &commonData);
102     bool ProcessBundleChangedEventForOtherUsers(const std::shared_ptr<BundleDataMgr> &dataMgr,
103         const std::string &bundleName, const std::string &action, const int32_t publishUserId,
104         const EventFwk::CommonEventData &commonData);
105     void Init();
106 
107     std::unordered_map<NotifyType, std::string> commonEventMap_;
108     std::set<std::string> eventSet_;
109 };
110 } // AppExecFwk
111 } // OHOS
112 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H