• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "native_module.h"
16 #include "permission_record_manager_napi.h"
17 #include "permission_used_request.h"
18 
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 EXTERN_C_START
23 /*
24  * function for module exports
25  */
Init(napi_env env,napi_value exports)26 static napi_value Init(napi_env env, napi_value exports)
27 {
28     napi_property_descriptor descriptor[] = {
29         DECLARE_NAPI_FUNCTION("addPermissionUsedRecord", AddPermissionUsedRecord),
30         DECLARE_NAPI_FUNCTION("startUsingPermission", StartUsingPermission),
31         DECLARE_NAPI_FUNCTION("stopUsingPermission", StopUsingPermission),
32         DECLARE_NAPI_FUNCTION("getPermissionUsedRecord", GetPermissionUsedRecords),
33         DECLARE_NAPI_FUNCTION("getPermissionUsedRecords", GetPermissionUsedRecords),
34         DECLARE_NAPI_FUNCTION("on", RegisterPermActiveChangeCallback),
35         DECLARE_NAPI_FUNCTION("off", UnregisterPermActiveChangeCallback)
36     };
37 
38     napi_define_properties(env, exports, sizeof(descriptor) / sizeof(descriptor[0]), descriptor);
39 
40     napi_value permissionUsageFlag = nullptr;
41     napi_create_object(env, &permissionUsageFlag);
42 
43     napi_value prop = nullptr;
44     napi_create_int32(env, FLAG_PERMISSION_USAGE_SUMMARY, &prop);
45     napi_set_named_property(env, permissionUsageFlag, "FLAG_PERMISSION_USAGE_SUMMARY", prop);
46 
47     prop = nullptr;
48     napi_create_int32(env, FLAG_PERMISSION_USAGE_DETAIL, &prop);
49     napi_set_named_property(env, permissionUsageFlag, "FLAG_PERMISSION_USAGE_DETAIL", prop);
50 
51     napi_value permActiveStatus = nullptr;
52     napi_create_object(env, &permActiveStatus); // create enmu permActiveStatus
53 
54     prop = nullptr;
55     napi_create_int32(env, PERM_INACTIVE, &prop);
56     napi_set_named_property(env, permActiveStatus, "PERM_INACTIVE", prop);
57 
58     prop = nullptr;
59     napi_create_int32(env, PERM_ACTIVE_IN_FOREGROUND, &prop);
60     napi_set_named_property(env, permActiveStatus, "PERM_ACTIVE_IN_FOREGROUND", prop);
61 
62     prop = nullptr;
63     napi_create_int32(env, PERM_ACTIVE_IN_BACKGROUND, &prop);
64     napi_set_named_property(env, permActiveStatus, "PERM_ACTIVE_IN_BACKGROUND", prop);
65 
66     napi_property_descriptor exportFuncs[] = {
67         DECLARE_NAPI_PROPERTY("PermissionUsageFlag ", permissionUsageFlag),
68         DECLARE_NAPI_PROPERTY("PermissionActiveStatus ", permActiveStatus)
69     };
70     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(exportFuncs[0]), exportFuncs);
71 
72     return exports;
73 }
74 EXTERN_C_END
75 
76 /*
77  * Module define
78  */
79 static napi_module g_module = {
80     .nm_version = 1,
81     .nm_flags = 0,
82     .nm_filename = nullptr,
83     .nm_register_func = Init,
84     .nm_modname = "privacyManager",
85     .nm_priv = ((void *)0),
86     .reserved = {0}
87 };
88 
89 /*
90  * Module register function
91  */
RegisterPrivacyModule(void)92 extern "C" __attribute__((constructor)) void RegisterPrivacyModule(void)
93 {
94     napi_module_register(&g_module);
95 }
96 }  // namespace AccessToken
97 }  // namespace Security
98 }  // namespace OHOS