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