From: luozheng <1732036298@qq.com> Date: Sat, 25 Oct 2025 09:58:06 +0000 (+0800) Subject: ln:添加debug调试界面 X-Git-Tag: V1.0.9_20251128_194606_LN~170^2~3 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=1d72f2893d3d07bb91e75036143adb19d733cde0;p=mirrors%2FFD230.git ln:添加debug调试界面 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index 351dee71d..f421625b5 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -260,6 +260,10 @@ namespace OHOS void at_set_fps(uint32_t freq); uint32_t at_get_fps(void); + public: + bool RegisterFuncKeyOnClick_6_timesEvent(void); + void RegisterAllKeyEvents(void); + private: ThunderBirdModel(); virtual ~ThunderBirdModel(); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index 9bb5d20bd..ac9dd9646 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -62,6 +62,9 @@ extern "C" { #endif + #include + #include "broadcast_feature.h" + int32_t AudioCaptureSample(int32_t argc, const char *argv[]); #ifdef __cplusplus @@ -106,6 +109,8 @@ // 初始化对话状态显示变量 m_currentExpression = "CloseEyes"; m_currentStatusText = "发呆中..."; + + RegisterAllKeyEvents(); } ThunderBirdModel::~ThunderBirdModel() @@ -2660,5 +2665,34 @@ } } + //按键注册事件回调 + static void FuncKeyOnClick_6_timesEventCallBack(void) + { + CustomEventPublish(TOPIC_EVENT_DEBUGOUTPUT, NULL, 0); + return; + } + static void HandFuncKeyOnClick_6_timesEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandFuncKeyOnClick_6_timesEvent"); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnClick_6_timesEventCallBack)); + } + bool ThunderBirdModel::RegisterFuncKeyOnClick_6_timesEvent(void) + { + // 注册按键按下6次事件 + int32_t powerret = uapi_button_register_event_cb(HandFuncKeyOnClick_6_timesEvent, BUTTON1_CLICKUP_6); + if (powerret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to register Power Button Press Event, ret = %d", powerret); + return false; + } + + return true; + } + + void ThunderBirdModel::RegisterAllKeyEvents(void) + { + RegisterFuncKeyOnClick_6_timesEvent(); + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/ln/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/ln/service/broadcast/include/broadcast_feature.h index 94ea4871e..b4a1d9a21 100644 --- a/code/sdk/application/wearable/ln/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/ln/service/broadcast/include/broadcast_feature.h @@ -50,6 +50,7 @@ typedef enum { TOPIC_EVENT_CHARGE_PLUG, TOPIC_EVENT_CHARGE_UNPLUG, TOPIC_EVENT_LOWPOWER_ALARM, + TOPIC_EVENT_DEBUGOUTPUT, TOPIC_END_NUM = 20000, } TopicNum; diff --git a/code/sdk/application/wearable/ln/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/ln/service/broadcast/src/broadcast_implement.c index b67018a03..4ccc12201 100644 --- a/code/sdk/application/wearable/ln/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/ln/service/broadcast/src/broadcast_implement.c @@ -39,6 +39,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_CHARGE_PLUG, A_CORE_MASK, 1}, {TOPIC_EVENT_CHARGE_UNPLUG, A_CORE_MASK, 1}, {TOPIC_EVENT_LOWPOWER_ALARM, A_CORE_MASK, 1}, + {TOPIC_EVENT_DEBUGOUTPUT,A_CORE_MASK,1}, }; /* 所有的topic,其对应的位图 */ diff --git a/code/sdk/application/wearable/ln/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/ln/service/msg_center/CMakeLists.txt index db5c1d1ac..4eca4ab4c 100644 --- a/code/sdk/application/wearable/ln/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/ln/service/msg_center/CMakeLists.txt @@ -128,6 +128,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include ${ROOT_DIR}/application/wearable/nativeabilityfwk/include ${ROOT_DIR}/open_source/openharmony/foundation/multimedia/player/interfaces/kits + ${ROOT_DIR}/zhihui/leiniao/imsl_ln/ ) @@ -142,6 +143,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/common/msg_center_self_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/src/NotifyOnKeyListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/phone_msg_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp ) else() set(SOURCES @@ -151,6 +153,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/ketinput/src/NotifyOnKeyListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/phone_msg_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/ln/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/ln/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h new file mode 100644 index 000000000..68d222bdb --- /dev/null +++ b/code/sdk/application/wearable/ln/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -0,0 +1,35 @@ +#ifndef DEBUG_OUTPUT_NOTIFICATION_H +#define DEBUG_OUTPUT_NOTIFICATION_H +#include "View.h" +#include +#include "key/KeyInputListener.h" +namespace OHOS +{ + UIViewGroup *CreateDebugOutputMainView(void); + void FreeDebugOutputMainView(void); + + class DebugOutputViewEventListener : public RootView::OnKeyActListener + { + public: + static DebugOutputViewEventListener &GetInstance(); + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + bool ClickFunc(int16_t interface); + bool CheckViewParam(int16_t hideView, int16_t showView); + void ChangeView(int16_t hideView, int16_t showView); + void UpdateView(void); + void SetCurViewIndex(int16_t viewIndex); + int GetCurViewIndex(void); + std::string GetLeiNiaoDeviceInfo(void); + + private: + DebugOutputViewEventListener(); + ~DebugOutputViewEventListener(); + DebugOutputViewEventListener(const DebugOutputViewEventListener &) = delete; + const DebugOutputViewEventListener &operator=(const DebugOutputViewEventListener &) = delete; + + int16_t curViewIndex{0}; + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/ln/service/msg_center/include/notify/notification_manager.h b/code/sdk/application/wearable/ln/service/msg_center/include/notify/notification_manager.h index 345828de1..9ed88f546 100644 --- a/code/sdk/application/wearable/ln/service/msg_center/include/notify/notification_manager.h +++ b/code/sdk/application/wearable/ln/service/msg_center/include/notify/notification_manager.h @@ -25,6 +25,7 @@ #include "alarm_notification.h" #include "makephone_notification.h" #include "phone_msg_notification.h" +#include "debug_output_notification/debug_output_notification.h" constexpr uint16_t HALF_SCREEN = 2; constexpr int16_t NOTIFY_PRIORITY_DEFAULT = 4; diff --git a/code/sdk/application/wearable/ln/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/ln/service/msg_center/src/msg_center_customer.cpp index 24bbee615..21a574557 100644 --- a/code/sdk/application/wearable/ln/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/ln/service/msg_center/src/msg_center_customer.cpp @@ -74,6 +74,7 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_BLOODOXYGEN_UPDATA, PRIORITY_TWO}, {TOPIC_EVENT_SPORT_DISTANCE, PRIORITY_TWO}, {TOPIC_EVENT_LOCATION, PRIORITY_TWO}, + {TOPIC_EVENT_DEBUGOUTPUT,PRIORITY_ONE},//开发调试专用窗口 }; bool g_pressFlag = false; @@ -115,6 +116,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_BLOODOXYGEN_UPDATA); MsgCenterSubscribeTopic(TOPIC_EVENT_SPORT_DISTANCE); MsgCenterSubscribeTopic(TOPIC_EVENT_LOCATION); + MsgCenterSubscribeTopic(TOPIC_EVENT_DEBUGOUTPUT); } static OHOS::UIViewGroup* ShowAlarmNotify(void) @@ -156,6 +158,11 @@ static OHOS::UIViewGroup* ShowMsgNotify(void) return OHOS::PhoneMsgView::CreatePhoneMsgView(); } +static OHOS::UIViewGroup* showDebugOutputNotify(void) +{ + return OHOS::CreateDebugOutputMainView(); +} + void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { unused(req); @@ -341,6 +348,18 @@ void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) // SendMsgToUIService(UI_UPDATE_GOAL, 0, nullptr, 0); } +void MsgCenterNotifyDebugOutProc(const Topic topic, Request* req) +{ + unused(req); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyDebugOutProc !"); + if (CheckPriority(topic)) + { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); + NotificationManager::GetInstance()->ShowNotify(showDebugOutputNotify, (uint16_t)topic, true); + } +} + + /* 订阅事件通知逻辑可定制 */ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_ALARM_RING, MsgCenterNotifyAlarmProc}, @@ -358,6 +377,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_BLOODOXYGEN_UPDATA, MsgCenterNotifyBloodOxygenProc}, {TOPIC_EVENT_SPORT_DISTANCE, MsgCenterNotifyDistanceProc}, {TOPIC_EVENT_LOCATION, MsgCenterNotifyLocationProc}, + {TOPIC_EVENT_DEBUGOUTPUT, MsgCenterNotifyDebugOutProc}, }; static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx) diff --git a/code/sdk/application/wearable/ln/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/ln/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp new file mode 100644 index 000000000..a915664b3 --- /dev/null +++ b/code/sdk/application/wearable/ln/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -0,0 +1,270 @@ +#include "notify/debug_output_notification/debug_output_notification.h" +#include "notification_manager.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "broadcast_feature.h" +#include "broadcast_service.h" +#include "components/ui_scroll_view.h" +#include "components/ui_toggle_button.h" +#include "graphic_service.h" +#include "custom_utils.h" +#include +#include "events/key_event.h" +#include "common/key_code.h" +#include "dock/input_device.h" + +/* 避免依赖深路径头文件:声明所需 C 接口,保持 C 链接名 */ +#ifdef __cplusplus +extern "C" +{ +#endif +#include "ln_api.h" + char *uapi_ln_get_device_id(void); + char *uapi_ln_get_device_iccid(void); + char *uapi_ln_get_device_model(void); + char *uapi_ln_get_device_version(void); +#ifdef __cplusplus +} +#endif + +namespace OHOS +{ + struct DebugOutputViewMapper + { + const int16_t viewId; + bool (DebugOutputViewEventListener::*func)(int16_t thisView); + }; + + static const DebugOutputViewMapper ViewMapper[] = {}; + + /* -------------------------------------------------------------------------- */ + UIViewGroup *DebugGroupView{nullptr}; + UILabel *debugOutputtitleLabel{nullptr}; + UILabel *debugOutputLabel{nullptr}; + /* -------------------------------------------------------------------------- */ + DebugOutputViewEventListener::DebugOutputViewEventListener() {} + + DebugOutputViewEventListener::~DebugOutputViewEventListener() {} + + DebugOutputViewEventListener &DebugOutputViewEventListener::GetInstance() + { + static DebugOutputViewEventListener instance; + return instance; + } + + // 增加按键事件 + bool DebugOutputViewEventListener::OnKeyAct(UIView &view, const KeyEvent &event) + { + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + int screenState = uapi_get_screen_state(); + + // 按键事件日志 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: keyID=%d, keyState=%d, screenState=%d", keyID, keyState, screenState); + + uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId(); + if (notifyId == TOPIC_EVENT_DEBUGOUTPUT && keyState == InputDevice::STATE_PRESS && uapi_get_screen_state() == 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TOPIC_EVENT_DEBUGOUTPUT"); + /* 使用 PRESS 触发,保证大多数机型都能响应 */ + switch (keyID) + { + case static_cast(ZliteKeyCode::ZLITE_KEY_FUNC): + NotificationManager::GetInstance()->StopNotify(); + return true; + case static_cast(ZliteKeyCode::ZLITE_KEY_VENDOR_UP): + { + static constexpr int16_t kMaxDebugViews = 1; /* 视图页数,如扩展多页可调整 */ + int16_t idx = OHOS::DebugOutputViewEventListener::GetInstance().GetCurViewIndex(); + idx = (idx + 1) % kMaxDebugViews; + OHOS::DebugOutputViewEventListener::GetInstance().SetCurViewIndex(idx); + OHOS::DebugOutputViewEventListener::GetInstance().UpdateView(); + return true; + } + case static_cast(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN): + { + static constexpr int16_t kMaxDebugViews = 1; + int16_t idx = OHOS::DebugOutputViewEventListener::GetInstance().GetCurViewIndex(); + idx = (idx - 1 < 0) ? (kMaxDebugViews - 1) : (idx - 1); + OHOS::DebugOutputViewEventListener::GetInstance().SetCurViewIndex(idx); + OHOS::DebugOutputViewEventListener::GetInstance().UpdateView(); + return true; + } + default: + break; + } + } + } + + bool DebugOutputViewEventListener::ClickFunc(int16_t interface) + { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + for (int i = 0; i < funcSize; i++) + { + if (interface == ViewMapper[i].viewId) + { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (jug == false) + { + return false; + } + return true; + } + } + return false; + } + bool DebugOutputViewEventListener::CheckViewParam(int16_t hideView, int16_t showView) + { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + if (showView < 0 || showView > funcSize) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showView err."); + return false; + } + + if (hideView < 0 || hideView > funcSize) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView err."); + return false; + } + + return true; + } + void DebugOutputViewEventListener::ChangeView(int16_t hideView, int16_t showView) + { + if (!CheckViewParam(hideView, showView)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckViewParam failed."); + return; + } + ClickFunc(showView); + RootView::GetInstance()->Invalidate(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hideView:%d -> showView:%d success!!", hideView, showView); + } + + void DebugOutputViewEventListener::SetCurViewIndex(int16_t viewNum) + { + curViewIndex = viewNum; + } + + int DebugOutputViewEventListener::GetCurViewIndex(void) + { + return curViewIndex; + } + + std::string DebugOutputViewEventListener::GetLeiNiaoDeviceInfo(void) + { + std::string deviceInfo = "设备号:" + std::string(uapi_ln_get_device_id()) + "\n"; + deviceInfo += "设备iccid:" + std::string(uapi_ln_get_device_iccid()) + "\n"; + deviceInfo += "设备version:" + std::string(uapi_ln_get_device_version()) + "\n"; + deviceInfo += "设备model:" + std::string(uapi_ln_get_device_model()) + "\n"; + return deviceInfo; + } + + void DebugOutputViewEventListener::UpdateView(void) + { + if (debugOutputLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr"); + return; + } + if (debugOutputtitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputtitleLabel is nullptr"); + return; + } + switch (GetCurViewIndex()) + { + case 0: + debugOutputtitleLabel->SetText("雷鸟设备信息"); + debugOutputLabel->SetText(DebugOutputViewEventListener::GetInstance().GetLeiNiaoDeviceInfo().c_str()); + break; + default: + debugOutputtitleLabel->SetText("无标题信息"); + debugOutputLabel->SetText("无内容信息"); + break; + } + debugOutputtitleLabel->Invalidate(); + debugOutputLabel->Invalidate(); + return; + } + + /*创建调试专用主窗口视图*/ + UIViewGroup *CreateDebugOutputMainView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateDebugOutputMainView"); + if (DebugGroupView == nullptr) + { + if (DebugGroupView == nullptr) + { + DebugGroupView = new UIViewGroup(); + if (DebugGroupView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugGroupView is new fail!!"); + return nullptr; + } + } + DebugGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + /* -------------------------------------------------------------------------- */ + if (debugOutputtitleLabel == nullptr) + { + debugOutputtitleLabel = new UILabel(); + if (debugOutputtitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " new debugOutputtitleLabel fail"); + return nullptr; + } + debugOutputtitleLabel->SetPosition(80, 40, 200, 35); + debugOutputtitleLabel->SetStyle(STYLE_TEXT_FONT, 30); + debugOutputtitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + debugOutputtitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + debugOutputtitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + DebugGroupView->Add(debugOutputtitleLabel); + } + /* -------------------------------------------------------------------------- */ + if (debugOutputLabel == nullptr) + { + debugOutputLabel = new UILabel(); + if (debugOutputLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new debugOutputLabel fail"); + return nullptr; + } + debugOutputLabel->SetPosition(30, 70, 300, 70); + debugOutputLabel->SetText(DebugOutputViewEventListener::GetInstance().GetLeiNiaoDeviceInfo().c_str()); + debugOutputLabel->SetStyle(STYLE_TEXT_FONT, 24); + debugOutputLabel->SetStyle(STYLE_LINE_HEIGHT, 24); + debugOutputLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + DebugGroupView->Add(debugOutputLabel); + } + RootView::GetInstance()->SetOnKeyActListener((OHOS::RootView::OnKeyActListener *)&DebugOutputViewEventListener::GetInstance()); + DebugOutputViewEventListener::GetInstance().UpdateView(); + /* -------------------------------------------------------------------------- */ + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView); + /* -------------------------------------------------------------------------- */ + } + return DebugGroupView; + } + + /*释放调试专用主窗口视图*/ + void FreeDebugOutputMainView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView"); + if (DebugGroupView != nullptr) + { + DebugGroupView->RemoveAll(); + + delete debugOutputtitleLabel; + debugOutputtitleLabel = nullptr; + delete debugOutputLabel; + debugOutputLabel = nullptr; + + RootView::GetInstance()->Remove(DebugGroupView); + delete DebugGroupView; + DebugGroupView = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!"); + } + return; + } +}