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 #ifndef INTERFACES_KITS_DEVICE_SETTINGS_INCLUDE_DEVICE_SETTINGS_ADDON_H 17 #define INTERFACES_KITS_DEVICE_SETTINGS_INCLUDE_DEVICE_SETTINGS_ADDON_H 18 19 #include "device_settings_proxy.h" 20 #include "edm_errors.h" 21 #include "napi/native_api.h" 22 #include "napi/native_common.h" 23 #include "napi/native_node_api.h" 24 #include "napi_edm_common.h" 25 #include "napi_edm_error.h" 26 #include "want.h" 27 28 namespace OHOS { 29 namespace EDM { 30 struct AsyncScreenOffTimeCallbackInfo : AsyncCallbackInfo { 31 OHOS::AppExecFwk::ElementName elementName; 32 int32_t time = 0; 33 }; 34 35 struct AsyncCertCallbackInfo : AsyncCallbackInfo { 36 OHOS::AppExecFwk::ElementName elementName; 37 std::vector<uint8_t> certArray; 38 std::string alias; 39 }; 40 41 class DeviceSettingsAddon { 42 public: 43 static napi_value Init(napi_env env, napi_value exports); 44 45 private: 46 static napi_value SetScreenOffTime(napi_env env, napi_callback_info info); 47 static napi_value GetScreenOffTime(napi_env env, napi_callback_info info); 48 static napi_value SetPowerPolicy(napi_env env, napi_callback_info info); 49 static napi_value GetPowerPolicy(napi_env env, napi_callback_info info); 50 static void NativeGetScreenOffTime(napi_env env, void *data); 51 52 static napi_value InstallUserCertificate(napi_env env, napi_callback_info info); 53 static napi_value UninstallUserCertificate(napi_env env, napi_callback_info info); 54 static void NativeInstallUserCertificate(napi_env env, void *data); 55 static void NativeUninstallUserCertificate(napi_env env, void *data); 56 static bool ParseCertBlob(napi_env env, napi_value object, AsyncCertCallbackInfo *asyncCertCallbackInfo); 57 static bool JsObjToPowerScene(napi_env env, napi_value object, PowerScene &powerScene); 58 static bool JsObjToPowerPolicy(napi_env env, napi_value object, PowerPolicy &powerPolicy); 59 static void CreatePowerSceneObject(napi_env env, napi_value value); 60 static void CreatePowerPolicyActionObject(napi_env env, napi_value value); 61 static napi_value ConvertPolicyPolicyToJs(napi_env env, PowerPolicy &powerPolicy); 62 63 static napi_value SetValue(napi_env env, napi_callback_info info); 64 static napi_value GetValue(napi_env env, napi_callback_info info); 65 static bool JsStrToPowerScene(napi_env env, std::string jsStr, PowerScene &powerScene); 66 static bool JsStrToPowerPolicy(napi_env env, std::string jsStr, PowerPolicy &powerPolicy); 67 static int32_t ConvertPowerPolicyToJsStr( 68 napi_env env, PowerScene &powerScene, PowerPolicy &powerPolicy, std::string &info); 69 }; 70 } // namespace EDM 71 } // namespace OHOS 72 73 #endif // INTERFACES_KITS_DEVICE_SETTINGS_INCLUDE_DEVICE_SETTINGS_ADDON_H 74