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 16 #ifndef OHOS_RESOURCE_MANAGER_HAPPARSERV1_H 17 #define OHOS_RESOURCE_MANAGER_HAPPARSERV1_H 18 19 #include "hap_parser.h" 20 21 namespace OHOS { 22 namespace Global { 23 namespace Resource { 24 class HapParserV1 : public HapParser { 25 public: 26 HapParserV1(); 27 28 HapParserV1(std::shared_ptr<ResConfigImpl> &defaultConfig, uint32_t selectedTypes, 29 bool loadAll, bool isUpdate = false); 30 31 virtual ~HapParserV1(); 32 33 virtual bool Init(const char *path); 34 35 virtual int32_t ParseResHex(); 36 37 virtual std::shared_ptr<HapResource> GetHapResource(const char *path, bool isSystem, bool isOverlay); 38 39 void SetResDesc(std::shared_ptr<ResDesc> &resDesc); 40 GetResDesc()41 inline const std::shared_ptr<ResDesc> GetResDesc() 42 { 43 return resDesc_; 44 } 45 private: 46 int32_t ParseKey(uint32_t &offset, std::shared_ptr<ResKey> key, bool &match, std::vector<bool> &keyTypes); 47 48 bool getKeyParams(uint32_t &offset, uint32_t paramsCount, bool &match, std::vector<bool> &keyTypes, 49 std::vector<std::shared_ptr<KeyParam>> &keyParams); 50 51 int32_t ParseKeyParam(uint32_t &offset, bool &match, std::shared_ptr<KeyParam> &kp); 52 53 void GetLimitKeyValue(KeyType type, std::vector<bool> &keyTypes); 54 55 bool SkipParseItem(const std::shared_ptr<ResKey> &key, bool &match); 56 57 int32_t ParseId(uint32_t &offset, std::shared_ptr<ResId> id); 58 59 int32_t ParseIdItem(uint32_t &offset, std::shared_ptr<IdItem> idItem); 60 61 int32_t ParseStringArray(uint32_t &offset, std::vector<std::string> &values); 62 63 int32_t ParseString(uint32_t &offset, std::string &id, bool includeTemi = true); 64 65 std::unique_ptr<uint8_t[]> buffer_{nullptr}; 66 size_t bufLen_{0}; 67 std::shared_ptr<ResDesc> resDesc_{std::make_shared<ResDesc>()}; 68 std::shared_ptr<ResConfigImpl> defaultConfig_{nullptr}; 69 uint32_t selectedTypes_{SELECT_ALL}; 70 std::string deviceType_; 71 std::vector<std::string> deviceTypes_; 72 bool loadAll_{false}; 73 bool isUpdate_{false}; 74 }; 75 } // namespace Resource 76 } // namespace Global 77 } // namespace OHOS 78 #endif 79