1 /*
2 * Copyright (c) 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_resource.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
BundleResourceExport(napi_env env,napi_value exports)26 static napi_value BundleResourceExport(napi_env env, napi_value exports)
27 {
28 napi_value resourceFlag = nullptr;
29 NAPI_CALL(env, napi_create_object(env, &resourceFlag));
30 CreateBundleResourceFlagObject(env, resourceFlag);
31
32 napi_property_descriptor desc[] = {
33 DECLARE_NAPI_FUNCTION("getBundleResourceInfo", GetBundleResourceInfo),
34 DECLARE_NAPI_FUNCTION("getLauncherAbilityResourceInfo", GetLauncherAbilityResourceInfo),
35 DECLARE_NAPI_FUNCTION("getAllBundleResourceInfo", GetAllBundleResourceInfo),
36 DECLARE_NAPI_FUNCTION("getAllLauncherAbilityResourceInfo", GetAllLauncherAbilityResourceInfo),
37 DECLARE_NAPI_PROPERTY("ResourceFlag", resourceFlag),
38 };
39
40 NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
41 APP_LOGI("init bundle resource success");
42 return exports;
43 }
44
45 static napi_module bundle_resource_module = {
46 .nm_version = 1,
47 .nm_flags = 0,
48 .nm_filename = nullptr,
49 .nm_register_func = BundleResourceExport,
50 .nm_modname = "bundle.bundleResourceManager",
51 .nm_priv = ((void *)0),
52 .reserved = {0}
53 };
54
BundleResourceRegister(void)55 extern "C" __attribute__((constructor)) void BundleResourceRegister(void)
56 {
57 napi_module_register(&bundle_resource_module);
58 }
59 }
60 }