• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 <cstdio>
17 #include <cstring>
18 #include <pthread.h>
19 #include <unistd.h>
20 
21 #include "app_log_wrapper.h"
22 #include "bundle_manager.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
BundleManagerExport(napi_env env,napi_value exports)26 static napi_value BundleManagerExport(napi_env env, napi_value exports)
27 {
28     napi_value abilityFlag = nullptr;
29     NAPI_CALL(env, napi_create_object(env, &abilityFlag));
30     CreateAbilityFlagObject(env, abilityFlag);
31 
32     napi_value extensionFlag = nullptr;
33     NAPI_CALL(env, napi_create_object(env, &extensionFlag));
34     CreateExtensionAbilityFlagObject(env, extensionFlag);
35 
36     napi_value extensionType = nullptr;
37     NAPI_CALL(env, napi_create_object(env, &extensionType));
38     CreateExtensionAbilityTypeObject(env, extensionType);
39 
40     napi_value applicationFlag = nullptr;
41     NAPI_CALL(env, napi_create_object(env, &applicationFlag));
42     CreateApplicationFlagObject(env, applicationFlag);
43 
44     napi_value bundleFlag = nullptr;
45     NAPI_CALL(env, napi_create_object(env, &bundleFlag));
46     CreateBundleFlagObject(env, bundleFlag);
47 
48     napi_value permissionGrantState = nullptr;
49     NAPI_CALL(env, napi_create_object(env, &permissionGrantState));
50     CreatePermissionGrantStateObject(env, permissionGrantState);
51 
52     napi_value nAbilityType = nullptr;
53     NAPI_CALL(env, napi_create_object(env, &nAbilityType));
54     CreateAbilityTypeObject(env, nAbilityType);
55 
56     napi_value nDisplayOrientation = nullptr;
57     NAPI_CALL(env, napi_create_object(env, &nDisplayOrientation));
58     CreateDisplayOrientationObject(env, nDisplayOrientation);
59 
60     napi_value nLaunchType = nullptr;
61     NAPI_CALL(env, napi_create_object(env, &nLaunchType));
62     CreateLaunchTypeObject(env, nLaunchType);
63 
64     napi_value nSupportWindowMode = nullptr;
65     NAPI_CALL(env, napi_create_object(env, &nSupportWindowMode));
66     CreateSupportWindowModesObject(env, nSupportWindowMode);
67 
68     napi_value nBundleType = nullptr;
69     NAPI_CALL(env, napi_create_object(env, &nBundleType));
70     CreateBundleTypeObject(env, nBundleType);
71 
72     napi_value nModuleType = nullptr;
73     NAPI_CALL(env, napi_create_object(env, &nModuleType));
74     CreateModuleTypeObject(env, nModuleType);
75 
76     napi_property_descriptor desc[] = {
77         DECLARE_NAPI_FUNCTION("getBundleArchiveInfo", GetBundleArchiveInfo),
78         DECLARE_NAPI_FUNCTION("getBundleNameByUid", GetBundleNameByUid),
79         DECLARE_NAPI_FUNCTION("queryAbilityInfo", QueryAbilityInfos),
80         DECLARE_NAPI_FUNCTION("queryExtensionAbilityInfo", QueryExtensionInfos),
81         DECLARE_NAPI_FUNCTION("setApplicationEnabled", SetApplicationEnabled),
82         DECLARE_NAPI_FUNCTION("setAbilityEnabled", SetAbilityEnabled),
83         DECLARE_NAPI_FUNCTION("isApplicationEnabled", IsApplicationEnabled),
84         DECLARE_NAPI_FUNCTION("isAbilityEnabled", IsAbilityEnabled),
85         DECLARE_NAPI_FUNCTION("getAbilityLabel", GetAbilityLabel),
86         DECLARE_NAPI_FUNCTION("getAbilityIcon", GetAbilityIcon),
87         DECLARE_NAPI_FUNCTION("cleanBundleCacheFiles", CleanBundleCacheFiles),
88         DECLARE_NAPI_FUNCTION("getLaunchWantForBundle", GetLaunchWantForBundle),
89         DECLARE_NAPI_FUNCTION("getProfileByAbility", GetProfileByAbility),
90         DECLARE_NAPI_FUNCTION("getProfileByExtensionAbility", GetProfileByExAbility),
91         DECLARE_NAPI_FUNCTION("getPermissionDef", GetPermissionDef),
92         DECLARE_NAPI_FUNCTION("getAllBundleInfo", GetBundleInfos),
93         DECLARE_NAPI_FUNCTION("getBundleInfo", GetBundleInfo),
94         DECLARE_NAPI_PROPERTY("AbilityFlag", abilityFlag),
95         DECLARE_NAPI_PROPERTY("ExtensionAbilityFlag", extensionFlag),
96         DECLARE_NAPI_PROPERTY("ExtensionAbilityType", extensionType),
97         DECLARE_NAPI_FUNCTION("getApplicationInfo", GetApplicationInfo),
98         DECLARE_NAPI_FUNCTION("getAllApplicationInfo", GetApplicationInfos),
99         DECLARE_NAPI_PROPERTY("ApplicationFlag", applicationFlag),
100         DECLARE_NAPI_PROPERTY("BundleFlag", bundleFlag),
101         DECLARE_NAPI_FUNCTION("getApplicationInfoSync", GetApplicationInfoSync),
102         DECLARE_NAPI_FUNCTION("getBundleInfoSync", GetBundleInfoSync),
103         DECLARE_NAPI_FUNCTION("getBundleInfoForSelf", GetBundleInfoForSelf),
104         DECLARE_NAPI_PROPERTY("PermissionGrantState", permissionGrantState),
105         DECLARE_NAPI_PROPERTY("AbilityType", nAbilityType),
106         DECLARE_NAPI_PROPERTY("BundleType", nBundleType),
107         DECLARE_NAPI_PROPERTY("ModuleType", nModuleType),
108         DECLARE_NAPI_PROPERTY("DisplayOrientation", nDisplayOrientation),
109         DECLARE_NAPI_PROPERTY("LaunchType", nLaunchType),
110         DECLARE_NAPI_PROPERTY("SupportWindowMode", nSupportWindowMode),
111     };
112 
113     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
114     APP_LOGI("init js bundle manager success.");
115     return exports;
116 }
117 
118 static napi_module bundle_manager_module = {
119     .nm_version = 1,
120     .nm_flags = 0,
121     .nm_filename = nullptr,
122     .nm_register_func = BundleManagerExport,
123     .nm_modname = "bundle.bundleManager",
124     .nm_priv = ((void *)0),
125     .reserved = {0}
126 };
127 
BundleManagerRegister(void)128 extern "C" __attribute__((constructor)) void BundleManagerRegister(void)
129 {
130     napi_module_register(&bundle_manager_module);
131 }
132 }
133 }