设置配对弹窗超时30s销毁
authorluozheng <1732036298@qq.com>
Fri, 12 Apr 2024 03:42:38 +0000 (11:42 +0800)
committerluozheng <1732036298@qq.com>
Fri, 12 Apr 2024 03:42:38 +0000 (11:42 +0800)
code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp

index 2db50e1..13093c1 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-22 09:48:07
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-28 10:29:29
+ * @LastEditTime: 2024-04-12 10:20:11
  * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h
  */
 #ifndef PAIRING_NOTIFICATION_H
@@ -28,6 +28,8 @@ namespace OHOS
         bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override;
         void SetDeviceName(const char *Name);
         const char *GetDeviceName();
+        void Pairing_StartTimer(uint32_t interval = 1000*30);
+        void Pairing_StopTimer(void);
     private:
         PairingViewEventListener();
         ~PairingViewEventListener();
index 53c69a2..eb07d31 100755 (executable)
@@ -192,6 +192,7 @@ static OHOS::UIViewGroup* CalldialNotify(void)
 /*显示绑定通知*/
 static OHOS::UIViewGroup* showDeviceBindingNotify(void)
 {
+    PairingViewEventListener::GetInstance().Pairing_StartTimer();
     return OHOS::CreateDeviceBindingView();
 }
 
index ff79143..d77c559 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-22 10:04:36
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-30 09:28:18
+ * @LastEditTime: 2024-04-12 11:37:28
  * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp
  */
 #include "notification_manager.h"
 #endif
 
 
+#include <cmsis_os2.h>
+#include <cmsis_os.h>
+#include <ohos_types.h>
+#include <service/graphic_service.h>
+#include "iostream"
+#include <broadcast_feature.h>
+#include <custom_utils.h>
+
 namespace OHOS
 {
     UIViewGroup *DeviceBindingView{nullptr};
@@ -634,4 +642,93 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FreeDeviceUnbindingRequestGroupView] success");
         }
     }
+
+    /* -------------------------------------------------------------------------- */
+    
+    // 声明定时器变量
+    static osTimerId_t g_timer = NULL;
+
+    /*定时器到期时的处理*/
+    static void Pairing_TimerCallbackProc(int data)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Pairing_TimerCallbackProc");
+        #ifdef SUPPORT_BLE_SERVICE
+        comfirmPaire(0);
+        #endif
+        if( NotificationManager::GetInstance()->GetShowingNotifyId() == TOPIC_EVENT_DEVICE_BIND && NotificationManager::GetInstance()->hasNotifyShowing() == true)
+        {
+            NotificationManager::GetInstance()->StopNotify();
+        }
+        
+        PairingViewEventListener::GetInstance().Pairing_StopTimer();
+    }
+    
+    /*
+     * @brief 回调函数
+     */
+    static void Pairing_TimerCallback(int data)
+    {
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(Pairing_TimerCallbackProc, data));
+    }
+
+    /*
+     *  @brief 开启定时器函数
+     *  @param interval 时间间隔,单位ms
+     */
+    void PairingViewEventListener::Pairing_StartTimer(uint32_t interval)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener::Pairing_StartTimer");
+        /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
+        if (g_timer != NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!");
+            return;
+        }
+
+        /* --------------------------------- 2.创建定时器 -------------------------------- */
+        g_timer = osTimerNew((osTimerFunc_t)Pairing_TimerCallback, osTimerOnce, NULL, NULL);
+        // 检查定时器创建是否成功
+        if (g_timer == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!");
+            return;
+        }
+
+        /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
+        int tick = osMs2Tick(interval);
+
+        /* --------------------------------- 4.启动定时器 -------------------------------- */
+        osStatus_t ret = osTimerStart(g_timer, tick);
+        /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */
+        if (ret != osOK)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret);
+            if (g_timer != NULL)
+            {
+                ret = osTimerDelete(g_timer);
+            }
+            g_timer = NULL;
+            return;
+        }
+        uapi_setScreenDuration(interval);
+        return;
+    }
+
+    /*
+     * @brief 停止定时器
+     */
+    void PairingViewEventListener::Pairing_StopTimer(void)
+    {
+        // 检查定时器是否存在
+        if (g_timer != NULL)
+        {
+            // 删除定时器并置为 NULL
+            osStatus_t ret = osTimerDelete(g_timer);
+            if (ret != osOK)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+            }
+            g_timer = NULL;
+        }
+    }
 }
\ No newline at end of file