• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)27 std::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         LOGW("container is null");
36         return rawAppName;
37     }
38     auto pipelineContext = container->GetPipelineContext();
39     if (!pipelineContext) {
40         LOGE("pipelineContext is null!");
41         return rawAppName;
42     }
43     auto themeManager = pipelineContext->GetThemeManager();
44     if (!themeManager) {
45         LOGE("themeManager is null!");
46         return rawAppName;
47     }
48 
49     auto resourceName = rawAppName.substr(APP_NAME_PREFIX.size());
50     auto themeConstants = themeManager->GetThemeConstants();
51     uint32_t resId = 0;
52     auto ret = themeConstants->GetResourceIdByName(resourceName, "string", resId);
53     if (!ret) {
54         LOGW("GetResourceIdByName failed");
55         return rawAppName;
56     }
57     return themeConstants->GetString(resId);
58 }
59 
60 } // namespace
61 
GetAppID() const62 const std::string& ManifestAppInfo::GetAppID() const
63 {
64     return appID_;
65 }
66 
GetAppName() const67 const std::string& ManifestAppInfo::GetAppName() const
68 {
69     return appName_;
70 }
71 
GetIcon() const72 const std::string& ManifestAppInfo::GetIcon() const
73 {
74     return icon_;
75 }
76 
GetVersionName() const77 const std::string& ManifestAppInfo::GetVersionName() const
78 {
79     return versionName_;
80 }
81 
GetVersionCode() const82 uint32_t ManifestAppInfo::GetVersionCode() const
83 {
84     return versionCode_;
85 }
86 
GetLogLevel() const87 const std::string& ManifestAppInfo::GetLogLevel() const
88 {
89     return logLevel_;
90 }
91 
AppInfoParse(const std::unique_ptr<JsonValue> & root)92 void ManifestAppInfo::AppInfoParse(const std::unique_ptr<JsonValue>& root)
93 {
94     if (!root) {
95         return;
96     }
97 
98     appName_ = root->GetString("appName");
99     versionName_ = root->GetString("versionName");
100     versionCode_ = root->GetUInt("versionCode");
101     logLevel_ = root->GetString("logLevel");
102     icon_ = root->GetString("icon");
103     appID_ = root->GetString("appID");
104     minPlatformVersion_ = root->GetInt("minPlatformVersion", 0);
105 }
106 
ParseI18nJsonInfo()107 void ManifestAppInfo::ParseI18nJsonInfo()
108 {
109     appName_ = ParseI18nAppName(appName_);
110 }
111 
112 } // namespace OHOS::Ace::Framework
113