199552fe9Sopenharmony_ci/* 299552fe9Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 399552fe9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 499552fe9Sopenharmony_ci * you may not use this file except in compliance with the License. 599552fe9Sopenharmony_ci * You may obtain a copy of the License at 699552fe9Sopenharmony_ci * 799552fe9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 899552fe9Sopenharmony_ci * 999552fe9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1099552fe9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1199552fe9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1299552fe9Sopenharmony_ci * See the License for the specific language governing permissions and 1399552fe9Sopenharmony_ci * limitations under the License. 1499552fe9Sopenharmony_ci */ 1599552fe9Sopenharmony_ci 1699552fe9Sopenharmony_ci#include "init.h" 1799552fe9Sopenharmony_ci 1899552fe9Sopenharmony_ci#include "allow_type.h" 1999552fe9Sopenharmony_ci#include "common.h" 2099552fe9Sopenharmony_ci#include "standby_napi_module.h" 2199552fe9Sopenharmony_ci 2299552fe9Sopenharmony_cinamespace OHOS { 2399552fe9Sopenharmony_cinamespace DevStandbyMgr { 2499552fe9Sopenharmony_ciEXTERN_C_START 2599552fe9Sopenharmony_ci 2699552fe9Sopenharmony_cinapi_value DeviceStandbyFuncInit(napi_env env, napi_value exports) 2799552fe9Sopenharmony_ci{ 2899552fe9Sopenharmony_ci napi_property_descriptor desc[] = { 2999552fe9Sopenharmony_ci DECLARE_NAPI_FUNCTION("isDeviceInStandby", IsDeviceInStandby), 3099552fe9Sopenharmony_ci DECLARE_NAPI_FUNCTION("getExemptedApps", GetExemptionListApps), 3199552fe9Sopenharmony_ci DECLARE_NAPI_FUNCTION("requestExemptionResource", ApplyAllowResource), 3299552fe9Sopenharmony_ci DECLARE_NAPI_FUNCTION("releaseExemptionResource", UnapplyAllowResource), 3399552fe9Sopenharmony_ci }; 3499552fe9Sopenharmony_ci NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); 3599552fe9Sopenharmony_ci 3699552fe9Sopenharmony_ci return exports; 3799552fe9Sopenharmony_ci} 3899552fe9Sopenharmony_ci 3999552fe9Sopenharmony_civoid SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName) 4099552fe9Sopenharmony_ci{ 4199552fe9Sopenharmony_ci napi_value prop = nullptr; 4299552fe9Sopenharmony_ci if (napi_create_int32(env, objName, &prop) == napi_ok) { 4399552fe9Sopenharmony_ci napi_set_named_property(env, dstObj, propName, prop); 4499552fe9Sopenharmony_ci } 4599552fe9Sopenharmony_ci} 4699552fe9Sopenharmony_ci 4799552fe9Sopenharmony_cinapi_value DeviceStandbyTypeInit(napi_env env, napi_value exports) 4899552fe9Sopenharmony_ci{ 4999552fe9Sopenharmony_ci napi_value obj = nullptr; 5099552fe9Sopenharmony_ci napi_create_object(env, &obj); 5199552fe9Sopenharmony_ci 5299552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::NETWORK), "NETWORK"); 5399552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::RUNNING_LOCK), "RUNNING_LOCK"); 5499552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::TIMER), "TIMER"); 5599552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::WORK_SCHEDULER), "WORK_SCHEDULER"); 5699552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::AUTO_SYNC), "AUTO_SYNC"); 5799552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::PUSH), "PUSH"); 5899552fe9Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(AllowType::FREEZE), "FREEZE"); 5999552fe9Sopenharmony_ci 6099552fe9Sopenharmony_ci napi_property_descriptor exportFuncs[] = { 6199552fe9Sopenharmony_ci DECLARE_NAPI_PROPERTY("ResourceType", obj), 6299552fe9Sopenharmony_ci }; 6399552fe9Sopenharmony_ci 6499552fe9Sopenharmony_ci napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); 6599552fe9Sopenharmony_ci return exports; 6699552fe9Sopenharmony_ci} 6799552fe9Sopenharmony_ci 6899552fe9Sopenharmony_ci/* 6999552fe9Sopenharmony_ci * Module export function 7099552fe9Sopenharmony_ci */ 7199552fe9Sopenharmony_cistatic napi_value DeviceStandbyInit(napi_env env, napi_value exports) 7299552fe9Sopenharmony_ci{ 7399552fe9Sopenharmony_ci /* 7499552fe9Sopenharmony_ci * Properties define 7599552fe9Sopenharmony_ci */ 7699552fe9Sopenharmony_ci DeviceStandbyFuncInit(env, exports); 7799552fe9Sopenharmony_ci DeviceStandbyTypeInit(env, exports); 7899552fe9Sopenharmony_ci return exports; 7999552fe9Sopenharmony_ci} 8099552fe9Sopenharmony_ci 8199552fe9Sopenharmony_ci/* 8299552fe9Sopenharmony_ci * Module register function 8399552fe9Sopenharmony_ci */ 8499552fe9Sopenharmony_ci__attribute__((constructor)) void RegisterModule(void) 8599552fe9Sopenharmony_ci{ 8699552fe9Sopenharmony_ci napi_module_register(&g_module); 8799552fe9Sopenharmony_ci} 8899552fe9Sopenharmony_ciEXTERN_C_END 8999552fe9Sopenharmony_ci} // namespace DevStandbyMgr 9099552fe9Sopenharmony_ci} // namespace OHOS 91