• 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 "inner_bundle_info.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 enum class NotifyType {
29     INSTALL = 1,
30     UPDATE,
31     UNINSTALL_BUNDLE,
32     UNINSTALL_MODULE,
33     ABILITY_ENABLE,
34     APPLICATION_ENABLE,
35     BUNDLE_DATA_CLEARED,
36     BUNDLE_CACHE_CLEARED,
37     OVERLAY_INSTALL,
38     OVERLAY_UPDATE,
39     OVERLAY_STATE_CHANGED,
40 };
41 
42 enum class SandboxInstallType : uint32_t {
43     INSTALL = 0,
44     UNINSTALL,
45 };
46 
47 struct NotifyBundleEvents {
48     std::string bundleName = "";
49     std::string modulePackage = "";
50     std::string abilityName = "";
51     ErrCode resultCode = ERR_OK;
52     NotifyType type = NotifyType::INSTALL;
53     int32_t uid = 0;
54     uint32_t accessTokenId = 0;
55     bool isAgingUninstall = false;
56 };
57 
58 class BundleCommonEventMgr {
59 public:
60     BundleCommonEventMgr();
61     virtual ~BundleCommonEventMgr() = default;
62     void NotifyBundleStatus(const NotifyBundleEvents &installResult,
63         const std::shared_ptr<BundleDataMgr> &dataMgr);
64     ErrCode NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId,
65         const SandboxInstallType &type);
66     void NotifyOverlayModuleStateStatus(const std::string &bundleName, const std::string &moduleName, bool isEnabled,
67         int32_t userId, int32_t uid);
68 
69 private:
70     std::string GetCommonEventData(const NotifyType &type);
71     void Init();
72 
73     std::unordered_map<NotifyType, std::string> commonEventMap_;
74 };
75 } // AppExecFwk
76 } // OHOS
77 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H