1 /*
2 * Copyright (c) 2022 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 <cstdio>
17 #include <cstring>
18 #include <pthread.h>
19 #include <unistd.h>
20
21 #include "app_log_wrapper.h"
22 #include "installer.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
BundleInstallerExport(napi_env env,napi_value exports)26 static napi_value BundleInstallerExport(napi_env env, napi_value exports)
27 {
28 APP_LOGD("export bundle installer begin");
29 napi_value m_classBundleInstaller;
30
31 napi_property_descriptor desc[] = {
32 DECLARE_NAPI_FUNCTION("getBundleInstaller", GetBundleInstaller),
33 DECLARE_NAPI_FUNCTION("getBundleInstallerSync", GetBundleInstallerSync),
34 };
35
36 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
37
38 napi_property_descriptor properties[] = {
39 DECLARE_NAPI_FUNCTION("install", Install),
40 DECLARE_NAPI_FUNCTION("recover", Recover),
41 DECLARE_NAPI_FUNCTION("uninstall", Uninstall),
42 DECLARE_NAPI_FUNCTION("updateBundleForSelf", UpdateBundleForSelf),
43 DECLARE_NAPI_FUNCTION("uninstallUpdates", UninstallAndRecover),
44 DECLARE_NAPI_FUNCTION("addExtResource", AddExtResource),
45 DECLARE_NAPI_FUNCTION("removeExtResource", RemoveExtResource),
46 DECLARE_NAPI_FUNCTION("createAppClone", CreateAppClone),
47 DECLARE_NAPI_FUNCTION("destroyAppClone", DestroyAppClone),
48 DECLARE_NAPI_FUNCTION("installPreexistingApp", InstallPreexistingApp),
49 DECLARE_NAPI_FUNCTION("installPlugin", InstallPlugin),
50 DECLARE_NAPI_FUNCTION("uninstallPlugin", UninstallPlugin),
51 };
52
53 NAPI_CALL(env,
54 napi_define_class(env,
55 "BundleInstaller",
56 NAPI_AUTO_LENGTH,
57 BundleInstallerConstructor,
58 nullptr,
59 sizeof(properties) / sizeof(*properties),
60 properties,
61 &m_classBundleInstaller));
62 napi_create_reference(env, m_classBundleInstaller, 1, &g_classBundleInstaller);
63 APP_LOGD("export bundle installer success");
64 return exports;
65 }
66
67 static napi_module bundle_installer_module = {
68 .nm_version = 1,
69 .nm_flags = 0,
70 .nm_filename = nullptr,
71 .nm_register_func = BundleInstallerExport,
72 .nm_modname = "bundle.installer",
73 .nm_priv = ((void *)0),
74 .reserved = {0}
75 };
76
BundleInstallerRegister(void)77 extern "C" __attribute__((constructor)) void BundleInstallerRegister(void)
78 {
79 napi_module_register(&bundle_installer_module);
80 }
81 }
82 }
83