87d4b2c8a9da3725de95e2cd32b3efa8d38d2f7d
[mirrors/FD230.git] /
1 #include "../notify/debug_output_notification/debug_output_notification_adapter.h"
2 #include "../notify/debug_output_notification/debug_output_notification_itemview.h"
3 #include "AppViewIDs.h"
4 #include "NativeAbility.h"
5 #include "battery_hal.h"
6 #include "battery_service.h"
7 #include "bleEvent.h"
8 #include "bluetooth/include/BluetoothModel.h"
9 #include "broadcast_feature.h"
10 #include "broadcast_service.h"
11 #include "cat1_ctl.h"
12 #include "cat1_server.h"
13 #include "components/ui_image_view.h"
14 #include "components/ui_label_button.h"
15 #include "components/ui_label_ext.h"
16 #include "components/ui_scroll_view.h"
17 #include "custom_runtime.h"
18 #include "custom_utils.h"
19 #include "graphic_service.h"
20 #include "lwip/apps/http_client.h"
21 #include "notification_manager.h"
22 #include "samgr_lite.h"
23 #include "system/include/SystemLogModel.h"
24 #include "tcxo.h"
25 #include "thread_adapter.h"
26 #include "thread_init.h"
27 #include "vibrator_service.h"
28 #include "wearable_log.h"
29 #include <array>
30 #include <cmsis_os2.h>
31 #include <cstdint>
32 #include <custom_runtime.h>
33 #include <custom_utils.h>
34 #include <dirent.h>
35 #include <fstream>
36 #include <iomanip>
37 #include <iostream>
38 #include <map>
39 #include <service/graphic_service.h>
40 #include <sstream>
41 #include <string>
42 #include <sys/types.h>
43 #include <vector>
44 #include <deque>
45 #include <cerrno>
46 #include "bleService.h"
47 #include "sleep/include/SleepModel.h"
48 #include "heartrate/include/HeartModel.h"
49 #include "heart_blood/health_service/health_service.h"
50 #include "BluetoothModel.h"
51 #include <iostream>  
52 #include <sstream>  
53 #include <vector>  
54 #include <dirent.h>  
55 #include <string>  
56 #include <cstring>  
57 #include <cstdint> 
58
59 namespace OHOS
60 {
61     /**************************************************************************************************** */
62     // 辅助函数
63
64     // 函数:读取文件夹中的文件  
65     std::vector<std::string> readDirectory(const char *path) {  
66         std::vector<std::string> fileNames; // 存储读取的文件名  
67         struct dirent *entry;                // 定义目录项  
68
69         // 打开目录  
70         DIR *dir = opendir(path);  
71         if (!dir) {  
72             std::cerr << "Error opening directory: " << path << " - " << strerror(errno) << std::endl;  
73             return fileNames; // 返回空列表  
74         }  
75
76         // 读取目录项  
77         while ((entry = readdir(dir)) != nullptr) {  
78             // 跳过 . 和 ..  
79             if (entry->d_name[0] != '.') {  
80                 fileNames.push_back(entry->d_name); // 存储文件名  
81             }  
82         }  
83
84         // 关闭目录  
85         closedir(dir);  
86         return fileNames;
87     }
88     
89     // 格式化时间的辅助函数  
90     std::string formatTime(uint32_t time) {  
91         char labelTime[20];  
92         if (uapi_get_TIME_STR(time, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) {  
93             return "--"; // 默认值  
94         } else {  
95             return labelTime; // 成功获取时间  
96         }
97     }
98     /**************************************************************************************************** */
99     
100     struct DebugOutputViewMapper
101     {
102         const int16_t viewId;
103         bool (DebugOutputViewEventListener::*func)(int16_t thisView);
104     };
105
106     static const DebugOutputViewMapper ViewMapper[] = {
107         {0, &DebugOutputViewEventListener::ChangeDebugOutputMainView},
108         {1, &DebugOutputViewEventListener::ChangeDebugOutputView1},
109     };
110
111     /* -------------------------------------------------------------------------- */
112     UIViewGroup *DebugGroupView{nullptr};
113     UIScrollView *DebugScrollView[sizeof(ViewMapper) / sizeof(ViewMapper[0])]{nullptr};
114     UIList *debugOutputList{nullptr};
115     DebugOutputAdapter *debugOutputAdapter{nullptr};
116     UILabel *debugOutputLabel{nullptr};
117     UILabelButton *debugOutputLabelButton{nullptr};
118     UILabelButton *debugOutputbleServiceLabelButton{nullptr};
119     static constexpr const char *DEBUGOUTPUTLABELBUTTON = "debugOutputLabelButton";
120     static constexpr const char *DEBUGOUTPUTBLESERVICELABELBUTTON = "debugOutputbleServiceLabelButton";
121     /* -------------------------------------------------------------------------- */
122
123     void DebugOutputViewEventListener::InitDebugOutputItem()
124     {
125         int index = 0;
126         debugOutputItemInfo[index++] = {index, "exit"}; // 标题:设置()
127         debugOutputItemInfo[index++] = {index, "bt_ble_connectstat"};
128         debugOutputItemInfo[index++] = {index, "cat1_runtime_status_t"};
129         debugOutputItemInfo[index++] = {index, "runtime_status_t"};
130         // 系统日志
131         debugOutputItemInfo[index++] = {index, "system_log"};
132         // 电池服务
133         debugOutputItemInfo[index++] = {index, "battery_service"};
134         // 死机文件列表
135         debugOutputItemInfo[index++] = {index, "shutdown_file_list"};
136         // 睡眠数据
137         debugOutputItemInfo[index++] = {index, "sleep_time"};
138         // 系统空闲内存
139         debugOutputItemInfo[index++] = {index, "system_free_memory"};
140         // nextday执行日志
141         debugOutputItemInfo[index++] = {index, "nextday_log"};
142          // 读取心率
143         debugOutputItemInfo[index++] = {index, "heart_rate_data"};
144         // 弹窗日志
145         debugOutputItemInfo[index++] = {index, "popup_windows_log"};
146         usedLen = index;
147         /* -------------------------------- Add data -------------------------------- */
148         for (uint8_t i = 0; i < usedLen; i++)
149         {
150             if (debugOutputAdapter)
151                 debugOutputAdapter->AddListItem(debugOutputItemInfo[i]);
152         }
153         /* -------------------------------------------------------------------------- */
154     }
155
156     DebugOutputViewEventListener::DebugOutputViewEventListener()
157     {
158         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::DebugOutputViewEventListener");
159     }
160
161     DebugOutputViewEventListener::~DebugOutputViewEventListener()
162     {
163         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::DebugOutputViewEventListener");
164     }
165
166     DebugOutputViewEventListener &DebugOutputViewEventListener::GetInstance()
167     {
168         static DebugOutputViewEventListener instance;
169         return instance;
170     }
171     static std::string getCurrentWatchMacAddress()
172     {
173         uint32_t len = 32;
174         char *buf_btaddr = (char *)malloc(32);
175         if (buf_btaddr == NULL)
176             return "";
177         memset_s(buf_btaddr, 32, 0, 32);
178         uint8_t ret = uapi_get_btaddr((uint8_t *)buf_btaddr, &len);
179         std::string str = std::string(buf_btaddr);
180         printf("%s | %s \n", buf_btaddr, str.c_str());
181         free(buf_btaddr);
182         return (str);
183     }
184
185     static std::string getCurrentWatchadvdata()
186     {
187         uint32_t len = 64;
188         char *buf_advdata = (char *)malloc(len);
189
190         if (buf_advdata == NULL)
191             return "";
192         memset_s(buf_advdata, 64, 0, 64);
193         get_adv_data(buf_advdata);
194
195         std::string str = std::string(buf_advdata);
196         printf("%s | %s \n", buf_advdata, str.c_str());
197
198         free(buf_advdata);
199         return (str);
200     }
201
202     std::string DebugOutputViewEventListener::get_bt_runtime_status_t(void)
203     {
204         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_bt_runtime_status_t");
205         std::string result = "bt_powerOn:" + std::to_string(uapi_dev_runtime_get_bt_powerstat()) + " ";
206         result += "bt_ble_connectstat:" + std::to_string(get_ble_connect()) + " ";
207         result += "bt_br_connectstat:" + std::to_string(uapi_get_acl_connect_state()) + " ";
208         result += "bt_earphone_connectstat:" + std::to_string(uapi_dev_runtime_get_earphone_connect_stat()) + " ";
209         result += "android_app_connected:" + std::to_string(get_ble_pair()) + " ";
210         result += "localAddress:" + (getCurrentWatchMacAddress()) + " ";
211         result += "advdata:" + (getCurrentWatchadvdata()) + " ";
212         result += "ble广播状态:" + std::to_string(get_ble_adv_status());
213
214         // 蓝牙ble广播开关,基础信息如,地址,广播状态
215
216         return result;
217     }
218
219     std::string DebugOutputViewEventListener::get_cat1_runtime_status_t(void)
220     {
221         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_cat1_runtime_status_t");
222         std::string cat1_powerOn = std::to_string(uapi_dev_runtime_get_cat1_powerstat());
223         std::string volte;
224         std::string network_on = std::to_string(uapi_dev_runtime_get_cat1_networkstat());
225         std::string cat1_network_type = std::to_string(uapi_dev_runtime_get_cat1_networtype());
226         std::string sim = std::to_string(uapi_dev_runtime_get_cat1_simstat());
227         std::string signal = std::to_string(uapi_dev_runtime_get_cat1_signal());
228         std::string opera = uapi_dev_runtime_get_cat1_operator();
229         std::string pyVer = uapi_dev_runtime_get_cat1_pyver();
230         std::string modemVer = uapi_dev_runtime_get_cat1_modemver();
231         std::string result = "cat1_powerOn:" + cat1_powerOn + " " + "volte: " + "network_on:" + network_on + " " + "cat1_network_type:" + cat1_network_type + " " + "sim:" + sim + " " + "signal:" + signal + " " + "opera:" + opera + " " + "pyVer:" + pyVer + " " + "modemVer:" + modemVer + " ";
232
233         return result;
234     }
235
236     std::string DebugOutputViewEventListener::get_runtime_status_t()
237     {
238         std::string result = "enter_safemode:" + std::to_string(uapi_dev_runtime_get_safemode_flag()) + " ";
239         result += "in_silent_mode: ";
240         result += "in_lowpower_mode: ";
241         result += "stepcount: ";
242         result += "vibmod:" + std::to_string(uapi_dev_runtime_get_vibmod()) + " ";
243         result += "current_dial_name:" + std::string(uapi_dev_runtime_get_dialname()) + " ";
244         result += "time_hour_show_model:" + std::to_string(uapi_dev_runtime_get_time_hour_show_model()) + " ";
245         result += "sleep_monitoring_status:" + std::to_string(uapi_dev_runtime_get_sleep_monitoring_status()) + " ";
246         result += "sleep_status:" + std::to_string(uapi_dev_runtime_get_sleep_status()) + " ";
247         result += "nap_status:" + std::to_string(uapi_dev_runtime_get_nap_status()) + " ";
248         result += "nap_monitoring_status:" + std::to_string(uapi_dev_runtime_get_nap_monitoring_status()) + " ";
249         result += "sedentary_status:" + std::to_string(uapi_dev_runtime_get_sedentary_status()) + " ";
250         result += "wear_status:" + std::to_string(uapi_dev_runtime_get_wear_status_flag()) + " ";
251         result += "drinkremind_status:" + std::to_string(uapi_dev_runtime_get_drinkremind_status()) + " ";
252         result += "train_status:" + std::to_string(uapi_dev_runtime_get_train_status()) + " ";
253         result += "saveele_status:" + std::to_string(uapi_dev_runtime_get_saveele_status()) + " ";
254         result += "lock_status:" + std::to_string(uapi_dev_runtime_get_lock_status()) + " ";
255         result += "motion_recognition_status:" + std::to_string(uapi_dev_runtime_get_motion_recognition_status()) + " ";
256         result += "sleep_mode_flag:" + std::to_string(uapi_sleep_mode_flag_get()) + " ";
257         result += "absolute_static_state:" + std::to_string(uapi_dev_runtime_get_absolute_static_status()) + " ";
258         result += "checkres_status:" + std::to_string(uapi_dev_runtime_get_checkres_status()) + " ";
259         result += "repair_download_status:" + std::to_string(uapi_dev_runtime_get_repair_download_status()) + " ";
260         result += "hrs_passivity_status:" + std::to_string(uapi_dev_runtime_get_hrs_passivity_flag()) + " ";
261         result += "mmc_status:" + std::to_string(uapi_dev_runtime_get_mmc_status_flag()) + " ";
262         result += "rwlock_status:" + std::to_string(uapi_dev_runtime_get_rwlock_status()) + " ";
263         result += "lock_flag_training:" + std::to_string(uapi_dev_runtime_get_train_storage_status()) + " ";
264         result += "lock_flag_heartrate:" + std::to_string(uapi_dev_runtime_get_heartrate_storage_status()) + " ";
265         result += "lock_flag_blood:" + std::to_string(uapi_dev_runtime_get_bloodoxygen_storage_status()) + " ";
266         result += "lock_flag_sleep:" + std::to_string(uapi_dev_runtime_get_sleep_storage_status()) + " ";
267         result += "lock_flag_goal:" + std::to_string(uapi_dev_runtime_get_goal_storage_status()) + " ";
268         result += "respiratory_training_status:" + std::to_string(uapi_dev_runtime_get_respiratory_training_status()) + " ";
269         result += "heartrate_detect_status:" + std::to_string(uapi_dev_runtime_get_heartrate_detect_status()) + " ";
270         result += "factory_test_status:" + std::to_string(uapi_dev_runtime_get_factory_test_status_flag()) + " ";
271         result += "screen_always_on_status:" + std::to_string(uapi_dev_runtime_get_screen_always_on_status()) + " ";
272         return result;
273     }
274
275     // 日志服务
276     std::string DebugOutputViewEventListener::get_system_log()
277     {
278         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log");
279
280         // 获取系统日志实例
281         auto logModel = SystemLogModel::GetInstance();
282         uint8_t logSize = logModel->getLogSize();
283         if (logSize == 0)
284         {
285             return "目前没有日志";
286         }
287
288         std::deque<SystemLogData> systemlogs = logModel->getLogData();
289         std::ostringstream str;
290
291         for (int i = 0; i < logSize; i++)
292         {
293             // 处理日志类型
294             switch (systemlogs[i].type)
295             {
296             case SystemLogType::POWER_ON:
297                 str << "开机:";
298                 break;
299             case SystemLogType::POWER_OFF:
300                 str << "关机:";
301                 break;
302             case SystemLogType::RESTART:
303                 str << "重启:";
304                 break;
305             case SystemLogType::FACTORY_RESET:
306                 str << "恢复出厂设置:";
307                 break;
308             case SystemLogType::SOFTWARE_UPDATE:
309                 str << "软件更新:";
310                 break;
311             default:
312                 str << "UNKNOWN:";
313                 break;
314             }
315
316             // 格式化时间  
317             std::string timestr;  
318             if (systemlogs[i].timestamp == 0) {  
319                 timestr = "--"; // 默认值  
320             } else {  
321                 timestr = formatTime(systemlogs[i].timestamp);
322             }
323             
324             str << "[" << timestr << "] "<< "\n"; // 拼接日志内容  
325         }  
326
327         return str.str(); // 返回拼接后的字符串
328     }
329
330     // 获取电池相关信息
331     std::string DebugOutputViewEventListener::get_battery_info()
332     {
333         // 获取电池温度
334         float bat_temp = 0.0f;
335         batteryservice_get_battery_temp(&bat_temp);
336
337         // 获取 PCB 温度
338         float pcb_temp = 0.0f;
339         batteryservice_get_pcb_temp(&pcb_temp);
340
341         // 获取电量
342         float voltage = 0.0f;
343         uint8_t percent = batteryservice_get_voltage(&voltage);
344
345         // 获取充电状态
346         bool isCharging = get_charge_stat();
347
348         // 拼接字符串,并简化为保留两位小数
349         std::ostringstream oss;
350         oss << std::fixed
351             << std::setprecision(2) // 设置为固定小数位,保留两位小数
352             << "Bat Temp: " << bat_temp << " °C\n"
353             << "PCB Temp: " << pcb_temp << " °C\n"
354             << "Voltage: " << voltage << " V\n"
355             << "Percent: " << static_cast<int>(percent)
356             << " %\n"
357             << "Charge: " << (isCharging ? "Yes" : "No");
358
359         return oss.str();
360     }
361
362     // 获取死机列表
363     static const char *SHUTDOWN_PATH = "/user/system/tar";
364     std::string DebugOutputViewEventListener::get_shutdown_info()
365     {
366         std::ostringstream oss;
367
368         // 打开目录
369         DIR *dir = opendir(SHUTDOWN_PATH);
370         if (dir == nullptr)
371         {
372             return "死机目录不存在: " + std::string(strerror(errno));
373         }
374
375         struct dirent *entry;
376         while ((entry = readdir(dir)) != nullptr)
377         {
378             // 跳过. 和 ..
379             if (entry->d_name[0] != '.')
380             {
381                 oss << entry->d_name << "\n"; // 逐行添加
382             }
383         }
384
385         closedir(dir); // 关闭目录
386
387         if (oss.str().empty())
388         {
389             return "无死机文件";
390         }
391
392         return oss.str(); // 返回以换行符分隔的文件名字符串
393     }
394
395     // 获取睡眠时间戳
396     std::string DebugOutputViewEventListener::get_sleep_time(void)
397     {
398         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_sleep_time");
399         do_custom_fileoperate_service_check_msg(
400             CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, nullptr, 0);
401         LOS_Msleep(100);
402         std::string result = "asleep_time:" + get_sleep_asleep_time_str() + " ";
403         result += "wake_time:" + get_sleep_wake_time_str() + " ";
404         return result;
405     }
406
407     // 获取系统free内存
408     std::string DebugOutputViewEventListener::get_free_memory()
409     {
410         auto logModel = SystemLogModel::GetInstance();
411         std::string result = logModel->get_system_mem_info();
412         return result;
413     }
414
415     std::string DebugOutputViewEventListener::get_nextday_log()
416     {
417         std::ostringstream result;
418         result << "nextday_log:\n"; // 添加标题
419
420         auto logModel = SystemLogModel::GetInstance();
421         const auto &nextday_logs = logModel->get_nextday_log();
422
423         // 遍历日志并拼接到结果字符串  
424         for (const auto &log : nextday_logs) {
425             std::string timestr;  
426             if (log == 0) {  
427                 timestr = "--"; // 默认值  
428             } else {  
429                 timestr = formatTime(log); 
430             }  
431             result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录  
432         }  
433
434         return result.str();
435         return result.str();
436     }
437
438     // 定义心率数据文件夹的路径  
439     static const char *HEART_DATA_PATH = "/user/userdata/health/heart";  
440
441     // 主要函数:获取心率  
442     std::string DebugOutputViewEventListener::get_heart_rate() {  
443         std::ostringstream result;  
444
445         // 1. 读取文件并形成文件名字符串  
446         std::vector<std::string> heartFiles = readDirectory(HEART_DATA_PATH);  
447         if (heartFiles.empty()) {  
448             result << "No heart rate files found in directory.\n";  
449         } else {  
450             result << "Heart rate files:\n";  
451             for (const auto &file : heartFiles) {  
452                 result << file << "\n"; // 输出文件名  
453             }  
454         }  
455
456         result << "=====================\n";  
457
458         // 2. 获取模型里的数据(当前值与时间)  
459         auto heartModel = HeartModel::GetInstance();  
460         uint32_t checkTime = heartModel->GetCheckTime();  
461         uint16_t currentHeartRate = heartModel->GetHeartdata();  
462
463         std::string timestr = formatTime(checkTime);  
464
465         result << "CurrentHeart: " << currentHeartRate << "\n"  
466             << "Time: " << timestr << "\n";
467
468         result << "=====================\n";
469         
470         // 3. 获取一天的心率列表  
471         result << "Today's HeartRate list\n";  
472         for (int serialIndex = 0; serialIndex < 24; ++serialIndex) {  
473             uint32_t heartRate = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);  
474             uint32_t time = HealthService::GetInstance()->GetHourlyTimestamp(serialIndex);  
475             
476             std::string timestr;  
477             if (time == 0) {  
478                 timestr = "--"; // 默认值  
479             } else {  
480                 timestr = formatTime(time); 
481             }  
482
483             result << "time " << timestr << ""<<"\n" <<"heart " << heartRate <<""<< "\n"; // 输出每小时的心率  
484         }  
485
486         result << "=====================\n";  
487         return result.str(); // 返回完整结果  
488     }
489
490     std::string DebugOutputViewEventListener::get_popup_windows_log(void)
491     {
492         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_popup_windows_log");
493         // 获取系统日志实例
494         auto logModel = SystemLogModel::GetInstance();
495         uint8_t logSize = logModel->get_popup_windows_log_size();
496         if (logSize == 0)
497         {
498             return "目前没有日志";
499         }
500
501         std::deque<popup_windows_log_data> popup_windows_logs = logModel->get_popup_windows_log();
502         std::ostringstream str;
503
504         for (int i = 0; i < logSize; i++)
505         {
506             // 处理日志类型
507             switch (popup_windows_logs[i].type)
508             {
509             case popup_windows_type::MOTION_RECOGNITION:
510                 str << "运动识别:";
511                 break;
512             case popup_windows_type::DRINK_WATER_REMINDER:
513                 str << "喝水提醒:";
514                 break;
515             case popup_windows_type::SEDENTARY_REMINDER:
516                 str << "久坐提醒:";
517                 break;
518             default:
519                 str << "UNKNOWN:";
520                 break;
521             }
522             str << "\n";
523             // 格式化时间
524             char labelTime[20];
525             std::string timestr;
526             if (uapi_get_TIME_STR(popup_windows_logs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
527             {
528                 timestr = "--";
529             }
530             else
531             {
532                 timestr = labelTime;
533             }
534             str << "[" << timestr << "] " << "\n"; // 拼接日志内容
535         }
536         return str.str(); // 返回拼接后的字符串
537     }
538
539     bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
540     {
541         std::string viewId = view.GetViewId();
542         int viewIndex;
543         std::string str;
544         if (viewId == DEBUGOUTPUTBLESERVICELABELBUTTON) // 开启ble广播
545         {
546             // if (BluetoothModel::GetInstance()->GetAdvStartState() == false) // 如果广播是关的就去开启广播
547             //     BleAdvStart();
548
549             svr_ble_adv_start();
550             return true;
551         }
552         else if (viewId == DEBUGOUTPUTLABELBUTTON) // 点击的是刷新按钮
553         {
554             viewIndex = GetCurViewIndex();
555         }
556         else // 如果点击的是列表中的itemview
557         {
558             DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
559             viewIndex = debugOutputItemView->GetViewIndex();
560             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "viewIndex:%d", viewIndex);
561             if (viewIndex == 0)
562             {
563                 NotificationManager::GetInstance()->StopNotify();
564                 return true;
565             }
566             ChangeView(0, 1);
567             SetCurViewIndex(viewIndex);
568         }
569         if (debugOutputLabel == nullptr)
570         {
571             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr");
572             return false;
573         }
574         switch (viewIndex)
575         {
576         case 1:
577             str = get_bt_runtime_status_t();
578             break;
579         case 2:
580             str = get_cat1_runtime_status_t();
581             break;
582         case 3:
583             str = get_runtime_status_t();
584             break;
585         case 4:
586             str = get_system_log();
587             break;
588         case 5:
589             str = get_battery_info();
590             break;
591         case 6:
592             str = get_shutdown_info();
593             break;
594         case 7:
595             str = get_sleep_time();
596             break;
597         case 8:
598             str = get_free_memory();
599             break;
600         case 9:
601             str = get_nextday_log();
602             break;
603         case 10:
604             str = get_heart_rate();
605             break;
606         case 11:
607             str = get_popup_windows_log();
608             break;
609         default:
610             str = "--";
611             break;
612         }
613
614         GraphicService::GetInstance()->PostGraphicEvent(std::bind(
615             &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(), str));
616
617         return true;
618     }
619
620     // 获取视图
621     void DebugOutputViewEventListener::UpdateView(std::string str)
622     {
623         if (debugOutputLabel != nullptr)
624         {
625             debugOutputLabel->SetText(str.c_str());
626         }
627         if (debugOutputLabelButton)
628         {
629             debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
630             debugOutputLabelButton->Invalidate();
631         }
632         debugOutputLabel->Invalidate();
633     }
634     bool DebugOutputViewEventListener::OnDrag(UIView &view, const DragEvent &event)
635     {
636         UNUSED(view);
637         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::OnDrag");
638         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
639         {
640             int16_t deltaX;
641             int16_t deltaY;
642             deltaX = event.GetDeltaX();
643             deltaY = event.GetDeltaY();
644             if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 20)
645             {
646                 X_DRAG_FLAG = true;
647             }
648         }
649         return true;
650     }
651
652     bool DebugOutputViewEventListener::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
653     {
654         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)
655         {
656             if (&view == DebugGroupView)
657             {
658                 NotificationManager::GetInstance()->StopNotify();
659             }
660             else if (&view == DebugScrollView[1])
661             {
662                 ChangeView(1, 0);
663             }
664             X_DRAG_FLAG = false;
665         }
666         return true;
667     }
668
669     bool DebugOutputViewEventListener::ClickFunc(int16_t interface)
670     {
671         int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
672         for (int i = 0; i < funcSize; i++)
673         {
674             if (interface == ViewMapper[i].viewId)
675             {
676                 bool jug = (this->*(ViewMapper[i].func))(interface);
677                 if (jug == false)
678                 {
679                     return false;
680                 }
681                 return true;
682             }
683         }
684         return false;
685     }
686
687     bool DebugOutputViewEventListener::CheckViewParam(int16_t hideView, int16_t showView)
688     {
689         int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
690         if (showView < 0 || showView > funcSize)
691         {
692             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showView err.");
693             return false;
694         }
695
696         if (hideView < 0 || hideView > funcSize)
697         {
698             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView err.");
699             return false;
700         }
701
702         return true;
703     }
704
705     void DebugOutputViewEventListener::DestroyTempView(int16_t hideView)
706     {
707         if (hideView == 1)
708         {
709             DebugGroupView->Remove(DebugScrollView[1]);
710             if (DebugScrollView[1] != nullptr)
711             {
712                 DebugScrollView[1]->RemoveAll();
713
714                 delete debugOutputLabel;
715                 debugOutputLabel = nullptr;
716
717                 delete debugOutputLabelButton;
718                 debugOutputLabelButton = nullptr;
719
720                 delete DebugScrollView[1];
721                 DebugScrollView[1] = nullptr;
722             }
723         }
724     }
725
726     void DebugOutputViewEventListener::ChangeView(int16_t hideView, int16_t showView)
727     {
728         if (!CheckViewParam(hideView, showView))
729         {
730             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckViewParam failed.");
731             return;
732         }
733         DebugScrollView[hideView]->SetVisible(false);
734         ClickFunc(showView);
735         DebugScrollView[showView]->SetVisible(true);
736         DestroyTempView(hideView);
737         RootView::GetInstance()->Invalidate();
738         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView:%d -> showView:%d success!!", hideView, showView);
739     }
740
741     UIScrollView *CreateDebugOutputView1(void)
742     {
743         if (DebugScrollView[1] == nullptr)
744         {
745             DebugScrollView[1] = new UIScrollView();
746             if (DebugScrollView[1] == nullptr)
747             {
748                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
749                 return nullptr;
750             }
751         }
752         DebugScrollView[1]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
753         DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
754         DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_OPA, 255);
755         DebugScrollView[1]->SetHorizontalScrollState(false);
756         DebugScrollView[1]->SetTouchable(true);
757         DebugScrollView[1]->SetScrollBlankSize(70);
758         DebugScrollView[1]->SetReboundSize(35);
759         DebugScrollView[1]->SetThrowDrag(true);
760         UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
761         if (dragListener == nullptr)
762         {
763             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
764             return nullptr;
765         }
766         DebugScrollView[1]->SetOnDragListener(dragListener);
767         /* -------------------------------------------------------------------------- */
768         debugOutputLabel = new UILabel();
769         if (debugOutputLabel == nullptr)
770         {
771             if (debugOutputLabel == nullptr)
772             {
773                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is new fail!!");
774                 return nullptr;
775             }
776         }
777         debugOutputLabel->SetPosition(53, 120, 360, 100);
778         debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 30);
779         debugOutputLabel->SetText("123");
780         debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
781         debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
782         DebugScrollView[1]->Add(debugOutputLabel);
783         /* -------------------------------------------------------------------------- */
784         if (debugOutputLabelButton == nullptr)
785         {
786             debugOutputLabelButton = new UILabelButton();
787             if (debugOutputLabelButton == nullptr)
788             {
789                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabelButton is new fail!!");
790                 return nullptr;
791             }
792         }
793         debugOutputLabelButton->SetPosition(43, debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
794         debugOutputLabelButton->Resize(380, 100);
795         debugOutputLabelButton->SetViewId(DEBUGOUTPUTLABELBUTTON);
796         debugOutputLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
797         debugOutputLabelButton->SetText("刷新");
798         debugOutputLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
799         debugOutputLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
800         UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
801         if (clickListener == nullptr)
802         {
803             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
804             return nullptr;
805         }
806         debugOutputLabelButton->SetOnClickListener(clickListener);
807         DebugScrollView[1]->Add(debugOutputLabelButton);
808
809         return DebugScrollView[1];
810     }
811
812     bool DebugOutputViewEventListener::ChangeDebugOutputMainView(int16_t thisView)
813     {
814         if (DebugScrollView[thisView] == nullptr)
815         {
816             DebugGroupView->Add(DebugScrollView[thisView]);
817         }
818         return true;
819     }
820
821     bool DebugOutputViewEventListener::ChangeDebugOutputView1(int16_t thisView)
822     {
823         if (DebugScrollView[thisView] == nullptr)
824         {
825             DebugScrollView[thisView] = CreateDebugOutputView1();
826             if (DebugScrollView[thisView] == nullptr)
827             {
828                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new DebugScrollView[%d] fail", thisView);
829                 return false;
830             }
831             DebugGroupView->Add(DebugScrollView[thisView]);
832         }
833         return true;
834     }
835
836     void DebugOutputViewEventListener::SetCurViewIndex(int16_t viewNum)
837     {
838         curView = viewNum;
839     }
840
841     int DebugOutputViewEventListener::GetCurViewIndex(void)
842     {
843         return curView;
844     }
845
846     /*创建调试专用主窗口视图*/
847     UIViewGroup *CreateDebugOutputMainView(void)
848     {
849         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateDebugOutputMainView");
850         if (DebugGroupView == nullptr)
851         {
852             if (DebugGroupView == nullptr)
853             {
854                 DebugGroupView = new UIViewGroup();
855                 if (DebugGroupView == nullptr)
856                 {
857                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugGroupView is new fail!!");
858                     return nullptr;
859                 }
860             }
861             DebugGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
862             UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
863             if (dragListener == nullptr)
864             {
865                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
866                 return nullptr;
867             }
868             DebugGroupView->SetOnDragListener(dragListener);
869             /* -------------------------------------------------------------------------- */
870             if (DebugScrollView[0] == nullptr)
871             {
872                 DebugScrollView[0] = new UIScrollView();
873                 if (DebugScrollView[0] == nullptr)
874                 {
875                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
876                     return nullptr;
877                 }
878             }
879             DebugScrollView[0]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
880             DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
881             DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_OPA, 255);
882             DebugScrollView[0]->SetHorizontalScrollState(false);
883             DebugScrollView[0]->SetTouchable(true);
884             DebugScrollView[0]->SetThrowDrag(true);
885             DebugScrollView[0]->SetScrollBlankSize(70);
886             DebugScrollView[0]->SetReboundSize(30);
887             DebugGroupView->Add(DebugScrollView[0]);
888             /* -------------------------------------------------------------------------- */
889             if (debugOutputAdapter == nullptr)
890             {
891                 debugOutputAdapter = new DebugOutputAdapter();
892                 if (debugOutputAdapter == nullptr)
893                 {
894                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputAdapter is new fail!!");
895                     return nullptr;
896                 }
897             }
898             UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
899             if (clickListener == nullptr)
900             {
901                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
902                 return nullptr;
903             }
904             debugOutputAdapter->SetItemClickListener(clickListener);
905             DebugOutputViewEventListener::GetInstance().InitDebugOutputItem();
906             /* -------------------------------------------------------------------------- */
907             if (debugOutputList == nullptr)
908             {
909                 debugOutputList = new UIList(UIList::VERTICAL);
910                 if (debugOutputList == nullptr)
911                 {
912                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputList is new fail!!");
913                     return nullptr;
914                 }
915             }
916             debugOutputList->SetPosition(0, 120, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
917             debugOutputList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
918             debugOutputList->EnableAutoAlign(true);      // 设置此列表的自动对齐状态。当滚动停止时,子视图被选中,其位置自动与预设位置对齐
919             debugOutputList->SetThrowDrag(true);         // 设置手指抬起屏幕后是否继续滚动。
920             debugOutputList->SetMaxScrollDistance(1000); // 设置手指抬起屏幕后的最大滚动距离。
921             debugOutputList->SetSwipeACCLevel(800);      /*设置手指抬起屏幕后的补偿距离。*/
922             debugOutputList->SetAdapter(debugOutputAdapter);
923             debugOutputList->RefreshList();
924             // debugOutputList->SetReboundSize(30);
925             // debugOutputList->SetScrollBlankSize(30);
926             debugOutputList->SetRotateFactor(1.0);
927             DebugScrollView[0]->Add(debugOutputList);
928             /* -------------------------------------------------------------------------- */
929             if (debugOutputbleServiceLabelButton == nullptr)
930             {
931                 debugOutputbleServiceLabelButton = new UILabelButton();
932                 if (debugOutputbleServiceLabelButton == nullptr)
933                 {
934                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputbleServiceLabelButton is new fail!!");
935                     return nullptr;
936                 }
937             }
938             debugOutputbleServiceLabelButton->SetPosition(43, debugOutputList->GetY() + debugOutputList->GetHeight());
939             debugOutputbleServiceLabelButton->SetViewId(DEBUGOUTPUTBLESERVICELABELBUTTON);
940             debugOutputbleServiceLabelButton->Resize(380, 100);
941             debugOutputbleServiceLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
942             debugOutputbleServiceLabelButton->SetText("开启ble广播");
943             debugOutputbleServiceLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
944             debugOutputbleServiceLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
945             debugOutputbleServiceLabelButton->SetOnClickListener(clickListener);
946             DebugScrollView[0]->Add(debugOutputbleServiceLabelButton);
947             /* -------------------------------------------------------------------------- */
948             NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
949             /* -------------------------------------------------------------------------- */
950             enable_drag(0, 1);
951             enable_drag(1, 1);
952         }
953         return DebugGroupView;
954     }
955
956     /*释放调试专用主窗口视图*/
957     void FreeDebugOutputMainView(void)
958     {
959         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView");
960
961         if (DebugGroupView != nullptr)
962         {
963             DebugGroupView->RemoveAll();
964             if (DebugScrollView[0] != nullptr)
965             {
966                 DebugScrollView[0]->RemoveAll();
967
968                 delete debugOutputList;
969                 debugOutputList = nullptr;
970
971                 delete debugOutputAdapter;
972                 debugOutputAdapter = nullptr;
973
974                 delete debugOutputbleServiceLabelButton;
975                 debugOutputbleServiceLabelButton = nullptr;
976
977                 delete DebugScrollView[0];
978                 DebugScrollView[0] = nullptr;
979             }
980             RootView::GetInstance()->Remove(DebugGroupView);
981             delete DebugGroupView;
982             DebugGroupView = nullptr;
983             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!");
984         }
985         if (uapi_dev_runtime_get_saveele_status() == 1) // 如果省电模式开启,该调试窗口关闭时候恢复原状态
986         {
987             enable_drag(0, 0);
988             enable_drag(1, 0);
989         }
990         return;
991     }
992 }