开发调试窗口新增开启ble广播按钮和广播状态显示,新增显示手表本地蓝牙地址。
authorluozheng <1732036298@qq.com>
Thu, 3 Oct 2024 10:18:18 +0000 (18:18 +0800)
committerluozheng <1732036298@qq.com>
Thu, 3 Oct 2024 10:18:18 +0000 (18:18 +0800)
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification_itemview.cpp

index 5b6af59..a8ce2ce 100644 (file)
@@ -7,6 +7,8 @@
 #include "../notify/debug_output_notification/debug_output_notification_adapter.h"
 #include "../notify/debug_output_notification/debug_output_notification_itemview.h"
 #include <custom_runtime.h>
+#include <custom_utils.h>
+#include "bluetooth/include/BluetoothModel.h"
 namespace OHOS
 {
 
@@ -28,12 +30,15 @@ namespace OHOS
     DebugOutputAdapter *debugOutputAdapter{nullptr};
     UILabel *debugOutputLabel{nullptr};
     UILabelButton *debugOutputLabelButton{nullptr};
+    UILabelButton *debugOutputbleServiceLabelButton{nullptr};
+    static constexpr const char *DEBUGOUTPUTLABELBUTTON = "debugOutputLabelButton";
+    static constexpr const char *DEBUGOUTPUTBLESERVICELABELBUTTON = "debugOutputbleServiceLabelButton";
     /* -------------------------------------------------------------------------- */
 
     void DebugOutputViewEventListener::InitDebugOutputItem()
     {
         int index = 0;
-        debugOutputItemInfo[index++] = {0, "debugOutpt"}; // 标题:设置()
+        debugOutputItemInfo[index++] = {0, "exit"}; // 标题:设置()
         debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"};
         debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"};
         debugOutputItemInfo[index++] = {3, "runtime_status_t"};
@@ -62,6 +67,18 @@ namespace OHOS
         static DebugOutputViewEventListener instance;
         return instance;
     }
+    static std::string getCurrentWatchMacAddress()
+    {
+        uint32_t len = 32;
+        char *buf_btaddr = (char *)malloc(32);
+        if (buf_btaddr == NULL)
+            return "";
+        uint8_t ret = uapi_get_btaddr((uint8_t *)buf_btaddr, &len);
+        std::string str = std::string(buf_btaddr);
+        printf("%s | %s \n", buf_btaddr, str.c_str());
+        free(buf_btaddr);
+        return (str);
+    }
 
     std::string DebugOutputViewEventListener::get_bt_runtime_status_t(void)
     {
@@ -80,6 +97,10 @@ namespace OHOS
         result += "ad2p_service_handler: ";
         result += "spp_service_handler: ";
         result += "hfp_service_handler: ";
+        result += "localAddress:" + (getCurrentWatchMacAddress()) + " ";
+        result += "ble广播状态:" + std::to_string(BluetoothModel::GetInstance()->GetAdvStartState());
+
+        // 蓝牙ble广播开关,基础信息如,地址,广播状态
 
         return result;
     }
@@ -137,18 +158,27 @@ namespace OHOS
 
     bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
     {
+        std::string viewId = view.GetViewId();
         int viewIndex;
-        if (&view == debugOutputLabelButton)
+        std::string str;
+        if (viewId == DEBUGOUTPUTBLESERVICELABELBUTTON) // 开启ble广播
+        {
+            if (BluetoothModel::GetInstance()->GetAdvStartState() == false) // 如果广播是关的就去开启广播
+                BleAdvStart();
+            return true;
+        }
+        else if (viewId == DEBUGOUTPUTLABELBUTTON) // 点击的是刷新按钮
         {
             viewIndex = GetCurViewIndex();
         }
-        else
+        else // 如果点击的是列表中的itemview
         {
             DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
             viewIndex = debugOutputItemView->GetViewIndex();
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "viewIndex:%d", viewIndex);
             if (viewIndex == 0)
             {
+                NotificationManager::GetInstance()->StopNotify();
                 return true;
             }
             ChangeView(0, 1);
@@ -159,7 +189,6 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputLabel is nullptr");
             return false;
         }
-        std::string str;
         switch (viewIndex)
         {
         case 1:
@@ -263,10 +292,10 @@ namespace OHOS
     {
         if (hideView == 1)
         {
-            DebugGroupView->Remove(DebugScrollView[hideView]);
-            if (DebugScrollView[hideView] != nullptr)
+            DebugGroupView->Remove(DebugScrollView[1]);
+            if (DebugScrollView[1] != nullptr)
             {
-                DebugScrollView[hideView]->RemoveAll();
+                DebugScrollView[1]->RemoveAll();
 
                 delete debugOutputLabel;
                 debugOutputLabel = nullptr;
@@ -349,6 +378,7 @@ namespace OHOS
         }
         debugOutputLabelButton->SetPosition(43, debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
         debugOutputLabelButton->Resize(380, 100);
+        debugOutputLabelButton->SetViewId(DEBUGOUTPUTLABELBUTTON);
         debugOutputLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
         debugOutputLabelButton->SetText("刷新");
         debugOutputLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
@@ -438,6 +468,8 @@ namespace OHOS
             DebugScrollView[0]->SetHorizontalScrollState(false);
             DebugScrollView[0]->SetTouchable(true);
             DebugScrollView[0]->SetThrowDrag(true);
+            DebugScrollView[0]->SetScrollBlankSize(70);
+            DebugScrollView[0]->SetReboundSize(30);
             DebugGroupView->Add(DebugScrollView[0]);
             /* -------------------------------------------------------------------------- */
             if (debugOutputAdapter == nullptr)
@@ -467,7 +499,7 @@ namespace OHOS
                     return nullptr;
                 }
             }
-            debugOutputList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+            debugOutputList->SetPosition(0, 120, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
             debugOutputList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
             debugOutputList->EnableAutoAlign(true);      // 设置此列表的自动对齐状态。当滚动停止时,子视图被选中,其位置自动与预设位置对齐
             debugOutputList->SetThrowDrag(true);         // 设置手指抬起屏幕后是否继续滚动。
@@ -475,13 +507,34 @@ namespace OHOS
             debugOutputList->SetSwipeACCLevel(800);      /*设置手指抬起屏幕后的补偿距离。*/
             debugOutputList->SetAdapter(debugOutputAdapter);
             debugOutputList->RefreshList();
-            debugOutputList->SetReboundSize(30);
+            // debugOutputList->SetReboundSize(30);
             // debugOutputList->SetScrollBlankSize(30);
             debugOutputList->SetRotateFactor(1.0);
             DebugScrollView[0]->Add(debugOutputList);
             /* -------------------------------------------------------------------------- */
+            if (debugOutputbleServiceLabelButton == nullptr)
+            {
+                debugOutputbleServiceLabelButton = new UILabelButton();
+                if (debugOutputbleServiceLabelButton == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "debugOutputbleServiceLabelButton is new fail!!");
+                    return nullptr;
+                }
+            }
+            debugOutputbleServiceLabelButton->SetPosition(43, debugOutputList->GetY() + debugOutputList->GetHeight());
+            debugOutputbleServiceLabelButton->SetViewId(DEBUGOUTPUTBLESERVICELABELBUTTON);
+            debugOutputbleServiceLabelButton->Resize(380, 100);
+            debugOutputbleServiceLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+            debugOutputbleServiceLabelButton->SetText("开启ble广播");
+            debugOutputbleServiceLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+            debugOutputbleServiceLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
+            debugOutputbleServiceLabelButton->SetOnClickListener(clickListener);
+            DebugScrollView[0]->Add(debugOutputbleServiceLabelButton);
+            /* -------------------------------------------------------------------------- */
             NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDebugOutputMainView);
             /* -------------------------------------------------------------------------- */
+            enable_drag(0, 1);
+            enable_drag(1, 1);
         }
         return DebugGroupView;
     }
@@ -504,6 +557,9 @@ namespace OHOS
                 delete debugOutputAdapter;
                 debugOutputAdapter = nullptr;
 
+                delete debugOutputbleServiceLabelButton;
+                debugOutputbleServiceLabelButton = nullptr;
+
                 delete DebugScrollView[0];
                 DebugScrollView[0] = nullptr;
             }
@@ -512,6 +568,11 @@ namespace OHOS
             DebugGroupView = nullptr;
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeDebugOutputMainView success!!");
         }
+        if (uapi_dev_runtime_get_saveele_status() == 1) // 如果省电模式开启,该调试窗口关闭时候恢复原状态
+        {
+            enable_drag(0, 0);
+            enable_drag(1, 0);
+        }
         return;
     }
 }
index b511f79..4754f25 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 19:48:49
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-10-03 09:48:15
+ * @LastEditTime: 2024-10-03 16:12:59
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/DebugOutputItemView.cpp
  */
 #include "../notify/debug_output_notification/debug_output_notification_itemview.h"
@@ -33,7 +33,7 @@ namespace OHOS
             labelButton.SetAlign(TEXT_ALIGNMENT_LEFT);
             labelButton.SetImagePosition(326, 37);
             labelButton.SetLabelPosition(47, 0);
-            labelButton.SetStyle(STYLE_BACKGROUND_OPA, 255);
+            // labelButton.SetStyle(STYLE_BACKGROUND_OPA, 255);
             labelButton.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
             SetTouchable(true);
         }
@@ -42,7 +42,7 @@ namespace OHOS
             labelButton.SetAlign(TEXT_ALIGNMENT_CENTER);
             labelButton.SetImagePosition(-100, 0);
             labelButton.SetLabelPosition(0, 0);
-            labelButton.SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+            // labelButton.SetStyle(STYLE_BACKGROUND_OPA, 0x00);
             labelButton.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED);
             SetTouchable(false);
         }