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 #ifndef INTERFACES_KITS_PERMISSION_USED_MANAGER_NAPI_H
16 #define INTERFACES_KITS_PERMISSION_USED_MANAGER_NAPI_H
17 
18 #include <string>
19 #include <vector>
20 
21 #include "access_token.h"
22 #include "active_change_response_info.h"
23 #include "napi/native_api.h"
24 #include "napi/native_node_api.h"
25 #include "napi_context_common.h"
26 #include "permission_used_request.h"
27 #include "permission_used_result.h"
28 #include "permission_used_type_info.h"
29 
30 namespace OHOS {
31 namespace Security {
32 namespace AccessToken {
33 struct RecordManagerAsyncContext : public PrivacyAsyncWorkData {
RecordManagerAsyncContextRecordManagerAsyncContext34     explicit RecordManagerAsyncContext(napi_env env) : PrivacyAsyncWorkData(env) {}
35 
36     AccessTokenID   tokenId = 0;
37     std::string     permissionName;
38     int32_t         successCount = 0;
39     int32_t         failCount = 0;
40     PermissionUsedType type = PermissionUsedType::NORMAL_TYPE;
41     PermissionUsedRequest request;
42     PermissionUsedResult result;
43     int32_t retCode = -1;
44 };
45 
46 struct PermissionUsedTypeAsyncContext : public PrivacyAsyncWorkData {
PermissionUsedTypeAsyncContextPermissionUsedTypeAsyncContext47     explicit PermissionUsedTypeAsyncContext(napi_env env) : PrivacyAsyncWorkData(env) {}
48     AccessTokenID tokenId = 0;
49     std::string permissionName;
50     std::vector<PermissionUsedTypeInfo> results;
51     int32_t retCode = -1;
52 };
53 
54 typedef PermActiveChangeContext RegisterPermActiveChangeContext;
55 
56 struct UnregisterPermActiveChangeContext : public PermActiveChangeContext {
57     std::vector<std::string> permList;
58 };
59 
60 napi_value AddPermissionUsedRecord(napi_env env, napi_callback_info cbinfo);
61 napi_value StartUsingPermission(napi_env env, napi_callback_info cbinfo);
62 napi_value StopUsingPermission(napi_env env, napi_callback_info cbinfo);
63 napi_value GetPermissionUsedRecords(napi_env env, napi_callback_info cbinfo);
64 napi_value RegisterPermActiveChangeCallback(napi_env env, napi_callback_info cbInfo);
65 napi_value UnregisterPermActiveChangeCallback(napi_env env, napi_callback_info cbInfo);
66 napi_value GetPermissionUsedTypeInfos(napi_env env, napi_callback_info cbInfo);
67 } // namespace AccessToken
68 } // namespace Security
69 } // namespace OHOS
70 #endif /* INTERFACES_KITS_PERMISSION_USED_MANAGER_NAPI_H */
71