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 #include <pthread.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <unistd.h>
19
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include "bundle_mgr.h"
23
24 EXTERN_C_START
25 /*
26 * function for module exports
27 */
Init(napi_env env,napi_value exports)28 static napi_value Init(napi_env env, napi_value exports)
29 {
30 napi_value nAbilityType = nullptr;
31 NAPI_CALL(env, napi_create_object(env, &nAbilityType));
32 CreateAbilityTypeObject(env, nAbilityType);
33
34 napi_value nAbilitySubType = nullptr;
35 NAPI_CALL(env, napi_create_object(env, &nAbilitySubType));
36 CreateAbilitySubTypeObject(env, nAbilitySubType);
37
38 napi_value nDisplayOrientation = nullptr;
39 NAPI_CALL(env, napi_create_object(env, &nDisplayOrientation));
40 CreateDisplayOrientationObject(env, nDisplayOrientation);
41
42 napi_value nLaunchMode = nullptr;
43 NAPI_CALL(env, napi_create_object(env, &nLaunchMode));
44 CreateLaunchModeObject(env, nLaunchMode);
45
46 napi_value nModuleUpdateFlag = nullptr;
47 NAPI_CALL(env, napi_create_object(env, &nModuleUpdateFlag));
48 CreateModuleUpdateFlagObject(env, nModuleUpdateFlag);
49
50 napi_value nFormType = nullptr;
51 NAPI_CALL(env, napi_create_object(env, &nFormType));
52 CreateFormTypeObject(env, nFormType);
53
54 napi_value nColorMode = nullptr;
55 NAPI_CALL(env, napi_create_object(env, &nColorMode));
56 CreateColorModeObject(env, nColorMode);
57
58 napi_value nGrantStatus = nullptr;
59 NAPI_CALL(env, napi_create_object(env, &nGrantStatus));
60 CreateGrantStatusObject(env, nGrantStatus);
61
62 napi_value nModuleRemoveFlag = nullptr;
63 NAPI_CALL(env, napi_create_object(env, &nModuleRemoveFlag));
64 CreateModuleRemoveFlagObject(env, nModuleRemoveFlag);
65
66 napi_value nSignatureCompareResult = nullptr;
67 NAPI_CALL(env, napi_create_object(env, &nSignatureCompareResult));
68 CreateSignatureCompareResultObject(env, nSignatureCompareResult);
69
70 napi_value nShortcutExistence = nullptr;
71 NAPI_CALL(env, napi_create_object(env, &nShortcutExistence));
72 CreateShortcutExistenceObject(env, nShortcutExistence);
73
74 napi_value nQueryShortCutFlag = nullptr;
75 NAPI_CALL(env, napi_create_object(env, &nQueryShortCutFlag));
76 CreateQueryShortCutFlagObject(env, nShortcutExistence);
77
78 napi_value nInstallErrorCode = nullptr;
79 NAPI_CALL(env, napi_create_object(env, &nInstallErrorCode));
80 CreateInstallErrorCodeObject(env, nInstallErrorCode);
81 /*
82 * Propertise define
83 */
84 napi_property_descriptor desc[] = {
85 DECLARE_NAPI_FUNCTION("getAllApplicationInfo", GetApplicationInfos),
86 DECLARE_NAPI_FUNCTION("getApplicationInfos", GetApplicationInfos),
87 DECLARE_NAPI_FUNCTION("getApplicationInfo", GetApplicationInfo),
88 DECLARE_NAPI_FUNCTION("getAllBundleInfo", GetBundleInfos),
89 DECLARE_NAPI_FUNCTION("getBundleInfos", GetBundleInfos),
90 DECLARE_NAPI_FUNCTION("getBundleInfo", GetBundleInfo),
91 DECLARE_NAPI_FUNCTION("getBundleArchiveInfo", GetBundleArchiveInfo),
92 DECLARE_NAPI_FUNCTION("getPermissionDef", GetPermissionDef),
93 DECLARE_NAPI_FUNCTION("queryAbilityByWant", QueryAbilityInfos),
94 DECLARE_NAPI_FUNCTION("getBundleInstaller", GetBundleInstaller),
95 DECLARE_NAPI_FUNCTION("getFormsInfoByModule", GetFormsInfoByModule),
96 DECLARE_NAPI_FUNCTION("getFormsInfo", GetFormsInfoByApp),
97 DECLARE_NAPI_FUNCTION("getAllFormsInfo", GetAllFormsInfo),
98 DECLARE_NAPI_FUNCTION("getAllShortcutInfo", GetShortcutInfos),
99 DECLARE_NAPI_FUNCTION("getModuleUsageRecords", GetModuleUsageRecords),
100 DECLARE_NAPI_FUNCTION("on", RegisterAllPermissionsChanged),
101 DECLARE_NAPI_FUNCTION("off", UnregisterPermissionsChanged),
102 DECLARE_NAPI_FUNCTION("checkPermission", CheckPermission),
103 DECLARE_NAPI_PROPERTY("AbilityType", nAbilityType),
104 DECLARE_NAPI_PROPERTY("AbilitySubType", nAbilitySubType),
105 DECLARE_NAPI_PROPERTY("DisplayOrientation", nDisplayOrientation),
106 DECLARE_NAPI_PROPERTY("LaunchMode", nLaunchMode),
107 DECLARE_NAPI_PROPERTY("ModuleUpdateFlag", nModuleUpdateFlag),
108 DECLARE_NAPI_PROPERTY("FormType", nFormType),
109 DECLARE_NAPI_PROPERTY("ColorMode", nColorMode),
110 DECLARE_NAPI_PROPERTY("GrantStatus", nGrantStatus),
111 DECLARE_NAPI_PROPERTY("ModuleRemoveFlag", nModuleRemoveFlag),
112 DECLARE_NAPI_PROPERTY("SignatureCompareResult", nSignatureCompareResult),
113 DECLARE_NAPI_PROPERTY("ShortcutExistence", nShortcutExistence),
114 DECLARE_NAPI_PROPERTY("QueryShortCutFlag", nQueryShortCutFlag),
115 DECLARE_NAPI_PROPERTY("InstallErrorCode", nInstallErrorCode)
116 };
117 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
118
119 napi_property_descriptor properties[] = {
120 DECLARE_NAPI_FUNCTION("install", Install),
121 DECLARE_NAPI_FUNCTION("uninstall", Uninstall),
122 };
123 NAPI_CALL(env,
124 napi_define_class(env,
125 "BundleInstaller",
126 NAPI_AUTO_LENGTH,
127 BundleInstallerConstructor,
128 nullptr,
129 sizeof(properties) / sizeof(*properties),
130 properties,
131 &g_classBundleInstaller));
132 HILOG_INFO("-----Init end------");
133 return exports;
134 }
135 EXTERN_C_END
136
137 /*
138 * Module define
139 */
140 static napi_module _module = {
141 .nm_version = 1,
142 .nm_flags = 0,
143 .nm_filename = nullptr,
144 .nm_register_func = Init,
145 .nm_modname = "bundle",
146 .nm_priv = ((void *)0),
147 .reserved = {0}
148 };
149 /*
150 * Module register function
151 */
RegisterModule(void)152 extern "C" __attribute__((constructor)) void RegisterModule(void)
153 {
154 napi_module_register(&_module);
155 }
156