• 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 "js_hap_module_info_utils.h"
17 
18 #include "js_data_struct_converter.h"
19 #include "js_runtime_utils.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
CreateJsHapModuleInfo(NativeEngine & engine,AppExecFwk::HapModuleInfo & hapModuleInfo)23 NativeValue* CreateJsHapModuleInfo(NativeEngine& engine, AppExecFwk::HapModuleInfo& hapModuleInfo)
24 {
25     NativeValue* objValue = engine.CreateObject();
26     NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
27 
28     object->SetProperty("name", CreateJsValue(engine, hapModuleInfo.name));
29     object->SetProperty("moduleName", CreateJsValue(engine, hapModuleInfo.moduleName));
30     object->SetProperty("description", CreateJsValue(engine, hapModuleInfo.description));
31     object->SetProperty("icon", CreateJsValue(engine, hapModuleInfo.iconPath));
32     object->SetProperty("label", CreateJsValue(engine, hapModuleInfo.label));
33     object->SetProperty("backgroundImg", CreateJsValue(engine, hapModuleInfo.backgroundImg));
34     object->SetProperty("mainAbilityName", CreateJsValue(engine, hapModuleInfo.mainAbility));
35     object->SetProperty("supportedModes", CreateJsValue(engine, hapModuleInfo.supportedModes));
36 
37     NativeValue *capArrayValue = engine.CreateArray(hapModuleInfo.reqCapabilities.size());
38     NativeArray *capArray = ConvertNativeValueTo<NativeArray>(capArrayValue);
39     if (capArray != nullptr) {
40         int index = 0;
41         for (auto cap : hapModuleInfo.reqCapabilities) {
42             capArray->SetElement(index++, CreateJsValue(engine, cap));
43         }
44     }
45     object->SetProperty("reqCapabilities", capArrayValue);
46 
47     NativeValue *deviceArrayValue = engine.CreateArray(hapModuleInfo.deviceTypes.size());
48     NativeArray *deviceArray = ConvertNativeValueTo<NativeArray>(deviceArrayValue);
49     if (deviceArray != nullptr) {
50         int index = 0;
51         for (auto device : hapModuleInfo.deviceTypes) {
52             deviceArray->SetElement(index++, CreateJsValue(engine, device));
53         }
54     }
55     object->SetProperty("deviceTypes", deviceArrayValue);
56 
57     NativeValue *abilityArrayValue = engine.CreateArray(hapModuleInfo.abilityInfos.size());
58     NativeArray *abilityArray = ConvertNativeValueTo<NativeArray>(abilityArrayValue);
59     if (abilityArray != nullptr) {
60         int index = 0;
61         for (auto abilityInfo : hapModuleInfo.abilityInfos) {
62             abilityArray->SetElement(index++, CreateJsAbilityInfo(engine, abilityInfo));
63         }
64     }
65     object->SetProperty("abilityInfo", abilityArrayValue);
66 
67     return objValue;
68 }
69 }  // namespace AbilityRuntime
70 }  // namespace OHOS
71