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 }; 38 39 enum class SandboxInstallType : uint32_t { 40 INSTALL = 0, 41 UNINSTALL, 42 }; 43 44 struct NotifyBundleEvents { 45 std::string bundleName = ""; 46 std::string modulePackage = ""; 47 std::string abilityName = ""; 48 ErrCode resultCode = ERR_OK; 49 NotifyType type = NotifyType::INSTALL; 50 int32_t uid = 0; 51 uint32_t accessTokenId = 0; 52 bool isAgingUninstall = false; 53 }; 54 55 class BundleCommonEventMgr { 56 public: 57 BundleCommonEventMgr(); 58 virtual ~BundleCommonEventMgr() = default; 59 void NotifyBundleStatus(const NotifyBundleEvents &installResult, 60 const std::shared_ptr<BundleDataMgr> &dataMgr); 61 ErrCode NotifySandboxAppStatus(const InnerBundleInfo &info, int32_t uid, int32_t userId, 62 const SandboxInstallType &type); 63 64 private: 65 std::string GetCommonEventData(const NotifyType &type); 66 void Init(); 67 68 std::unordered_map<NotifyType, std::string> commonEventMap_; 69 }; 70 } // AppExecFwk 71 } // OHOS 72 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_COMMON_EVENT_MGR_H