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 NAPI_SCREENLOCK_ABILITY_H
16 #define NAPI_SCREENLOCK_ABILITY_H
17 
18 #include "async_call.h"
19 #include "napi/native_common.h"
20 #include "napi/native_node_api.h"
21 
22 namespace OHOS {
23 namespace ScreenLock {
24 struct AsyncScreenLockInfo : public AsyncCall::Context {
25     napi_status status;
26     bool allowed;
AsyncScreenLockInfoAsyncScreenLockInfo27     AsyncScreenLockInfo() : Context(nullptr, nullptr), allowed(false){};
AsyncScreenLockInfoAsyncScreenLockInfo28     AsyncScreenLockInfo(InputAction input, OutputAction output)
29         : Context(std::move(input), std::move(output)), allowed(false){};
~AsyncScreenLockInfoAsyncScreenLockInfo30     ~AsyncScreenLockInfo() override{};
31 };
32 
33 struct SendEventInfo : public AsyncCall::Context {
34     int32_t param;
35     std::string eventInfo;
36     bool flag;
37     napi_status status;
38     bool allowed;
SendEventInfoSendEventInfo39     SendEventInfo()
40         : Context(nullptr, nullptr), param(0), eventInfo(""), flag(false), status(napi_generic_failure),
41           allowed(false){};
SendEventInfoSendEventInfo42     SendEventInfo(InputAction input, OutputAction output)
43         : Context(std::move(input), std::move(output)), param(0), eventInfo(""), flag(false),
44           status(napi_generic_failure), allowed(false){};
~SendEventInfoSendEventInfo45     ~SendEventInfo() override{};
46 };
47 
48 struct ScreenLockDisableInfo : public AsyncCall::Context {
49     bool disable;
50     int32_t userId;
51     napi_status status;
52     bool allowed;
ScreenLockDisableInfoScreenLockDisableInfo53     ScreenLockDisableInfo()
54         : Context(nullptr, nullptr), disable(false), userId(-1), status(napi_generic_failure),
55           allowed(false){};
ScreenLockDisableInfoScreenLockDisableInfo56     ScreenLockDisableInfo(InputAction input, OutputAction output)
57         : Context(std::move(input), std::move(output)), disable(false), userId(-1),
58           status(napi_generic_failure), allowed(false){};
~ScreenLockDisableInfoScreenLockDisableInfo59     ~ScreenLockDisableInfo() override{};
60 };
61 
62 struct ScreenLockAuthStatInfo : public AsyncCall::Context {
63     int32_t userId;
64     int32_t authState;
65     std::string authToken;
66     napi_status status;
67     bool allowed;
ScreenLockAuthStatInfoScreenLockAuthStatInfo68     ScreenLockAuthStatInfo()
69         : Context(nullptr, nullptr), userId(-1), authState(-1), authToken(""), status(napi_generic_failure),
70           allowed(false){};
ScreenLockAuthStatInfoScreenLockAuthStatInfo71     ScreenLockAuthStatInfo(InputAction input, OutputAction output)
72         : Context(std::move(input), std::move(output)), userId(-1), authState(-1), authToken(""),
73           status(napi_generic_failure), allowed(false){};
~ScreenLockAuthStatInfoScreenLockAuthStatInfo74     ~ScreenLockAuthStatInfo() override{};
75 };
76 
77 struct ScreenLockStrongAuthInfo : public AsyncCall::Context {
78     int32_t reasonFlag;
79     int32_t userId;
80     napi_status status;
81     bool allowed;
ScreenLockStrongAuthInfoScreenLockStrongAuthInfo82     ScreenLockStrongAuthInfo()
83         : Context(nullptr, nullptr), reasonFlag(-1), userId(-1), status(napi_generic_failure),
84           allowed(false){};
ScreenLockStrongAuthInfoScreenLockStrongAuthInfo85     ScreenLockStrongAuthInfo(InputAction input, OutputAction output)
86         : Context(std::move(input), std::move(output)), reasonFlag(-1), userId(-1),
87           status(napi_generic_failure), allowed(false){};
~ScreenLockStrongAuthInfoScreenLockStrongAuthInfo88     ~ScreenLockStrongAuthInfo() override{};
89 };
90 
91 napi_status IsValidEvent(const std::string &type);
92 napi_status CheckParamNumber(size_t argc, std::uint32_t paramNumber);
93 napi_status CheckParamType(napi_env env, napi_value jsType, napi_status status);
94 void ThrowError(napi_env env, const uint32_t &code, const std::string &msg);
95 void GetErrorInfo(int32_t errorCode, ErrorInfo &errorInfo);
96 std::string GetErrorMessage(const uint32_t &code);
97 napi_status Init(napi_env env, napi_value exports);
98 napi_value NAPI_IsScreenLocked(napi_env env, napi_callback_info info);
99 napi_value NAPI_IsLocked(napi_env env, napi_callback_info info);
100 napi_value NAPI_UnlockScreen(napi_env env, napi_callback_info info);
101 napi_value NAPI_Unlock(napi_env env, napi_callback_info info);
102 napi_value NAPI_Lock(napi_env env, napi_callback_info info);
103 napi_value NAPI_IsSecureMode(napi_env env, napi_callback_info info);
104 napi_value NAPI_ScreenLockSendEvent(napi_env env, napi_callback_info info);
105 napi_value NAPI_OnSystemEvent(napi_env env, napi_callback_info info);
106 napi_value NAPI_IsScreenLockDisabled(napi_env env, napi_callback_info info);
107 napi_value NAPI_SetScreenLockDisabled(napi_env env, napi_callback_info info);
108 napi_value NAPI_SetScreenLockAuthState(napi_env env, napi_callback_info info);
109 napi_value NAPI_GetScreenLockAuthState(napi_env env, napi_callback_info info);
110 napi_value NAPI_RequestStrongAuth(napi_env env, napi_callback_info info);
111 napi_value NAPI_GetStrongAuth(napi_env env, napi_callback_info info);
112 } // namespace ScreenLock
113 } // namespace OHOS
114 #endif //  NAPI_SCREENLOCK_ABILITY_H