• 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 "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/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     bool IsEmpty();
39 
40     int32_t CloseRawFd(const std::string &name) override;
41 
42     int32_t GetRawFd(const std::string &rawFileName,
43         Global::Resource::ResourceManager::RawFileDescriptor &descriptor) override;
44 
45     int32_t GetRawFileContent(const std::string &name, size_t &len, std::unique_ptr<uint8_t[]> &outValue) override;
46 
47     int32_t GetRawFileList(const std::string &rawDirPath, std::vector<std::string>& rawfileList) override;
48 
49     int32_t GetPluralStringValue(uint32_t resId, int64_t num, std::string &outValue) override;
50 
51     int32_t GetPluralStringValue(const char *name, int64_t num, std::string &outValue) override;
52 
53     int32_t GetStringArrayValue(uint32_t resId, std::vector<std::string> &outValue) override;
54 
55     int32_t GetStringArrayByName(const char *name, std::vector<std::string> &outValue) override;
56 
57     int32_t GetString(uint32_t resId, std::string &outValue) override;
58 
59     int32_t GetStringByName(const char *name, std::string &outValue) override;
60 
61     int32_t AddResource(const char *path) override;
62 
63     int32_t RemoveResource(const char *path) override;
64 
65     int32_t GetColorByName(const char *name, uint32_t &outValue) override;
66 
67     int32_t GetColorById(uint32_t id, uint32_t &outValue) override;
68 
69     int32_t GetBooleanById(uint32_t id, bool &outValue) override;
70 
71     int32_t GetBooleanByName(const char *name, bool &outValue) override;
72 
73     int32_t GetIntegerById(uint32_t id, int &outValue) override;
74 
75     int32_t GetIntegerByName(const char *name, int &outValue) override;
76 
77     int32_t GetFloatById(uint32_t id, float &outValue) override;
78 
79     int32_t GetFloatByName(const char *name, float &outValue) override;
80 
81     void GetConfiguration(Configuration &configuration) override;
82 
83     void GetDeviceCapability(DeviceCapability &deviceCapability) override;
84 
85     int32_t GetMediaDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
86         uint32_t density) override;
87 
88     int32_t GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue,
89         uint32_t density) override;
90 
91     int32_t GetMediaContentBase64ById(uint32_t id, std::string &outValue, uint32_t density) override;
92 
93     int32_t GetMediaContentBase64ByName(const char *name, std::string &outValue, uint32_t density) override;
94 
95     int32_t GetDrawableDescriptor(uint32_t id, int64_t &outValue, uint32_t density) override;
96 
97     int32_t GetDrawableDescriptorByName(const char *name, int64_t &outValue, uint32_t density) override;
98 
99     void GetLocales(bool includeSystem, std::vector<std::string> &outValue) override;
100 
101     int32_t GetSymbolById(uint32_t id, uint32_t &outValue) override;
102 
103     int32_t GetSymbolByName(const char *name, uint32_t &outValue) override;
104 
105     bool GetHapResourceManager(Global::Resource::ResourceManager::Resource resource,
106         std::shared_ptr<Global::Resource::ResourceManager> &resMgr, uint32_t &resId);
107 private:
108     std::shared_ptr<Global::Resource::ResourceManager> resMgr_;
109     bool isSystem_ = false;
110     std::string bundleName_;
111     std::shared_ptr<AbilityRuntime::Context> context_;
112     std::string GetLocale(std::unique_ptr<Global::Resource::ResConfig> &cfg);
113 };
114 
115 class DrawableDescriptorImpl : public OHOS::FFI::FFIData {
116 public:
117     DECL_TYPE(DrawableDescriptorImpl, OHOS::FFI::FFIData);
DrawableDescriptorImpl(OHOS::Ace::Napi::DrawableDescriptor * drawableDescriptor)118     explicit DrawableDescriptorImpl(OHOS::Ace::Napi::DrawableDescriptor* drawableDescriptor)
119         :drawableDescriptor_(std::shared_ptr<OHOS::Ace::Napi::DrawableDescriptor>(drawableDescriptor)){};
120 private:
121     std::shared_ptr<OHOS::Ace::Napi::DrawableDescriptor> drawableDescriptor_;
122 };
123 
124 OHOS::Ace::Napi::DrawableDescriptor* GetDrawableDescriptorPtr(uint32_t id,
125     std::shared_ptr<Global::Resource::ResourceManager> resMgr, uint32_t density, Global::Resource::RState &state);
126 } // namespace OHOS::Resource
127 
128 #endif // RESOURCE_MANAGER_IMPL_H
129