1 /*
2  * Copyright (c) 2022 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 {
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 };
45 
46 enum class SandboxInstallType : uint32_t {
47     INSTALL = 0,
48     UNINSTALL,
49 };
50 
51 struct NotifyBundleEvents {
52     std::string bundleName = "";
53     std::string modulePackage = "";
54     std::string abilityName = "";
55     ErrCode resultCode = ERR_OK;
56     NotifyType type = NotifyType::INSTALL;
57     int32_t uid = 0;
58     uint32_t accessTokenId = 0;
59     bool isAgingUninstall = false;
60     bool isBmsExtensionUninstalled = false;
61     std::string appId;
62     std::string appIdentifier;
63     bool isModuleUpdate = false;
64     std::string appDistributionType;
65     int32_t bundleType = 0;
66     int32_t atomicServiceModuleUpgrade = 0;
67     int32_t appIndex = 0;
68     bool isApplicationEnabled = true;
69 };
70 
71 class BundleCommonEventMgr {
72 public:
73     BundleCommonEventMgr();
74     virtual ~BundleCommonEventMgr() = default;
75     void NotifyBundleStatus(const NotifyBundleEvents &installResult,
76         const std::shared_ptr<BundleDataMgr> &dataMgr);
77     ErrCode NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,
78         const SandboxInstallType &type);
79     void NotifyOverlayModuleStateStatus(const std::string &bundleName, const std::string &moduleName, bool isEnabled,
80         int32_t userId, int32_t uid);
81     void NotifySetDiposedRule(const std::string &appId, int32_t userId, const std::string &data, int32_t appIndex);
82     void NotifyDeleteDiposedRule(const std::string &appId, int32_t userId, int32_t appIndex);
83     void NotifyDynamicIconEvent(
84         const std::string &bundleName, bool isEnableDynamicIcon);
85     void NotifyBundleResourcesChanged(const int32_t userId, const uint32_t type);
86 
87 private:
88     std::string GetCommonEventData(const NotifyType &type);
89     void SetNotifyWant(OHOS::AAFwk::Want& want, const NotifyBundleEvents &installResult);
90     void Init();
91 
92     std::unordered_map<NotifyType, std::string> commonEventMap_;
93 };
94 } // AppExecFwk
95 } // OHOS
96 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H