17c804472Sopenharmony_ci/*
27c804472Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47c804472Sopenharmony_ci * you may not use this file except in compliance with the License.
57c804472Sopenharmony_ci * You may obtain a copy of the License at
67c804472Sopenharmony_ci *
77c804472Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87c804472Sopenharmony_ci *
97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127c804472Sopenharmony_ci * See the License for the specific language governing permissions and
137c804472Sopenharmony_ci * limitations under the License.
147c804472Sopenharmony_ci */
157c804472Sopenharmony_ci
167c804472Sopenharmony_ci#include "TimerTaskHandler.h"
177c804472Sopenharmony_ci
187c804472Sopenharmony_ci#if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
197c804472Sopenharmony_ci#include "CallbackManager.h"
207c804472Sopenharmony_ci#endif
217c804472Sopenharmony_ci
227c804472Sopenharmony_ci#include "font/ui_font.h"
237c804472Sopenharmony_ci#include "global.h"
247c804472Sopenharmony_ci#include "JsonReader.h"
257c804472Sopenharmony_ci#include "task_manager.h"
267c804472Sopenharmony_ci
277c804472Sopenharmony_ci#include "AsyncWorkManager.h"
287c804472Sopenharmony_ci#include "CommandLineInterface.h"
297c804472Sopenharmony_ci#include "JsAppImpl.h"
307c804472Sopenharmony_ci#include "LanguageManagerImpl.h"
317c804472Sopenharmony_ci#include "PreviewerEngineLog.h"
327c804472Sopenharmony_ci#include "SharedDataManager.h"
337c804472Sopenharmony_ci
347c804472Sopenharmony_ci#if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
357c804472Sopenharmony_ci#include "VirtualLocation.h"
367c804472Sopenharmony_ci#endif
377c804472Sopenharmony_ci
387c804472Sopenharmony_ci#include "VirtualScreenImpl.h"
397c804472Sopenharmony_ci
407c804472Sopenharmony_ciusing namespace OHOS::ACELite;
417c804472Sopenharmony_ci
427c804472Sopenharmony_civoid TimerTaskHandler::TaskHandle()
437c804472Sopenharmony_ci{
447c804472Sopenharmony_ci    OHOS::TaskManager::GetInstance()->TaskHandler();
457c804472Sopenharmony_ci    VirtualScreenImpl::CheckBufferSend();
467c804472Sopenharmony_ci}
477c804472Sopenharmony_ci
487c804472Sopenharmony_civoid TimerTaskHandler::CheckDevice()
497c804472Sopenharmony_ci{
507c804472Sopenharmony_ci    SharedDataManager::CheckTick();
517c804472Sopenharmony_ci
527c804472Sopenharmony_ci#if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
537c804472Sopenharmony_ci    if (VirtualLocation::GetInstance().IsPostionChanged()) {
547c804472Sopenharmony_ci        VirtualLocation::GetInstance().ExecCallBack();
557c804472Sopenharmony_ci    }
567c804472Sopenharmony_ci#endif
577c804472Sopenharmony_ci
587c804472Sopenharmony_ci    AsyncWorkManager::GetInstance().ExecAllAsyncWork();
597c804472Sopenharmony_ci}
607c804472Sopenharmony_ci
617c804472Sopenharmony_ci#if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
627c804472Sopenharmony_civoid TimerTaskHandler::CheckBarometerChanged(uint32_t value)
637c804472Sopenharmony_ci{
647c804472Sopenharmony_ci    ILOG("CheckBarometerChanged value: %d", value);
657c804472Sopenharmony_ci    CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_BAROMETER, "pressure",
667c804472Sopenharmony_ci                                                            value);
677c804472Sopenharmony_ci}
687c804472Sopenharmony_ci
697c804472Sopenharmony_civoid TimerTaskHandler::CheckStepCountChanged(uint32_t value)
707c804472Sopenharmony_ci{
717c804472Sopenharmony_ci    ILOG("CheckStepCountChanged value: %d", value);
727c804472Sopenharmony_ci    CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_STEP_COUNTER, "steps",
737c804472Sopenharmony_ci                                                            value);
747c804472Sopenharmony_ci}
757c804472Sopenharmony_ci
767c804472Sopenharmony_civoid TimerTaskHandler::CheckHeartRateChanged(uint8_t value)
777c804472Sopenharmony_ci{
787c804472Sopenharmony_ci    ILOG("CheckHeartRateChanged value: %d", value);
797c804472Sopenharmony_ci    CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_HEART_RATE, "heartRate",
807c804472Sopenharmony_ci                                                            value);
817c804472Sopenharmony_ci}
827c804472Sopenharmony_ci
837c804472Sopenharmony_civoid TimerTaskHandler::CheckOnBodyStateChanged(bool value)
847c804472Sopenharmony_ci{
857c804472Sopenharmony_ci    ILOG("CheckOnBodyStateChanged value: %d", value);
867c804472Sopenharmony_ci    CallbackManager::GetInstance().ExecuteBooleanInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_ON_BODY_STATE, "value",
877c804472Sopenharmony_ci                                                             value);
887c804472Sopenharmony_ci}
897c804472Sopenharmony_ci#endif
907c804472Sopenharmony_ci
917c804472Sopenharmony_civoid TimerTaskHandler::CheckLanguageChanged(std::string language)
927c804472Sopenharmony_ci{
937c804472Sopenharmony_ci    ILOG("CheckLanguageChanged value: %s", language.c_str());
947c804472Sopenharmony_ci    GLOBAL_ConfigLanguage(language.data());
957c804472Sopenharmony_ci}
967c804472Sopenharmony_ci
977c804472Sopenharmony_civoid TimerTaskHandler::CheckBrightnessValueChanged(uint8_t value)
987c804472Sopenharmony_ci{
997c804472Sopenharmony_ci    Json2::Value result = JsonReader::CreateObject();
1007c804472Sopenharmony_ci    result.Add("version", CommandLineInterface::COMMAND_VERSION.c_str());
1017c804472Sopenharmony_ci    result.Add("property", "Brightness");
1027c804472Sopenharmony_ci    Json2::Value brightness = JsonReader::CreateObject();
1037c804472Sopenharmony_ci    brightness.Add("Brightness", static_cast<double>(value));
1047c804472Sopenharmony_ci    result.Add("result", brightness);
1057c804472Sopenharmony_ci    ILOG("CheckBrightnessValueChanged send Brightness: %d", static_cast<uint32_t>(value));
1067c804472Sopenharmony_ci    CommandLineInterface::SendJsonData(result);
1077c804472Sopenharmony_ci}
1087c804472Sopenharmony_ci
1097c804472Sopenharmony_civoid TimerTaskHandler::CheckJsRunning()
1107c804472Sopenharmony_ci{
1117c804472Sopenharmony_ci    JsAppImpl::GetInstance().SetRunning(true);
1127c804472Sopenharmony_ci}
113