From 0c268ea7fded5f2dd796fb4707277eb0998dd924 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 18 Oct 2024 18:35:56 +0800 Subject: [PATCH] =?utf8?q?#1023,=E8=A7=A3=E5=86=B3=E9=97=B9=E9=92=9F?= =?utf8?q?=E6=9C=89=E5=87=BA=E7=8E=B0=E6=B2=A1=E6=9C=89=E5=A3=B0=E9=9F=B3?= =?utf8?q?=E7=8E=B0=E8=B1=A1bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/notify/findwatch_notification.cpp | 75 +++++++------------ 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp index f04073628..0f6e1288b 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-25 17:33:47 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-10 11:50:28 + * @LastEditTime: 2024-10-18 18:02:00 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/src/notify/findwatch_notification.cpp * @details:实现查找手表的功能一般需要手表和智能手机之间的配合,通常是通过手机上的应用(App)或其他设备发送指令给手表,触发手表的查找功能。 * 以下是基本的实现步骤: @@ -113,14 +113,6 @@ namespace OHOS void FindWatchViewEventListener::SetFindWatchNotifyFlag(bool flag) { FindWatchNotifyFlag = flag; - // if(FindWatchNotifyFlag) - // { - // FindWatch_StartTimer(); - // } - // else - // { - // FindWatch_StopTimer(); - // } } // 获取查找手表通知状态 @@ -129,28 +121,26 @@ namespace OHOS return FindWatchNotifyFlag; } + // 震动 void FindWatchViewEventListener::SetVibration(void) { - // if(true == ConfigModel::GetInstance()->GetDnotdisturb() || (uapi_sleep_mode_flag_get())) - // { - // return; - // } - - if(nullptr != FindWatchGroupView) + if (nullptr != FindWatchGroupView) { ui_api_vibrate_once_func(); } } + // 闪烁屏幕 void FindWatchViewEventListener::SetLCDFlicker(bool state) { - if(nullptr != FindWatchGroupView) + if (nullptr != FindWatchGroupView) { FindWatchGroupView->SetStyle(STYLE_BACKGROUND_COLOR, state ? 0xff000000 : 0xffffffff); FindWatchGroupView->Invalidate(); } } + /*设置屏幕亮度100%*/ void FindWatchViewEventListener::SetScreenBrightness(void) { const power_display_svr_api_t *display_api = power_display_svr_get_api(); @@ -173,13 +163,13 @@ namespace OHOS if (display_api) { int brightnessValue; - if(uapi_dev_runtime_get_saveele_status()) //如果是省电模式状态下退出要把亮度设置为最低 + if (uapi_dev_runtime_get_saveele_status()) // 如果是省电模式状态下退出要把亮度设置为最低 { - brightnessValue = MIN_BRIGHTNESS;//恢复到最低亮度 + brightnessValue = MIN_BRIGHTNESS; // 恢复到最低亮度 } else { - brightnessValue= ConfigModel::GetInstance()->GetBrightness(); + brightnessValue = ConfigModel::GetInstance()->GetBrightness(); } if (display_api->set_brightness(brightnessValue) != ERRCODE_SUCC) { @@ -197,14 +187,10 @@ namespace OHOS { // 本地播放文件路径和状态 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RingPlayerInit start!,%s", path); - // std::string strSrcMusic("/music/ring"); - // std::string tempStr("/"); - // std::string strName = RingMusicName; - // uri = strSrcMusic + tempStr + strName; uri = path; // 创建 AM playerCtr = std::make_shared(); - if (playerCtr.get() == nullptr) + if (playerCtr == nullptr || playerCtr.get() == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playerCtr new fail"); return OHOS_FAILURE; @@ -245,8 +231,8 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchRing Player url:%s", uri.c_str()); playerCtr->SetSource(*source); /* --------------------------------- 4.配置播放器 -------------------------------- */ - playerCtr->SetAudioStreamType(AUDIO_STREAM_MUSIC); // 设置播放器的音频流类型为闹钟音乐。 - playerCtr->Prepare(); // 准备播放器对象以播放音频。 + playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型,支持混音 + playerCtr->Prepare(); // 准备播放器对象以播放音频。 /* -------------------------------- 5.请求音频焦点 -------------------------------- */ AudioManager &amIntance = AudioManager::GetInstance(); sessionId = amIntance.MakeSessionId(); @@ -263,7 +249,7 @@ namespace OHOS return OHOS_FAILURE; } playerInterruptListener->SetOwner(playerCtr); - interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; + interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener}; // 激活音频中断 5s超时 if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { @@ -274,6 +260,7 @@ namespace OHOS playerCtr->SetAudioSessionId(sessionId); // 播放 playerCtr->Play(); + playerCtr->EnableSingleLooping(true); // 设置是否循环播放 return OHOS_SUCCESS; } /* @@ -328,19 +315,13 @@ namespace OHOS { path_ = path; ScreenTurnOn(-1); // 亮屏操作 - - // if(true == ConfigModel::GetInstance()->GetDnotdisturb() || (uapi_sleep_mode_flag_get())) - // { - // return; - // } - // 将"开启查找手表铃声"任务发布到异步线程 GraphicService::GetInstance()->PostGraphicEvent( std::bind(&FindWatchViewEventListener::FindWatchRingPlayStart, &FindWatchViewEventListener::GetInstance(), path_)); } // 声明定时器变量 - static osTimerId_t g_timer = NULL; + static osTimerId_t g_timer = nullptr; static bool findwatch_time = true; /*定时器到期时的处理*/ static void FindWatch_TimerCallbackProc(int data) @@ -364,16 +345,16 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StartTimer"); /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Timer already exists!!"); return; } /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, NULL, NULL); + g_timer = osTimerNew((osTimerFunc_t)FindWatch_TimerCallback, osTimerPeriodic, nullptr, nullptr); // 检查定时器创建是否成功 - if (g_timer == NULL) + if (g_timer == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); return; @@ -384,15 +365,15 @@ namespace OHOS /* --------------------------------- 4.启动定时器 -------------------------------- */ osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != NULL) + if (g_timer != nullptr) { ret = osTimerDelete(g_timer); } - g_timer = NULL; + g_timer = nullptr; return; } @@ -403,17 +384,17 @@ namespace OHOS void FindWatchViewEventListener::FindWatch_StopTimer(void) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindWatchViewEventListener::FindWatch_StopTimer"); osTimerStop(g_timer); - // 删除定时器并置为 NULL + // 删除定时器并置为 nullptr osStatus_t ret = osTimerDelete(g_timer); if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); } - g_timer = NULL; + g_timer = nullptr; } } @@ -472,7 +453,7 @@ namespace OHOS FindWatchViewEventListener::GetInstance().FindWatch_StartTimer(700); FindWatchViewEventListener::GetInstance().SetScreenBrightness(); - + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeFindWatchView); return FindWatchGroupView; } @@ -587,9 +568,9 @@ namespace OHOS void FindWatchRingPlayerCallbackImpl::OnPlaybackComplete(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete"); - FindWatchViewEventListener::GetInstance().PopInterCancelMusic(); - const char *path = FindWatchViewEventListener::GetInstance().GetPath(); - FindWatchViewEventListener::GetInstance().PopInterPlayMusic((path != nullptr) ? path : nullptr); + // FindWatchViewEventListener::GetInstance().PopInterCancelMusic(); + // const char *path = FindWatchViewEventListener::GetInstance().GetPath(); + // FindWatchViewEventListener::GetInstance().PopInterPlayMusic((path != nullptr) ? path : nullptr); } void FindWatchRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) -- 2.17.1