• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 : 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     NotifyType type = NotifyType::INSTALL;
57     ErrCode resultCode = ERR_OK;
58     uint32_t accessTokenId = 0;
59     int32_t uid = 0;
60     int32_t bundleType = 0;
61     int32_t atomicServiceModuleUpgrade = 0;
62     int32_t appIndex = 0;
63     std::string bundleName = "";
64     std::string modulePackage = "";
65     std::string abilityName = "";
66     std::string appId;
67     std::string appIdentifier;
68     std::string appDistributionType;
69     std::string developerId;
70     std::string assetAccessGroups;
71 };
72 
73 class BundleCommonEventMgr {
74 public:
75     BundleCommonEventMgr();
76     virtual ~BundleCommonEventMgr() = default;
77     void NotifyBundleStatus(const NotifyBundleEvents &installResult,
78         const std::shared_ptr<BundleDataMgr> &dataMgr);
79     ErrCode NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,
80         const SandboxInstallType &type);
81     void NotifyOverlayModuleStateStatus(const std::string &bundleName, const std::string &moduleName, bool isEnabled,
82         int32_t userId, int32_t uid);
83     void NotifySetDiposedRule(const std::string &appId, int32_t userId, const std::string &data, int32_t appIndex);
84     void NotifyDeleteDiposedRule(const std::string &appId, int32_t userId, int32_t appIndex);
85     void NotifyDynamicIconEvent(
86         const std::string &bundleName, bool isEnableDynamicIcon);
87     void NotifyBundleResourcesChanged(const int32_t userId, const uint32_t type);
88 
89 private:
90     std::string GetCommonEventData(const NotifyType &type);
91     void SetNotifyWant(OHOS::AAFwk::Want& want, const NotifyBundleEvents &installResult);
92     void Init();
93 
94     std::unordered_map<NotifyType, std::string> commonEventMap_;
95 };
96 } // AppExecFwk
97 } // OHOS
98 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H