• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "TimerTaskHandler.h"
17 
18 #if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
19 #include "CallbackManager.h"
20 #endif
21 
22 #include "font/ui_font.h"
23 #include "global.h"
24 #include "JsonReader.h"
25 #include "task_manager.h"
26 
27 #include "AsyncWorkManager.h"
28 #include "CommandLineInterface.h"
29 #include "JsAppImpl.h"
30 #include "LanguageManagerImpl.h"
31 #include "PreviewerEngineLog.h"
32 #include "SharedDataManager.h"
33 
34 #if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
35 #include "VirtualLocation.h"
36 #endif
37 
38 #include "VirtualScreenImpl.h"
39 
40 using namespace OHOS::ACELite;
41 
TaskHandle()42 void TimerTaskHandler::TaskHandle()
43 {
44     OHOS::TaskManager::GetInstance()->TaskHandler();
45     VirtualScreenImpl::CheckBufferSend();
46 }
47 
CheckDevice()48 void TimerTaskHandler::CheckDevice()
49 {
50     SharedDataManager::CheckTick();
51 
52 #if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
53     if (VirtualLocation::GetInstance().IsPostionChanged()) {
54         VirtualLocation::GetInstance().ExecCallBack();
55     }
56 #endif
57 
58     AsyncWorkManager::GetInstance().ExecAllAsyncWork();
59 }
60 
61 #if defined(LITEWEARABLE_SUPPORTED) && LITEWEARABLE_SUPPORTED
CheckBarometerChanged(uint32_t value)62 void TimerTaskHandler::CheckBarometerChanged(uint32_t value)
63 {
64     ILOG("CheckBarometerChanged value: %d", value);
65     CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_BAROMETER, "pressure",
66                                                             value);
67 }
68 
CheckStepCountChanged(uint32_t value)69 void TimerTaskHandler::CheckStepCountChanged(uint32_t value)
70 {
71     ILOG("CheckStepCountChanged value: %d", value);
72     CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_STEP_COUNTER, "steps",
73                                                             value);
74 }
75 
CheckHeartRateChanged(uint8_t value)76 void TimerTaskHandler::CheckHeartRateChanged(uint8_t value)
77 {
78     ILOG("CheckHeartRateChanged value: %d", value);
79     CallbackManager::GetInstance().ExecuteNumberInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_HEART_RATE, "heartRate",
80                                                             value);
81 }
82 
CheckOnBodyStateChanged(bool value)83 void TimerTaskHandler::CheckOnBodyStateChanged(bool value)
84 {
85     ILOG("CheckOnBodyStateChanged value: %d", value);
86     CallbackManager::GetInstance().ExecuteBooleanInfoSuccess(SIMULATOR_JS_ATAPTER_SUBSCRIBE_ON_BODY_STATE, "value",
87                                                              value);
88 }
89 #endif
90 
CheckLanguageChanged(std::string language)91 void TimerTaskHandler::CheckLanguageChanged(std::string language)
92 {
93     ILOG("CheckLanguageChanged value: %s", language.c_str());
94     GLOBAL_ConfigLanguage(language.data());
95 }
96 
CheckBrightnessValueChanged(uint8_t value)97 void TimerTaskHandler::CheckBrightnessValueChanged(uint8_t value)
98 {
99     Json2::Value result = JsonReader::CreateObject();
100     result.Add("version", CommandLineInterface::COMMAND_VERSION.c_str());
101     result.Add("property", "Brightness");
102     Json2::Value brightness = JsonReader::CreateObject();
103     brightness.Add("Brightness", static_cast<double>(value));
104     result.Add("result", brightness);
105     ILOG("CheckBrightnessValueChanged send Brightness: %d", static_cast<uint32_t>(value));
106     CommandLineInterface::SendJsonData(result);
107 }
108 
CheckJsRunning()109 void TimerTaskHandler::CheckJsRunning()
110 {
111     JsAppImpl::GetInstance().SetRunning(true);
112 }
113