1 /*
2  * Copyright (c) 2023 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 "adapter/preview/external/ability/stage/stage_hap_module_info.h"
17 
18 namespace OHOS::Ace {
Parse(const std::unique_ptr<JsonValue> & root)19 void StageHapModuleInfo::Parse(const std::unique_ptr<JsonValue>& root)
20 {
21     if (!root) {
22         LOGW("The information of stage model application is empty.");
23         return;
24     }
25     compileMode_ = root->GetString("compileMode");
26     moduleName_ = root->GetString("name");
27     pageProfile_ = root->GetString("pages");
28     auto metaData = root->GetValue("metadata");
29     if (metaData && metaData->IsArray()) {
30         for (auto index = 0; index < metaData->GetArraySize(); ++index) {
31             auto item = metaData->GetArrayItem(index);
32             if (item && item->GetString("name") == "ArkTSPartialUpdate") {
33                 isPartialUpdate_ = (item->GetString("value", "true") != "false");
34             }
35         }
36     }
37     auto abilities = root->GetValue("abilities");
38     if (abilities && abilities->IsArray()) {
39         auto item = abilities->GetArrayItem(0);
40         if (item) {
41             labelId_ = item->GetUInt("labelId", 0);
42         }
43     }
44 }
45 
GetCompileMode() const46 const std::string& StageHapModuleInfo::GetCompileMode() const
47 {
48     return compileMode_;
49 }
50 
GetModuleName() const51 const std::string& StageHapModuleInfo::GetModuleName() const
52 {
53     return moduleName_;
54 }
55 
GetPageProfile() const56 const std::string& StageHapModuleInfo::GetPageProfile() const
57 {
58     return pageProfile_;
59 }
60 
GetPartialUpdateFlag() const61 bool StageHapModuleInfo::GetPartialUpdateFlag() const
62 {
63     return isPartialUpdate_;
64 }
65 
GetLabelId() const66 uint32_t StageHapModuleInfo::GetLabelId() const
67 {
68     return labelId_;
69 }
70 } // namespace OHOS::Ace
71