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_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_PARSER_H
17 #define FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_PARSER_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "resource_info.h"
23 #include "resource_manager.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 class BundleResourceParser {
28 public:
29     BundleResourceParser();
30 
31     ~BundleResourceParser();
32     // parse label and icon
33     bool ParseResourceInfo(const int32_t userId, ResourceInfo &resourceInfo);
34 
35     // parse label and icon
36     bool ParseResourceInfos(const int32_t userId, std::vector<ResourceInfo> &resourceInfos);
37 
38     // parse icon resource by hapPath
39     bool ParseIconResourceByPath(const std::string &hapPath, const uint32_t iconId, ResourceInfo &resourceInfo);
40 
41     // parse clone bundle resource info
42     bool ParserCloneResourceInfo(const int32_t appIndex, std::vector<ResourceInfo> &resourceInfos);
43 
44 private:
45     // for defaultIconPath is empty, icon and label exist in same hap.
46     bool ParseResourceInfoWithSameHap(const int32_t userId, ResourceInfo &resourceInfo);
47 
48     // parse label resource by hapPath
49     bool ParseLabelResourceByPath(const std::string &hapPath, const uint32_t labelId, std::string &label);
50 
51     bool ParseResourceInfoByResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> resourceManager,
52         ResourceInfo &resourceInfo);
53 
54     // parse label resource by resourceManager
55     bool ParseLabelResourceByResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> resourceManager,
56         const uint32_t labelId, std::string &label);
57 
58     // parse foreground/background/mask icons resource by resourceManager
59     bool ParseIconResourceByResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> resourceManager,
60         ResourceInfo &resourceInfo);
61 
62     bool ParseForegroundAndBackgroundResource(
63         const std::shared_ptr<Global::Resource::ResourceManager> resourceManager,
64         const std::string &jsonBuff, const int32_t density, ResourceInfo &resourceInfo);
65 
66     bool ParseIconIdFromJson(const std::string &jsonBuff, uint32_t &foregroundId, uint32_t &backgroundId);
67 
68     bool GetMediaDataById(const std::shared_ptr<Global::Resource::ResourceManager> resourceManager,
69         const uint32_t iconId, const int32_t density, std::vector<uint8_t> &data);
70 
71     bool IsNeedToParseResourceInfo(const ResourceInfo &newResourceInfo, const ResourceInfo &oldResourceInfo);
72 
73     void ProcessSpecialBundleResource(const int32_t userId, std::vector<ResourceInfo> &resourceInfos);
74 };
75 } // AppExecFwk
76 } // OHOS
77 #endif // FOUNDATION_BUNDLEMANAGER_BUNDLE_FRAMEWORK_SERVICES_BUNDLEMGR_BUNDLE_RESOURCE_PARSER_H
78