1 /* 2 * Copyright (c) 2021 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 #include "frameworks/bridge/common/manifest/manifest_appinfo.h" 17 18 #include "core/common/container.h" 19 #include "core/components/theme/theme_manager.h" 20 21 namespace OHOS::Ace::Framework { 22 23 namespace { 24 25 const std::string APP_NAME_PREFIX = "$string:"; 26 ParseI18nAppName(std::string & rawAppName)27std::string ParseI18nAppName(std::string& rawAppName) 28 { 29 if (!StringUtils::StartWith(rawAppName, APP_NAME_PREFIX) || rawAppName.size() <= APP_NAME_PREFIX.size()) { 30 return rawAppName; 31 } 32 33 auto container = Container::Current(); 34 if (!container) { 35 return rawAppName; 36 } 37 auto pipelineContext = container->GetPipelineContext(); 38 if (!pipelineContext) { 39 return rawAppName; 40 } 41 auto themeManager = pipelineContext->GetThemeManager(); 42 if (!themeManager) { 43 return rawAppName; 44 } 45 46 auto resourceName = rawAppName.substr(APP_NAME_PREFIX.size()); 47 auto themeConstants = themeManager->GetThemeConstants(); 48 uint32_t resId = 0; 49 auto ret = themeConstants->GetResourceIdByName(resourceName, "string", resId); 50 if (!ret) { 51 return rawAppName; 52 } 53 return themeConstants->GetString(resId); 54 } 55 56 } // namespace 57 GetAppID() const58const std::string& ManifestAppInfo::GetAppID() const 59 { 60 return appID_; 61 } 62 GetAppName() const63const std::string& ManifestAppInfo::GetAppName() const 64 { 65 return appName_; 66 } 67 GetIcon() const68const std::string& ManifestAppInfo::GetIcon() const 69 { 70 return icon_; 71 } 72 GetVersionName() const73const std::string& ManifestAppInfo::GetVersionName() const 74 { 75 return versionName_; 76 } 77 GetVersionCode() const78uint32_t ManifestAppInfo::GetVersionCode() const 79 { 80 return versionCode_; 81 } 82 GetLogLevel() const83const std::string& ManifestAppInfo::GetLogLevel() const 84 { 85 return logLevel_; 86 } 87 AppInfoParse(const std::unique_ptr<JsonValue> & root)88void ManifestAppInfo::AppInfoParse(const std::unique_ptr<JsonValue>& root) 89 { 90 if (!root) { 91 return; 92 } 93 94 appName_ = root->GetString("appName"); 95 versionName_ = root->GetString("versionName"); 96 versionCode_ = root->GetUInt("versionCode"); 97 logLevel_ = root->GetString("logLevel"); 98 icon_ = root->GetString("icon"); 99 appID_ = root->GetString("appID"); 100 minPlatformVersion_ = root->GetInt("minPlatformVersion", 0); 101 } 102 ParseI18nJsonInfo()103void ManifestAppInfo::ParseI18nJsonInfo() 104 { 105 appName_ = ParseI18nAppName(appName_); 106 } 107 108 } // namespace OHOS::Ace::Framework 109