1 /* 2 * Copyright (c) 2023 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_INCLUDE_BUNDLE_OVERLAY_DATA_MANAGER_H 17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_OVERLAY_DATA_MANAGER_H 18 19 #include "bundle_data_mgr.h" 20 #include "singleton.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { 24 class OverlayDataMgr final : public DelayedSingleton<OverlayDataMgr> { 25 public: 26 OverlayDataMgr() = default; 27 virtual ~OverlayDataMgr() = default; 28 29 bool IsExistedNonOverlayHap(const std::string &bundleName); 30 31 ErrCode UpdateOverlayInfo(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo, 32 InnerBundleInfo &targetInnerBundleInfo); 33 34 ErrCode UpdateInternalOverlayInfo(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 35 36 ErrCode UpdateExternalOverlayInfo(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo, 37 InnerBundleInfo &targetInnerBundleInfo); 38 39 ErrCode BuildOverlayConnection(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 40 41 ErrCode GetBundleDir(const std::string &moduleHapPath, std::string &bundleDir) const; 42 43 ErrCode RemoveOverlayModuleConnection(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 44 45 void RemoveOverlayBundleInfo(const std::string &bundleName, InnerBundleInfo &targetInnerBundleInfo); 46 47 void RemoveOverlayModuleInfo(const std::string &bundleName, const std::string &modulePackage, 48 InnerBundleInfo &oldInfo, InnerBundleInfo &targetInnerBundleInfo); 49 50 void BuildInternalOverlayConnection(const std::string &moduleName, InnerBundleInfo &oldInfo, int32_t userId); 51 52 bool QueryOverlayInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info); 53 54 ErrCode SaveInternalOverlayModuleState(const OverlayModuleInfo &overlayModuleInfo, 55 InnerBundleInfo &innerBundleInfo); 56 57 ErrCode SaveExternalOverlayModuleState(const OverlayModuleInfo &overlayModuleInfo, 58 const InnerBundleInfo &targetInnerBundleInfo, int32_t userId, InnerBundleInfo &innerBundleInfo); 59 60 void ResetInternalOverlayModuleState(const std::map<std::string, InnerModuleInfo> &innerModuleInfos, 61 const std::string &modulePackage, InnerBundleInfo &oldInfo); 62 63 ErrCode GetAllOverlayModuleInfo(const std::string &bundleName, std::vector<OverlayModuleInfo> &overlayModuleInfos, 64 int32_t userId); 65 66 ErrCode GetOverlayModuleInfo(const std::string &bundleName, const std::string &moduleName, 67 OverlayModuleInfo &overlayModuleInfo, int32_t userId); 68 69 ErrCode GetOverlayBundleInfoForTarget(const std::string &targetBundleName, 70 std::vector<OverlayBundleInfo> &overlayBundleInfo, int32_t userId); 71 72 ErrCode GetOverlayModuleInfoForTarget(const std::string &targetBundleName, const std::string &targetModuleName, 73 std::vector<OverlayModuleInfo> &overlayModuleInfo, int32_t userId); 74 75 ErrCode SetOverlayEnabled(const std::string &bundleName, const std::string &moduleName, bool isEnabled, 76 int32_t userId); 77 78 std::string GetCallingBundleName(); 79 80 void AddOverlayModuleStates(const InnerBundleInfo &innerBundleInfo, InnerBundleUserInfo &userInfo); 81 82 ErrCode UpdateOverlayModule(const InnerBundleInfo &newInfo, InnerBundleInfo &oldInfo); 83 84 private: 85 ErrCode GetBundleDataMgr(); 86 87 std::map<std::string, int32_t> GetModulesStateFromUserInfo(const InnerBundleUserInfo &userInfo) const; 88 89 ErrCode ObtainOverlayModuleState(OverlayModuleInfo &overlayModuleInfo, int32_t userId); 90 91 ErrCode GetOverlayModuleInfoForTarget(const InnerBundleInfo &innerBundleInfo, 92 std::vector<OverlayModuleInfo> &overlayModuleInfo, int32_t userId); 93 94 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; 95 }; 96 } // AppExecFwk 97 } // OHOS 98 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_OVERLAY_DATA_MANAGER_H