• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RESOURCE_MANAGER_IMPL_H
17 #define RESOURCE_MANAGER_IMPL_H
18 
19 #include "application_context.h"
20 #include "resource_manager.h"
21 #include "ffi_remote_data.h"
22 #include "resource_manager_interface.h"
23 #include "drawable_descriptor/drawable_descriptor.h"
24 
25 #include <cstdint>
26 #include <string>
27 
28 namespace OHOS::Resource {
29 
30 class ResourceManagerImpl : public virtual IResourceManager, public OHOS::FFI::FFIData {
31 public:
32     DECL_TYPE(ResourceManagerImpl, OHOS::FFI::FFIData);
33 
34     explicit ResourceManagerImpl(OHOS::AbilityRuntime::Context* context);
35 
36     ResourceManagerImpl();
37 
38     ResourceManagerImpl(std::string bundleName, std::shared_ptr<Global::Resource::ResourceManager> resMgr,
39         std::shared_ptr<AbilityRuntime::Context> context);
40 
41     bool IsEmpty();
42 
43     int32_t CloseRawFd(const std::string &name) override;
44 
45     int32_t GetRawFd(const std::string &rawFileName,
46         Global::Resource::ResourceManager::RawFileDescriptor &descriptor) override;
47 
48     int32_t GetRawFileContent(const std::string &name, size_t &len, std::unique_ptr<uint8_t[]> &outValue) override;
49 
50     int32_t GetRawFileList(const std::string &rawDirPath, std::vector<std::string>& rawfileList) override;
51 
52     int32_t GetPluralStringValue(uint32_t resId, int64_t num, std::string &outValue) override;
53 
54     int32_t GetPluralStringValue(const char *name, int64_t num, std::string &outValue) override;
55 
56     int32_t GetStringArrayValue(uint32_t resId, std::vector<std::string> &outValue) override;
57 
58     int32_t GetStringArrayByName(const char *name, std::vector<std::string> &outValue) override;
59 
60     int32_t GetString(uint32_t resId, std::string &outValue) override;
61 
62     int32_t GetStringByName(const char *name, std::string &outValue) override;
63 
64     int32_t AddResource(const char *path) override;
65 
66     int32_t RemoveResource(const char *path) override;
67 
68     int32_t GetColorByName(const char *name, uint32_t &outValue) override;
69 
70     int32_t GetColorById(uint32_t id, uint32_t &outValue) override;
71 
72     int32_t GetBooleanById(uint32_t id, bool &outValue) override;
73 
74     int32_t GetBooleanByName(const char *name, bool &outValue) override;
75 
76     int32_t GetIntegerById(uint32_t id, int &outValue) override;
77 
78     int32_t GetIntegerByName(const char *name, int &outValue) override;
79 
80     int32_t GetFloatById(uint32_t id, float &outValue) override;
81 
82     int32_t GetFloatByName(const char *name, float &outValue) override;
83 
84     void GetConfiguration(Configuration &configuration) override;
85 
86     void GetConfiguration(ConfigurationEx *configuration) override;
87 
88     void GetOverrideConfiguration(ConfigurationEx *configuration) override;
89 
90     void GetDeviceCapability(DeviceCapability &deviceCapability) override;
91 
92     int32_t GetMediaDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
93         uint32_t density) override;
94 
95     int32_t GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
96         uint32_t density) override;
97 
98     int32_t GetMediaContentBase64ById(uint32_t id, std::string &outValue, uint32_t density) override;
99 
100     int32_t GetMediaContentBase64ByName(const char *name, std::string &outValue, uint32_t density) override;
101 
102     int32_t GetDrawableDescriptor(uint32_t id, int64_t &outValue, uint32_t density) override;
103 
104     int32_t GetDrawableDescriptorByName(const char *name, int64_t &outValue, uint32_t density) override;
105 
106     void GetLocales(bool includeSystem, std::vector<std::string> &outValue) override;
107 
108     int32_t GetSymbolById(uint32_t id, uint32_t &outValue) override;
109 
110     int32_t GetSymbolByName(const char *name, uint32_t &outValue) override;
111 
112     std::shared_ptr<Global::Resource::ResourceManager> GetOverrideResMgr(ConfigurationEx &configuration,
113         int32_t &errCode) override;
114 
115     bool GetHapResourceManager(Global::Resource::ResourceManager::Resource resource,
116         std::shared_ptr<Global::Resource::ResourceManager> &resMgr, uint32_t &resId);
117 
118     std::string GetBundleName();
119 
120     std::shared_ptr<AbilityRuntime::Context> GetContext();
121 private:
122     std::shared_ptr<Global::Resource::ResourceManager> resMgr_;
123     bool isSystem_ = false;
124     std::string bundleName_;
125     std::shared_ptr<AbilityRuntime::Context> context_;
126     bool isOverride_ = false;
127 };
128 
129 class DrawableDescriptorImpl : public OHOS::FFI::FFIData {
130 public:
131     DECL_TYPE(DrawableDescriptorImpl, OHOS::FFI::FFIData);
DrawableDescriptorImpl(OHOS::Ace::Napi::DrawableDescriptor * drawableDescriptor)132     explicit DrawableDescriptorImpl(OHOS::Ace::Napi::DrawableDescriptor* drawableDescriptor)
133         :drawableDescriptor_(std::shared_ptr<OHOS::Ace::Napi::DrawableDescriptor>(drawableDescriptor)){};
134 private:
135     std::shared_ptr<OHOS::Ace::Napi::DrawableDescriptor> drawableDescriptor_;
136 };
137 
138 OHOS::Ace::Napi::DrawableDescriptor* GetDrawableDescriptorPtr(uint32_t id,
139     std::shared_ptr<Global::Resource::ResourceManager> resMgr, uint32_t density, Global::Resource::RState &state);
140 } // namespace OHOS::Resource
141 
142 #endif // RESOURCE_MANAGER_IMPL_H
143