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