1 /* 2 * Copyright (c) 2024 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_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H 17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H 18 19 #include "extend_resource_manager_host.h" 20 #include "inner_bundle_info.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { 24 class ExtendResourceManagerHostImpl : public ExtendResourceManagerHost { 25 public: 26 ExtendResourceManagerHostImpl(); 27 virtual ~ExtendResourceManagerHostImpl(); 28 29 ErrCode AddExtResource( 30 const std::string &bundleName, const std::vector<std::string> &filePaths) override; 31 ErrCode RemoveExtResource( 32 const std::string &bundleName, const std::vector<std::string> &moduleNames) override; 33 ErrCode GetExtResource( 34 const std::string &bundleName, std::vector<std::string> &moduleNames) override; 35 ErrCode EnableDynamicIcon( 36 const std::string &bundleName, const std::string &moduleName) override; 37 ErrCode EnableDynamicIcon( 38 const std::string &bundleName, const std::string &moduleName, 39 const int32_t userId, const int32_t appIndex) override; 40 ErrCode DisableDynamicIcon(const std::string &bundleName) override; 41 ErrCode DisableDynamicIcon(const std::string &bundleName, 42 const int32_t userId, const int32_t appIndex) override; 43 ErrCode GetDynamicIcon(const std::string &bundleName, std::string &moduleName) override; 44 ErrCode GetDynamicIcon( 45 const std::string &bundleName, const int32_t userId, const int32_t appIndex, std::string &moduleName) override; 46 47 ErrCode CreateFd(const std::string &fileName, int32_t &fd, std::string &path) override; 48 49 ErrCode GetAllDynamicIconInfo(std::vector<DynamicIconInfo> &dynamicInfos) override; 50 51 ErrCode GetAllDynamicIconInfo(const int32_t userId, std::vector<DynamicIconInfo> &dynamicInfos) override; 52 53 ErrCode GetDynamicIconInfo(const std::string &bundleName, std::vector<DynamicIconInfo> &dynamicInfos) override; 54 55 private: 56 ErrCode BeforeAddExtResource( 57 const std::string &bundleName, const std::vector<std::string> &filePaths); 58 bool CheckFileParam(const std::string &filePath); 59 ErrCode ProcessAddExtResource( 60 const std::string &bundleName, const std::vector<std::string> &filePaths); 61 ErrCode CopyToTempDir(const std::string &bundleName, 62 const std::vector<std::string> &oldFilePaths, std::vector<std::string> &newFilePaths); 63 bool GetInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info); 64 void RollBack(const std::vector<std::string> &filePaths); 65 ErrCode MkdirIfNotExist(const std::string &dir); 66 ErrCode ParseExtendResourceFile( 67 const std::string &bundleName, 68 const std::vector<std::string> &filePaths, 69 std::vector<ExtendResourceInfo> &extendResourceInfos); 70 bool UpateExtResourcesDb(const std::string &bundleName, 71 const std::vector<ExtendResourceInfo> &extendResourceInfos); 72 bool RemoveExtResourcesDb( 73 const std::string &bundleName, const std::vector<std::string> &moduleNames); 74 void InnerSaveExtendResourceInfo( 75 const std::string &bundleName, const std::vector<std::string> &filePaths, 76 const std::vector<ExtendResourceInfo> &extendResourceInfos); 77 ErrCode CheckModuleExist( 78 const std::string &bundleName, const std::vector<std::string> &moduleNames, 79 std::vector<ExtendResourceInfo> &collectorExtResourceInfos); 80 void InnerRemoveExtendResources( 81 const std::string &bundleName, const std::vector<std::string> &moduleNames, 82 std::vector<ExtendResourceInfo> &extResourceInfos); 83 ErrCode GetExtendResourceInfo(const std::string &bundleName, 84 const std::string &moduleName, ExtendResourceInfo &extendResourceInfo, 85 const int32_t userId = Constants::UNSPECIFIED_USERID, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); 86 bool ParseBundleResource( 87 const std::string &bundleName, const ExtendResourceInfo &extendResourceInfo, 88 const int32_t userId = Constants::UNSPECIFIED_USERID, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); 89 void SendBroadcast(const std::string &bundleName, bool isEnableDynamicIcon, 90 const int32_t userId = Constants::UNSPECIFIED_USERID, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); 91 void SaveCurDynamicIcon(const std::string &bundleName, const std::string &moduleName, 92 const int32_t userId = Constants::UNSPECIFIED_USERID, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); 93 bool ResetBundleResourceIcon(const std::string &bundleName, 94 const int32_t userId = Constants::UNSPECIFIED_USERID, const int32_t appIndex = Constants::DEFAULT_APP_INDEX); 95 ErrCode CheckParamInvalid(const InnerBundleInfo &bundleInfo, 96 const int32_t userId, const int32_t appIndex); 97 bool IsNeedUpdateBundleResourceInfo(const std::string &bundleName, const int32_t userId); 98 bool CheckAcrossUserPermission(const int32_t userId); 99 bool CheckWhetherDynamicIconNeedProcess(const std::string &bundleName, const int32_t userId); 100 101 std::atomic<uint32_t> id_ = 0; 102 }; 103 } // AppExecFwk 104 } // OHOS 105 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICE_BUNDLEMGR_INCLUDE_EXTEND_RESOURCE_MANAGER_HOST_IMPL_H 106