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 "js_app_control.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
AppControlExport(napi_env env,napi_value exports)26 static napi_value AppControlExport(napi_env env, napi_value exports)
27 {
28 napi_value applicationType = nullptr;
29 NAPI_CALL(env, napi_create_object(env, &applicationType));
30 napi_value componentType = nullptr;
31 NAPI_CALL(env, napi_create_object(env, &componentType));
32 CreateComponentType(env, componentType);
33 napi_value uninstallComponentType = nullptr;
34 NAPI_CALL(env, napi_create_object(env, &uninstallComponentType));
35 CreateUninstallComponentType(env, uninstallComponentType);
36 napi_value disposedType = nullptr;
37 NAPI_CALL(env, napi_create_object(env, &disposedType));
38 CreateDisposedType(env, disposedType);
39 napi_value controlType = nullptr;
40 NAPI_CALL(env, napi_create_object(env, &controlType));
41 CreateControlType(env, controlType);
42
43 napi_property_descriptor desc[] = {
44 DECLARE_NAPI_FUNCTION("getDisposedStatus", GetDisposedStatus),
45 DECLARE_NAPI_FUNCTION("setDisposedStatus", SetDisposedStatus),
46 DECLARE_NAPI_FUNCTION("deleteDisposedStatus", DeleteDisposedStatus),
47 DECLARE_NAPI_FUNCTION("getDisposedStatusSync", GetDisposedStatusSync),
48 DECLARE_NAPI_FUNCTION("setDisposedStatusSync", SetDisposedStatusSync),
49 DECLARE_NAPI_FUNCTION("deleteDisposedStatusSync", DeleteDisposedStatusSync),
50 DECLARE_NAPI_FUNCTION("getDisposedRule", GetDisposedRule),
51 DECLARE_NAPI_FUNCTION("setDisposedRule", SetDisposedRule),
52 DECLARE_NAPI_FUNCTION("getUninstallDisposedRule", GetUninstallDisposedRule),
53 DECLARE_NAPI_FUNCTION("setUninstallDisposedRule", SetUninstallDisposedRule),
54 DECLARE_NAPI_FUNCTION("deleteUninstallDisposedRule", DeleteUninstallDisposedRule),
55 DECLARE_NAPI_PROPERTY("ComponentType", componentType),
56 DECLARE_NAPI_PROPERTY("UninstallComponentType", uninstallComponentType),
57 DECLARE_NAPI_PROPERTY("DisposedType", disposedType),
58 DECLARE_NAPI_PROPERTY("ControlType", controlType),
59 };
60
61 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
62 APP_LOGD("init js app control success");
63 return exports;
64 }
65
66 static napi_module app_control_module = {
67 .nm_version = 1,
68 .nm_flags = 0,
69 .nm_filename = nullptr,
70 .nm_register_func = AppControlExport,
71 .nm_modname = "bundle.appControl",
72 .nm_priv = ((void *)0),
73 .reserved = {0}
74 };
75
AppControlRegister(void)76 extern "C" __attribute__((constructor)) void AppControlRegister(void)
77 {
78 napi_module_register(&app_control_module);
79 }
80 }
81 }