11ebd3d54Sopenharmony_ci/* 21ebd3d54Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31ebd3d54Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41ebd3d54Sopenharmony_ci * you may not use this file except in compliance with the License. 51ebd3d54Sopenharmony_ci * You may obtain a copy of the License at 61ebd3d54Sopenharmony_ci * 71ebd3d54Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81ebd3d54Sopenharmony_ci * 91ebd3d54Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101ebd3d54Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111ebd3d54Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121ebd3d54Sopenharmony_ci * See the License for the specific language governing permissions and 131ebd3d54Sopenharmony_ci * limitations under the License. 141ebd3d54Sopenharmony_ci */ 151ebd3d54Sopenharmony_ci 161ebd3d54Sopenharmony_ci#include "init.h" 171ebd3d54Sopenharmony_ci 181ebd3d54Sopenharmony_ci#include "background_mode.h" 191ebd3d54Sopenharmony_ci#include "bg_continuous_task_napi_module.h" 201ebd3d54Sopenharmony_ci#include "cancel_suspend_delay.h" 211ebd3d54Sopenharmony_ci#include "get_remaining_delay_time.h" 221ebd3d54Sopenharmony_ci#include "request_suspend_delay.h" 231ebd3d54Sopenharmony_ci#include "transient_task_log.h" 241ebd3d54Sopenharmony_ci#include "efficiency_resources_operation.h" 251ebd3d54Sopenharmony_ci#include "resource_type.h" 261ebd3d54Sopenharmony_ci#include "common.h" 271ebd3d54Sopenharmony_ci 281ebd3d54Sopenharmony_cinamespace OHOS { 291ebd3d54Sopenharmony_cinamespace BackgroundTaskMgr { 301ebd3d54Sopenharmony_ciEXTERN_C_START 311ebd3d54Sopenharmony_ci 321ebd3d54Sopenharmony_cinapi_value BackgroundTaskManagerInit(napi_env env, napi_value exports) 331ebd3d54Sopenharmony_ci{ 341ebd3d54Sopenharmony_ci napi_property_descriptor desc[] = { 351ebd3d54Sopenharmony_ci DECLARE_NAPI_FUNCTION("requestSuspendDelay", RequestSuspendDelay), 361ebd3d54Sopenharmony_ci DECLARE_NAPI_FUNCTION("cancelSuspendDelay", CancelSuspendDelay), 371ebd3d54Sopenharmony_ci DECLARE_NAPI_FUNCTION("getRemainingDelayTime", GetRemainingDelayTime), 381ebd3d54Sopenharmony_ci DECLARE_NAPI_FUNCTION("startBackgroundRunning", StartBackgroundRunning), 391ebd3d54Sopenharmony_ci DECLARE_NAPI_FUNCTION("stopBackgroundRunning", StopBackgroundRunning), 401ebd3d54Sopenharmony_ci }; 411ebd3d54Sopenharmony_ci 421ebd3d54Sopenharmony_ci NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); 431ebd3d54Sopenharmony_ci 441ebd3d54Sopenharmony_ci return exports; 451ebd3d54Sopenharmony_ci} 461ebd3d54Sopenharmony_ci 471ebd3d54Sopenharmony_civoid SetNamedPropertyByInteger(napi_env env, napi_value dstObj, int32_t objName, const char *propName) 481ebd3d54Sopenharmony_ci{ 491ebd3d54Sopenharmony_ci napi_value prop = nullptr; 501ebd3d54Sopenharmony_ci if (napi_create_int32(env, objName, &prop) == napi_ok) { 511ebd3d54Sopenharmony_ci napi_set_named_property(env, dstObj, propName, prop); 521ebd3d54Sopenharmony_ci } 531ebd3d54Sopenharmony_ci} 541ebd3d54Sopenharmony_ci 551ebd3d54Sopenharmony_cinapi_value BackgroundModeInit(napi_env env, napi_value exports) 561ebd3d54Sopenharmony_ci{ 571ebd3d54Sopenharmony_ci napi_value obj = nullptr; 581ebd3d54Sopenharmony_ci napi_create_object(env, &obj); 591ebd3d54Sopenharmony_ci 601ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::DATA_TRANSFER), "DATA_TRANSFER"); 611ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::AUDIO_PLAYBACK), "AUDIO_PLAYBACK"); 621ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::AUDIO_RECORDING), "AUDIO_RECORDING"); 631ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::LOCATION), "LOCATION"); 641ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::BLUETOOTH_INTERACTION), 651ebd3d54Sopenharmony_ci "BLUETOOTH_INTERACTION"); 661ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::MULTI_DEVICE_CONNECTION), 671ebd3d54Sopenharmony_ci "MULTI_DEVICE_CONNECTION"); 681ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::WIFI_INTERACTION), "WIFI_INTERACTION"); 691ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::VOIP), "VOIP"); 701ebd3d54Sopenharmony_ci SetNamedPropertyByInteger(env, obj, static_cast<uint32_t>(BackgroundMode::TASK_KEEPING), "TASK_KEEPING"); 711ebd3d54Sopenharmony_ci 721ebd3d54Sopenharmony_ci napi_property_descriptor exportFuncs[] = { 731ebd3d54Sopenharmony_ci DECLARE_NAPI_PROPERTY("BackgroundMode", obj), 741ebd3d54Sopenharmony_ci }; 751ebd3d54Sopenharmony_ci 761ebd3d54Sopenharmony_ci napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); 771ebd3d54Sopenharmony_ci return exports; 781ebd3d54Sopenharmony_ci} 791ebd3d54Sopenharmony_ci 801ebd3d54Sopenharmony_ci/* 811ebd3d54Sopenharmony_ci * Module export function 821ebd3d54Sopenharmony_ci */ 831ebd3d54Sopenharmony_cistatic napi_value Init(napi_env env, napi_value exports) 841ebd3d54Sopenharmony_ci{ 851ebd3d54Sopenharmony_ci /* 861ebd3d54Sopenharmony_ci * Properties define 871ebd3d54Sopenharmony_ci */ 881ebd3d54Sopenharmony_ci BackgroundTaskManagerInit(env, exports); 891ebd3d54Sopenharmony_ci BackgroundModeInit(env, exports); 901ebd3d54Sopenharmony_ci return exports; 911ebd3d54Sopenharmony_ci} 921ebd3d54Sopenharmony_ci 931ebd3d54Sopenharmony_ci/* 941ebd3d54Sopenharmony_ci * Module register function 951ebd3d54Sopenharmony_ci */ 961ebd3d54Sopenharmony_ci__attribute__((constructor)) void RegisterModule(void) 971ebd3d54Sopenharmony_ci{ 981ebd3d54Sopenharmony_ci napi_module_register(&g_module); 991ebd3d54Sopenharmony_ci} 1001ebd3d54Sopenharmony_ciEXTERN_C_END 1011ebd3d54Sopenharmony_ci} // namespace BackgroundTaskMgr 1021ebd3d54Sopenharmony_ci} // namespace OHOS 103