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 20 namespace OHOS::Ace::Framework { 21 22 namespace { 23 24 const std::string APP_NAME_PREFIX = "$string:"; 25 ParseI18nAppName(std::string & rawAppName)26std::string ParseI18nAppName(std::string& rawAppName) 27 { 28 if (!StringUtils::StartWith(rawAppName, APP_NAME_PREFIX) || rawAppName.size() <= APP_NAME_PREFIX.size()) { 29 return rawAppName; 30 } 31 32 auto container = Container::Current(); 33 if (!container) { 34 return rawAppName; 35 } 36 auto pipelineContext = container->GetPipelineContext(); 37 if (!pipelineContext) { 38 return rawAppName; 39 } 40 auto themeManager = pipelineContext->GetThemeManager(); 41 if (!themeManager) { 42 return rawAppName; 43 } 44 45 auto resourceName = rawAppName.substr(APP_NAME_PREFIX.size()); 46 auto themeConstants = themeManager->GetThemeConstants(); 47 uint32_t resId = 0; 48 auto ret = themeConstants->GetResourceIdByName(resourceName, "string", resId); 49 if (!ret) { 50 return rawAppName; 51 } 52 return themeConstants->GetString(resId); 53 } 54 55 } // namespace 56 GetAppID() const57const std::string& ManifestAppInfo::GetAppID() const 58 { 59 return appID_; 60 } 61 GetAppName() const62const std::string& ManifestAppInfo::GetAppName() const 63 { 64 return appName_; 65 } 66 GetIcon() const67const std::string& ManifestAppInfo::GetIcon() const 68 { 69 return icon_; 70 } 71 GetVersionName() const72const std::string& ManifestAppInfo::GetVersionName() const 73 { 74 return versionName_; 75 } 76 GetVersionCode() const77uint32_t ManifestAppInfo::GetVersionCode() const 78 { 79 return versionCode_; 80 } 81 GetLogLevel() const82const std::string& ManifestAppInfo::GetLogLevel() const 83 { 84 return logLevel_; 85 } 86 AppInfoParse(const std::unique_ptr<JsonValue> & root)87void ManifestAppInfo::AppInfoParse(const std::unique_ptr<JsonValue>& root) 88 { 89 if (!root) { 90 return; 91 } 92 93 appName_ = root->GetString("appName"); 94 versionName_ = root->GetString("versionName"); 95 versionCode_ = root->GetUInt("versionCode"); 96 logLevel_ = root->GetString("logLevel"); 97 icon_ = root->GetString("icon"); 98 appID_ = root->GetString("appID"); 99 minPlatformVersion_ = root->GetInt("minPlatformVersion", 0); 100 } 101 ParseI18nJsonInfo()102void ManifestAppInfo::ParseI18nJsonInfo() 103 { 104 appName_ = ParseI18nAppName(appName_); 105 } 106 107 } // namespace OHOS::Ace::Framework 108