From: luozheng <1732036298@qq.com> Date: Fri, 12 Apr 2024 03:42:38 +0000 (+0800) Subject: 设置配对弹窗超时30s销毁 X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~13 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=124c6b565caeeb9ff97a4dcb2c8557afd1d2bab7;p=mirrors%2FFD230.git 设置配对弹窗超时30s销毁 --- diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h index 2db50e1f9..13093c1f1 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h @@ -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(); diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 53c69a28c..eb07d3100 100755 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -192,6 +192,7 @@ static OHOS::UIViewGroup* CalldialNotify(void) /*显示绑定通知*/ static OHOS::UIViewGroup* showDeviceBindingNotify(void) { + PairingViewEventListener::GetInstance().Pairing_StartTimer(); return OHOS::CreateDeviceBindingView(); } diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp index ff79143e1..d77c55955 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp @@ -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" @@ -18,6 +18,14 @@ #endif +#include +#include +#include +#include +#include "iostream" +#include +#include + 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