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 #include "screenlock_system_ability_interface.h" 22 23 namespace OHOS { 24 namespace ScreenLock { 25 struct AsyncScreenLockInfo : public AsyncCall::Context { 26 napi_status status; 27 bool allowed; AsyncScreenLockInfoAsyncScreenLockInfo28 AsyncScreenLockInfo() : Context(nullptr, nullptr), allowed(false) {}; AsyncScreenLockInfoAsyncScreenLockInfo29 AsyncScreenLockInfo(InputAction input, OutputAction output) 30 : Context(std::move(input), std::move(output)), allowed(false) {}; ~AsyncScreenLockInfoAsyncScreenLockInfo31 ~AsyncScreenLockInfo() override{}; 32 }; 33 34 struct SendEventInfo : public AsyncCall::Context { 35 int32_t param; 36 std::string eventInfo; 37 bool flag; 38 napi_status status; 39 bool allowed; SendEventInfoSendEventInfo40 SendEventInfo() 41 : Context(nullptr, nullptr), param(0), eventInfo(""), flag(false), status(napi_generic_failure), 42 allowed(false){}; SendEventInfoSendEventInfo43 SendEventInfo(InputAction input, OutputAction output) 44 : Context(std::move(input), std::move(output)), param(0), eventInfo(""), flag(false), 45 status(napi_generic_failure), allowed(false){}; ~SendEventInfoSendEventInfo46 ~SendEventInfo() override{}; 47 }; 48 49 struct ScreenlockOnCallBack { 50 napi_env env; 51 napi_ref callbackref; 52 napi_value thisVar; 53 SystemEvent systemEvent; 54 ErrorInfo errorInfo; 55 napi_deferred deferred = nullptr; 56 bool callBackResult = false; 57 }; 58 59 napi_status IsVaildEvent(const std::string &type); 60 napi_status CheckParamNumber(size_t argc, std::uint32_t paramNumber); 61 napi_status CheckParamType(napi_env env, napi_value jsType, napi_status status); 62 void ThrowError(napi_env env, const uint32_t &code, const std::string &msg); 63 void GetErrorInfo(int32_t errorCode, ErrorInfo &errorInfo); 64 std::string GetErrorMessage(const uint32_t &code); 65 napi_status Init(napi_env env, napi_value exports); 66 napi_value NAPI_IsScreenLocked(napi_env env, napi_callback_info info); 67 napi_value NAPI_IsLocked(napi_env env, napi_callback_info info); 68 napi_value NAPI_UnlockScreen(napi_env env, napi_callback_info info); 69 napi_value NAPI_Unlock(napi_env env, napi_callback_info info); 70 napi_value NAPI_Lock(napi_env env, napi_callback_info info); 71 napi_value NAPI_IsSecureMode(napi_env env, napi_callback_info info); 72 napi_value NAPI_ScreenLockSendEvent(napi_env env, napi_callback_info info); 73 napi_value NAPI_OnSystemEvent(napi_env env, napi_callback_info info); 74 } // namespace ScreenLock 75 } // namespace OHOS 76 #endif // NAPI_SCREENLOCK_ABILITY_H