• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_HAPPARSERV2_H
17 #define OHOS_RESOURCE_MANAGER_HAPPARSERV2_H
18 
19 #include "hap_parser.h"
20 
21 #include "hap_resource_v2.h"
22 #include "res_config_impl.h"
23 
24 namespace OHOS {
25 namespace Global {
26 namespace Resource {
27 class HapParserV2 : public HapParser {
28 public:
29     HapParserV2();
30 
31     virtual ~HapParserV2();
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     static int32_t ParseResInfo(uint32_t &offset, ResInfo &resInfo, const size_t bufLen, const uint8_t *buf);
40 
41     static int32_t ParseConfigItem(uint32_t &offset, ConfigItem &resInfo, const size_t bufLen, const uint8_t *buf);
42 
43     static int32_t ParseStringArray(uint32_t &offset, std::vector<std::string> &values, size_t bufLen, uint8_t *buf);
44 
45     static int32_t ParseString(uint32_t &offset, std::string &id, size_t bufLen, uint8_t *buf);
46 private:
47     bool GetIndexMmap(const char *path);
48 
49     bool GetIndexMmapFromHap(const char *path);
50 
51     bool GetIndexMmapFromIndex(const char *path);
52 
53     int32_t ParseHeader(uint32_t &offset);
54 
55     int32_t ParseKeys(uint32_t &offset);
56 
57     int32_t ParseKey(uint32_t &offset, std::shared_ptr<KeyInfo> key);
58 
59     int32_t ParseKeyParam(uint32_t &offset, std::shared_ptr<KeyParam> keyParam);
60 
61     void GetLimitKeyValue(KeyType type);
62 
63     int32_t ParseIds(uint32_t &offset);
64 
65     int32_t ParseType(uint32_t &offset);
66 
67     int32_t ParseItem(uint32_t &offset, const TypeInfo &typeInfo);
68 
69     std::shared_ptr<MmapFile> mMapFile_{nullptr};
70 
71     ResIndexHeader resHeader_;
72 
73     IdsHeader idsHeader_;
74 
75     // <resconfig id, resconfig>
76     std::unordered_map<uint32_t, std::shared_ptr<ResConfigImpl>> keys_;
77 
78     // <resource id, resource>
79     std::unordered_map<uint32_t, std::shared_ptr<IdValuesV2>> idMap_;
80 
81     // <type, <resource name, resource>>
82     std::unordered_map<uint32_t, std::unordered_map<std::string, std::shared_ptr<IdValuesV2>>> typeNameMap_;
83 
84     // judge the resource is adapt dark mode or not.
85     bool hasDarkRes_{false};
86 };
87 } // namespace Resource
88 } // namespace Global
89 } // namespace OHOS
90 #endif
91