1 /* 2 * Copyright (c) 2021-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 #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H 16 #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H 17 18 #include <map> 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include "hap_manager.h" 23 #include "resource_manager.h" 24 #include "res_config_impl.h" 25 #include "utils/psue_manager.h" 26 #include "theme_pack_manager.h" 27 28 namespace OHOS { 29 namespace Global { 30 namespace Resource { 31 class ResourceManagerImpl : public ResourceManager { 32 public: 33 ResourceManagerImpl(bool isOverrideResMgr = false); 34 35 ~ResourceManagerImpl(); 36 37 /** 38 * Init resource manager. 39 * 40 * @param isSystem indicate the resource manager is system or not. 41 * @return true if init success, else false 42 */ 43 bool Init(bool isSystem = false); 44 45 /** 46 * Init resource manager. 47 * 48 * @param hapManager hapManager. 49 * @return true if init success, else false 50 */ 51 bool Init(std::shared_ptr<HapManager> hapManager); 52 53 /** 54 * Add system resource to hap resource vector. 55 * 56 * @param systemResourceManager the system resource manager. 57 */ 58 void AddSystemResource(ResourceManagerImpl *systemResourceManager); 59 60 /** 61 * Add system resource to hap resource vector. 62 * 63 * @param systemResourceManager the system resource manager. 64 * @return true if AddSystemResource success, else false 65 */ 66 bool AddSystemResource(const std::shared_ptr<ResourceManagerImpl> &systemResourceManager); 67 68 /** 69 * Add resource path to hap paths 70 * @param path the resource path 71 * @param forceReload is reload resource 72 * @return true if add resource path success, else false 73 */ 74 virtual bool AddResource(const char *path, const uint32_t &selectedTypes = SELECT_ALL, 75 bool forceReload = false); 76 77 virtual bool AddPatchResource(const char *path, const char *patchPath); 78 79 /** 80 * Add resource path to overlay paths 81 * @param path the resource path 82 * @param overlayPaths the exist overlay resource path 83 * @return true if add resource path success, else false 84 */ 85 virtual bool AddResource(const std::string &path, const std::vector<std::string> &overlayPaths); 86 87 /** 88 * Remove resource path to overlay paths 89 * @param path the resource path 90 * @param overlayPaths the exist overlay resource path 91 * @return true if add resource path success, else false 92 */ 93 virtual bool RemoveResource(const std::string &path, const std::vector<std::string> &overlayPaths); 94 95 /** 96 * Add the overlay resource for current application 97 * 98 * @param path the overlay resource path 99 * @return true if add resource path success, else false 100 */ 101 virtual bool AddAppOverlay(const std::string &path); 102 103 /** 104 * Remove the overlay resource for current application 105 * 106 * @param path the overlay resource path 107 * @return true if add resource path success, else false 108 */ 109 virtual bool RemoveAppOverlay(const std::string &path); 110 111 /** 112 * Update the resConfig 113 * @param resConfig the resource config 114 * @return SUCCESS if the resConfig updated success, else HAP_INIT_FAILED 115 */ 116 virtual RState UpdateResConfig(ResConfig &resConfig, bool isUpdateTheme = false); 117 118 /** 119 * Get the resConfig 120 * @param resConfig the resource config 121 */ 122 virtual void GetResConfig(ResConfig &resConfig); 123 124 /** 125 * Get resConfig by id 126 * @param resId the resource Id 127 * @param resConfig the resource config 128 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 129 * @return SUCCESS if config exist, else NOT_FOUND 130 */ 131 virtual RState GetResConfigById(uint32_t resId, ResConfig &resConfig, uint32_t density = 0); 132 133 /** 134 * Get resConfig by name 135 * @param name the resource name 136 * @param type the resource type 137 * @param resConfig the resource config 138 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 139 * @return SUCCESS if config exist, else NOT_FOUND 140 */ 141 virtual RState GetResConfigByName(const std::string &name, const ResType type, 142 ResConfig &resConfig, uint32_t density = 0); 143 144 /** 145 * Get string resource by Id 146 * @param id the resource Id 147 * @param outValue the string resource write to 148 * @return SUCCESS if resource exist, else NOT_FOUND 149 */ 150 virtual RState GetStringById(uint32_t id, std::string &outValue); 151 152 /** 153 * Get string by resource name 154 * @param name the resource name 155 * @param outValue the resource write to 156 * @return SUCCESS if resource exist, else NOT_FOUND 157 */ 158 virtual RState GetStringByName(const char *name, std::string &outValue); 159 160 /** 161 * Get string format by resource id 162 * @param id the resource id 163 * @param outValue the resource write to 164 * @return SUCCESS if resource exist, else NOT_FOUND 165 */ 166 virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...); 167 168 /** 169 * Get string format by resource name 170 * @param name the resource name 171 * @param outValue the resource write to 172 * @return SUCCESS if resource exist, else NOT_FOUND 173 */ 174 virtual RState GetStringFormatByName(std::string &outValue, const char *name, ...); 175 176 /** 177 * Get the STRINGARRAY resource by resource id 178 * @param id the resource id 179 * @param outValue the resource write to 180 * @return SUCCESS if resource exist, else NOT_FOUND 181 */ 182 virtual RState GetStringArrayById(uint32_t id, std::vector<std::string> &outValue); 183 184 /** 185 * Get the STRINGARRAY resource by resource name 186 * @param name the resource name 187 * @param outValue the resource write to 188 * @return SUCCESS if resource exist, else NOT_FOUND 189 */ 190 virtual RState GetStringArrayByName(const char *name, std::vector<std::string> &outValue); 191 192 /** 193 * Get the PATTERN resource by resource id 194 * @param id the resource id 195 * @param outValue the resource write to 196 * @return SUCCESS if resource exist, else NOT_FOUND 197 */ 198 virtual RState GetPatternById(uint32_t id, std::map<std::string, std::string> &outValue); 199 200 /** 201 * Get the PATTERN resource by resource name 202 * @param name the resource name 203 * @param outValue the resource write to 204 * @return SUCCESS if resource exist, else NOT_FOUND 205 */ 206 virtual RState GetPatternByName(const char *name, std::map<std::string, std::string> &outValue); 207 208 /** 209 * Get the plural string by resource id 210 * @param id the resource id 211 * @param quantity the language quantity 212 * @param outValue the resource write to 213 * @return SUCCESS if resource exist, else NOT_FOUND 214 */ 215 virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue); 216 217 /** 218 * Get the plural string by resource name 219 * @param name the resource name 220 * @param quantity the language quantity 221 * @param outValue the resource write to 222 * @return SUCCESS if resource exist, else NOT_FOUND 223 */ 224 virtual RState GetPluralStringByName(const char *name, int quantity, std::string &outValue); 225 226 /** 227 * Get the plural format string by resource id 228 * @param outValue the resource write to 229 * @param id the resource id 230 * @param quantity the language quantity 231 * @return SUCCESS if resource exist, else NOT_FOUND 232 */ 233 virtual RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...); 234 235 /** 236 * Get the plural format string by resource name 237 * @param outValue the resource write to 238 * @param id the resource id 239 * @param quantity the language quantity 240 * @return SUCCESS if resource exist, else NOT_FOUND 241 */ 242 virtual RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...); 243 244 /** 245 * Get the THEME resource by resource id 246 * @param id the resource id 247 * @param outValue the resource write to 248 * @return SUCCESS if resource exist, else NOT_FOUND 249 */ 250 virtual RState GetThemeById(uint32_t id, std::map<std::string, std::string> &outValue); 251 252 /** 253 * Get the THEME resource by resource name 254 * @param name the resource name 255 * @param outValue the resource write to 256 * @return SUCCESS if resource exist, else NOT_FOUND 257 */ 258 virtual RState GetThemeByName(const char *name, std::map<std::string, std::string> &outValue); 259 260 /** 261 * Get the BOOLEAN resource by resource id 262 * @param id the resource id 263 * @param outValue the obtain boolean value write to 264 * @return SUCCESS if resource exist, else NOT_FOUND 265 */ 266 virtual RState GetBooleanById(uint32_t id, bool &outValue); 267 268 /** 269 * Get the BOOLEAN resource by resource name 270 * @param name the resource name 271 * @param outValue the obtain boolean value write to 272 * @return SUCCESS if resource exist, else NOT_FOUND 273 */ 274 virtual RState GetBooleanByName(const char *name, bool &outValue); 275 276 /** 277 * Get the INTEGER resource by resource id 278 * @param id the resource id 279 * @param outValue the obtain Integer value write to 280 * @return SUCCESS if resource exist, else NOT_FOUND 281 */ 282 virtual RState GetIntegerById(uint32_t id, int &outValue); 283 284 /** 285 * Get the INTEGER resource by resource name 286 * @param name the resource name 287 * @param outValue the obtain Integer value write to 288 * @return SUCCESS if resource exist, else NOT_FOUND 289 */ 290 virtual RState GetIntegerByName(const char *name, int &outValue); 291 292 /** 293 * Get the FLOAT resource by resource id 294 * @param id the resource id 295 * @param outValue the obtain float value write to 296 * @return SUCCESS if resource exist, else NOT_FOUND 297 */ 298 virtual RState GetFloatById(uint32_t id, float &outValue); 299 300 /** 301 * Get the FLOAT resource by resource id 302 * @param id the resource id 303 * @param outValue the obtain float value write to 304 * @param unit the unit do not in parsing 305 * @return SUCCESS if resource exist, else NOT_FOUND 306 */ 307 virtual RState GetFloatById(uint32_t id, float &outValue, std::string &unit); 308 309 /** 310 * Get the FLOAT resource by resource name 311 * @param name the resource name 312 * @param outValue the obtain float value write to 313 * @return SUCCESS if resource exist, else NOT_FOUND 314 */ 315 virtual RState GetFloatByName(const char *name, float &outValue); 316 317 /** 318 * Get the FLOAT resource by resource id 319 * @param id the resource id 320 * @param outValue the obtain float value write to 321 * @param unit the string do not in parsing 322 * @return SUCCESS if resource exist, else NOT_FOUND 323 */ 324 virtual RState GetFloatByName(const char *name, float &outValue, std::string &unit); 325 326 /** 327 * Get the INTARRAY resource by resource id 328 * @param id the resource id 329 * @param outValue the obtain resource value convert to vector<int> write to 330 * @return SUCCESS if resource exist, else NOT_FOUND 331 */ 332 virtual RState GetIntArrayById(uint32_t id, std::vector<int> &outValue); 333 334 /** 335 * Get the INTARRAY resource by resource name 336 * @param name the resource name 337 * @param outValue the obtain resource value convert to vector<int> write to 338 * @return SUCCESS if resource exist, else NOT_FOUND 339 */ 340 virtual RState GetIntArrayByName(const char *name, std::vector<int> &outValue); 341 342 /** 343 * Get the COLOR resource by resource id 344 * @param id the resource id 345 * @param outValue the obtain resource value convert to uint32_t write to 346 * @return SUCCESS if resource exist, else NOT_FOUND 347 */ 348 virtual RState GetColorById(uint32_t id, uint32_t &outValue); 349 350 /** 351 * Get the COLOR resource by resource name 352 * @param name the resource name 353 * @param outValue the obtain resource value convert to uint32_t write to 354 * @return SUCCESS if resource exist, else NOT_FOUND 355 */ 356 virtual RState GetColorByName(const char *name, uint32_t &outValue); 357 358 /** 359 * Get the SYMBOL resource by resource id 360 * @param id the resource id 361 * @param outValue the obtain resource value convert to uint32_t write to 362 * @return SUCCESS if resource exist, else NOT_FOUND 363 */ 364 virtual RState GetSymbolById(uint32_t id, uint32_t &outValue); 365 366 /** 367 * Get the SYMBOL resource by resource name 368 * @param name the resource name 369 * @param outValue the obtain resource value convert to uint32_t write to 370 * @return SUCCESS if resource exist, else NOT_FOUND 371 */ 372 virtual RState GetSymbolByName(const char *name, uint32_t &outValue); 373 374 /** 375 * Get the PROF resource by resource id 376 * @param id the resource id 377 * @param outValue the obtain resource path write to 378 * @return SUCCESS if resource exist, else NOT_FOUND 379 */ 380 virtual RState GetProfileById(uint32_t id, std::string &outValue); 381 382 /** 383 * Get the PROF resource by resource name 384 * @param name the resource name 385 * @param outValue the obtain resource path write to 386 * @return SUCCESS if resource exist, else NOT_FOUND 387 */ 388 virtual RState GetProfileByName(const char *name, std::string &outValue); 389 390 /** 391 * Get the MEDIA resource by resource id 392 * @param id the resource id 393 * @param outValue the obtain resource path write to 394 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 395 * @return SUCCESS if resource exist, else NOT_FOUND 396 */ 397 virtual RState GetMediaById(uint32_t id, std::string &outValue, uint32_t density = 0); 398 399 /** 400 * Get the MEDIA resource by resource name 401 * @param name the resource name 402 * @param outValue the obtain resource path write to 403 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 404 * @return SUCCESS if resource exist, else NOT_FOUND 405 */ 406 virtual RState GetMediaByName(const char *name, std::string &outValue, uint32_t density = 0); 407 408 /** 409 * Get the raw file path by resource name 410 * @param name the resource name 411 * @param outValue the obtain resource path write to 412 * @return SUCCESS if resource exist, else NOT_FOUND 413 */ 414 virtual RState GetRawFilePathByName(const std::string &name, std::string &outValue); 415 416 /** 417 * Get the rawFile descriptor by resource name 418 * @param name the resource name 419 * @param descriptor the obtain raw file member fd, length, offet write to 420 * @return SUCCESS if resource exist, else ERROR 421 */ 422 virtual RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor); 423 424 /** 425 * Get the rawFile descriptor by resource name 426 * @param name the resource name 427 * @param descriptor the obtain raw file member fd, length, offet write to 428 * @return SUCCESS if resource exist, else ERROR 429 */ 430 virtual RState GetRawFdNdkFromHap(const std::string &name, RawFileDescriptor &descriptor); 431 432 /** 433 * Close rawFile descriptor by resource name 434 * @param name the resource name 435 * @return SUCCESS if close the rawFile descriptor, else ERROR 436 */ 437 virtual RState CloseRawFileDescriptor(const std::string &name); 438 439 /** 440 * Get all resource paths 441 * @return The vector of resource paths 442 */ 443 std::vector<std::string> GetResourcePaths(); 444 445 /** 446 * Get the MEDIA data by resource id 447 * @param id the resource id 448 * @param len the data len write to 449 * @param outValue the obtain resource path write to 450 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 451 * @return SUCCESS if resource exist, else NOT_FOUND 452 */ 453 virtual RState GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue, 454 uint32_t density = 0); 455 456 /** 457 * Get the MEDIA data by resource name 458 * @param name the resource name 459 * @param len the data len write to 460 * @param outValue the obtain resource path write to 461 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 462 * @return SUCCESS if resource exist, else NOT_FOUND 463 */ 464 virtual RState GetMediaDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue, 465 uint32_t density = 0); 466 467 /** 468 * Get the MEDIA base64 data resource by resource id 469 * @param id the resource id 470 * @param outValue the media base64 data 471 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 472 * @return SUCCESS if resource exist, else NOT_FOUND 473 */ 474 virtual RState GetMediaBase64DataById(uint32_t id, std::string &outValue, uint32_t density = 0); 475 476 /** 477 * Get the MEDIA base64 data resource by resource id 478 * @param name the resource name 479 * @param outValue the media base64 data 480 * @param density the screen density, within the area of OHOS::Global::Resource::ScreenDensity 481 * @return SUCCESS if resource exist, else NOT_FOUND 482 */ 483 virtual RState GetMediaBase64DataByName(const char *name, std::string &outValue, uint32_t density = 0); 484 485 /** 486 * Get the PROF resource by resource id 487 * @param name the resource id 488 * @param len the data len write to 489 * @param outValue the obtain resource path write to 490 * @return SUCCESS if resource exist, else NOT_FOUND 491 */ 492 virtual RState GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr<uint8_t[]> &outValue); 493 494 /** 495 * Get the PROF resource by resource name 496 * @param name the resource name 497 * @param len the data len write to 498 * @param outValue the obtain resource path write to 499 * @return SUCCESS if resource exist, else NOT_FOUND 500 */ 501 virtual RState GetProfileDataByName(const char *name, size_t &len, std::unique_ptr<uint8_t[]> &outValue); 502 503 /** 504 * Get the rawFile base64 from hap by rawFile name 505 * @param rawFileName the rawFile name 506 * @param len the data len write to 507 * @param outValue the obtain resource path write to 508 * @return SUCCESS if resource exist, else NOT_FOUND 509 */ 510 virtual RState GetRawFileFromHap(const std::string &rawFileName, size_t &len, 511 std::unique_ptr<uint8_t[]> &outValue); 512 513 /** 514 * Get the rawFile Descriptor from hap by rawFile name 515 * @param rawFileName the rawFile name 516 * @param descriptor the raw file member fd, length, offet write to 517 * @return SUCCESS if resource exist, else NOT_FOUND 518 */ 519 virtual RState GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor); 520 521 /** 522 * Is load hap 523 * @param hapPath the hap path 524 */ 525 virtual RState IsLoadHap(std::string &hapPath); 526 527 /** 528 * Get the raw file list 529 * @param rawDirPath the rawfile directory path 530 * @param rawfileList the rawfile list write to 531 * @return SUCCESS if resource exist, else not found 532 */ 533 virtual RState GetRawFileList(const std::string &rawDirPath, std::vector<std::string>& rawfileList); 534 535 /** 536 * Get the drawable information for given resId, mainly about type, len, buffer 537 * @param id the resource id 538 * @param type the drawable type 539 * @param len the drawable buffer length 540 * @param outValue the drawable buffer write to 541 * @param density the drawable density 542 * @return SUCCESS if resource exist, else not found 543 */ 544 virtual RState GetDrawableInfoById(uint32_t id, std::string &type, size_t &len, 545 std::unique_ptr<uint8_t[]> &outValue, uint32_t density = 0); 546 547 /** 548 * Get the drawable information for given resName, mainly about type, len, buffer 549 * @param name the resource Name 550 * @param type the drawable type 551 * @param len the drawable buffer length 552 * @param outValue the drawable buffer write to 553 * @param density the drawable density 554 * @return SUCCESS if resource exist, else not found 555 */ 556 virtual RState GetDrawableInfoByName(const char *name, std::string &type, size_t &len, 557 std::unique_ptr<uint8_t[]> &outValue, uint32_t density = 0); 558 559 /** 560 * Get string format by resource id 561 * @param id the resource id 562 * @param outValue the resource write to 563 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 564 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 565 * the tuple second parameter represents the value 566 * @return SUCCESS if resource exists and was formatted successfully, else ERROR 567 */ 568 virtual RState GetStringFormatById(uint32_t id, std::string &outValue, 569 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 570 571 /** 572 * Get string format by resource name 573 * @param name the resource name 574 * @param outValue the resource write to 575 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 576 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 577 * the tuple second parameter represents the value 578 * @return SUCCESS if resource exists and was formatted successfully, else ERROR 579 */ 580 virtual RState GetStringFormatByName(const char *name, std::string &outValue, 581 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 582 583 /** 584 * Get the plural format string by resource id 585 * @param outValue the resource write to 586 * @param id the resource id 587 * @param quantity the language quantity 588 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 589 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 590 * the tuple second parameter represents the value 591 * @return SUCCESS if resource exist, else NOT_FOUND 592 */ 593 virtual RState GetFormatPluralStringById(std::string &outValue, uint32_t id, int quantity, 594 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 595 596 /** 597 * Get the plural format string by resource name 598 * @param outValue the resource write to 599 * @param name the resource name 600 * @param quantity the language quantity 601 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 602 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 603 * the tuple second parameter represents the value 604 * @return SUCCESS if resource exist, else NOT_FOUND 605 */ 606 virtual RState GetFormatPluralStringByName(std::string &outValue, const char *name, int quantity, 607 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 608 609 /** 610 * Get the resource limit keys value which every binary bit corresponds to existing limit key {@link KeyType}, 611 * enum KeyType { 612 * LANGUAGES = 0, 613 * REGION = 1, 614 * SCREEN_DENSITY = 2, 615 * DIRECTION = 3, 616 * DEVICETYPE = 4, 617 * SCRIPT = 5, 618 * COLORMODE = 6 619 * MCC = 7, 620 * MNC = 8, 621 * // RESERVER 9 622 * INPUTDEVICE = 10, 623 * KEY_TYPE_MAX, 624 * } 625 * 626 * @return the resource limit keys, like if resource has LANGUAGES/REGION/DEVICETYPE, then the return value to 627 * binary bits is 0000010011 628 */ 629 virtual uint32_t GetResourceLimitKeys(); 630 631 /** 632 * Get the resource id by resType and resName 633 * 634 * @param resTypeName the resType and resName 635 * @param resId the resId write to 636 * @return SUCCESS if resource exist, else ERROR 637 */ 638 virtual RState GetResId(const std::string &resTypeName, uint32_t &resId); 639 640 /** 641 * Get locale list 642 * 643 * @param outValue the locales write to, the locale string is divided into three parts: language, 644 * script (optional), and region (optional), concatenated by the connector (-). 645 * @param includeSystem the parameter controls whether to include system resources, 646 * the default value is false, it has no effect when only system resources query the locales list. 647 */ 648 virtual void GetLocales(std::vector<std::string> &outValue, bool includeSystem = false); 649 650 /** 651 * Get the drawable information for given resId, mainly about type, len, buffer 652 * @param id the resource id 653 * @param drawableInfo the drawable info 654 * @param outValue the drawable buffer write to 655 * @param iconType the drawable type 656 * @param density the drawable density 657 * @return SUCCESS if resource exist, else not found 658 */ 659 virtual RState GetDrawableInfoById(uint32_t id, 660 std::tuple<std::string, size_t, std::string> &drawableInfo, 661 std::unique_ptr<uint8_t[]> &outValue, uint32_t iconType, uint32_t density = 0); 662 663 /** 664 * Get the drawable information for given resName, mainly about type, len, buffer 665 * @param name the resource Name 666 * @param drawableInfo the drawable info 667 * @param outValue the drawable buffer write to 668 * @param iconType the drawable type 669 * @param density the drawable density 670 * @return SUCCESS if resource exist, else not found 671 */ 672 virtual RState GetDrawableInfoByName(const char *name, 673 std::tuple<std::string, size_t, std::string> &drawableInfo, 674 std::unique_ptr<uint8_t[]> &outValue, uint32_t iconType, uint32_t density = 0); 675 676 /** 677 * Get the theme icon from theme pack 678 * 679 * @param resId the resource id 680 * @param foregroundInfo the foreground info 681 * @param backgroundInfo the background info 682 * @param density the drawable density 683 * @param abilityName the hap abilityName 684 * @return SUCCESS if resource exist, else not found 685 */ 686 virtual RState GetThemeIcons(uint32_t resId, std::pair<std::unique_ptr<uint8_t[]>, size_t> &foregroundInfo, 687 std::pair<std::unique_ptr<uint8_t[]>, size_t> &backgroundInfo, uint32_t density = 0, 688 const std::string &abilityName = ""); 689 690 /** 691 * Get the theme mask 692 * 693 * @return the theme mask path, else empty 694 */ 695 virtual std::string GetThemeMask(); 696 697 /** 698 * Whether an icon exists in the theme 699 * 700 * @param bundleName the hap bundleName 701 * @return true if icon exists, else no exists 702 */ 703 virtual bool HasIconInTheme(const std::string &bundleName); 704 705 /** 706 * Get icons info in other icons by icon name 707 * 708 * @param iconName the icon name 709 * @param outValue the obtain resource wirte to 710 * @param len the data len wirte to 711 * @param isGlobalMask true if the global mask, else other icons 712 * @return SUCCESS if the theme icon get success, else failed 713 */ 714 virtual RState GetOtherIconsInfo(const std::string &iconName, 715 std::unique_ptr<uint8_t[]> &outValue, size_t &len, bool isGlobalMask); 716 717 /** 718 * Whether this raw resource is a directory 719 * 720 * @param pathName the raw resource path 721 * @param outValue the obtain boolean value write to 722 * @return SUCCESS if raw resource is a directory, else not found 723 */ 724 virtual RState IsRawDirFromHap(const std::string &pathName, bool &outValue); 725 726 /** 727 * Get override ResourceManager 728 * 729 * @param overrideResConfig the override resource config 730 * @return ResourceManager if success, else nullptr 731 */ 732 virtual std::shared_ptr<ResourceManager> GetOverrideResourceManager(std::shared_ptr<ResConfig> overrideResConfig); 733 734 /** 735 * Update the override resConfig 736 * @param resConfig the override resource config 737 * @return SUCCESS if the override resConfig updated success, else ERROR 738 */ 739 virtual RState UpdateOverrideResConfig(ResConfig &resConfig); 740 741 /** 742 * Get the override resConfig 743 * @param resConfig the override resource config 744 */ 745 virtual void GetOverrideResConfig(ResConfig &resConfig); 746 747 virtual RState GetDynamicIcon(const std::string &resName, std::pair<std::unique_ptr<uint8_t[]>, size_t> &iconInfo, 748 uint32_t density = 0); 749 750 /** 751 * Get string format by resource id 752 * @param id the resource id 753 * @param outValue the resource write to 754 * @param args the variable argument list 755 * @return SUCCESS if resource exists and was formatted successfully, else ERROR 756 */ 757 virtual RState GetStringFormatById(std::string &outValue, uint32_t id, va_list args); 758 759 /** 760 * Get string format by resource name 761 * @param name the resource name 762 * @param outValue the resource write to 763 * @param args the variable argument list 764 * @return SUCCESS if resource exists and was formatted successfully, else ERROR 765 */ 766 virtual RState GetStringFormatByName(std::string &outValue, const char *name, va_list args); 767 768 /** 769 * Get the THEME resource by resource name 770 * @param name the resource name 771 * @param outValue the resource write to 772 * @return SUCCESS if resource exist, else NOT_FOUND 773 */ 774 virtual RState GetThemeDataByName(const char *name, std::map<std::string, ResData> &outValue); 775 776 /** 777 * Get the THEME resource by resource id 778 * @param id the resource id 779 * @param outValue the resource write to 780 * @return SUCCESS if resource exist, else NOT_FOUND 781 */ 782 virtual RState GetThemeDataById(uint32_t id, std::map<std::string, ResData> &outValue); 783 784 /** 785 * Get the PATTERN resource by resource id 786 * @param id the resource id 787 * @param outValue the resource write to 788 * @return SUCCESS if resource exist, else NOT_FOUND 789 */ 790 virtual RState GetPatternDataById(uint32_t id, std::map<std::string, ResData> &outValue); 791 792 /** 793 * Get the PATTERN resource by resource name 794 * @param name the resource name 795 * @param outValue the resource write to 796 * @return SUCCESS if resource exist, else NOT_FOUND 797 */ 798 virtual RState GetPatternDataByName(const char *name, std::map<std::string, ResData> &outValue); 799 800 /** 801 * Get the plural format string by resource id 802 * @param outValue the resource write to 803 * @param id the resource id 804 * @param quantity the language quantity 805 * @param args the variable argument list 806 * @return SUCCESS if resource exist, else NOT_FOUND 807 */ 808 virtual RState GetFormatPluralStringById(std::string &outValue, uint32_t id, Quantity quantity, 809 va_list args); 810 811 /** 812 * Get the plural format string by resource id 813 * @param outValue the resource write to 814 * @param id the resource id 815 * @param quantity the language quantity 816 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 817 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 818 * the tuple second parameter represents the value 819 * @return SUCCESS if resource exist, else NOT_FOUND 820 */ 821 virtual RState GetFormatPluralStringById(std::string &outValue, uint32_t id, Quantity quantity, 822 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 823 824 /** 825 * Get the plural format string by resource name 826 * @param outValue the resource write to 827 * @param name the resource name 828 * @param quantity the language quantity 829 * @param args the variable argument list 830 * @return SUCCESS if resource exist, else NOT_FOUND 831 */ 832 virtual RState GetFormatPluralStringByName(std::string &outValue, const char *name, Quantity quantity, 833 va_list args); 834 835 /** 836 * Get the plural format string by resource name 837 * @param outValue the resource write to 838 * @param name the resource name 839 * @param quantity the language quantity 840 * @param jsParams the formatting string resource js parameters, the tuple first parameter represents the type, 841 * napi_number is denoted by NAPI_NUMBER, napi_string is denoted by NAPI_STRING, 842 * the tuple second parameter represents the value 843 * @return SUCCESS if resource exist, else NOT_FOUND 844 */ 845 virtual RState GetFormatPluralStringByName(std::string &outValue, const char *name, Quantity quantity, 846 std::vector<std::tuple<ResourceManager::NapiValueType, std::string>> &jsParams); 847 848 /** 849 * Get the hap manager 850 * 851 * @return the hap manager 852 */ 853 std::shared_ptr<HapManager> GetHapManager(); 854 855 private: 856 RState GetString(const std::shared_ptr<IdItem> idItem, std::string &outValue); 857 858 RState GetStringArray(const std::shared_ptr<IdItem> idItem, std::vector<std::string> &outValue); 859 860 RState GetPattern(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue); 861 862 RState GetTheme(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue); 863 864 RState GetPluralString(const std::shared_ptr<IdItem> &idItem, Quantity quantity, std::string &outValue); 865 866 RState ResolveReference(const std::string value, std::string &outValue); 867 868 RState GetBoolean(const std::shared_ptr<IdItem> idItem, bool &outValue); 869 870 RState ParseFloat(const std::string &strValue, float &result, std::string &unit); 871 872 RState RecalculateFloat(const std::string &unit, float &result); 873 874 RState GetFloat(const std::shared_ptr<IdItem> idItem, float &outValue, std::string &unit); 875 876 RState GetInteger(const std::shared_ptr<IdItem> idItem, int &outValue); 877 878 RState GetColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue); 879 880 RState GetIntArray(const std::shared_ptr<IdItem> idItem, std::vector<int> &outValue); 881 882 RState GetSymbol(const std::shared_ptr<IdItem> idItem, uint32_t &outValue); 883 884 void ProcessPsuedoTranslate(std::string &outValue); 885 886 RState ResolveParentReference(const std::shared_ptr<IdItem> idItem, std::map<std::string, std::string> &outValue); 887 888 bool IsDensityValid(uint32_t density); 889 890 RState GetThemeColor(const std::shared_ptr<IdItem> idItem, uint32_t &outValue); 891 892 RState GetThemeFloat(const std::shared_ptr<IdItem> idItem, float &outValue); 893 894 RState GetThemeFloat(const std::shared_ptr<IdItem> idItem, float &outValue, std::string &unit); 895 896 RState GetThemeMedia(const std::shared_ptr<IdItem> idItem, size_t &len, 897 std::unique_ptr<uint8_t[]> &outValue, uint32_t density); 898 899 RState GetThemeMediaBase64(const std::shared_ptr<IdItem> idItem, std::string &outValue); 900 901 RState GetThemeDrawable(const std::shared_ptr<IdItem> idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue, 902 uint32_t iconType, uint32_t density); 903 904 RState GetThemeIcon(const std::shared_ptr<IdItem> idItem, size_t &len, std::unique_ptr<uint8_t[]> &outValue, 905 uint32_t density); 906 907 RState ProcessReference(const std::string value, std::vector<std::shared_ptr<IdItem>> &idItems); 908 909 RState GetThemeIconInfo(const std::string &iconName, size_t &len, std::unique_ptr<uint8_t[]> &outValue, 910 const std::string &abilityName = ""); 911 912 RState GetThemeValues(const std::string &value, std::string &outValue, const ResConfigImpl &resConfig); 913 914 RState UpdateFakeLocaleFlag(ResConfig &resConfig); 915 916 RState GetThemeData(const std::shared_ptr<IdItem> idItem, std::map<std::string, ResData> &outValue); 917 918 RState ResolveResData(const std::shared_ptr<IdItem> idItem, std::map<std::string, ResData> &outValue); 919 920 RState ResolveDataReference(const std::string key, const std::string value, 921 std::map<std::string, ResData> &outValue); 922 923 RState GetPatternData(const std::shared_ptr<IdItem> idItem, std::map<std::string, ResData> &outValue); 924 925 RState ProcessItem(std::shared_ptr<IdItem> idItem, std::map<std::string, ResData> &outValue); 926 927 void UpdateSystemResourceResConfig(); 928 929 std::string ReadParameter(const char *paramKey, const int paramLength); 930 931 std::shared_ptr<HapManager> hapManager_; 932 933 std::shared_ptr<ResourceManagerImpl> systemResourceManager_{nullptr}; 934 935 float fontRatio_ = 0.0f; 936 937 bool isFakeLocale = false; 938 939 bool isBidirectionFakeLocale = false; 940 941 std::shared_ptr<PsueManager> psueManager_; 942 943 const std::string VIRTUAL_PIXEL = "vp"; 944 945 const std::string FONT_SIZE_PIXEL = "fp"; 946 947 bool isOverrideResMgr_ = false; 948 949 bool isSystemResMgr_ = false; 950 951 static constexpr int CONFIG_LEN = 128; 952 953 static const char* LANGUAGE_KEY; 954 }; 955 } // namespace Resource 956 } // namespace Global 957 } // namespace OHOS 958 #endif