1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_RESOURCE_MANAGER_HAPRESOURCEV1_H 16 #define OHOS_RESOURCE_MANAGER_HAPRESOURCEV1_H 17 18 #include "hap_resource.h" 19 20 namespace OHOS { 21 namespace Global { 22 namespace Resource { 23 class ValueUnderQualifierDirV1 : public ValueUnderQualifierDir { 24 public: 25 ValueUnderQualifierDirV1(const std::shared_ptr<ResKey> &resKey, const std::shared_ptr<IdItem> &idItem, 26 const std::pair<std::string, std::string> &resPath, bool isOverlay = false, bool isSystemResource = false); 27 28 virtual ~ValueUnderQualifierDirV1(); 29 30 virtual std::shared_ptr<IdItem> GetIdItem() const; 31 private: 32 friend class HapResourceV1; 33 34 // the value 35 std::shared_ptr<IdItem> idItem_; 36 }; 37 38 class IdValuesV1 : public IdValues { 39 public: 40 virtual ~IdValuesV1(); 41 42 virtual const std::vector<std::shared_ptr<ValueUnderQualifierDir>> &GetLimitPathsConst() const; 43 AddLimitPath(std::shared_ptr<ValueUnderQualifierDirV1> vuqd)44 inline void AddLimitPath(std::shared_ptr<ValueUnderQualifierDirV1> vuqd) 45 { 46 limitPaths_.push_back(vuqd); 47 } 48 private: 49 // the folder desc 50 std::vector<std::shared_ptr<ValueUnderQualifierDir>> limitPaths_; 51 }; 52 53 /** 54 * HapResource describe a resource of hap zip file. 55 * 56 */ 57 class HapResourceV1 : public HapResource { 58 public: 59 HapResourceV1(const std::string path, time_t lastModTime, std::shared_ptr<ResDesc> resDes, 60 bool isSystem = false, bool isOverlay = false); 61 virtual ~HapResourceV1(); 62 virtual bool IsSystemResource() const; 63 virtual bool IsOverlayResource() const; 64 virtual const std::shared_ptr<IdValues> GetIdValues(const uint32_t id); 65 virtual const std::shared_ptr<IdValues> GetIdValuesByName(const std::string name, const ResType resType); 66 virtual RState Update(std::shared_ptr<ResConfigImpl> &defaultConfig); 67 virtual std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> BuildNameTypeIdMapping(); 68 virtual void GetLocales(std::set<std::string> &outValue, bool includeSystem); 69 virtual void UpdateOverlayInfo(std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> &nameTypeId); 70 71 bool Init(std::shared_ptr<ResConfigImpl> &defaultConfig); 72 SetSelectedType(uint32_t type)73 inline void SetSelectedType(uint32_t type) 74 { 75 selectedTypes_ = type; 76 } 77 private: 78 friend class HapResourceManager; 79 friend class HapParser; 80 81 void IsAppDarkRes(const std::shared_ptr<ValueUnderQualifierDir> &limitPath, 82 std::shared_ptr<ResConfigImpl> &defaultConfig); 83 84 RState UpdateResConfig(std::shared_ptr<ResConfigImpl> &defaultConfig); 85 86 bool InitIdList(std::shared_ptr<ResConfigImpl> &defaultConfig); 87 88 bool InitMap(const std::shared_ptr<ResKey> &resKey, const std::pair<std::string, std::string> &resPath, 89 std::shared_ptr<ResConfigImpl> &defaultConfig); 90 91 // resource information stored in resDesc_ 92 std::shared_ptr<ResDesc> resDesc_; 93 94 std::set<std::shared_ptr<ResConfigImpl>> loadedConfig_; 95 96 std::map<uint32_t, std::shared_ptr<IdValuesV1>> idValuesMap_; 97 98 // the key is name, each restype holds one map 99 // name may conflict in same restype ! 100 std::vector<std::shared_ptr<std::map<std::string, std::shared_ptr<IdValuesV1>>>> idValuesNameMap_; 101 102 uint32_t selectedTypes_{SELECT_ALL}; 103 104 // judge the hap resource is system or not. 105 bool isSystem_; 106 107 // judge the hap resource is overlay or not. 108 bool isOverlay_; 109 }; 110 } 111 } 112 } 113 #endif 114