0da23904b461e535beb6bea3ab42f4e720503cf2
[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     std::string DebugOutputViewEventListener::get_nextday_log()
415     {
416         std::ostringstream result;
417         result << "nextday_log:\n"; // 添加标题
418
419         auto logModel = SystemLogModel::GetInstance();
420         const auto &nextday_logs = logModel->get_nextday_log();
421
422         // 遍历日志并拼接到结果字符串
423         for (const auto &log : nextday_logs) {
424             std::string timestr;
425             if (log.timestamp == 0) {
426                 timestr = "--"; // 默认值
427             } else {
428                 timestr = formatTime(log.timestamp);
429                 if (log.type == nextday_type::NEXTDAY_BEGAN) {
430                     timestr += " 开始";
431                 } else if(log.type == nextday_type::NEXTDAY_END){
432                     timestr += " 结束:";
433                 }
434             }
435             result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录
436         }
437
438         return result.str();
439     }
440
441
442     // 定义心率数据文件夹的路径  
443     static const char *HEART_DATA_PATH = "/user/userdata/health/heart";  
444
445     // 主要函数:获取心率  
446     std::string DebugOutputViewEventListener::get_heart_rate() {  
447         std::ostringstream result;  
448
449         // 1. 读取文件并形成文件名字符串  
450         std::vector<std::string> heartFiles = readDirectory(HEART_DATA_PATH);  
451         if (heartFiles.empty()) {  
452             result << "No heart rate files found in directory.\n";  
453         } else {  
454             result << "Heart rate files:\n";  
455             for (const auto &file : heartFiles) {  
456                 result << file << "\n"; // 输出文件名  
457             }  
458         }  
459
460         result << "=====================\n";  
461
462         // 2. 获取模型里的数据(当前值与时间)  
463         auto heartModel = HeartModel::GetInstance();  
464         uint32_t checkTime = heartModel->GetCheckTime();  
465         uint16_t currentHeartRate = heartModel->GetHeartdata();  
466
467         std::string timestr = formatTime(checkTime);  
468
469         result << "CurrentHeart: " << currentHeartRate << "\n"  
470             << "Time: " << timestr << "\n";
471
472         result << "=====================\n";
473         
474         // 3. 获取一天的心率列表  
475         result << "Today's HeartRate list\n";  
476         for (int serialIndex = 0; serialIndex < 24; ++serialIndex) {  
477             uint32_t heartRate = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);  
478             uint32_t time = HealthService::GetInstance()->GetHourlyTimestamp(serialIndex);  
479             
480             std::string timestr;  
481             if (time == 0) {  
482                 timestr = "--"; // 默认值  
483             } else {  
484                 timestr = formatTime(time); 
485             }  
486
487             result << "time " << timestr << ""<<"\n" <<"heart " << heartRate <<""<< "\n"; // 输出每小时的心率  
488         }  
489
490         result << "=====================\n";  
491         return result.str(); // 返回完整结果  
492     }
493
494     std::string DebugOutputViewEventListener::get_popup_windows_log(void)
495     {
496         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_popup_windows_log");
497         // 获取系统日志实例
498         auto logModel = SystemLogModel::GetInstance();
499         uint8_t logSize = logModel->get_popup_windows_log_size();
500         if (logSize == 0)
501         {
502             return "目前没有日志";
503         }
504
505         std::deque<popup_windows_log_data> popup_windows_logs = logModel->get_popup_windows_log();
506         std::ostringstream str;
507
508         for (int i = 0; i < logSize; i++)
509         {
510             // 处理日志类型
511             switch (popup_windows_logs[i].type)
512             {
513             case popup_windows_type::MOTION_RECOGNITION:
514                 str << "运动识别:";
515                 break;
516             case popup_windows_type::DRINK_WATER_REMINDER:
517                 str << "喝水提醒:";
518                 break;
519             case popup_windows_type::SEDENTARY_REMINDER:
520                 str << "久坐提醒:";
521                 break;
522             default:
523                 str << "UNKNOWN:";
524                 break;
525             }
526             str << "\n";
527             // 格式化时间
528             char labelTime[20];
529             std::string timestr;
530             if (uapi_get_TIME_STR(popup_windows_logs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
531             {
532                 timestr = "--";
533             }
534             else
535             {
536                 timestr = labelTime;
537             }
538             str << "[" << timestr << "] " << "\n"; // 拼接日志内容
539         }
540         return str.str(); // 返回拼接后的字符串
541     }
542
543     bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
544     {
545         std::string viewId = view.GetViewId();
546         int viewIndex;
547         std::string str;
548         if (viewId == DEBUGOUTPUTBLESERVICELABELBUTTON) // 开启ble广播
549         {
550             // if (BluetoothModel::GetInstance()->GetAdvStartState() == false) // 如果广播是关的就去开启广播
551             //     BleAdvStart();
552
553             svr_ble_adv_start();
554             return true;
555         }
556         else if (viewId == DEBUGOUTPUTLABELBUTTON) // 点击的是刷新按钮
557         {
558             viewIndex = GetCurViewIndex();
559         }
560         else // 如果点击的是列表中的itemview
561         {
562             DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
563             viewIndex = debugOutputItemView->GetViewIndex();
564             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "viewIndex:%d", viewIndex);
565             if (viewIndex == 0)
566             {
567                 NotificationManager::GetInstance()->StopNotify();
568                 return true;
569             }
570             ChangeView(0, 1);
571             SetCurViewIndex(viewIndex);
572         }
573         if (debugOutputLabel == nullptr)
574         {
575             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr");
576             return false;
577         }
578         switch (viewIndex)
579         {
580         case 1:
581             str = get_bt_runtime_status_t();
582             break;
583         case 2:
584             str = get_cat1_runtime_status_t();
585             break;
586         case 3:
587             str = get_runtime_status_t();
588             break;
589         case 4:
590             str = get_system_log();
591             break;
592         case 5:
593             str = get_battery_info();
594             break;
595         case 6:
596             str = get_shutdown_info();
597             break;
598         case 7:
599             str = get_sleep_time();
600             break;
601         case 8:
602             str = get_free_memory();
603             break;
604         case 9:
605             str = get_nextday_log();
606             break;
607         case 10:
608             str = get_heart_rate();
609             break;
610         case 11:
611             str = get_popup_windows_log();
612             break;
613         default:
614             str = "--";
615             break;
616         }
617
618         GraphicService::GetInstance()->PostGraphicEvent(std::bind(
619             &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(), str));
620
621         return true;
622     }
623
624     // 获取视图
625     void DebugOutputViewEventListener::UpdateView(std::string str)
626     {
627         if (debugOutputLabel != nullptr)
628         {
629             debugOutputLabel->SetText(str.c_str());
630         }
631         if (debugOutputLabelButton)
632         {
633             debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
634             debugOutputLabelButton->Invalidate();
635         }
636         debugOutputLabel->Invalidate();
637     }
638     bool DebugOutputViewEventListener::OnDrag(UIView &view, const DragEvent &event)
639     {
640         UNUSED(view);
641         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::OnDrag");
642         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
643         {
644             int16_t deltaX;
645             int16_t deltaY;
646             deltaX = event.GetDeltaX();
647             deltaY = event.GetDeltaY();
648             if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 20)
649             {
650                 X_DRAG_FLAG = true;
651             }
652         }
653         return true;
654     }
655
656     bool DebugOutputViewEventListener::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
657     {
658         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)
659         {
660             if (&view == DebugGroupView)
661             {
662                 NotificationManager::GetInstance()->StopNotify();
663             }
664             else if (&view == DebugScrollView[1])
665             {
666                 ChangeView(1, 0);
667             }
668             X_DRAG_FLAG = false;
669         }
670         return true;
671     }
672
673     bool DebugOutputViewEventListener::ClickFunc(int16_t interface)
674     {
675         int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
676         for (int i = 0; i < funcSize; i++)
677         {
678             if (interface == ViewMapper[i].viewId)
679             {
680                 bool jug = (this->*(ViewMapper[i].func))(interface);
681                 if (jug == false)
682                 {
683                     return false;
684                 }
685                 return true;
686             }
687         }
688         return false;
689     }
690
691     bool DebugOutputViewEventListener::CheckViewParam(int16_t hideView, int16_t showView)
692     {
693         int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
694         if (showView < 0 || showView > funcSize)
695         {
696             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showView err.");
697             return false;
698         }
699
700         if (hideView < 0 || hideView > funcSize)
701         {
702             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView err.");
703             return false;
704         }
705
706         return true;
707     }
708
709     void DebugOutputViewEventListener::DestroyTempView(int16_t hideView)
710     {
711         if (hideView == 1)
712         {
713             DebugGroupView->Remove(DebugScrollView[1]);
714             if (DebugScrollView[1] != nullptr)
715             {
716                 DebugScrollView[1]->RemoveAll();
717
718                 delete debugOutputLabel;
719                 debugOutputLabel = nullptr;
720
721                 delete debugOutputLabelButton;
722                 debugOutputLabelButton = nullptr;
723
724                 delete DebugScrollView[1];
725                 DebugScrollView[1] = nullptr;
726             }
727         }
728     }
729
730     void DebugOutputViewEventListener::ChangeView(int16_t hideView, int16_t showView)
731     {
732         if (!CheckViewParam(hideView, showView))
733         {
734             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckViewParam failed.");
735             return;
736         }
737         DebugScrollView[hideView]->SetVisible(false);
738         ClickFunc(showView);
739         DebugScrollView[showView]->SetVisible(true);
740         DestroyTempView(hideView);
741         RootView::GetInstance()->Invalidate();
742         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView:%d -> showView:%d success!!", hideView, showView);
743     }
744
745     UIScrollView *CreateDebugOutputView1(void)
746     {
747         if (DebugScrollView[1] == nullptr)
748         {
749             DebugScrollView[1] = new UIScrollView();
750             if (DebugScrollView[1] == nullptr)
751             {
752                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
753                 return nullptr;
754             }
755         }
756         DebugScrollView[1]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
757         DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
758         DebugScrollView[1]->SetStyle(STYLE_BACKGROUND_OPA, 255);
759         DebugScrollView[1]->SetHorizontalScrollState(false);
760         DebugScrollView[1]->SetTouchable(true);
761         DebugScrollView[1]->SetScrollBlankSize(70);
762         DebugScrollView[1]->SetReboundSize(35);
763         DebugScrollView[1]->SetThrowDrag(true);
764         UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
765         if (dragListener == nullptr)
766         {
767             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
768             return nullptr;
769         }
770         DebugScrollView[1]->SetOnDragListener(dragListener);
771         /* -------------------------------------------------------------------------- */
772         debugOutputLabel = new UILabel();
773         if (debugOutputLabel == nullptr)
774         {
775             if (debugOutputLabel == nullptr)
776             {
777                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is new fail!!");
778                 return nullptr;
779             }
780         }
781         debugOutputLabel->SetPosition(53, 120, 360, 100);
782         debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 30);
783         debugOutputLabel->SetText("123");
784         debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
785         debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
786         DebugScrollView[1]->Add(debugOutputLabel);
787         /* -------------------------------------------------------------------------- */
788         if (debugOutputLabelButton == nullptr)
789         {
790             debugOutputLabelButton = new UILabelButton();
791             if (debugOutputLabelButton == nullptr)
792             {
793                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabelButton is new fail!!");
794                 return nullptr;
795             }
796         }
797         debugOutputLabelButton->SetPosition(43, debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
798         debugOutputLabelButton->Resize(380, 100);
799         debugOutputLabelButton->SetViewId(DEBUGOUTPUTLABELBUTTON);
800         debugOutputLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
801         debugOutputLabelButton->SetText("刷新");
802         debugOutputLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
803         debugOutputLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
804         UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
805         if (clickListener == nullptr)
806         {
807             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
808             return nullptr;
809         }
810         debugOutputLabelButton->SetOnClickListener(clickListener);
811         DebugScrollView[1]->Add(debugOutputLabelButton);
812
813         return DebugScrollView[1];
814     }
815
816     bool DebugOutputViewEventListener::ChangeDebugOutputMainView(int16_t thisView)
817     {
818         if (DebugScrollView[thisView] == nullptr)
819         {
820             DebugGroupView->Add(DebugScrollView[thisView]);
821         }
822         return true;
823     }
824
825     bool DebugOutputViewEventListener::ChangeDebugOutputView1(int16_t thisView)
826     {
827         if (DebugScrollView[thisView] == nullptr)
828         {
829             DebugScrollView[thisView] = CreateDebugOutputView1();
830             if (DebugScrollView[thisView] == nullptr)
831             {
832                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new DebugScrollView[%d] fail", thisView);
833                 return false;
834             }
835             DebugGroupView->Add(DebugScrollView[thisView]);
836         }
837         return true;
838     }
839
840     void DebugOutputViewEventListener::SetCurViewIndex(int16_t viewNum)
841     {
842         curView = viewNum;
843     }
844
845     int DebugOutputViewEventListener::GetCurViewIndex(void)
846     {
847         return curView;
848     }
849
850     /*创建调试专用主窗口视图*/
851     UIViewGroup *CreateDebugOutputMainView(void)
852     {
853         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateDebugOutputMainView");
854         if (DebugGroupView == nullptr)
855         {
856             if (DebugGroupView == nullptr)
857             {
858                 DebugGroupView = new UIViewGroup();
859                 if (DebugGroupView == nullptr)
860                 {
861                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugGroupView is new fail!!");
862                     return nullptr;
863                 }
864             }
865             DebugGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
866             UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
867             if (dragListener == nullptr)
868             {
869                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is new fail!!");
870                 return nullptr;
871             }
872             DebugGroupView->SetOnDragListener(dragListener);
873             /* -------------------------------------------------------------------------- */
874             if (DebugScrollView[0] == nullptr)
875             {
876                 DebugScrollView[0] = new UIScrollView();
877                 if (DebugScrollView[0] == nullptr)
878                 {
879                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::DebugScrollView[0] is new fail!!");
880                     return nullptr;
881                 }
882             }
883             DebugScrollView[0]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
884             DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
885             DebugScrollView[0]->SetStyle(STYLE_BACKGROUND_OPA, 255);
886             DebugScrollView[0]->SetHorizontalScrollState(false);
887             DebugScrollView[0]->SetTouchable(true);
888             DebugScrollView[0]->SetThrowDrag(true);
889             DebugScrollView[0]->SetScrollBlankSize(70);
890             DebugScrollView[0]->SetReboundSize(30);
891             DebugGroupView->Add(DebugScrollView[0]);
892             /* -------------------------------------------------------------------------- */
893             if (debugOutputAdapter == nullptr)
894             {
895                 debugOutputAdapter = new DebugOutputAdapter();
896                 if (debugOutputAdapter == nullptr)
897                 {
898                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputAdapter is new fail!!");
899                     return nullptr;
900                 }
901             }
902             UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
903             if (clickListener == nullptr)
904             {
905                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
906                 return nullptr;
907             }
908             debugOutputAdapter->SetItemClickListener(clickListener);
909             DebugOutputViewEventListener::GetInstance().InitDebugOutputItem();
910             /* -------------------------------------------------------------------------- */
911             if (debugOutputList == nullptr)
912             {
913                 debugOutputList = new UIList(UIList::VERTICAL);
914                 if (debugOutputList == nullptr)
915                 {
916                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputList is new fail!!");
917                     return nullptr;
918                 }
919             }
920             debugOutputList->SetPosition(0, 120, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
921             debugOutputList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
922             debugOutputList->EnableAutoAlign(true);      // 设置此列表的自动对齐状态。当滚动停止时,子视图被选中,其位置自动与预设位置对齐
923             debugOutputList->SetThrowDrag(true);         // 设置手指抬起屏幕后是否继续滚动。
924             debugOutputList->SetMaxScrollDistance(1000); // 设置手指抬起屏幕后的最大滚动距离。
925             debugOutputList->SetSwipeACCLevel(200);      /*设置手指抬起屏幕后的补偿距离。*/
926             debugOutputList->SetAdapter(debugOutputAdapter);
927             debugOutputList->RefreshList();
928             // debugOutputList->SetReboundSize(30);
929             // debugOutputList->SetScrollBlankSize(30);
930             debugOutputList->SetRotateFactor(1.0);
931             DebugScrollView[0]->Add(debugOutputList);
932             /* -------------------------------------------------------------------------- */
933             if (debugOutputbleServiceLabelButton == nullptr)
934             {
935                 debugOutputbleServiceLabelButton = new UILabelButton();
936                 if (debugOutputbleServiceLabelButton == nullptr)
937                 {
938                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputbleServiceLabelButton is new fail!!");
939                     return nullptr;
940                 }
941             }
942             debugOutputbleServiceLabelButton->SetPosition(43, debugOutputList->GetY() + debugOutputList->GetHeight());
943             debugOutputbleServiceLabelButton->SetViewId(DEBUGOUTPUTBLESERVICELABELBUTTON);
944             debugOutputbleServiceLabelButton->Resize(380, 100);
945             debugOutputbleServiceLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
946             debugOutputbleServiceLabelButton->SetText("开启ble广播");
947             debugOutputbleServiceLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
948             debugOutputbleServiceLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
949             debugOutputbleServiceLabelButton->SetOnClickListener(clickListener);
950             DebugScrollView[0]->Add(debugOutputbleServiceLabelButton);
951             /* -------------------------------------------------------------------------- */
952             NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
953             /* -------------------------------------------------------------------------- */
954             enable_drag(0, 1);
955             enable_drag(1, 1);
956         }
957         return DebugGroupView;
958     }
959
960     /*释放调试专用主窗口视图*/
961     void FreeDebugOutputMainView(void)
962     {
963         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView");
964
965         if (DebugGroupView != nullptr)
966         {
967             DebugGroupView->RemoveAll();
968             if (DebugScrollView[0] != nullptr)
969             {
970                 DebugScrollView[0]->RemoveAll();
971
972                 delete debugOutputList;
973                 debugOutputList = nullptr;
974
975                 delete debugOutputAdapter;
976                 debugOutputAdapter = nullptr;
977
978                 delete debugOutputbleServiceLabelButton;
979                 debugOutputbleServiceLabelButton = nullptr;
980
981                 delete DebugScrollView[0];
982                 DebugScrollView[0] = nullptr;
983             }
984             RootView::GetInstance()->Remove(DebugGroupView);
985             delete DebugGroupView;
986             DebugGroupView = nullptr;
987             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!");
988         }
989         if (uapi_dev_runtime_get_saveele_status() == 1) // 如果省电模式开启,该调试窗口关闭时候恢复原状态
990         {
991             enable_drag(0, 0);
992             enable_drag(1, 0);
993         }
994         return;
995     }
996 }