增加全局黑脸恢复操作(已验证)
authorxue <2144439972@qq.com>
Sat, 17 Jan 2026 10:18:23 +0000 (18:18 +0800)
committerxue <2144439972@qq.com>
Sat, 17 Jan 2026 10:18:23 +0000 (18:18 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp

index dcb2647..0bb0f00 100644 (file)
@@ -460,6 +460,10 @@ namespace OHOS
         bool m_screenImageClosedForDialogue = false; // 进入对话模式时是否关闭了屏保
         bool m_screenImageClosedForLullaby = false; // 进入哄睡模式时是否关闭了屏保
 
+        // 视频线程恢复相关标志
+        bool m_videoThreadRecoveryInProgress = false; // 视频线程恢复进行中标志
+        int m_videoThreadRecoveryAttempts = 0;        // 视频线程恢复尝试次数(最多3次)
+
     };
 }
 
index 8286f17..68f1950 100644 (file)
@@ -634,12 +634,23 @@ namespace OHOS
         std::string targetPath = std::string(uri);
         
         // 检查是否尝试切换到同一个文件
-        if (currentVideoPath_ == targetPath)
+        // 但是,如果视频线程不存在(videoPlay_ == nullptr 或 isExited_),则强制切换
+        bool videoThreadExists = (videoPlay_ != nullptr && 
+                                 videoPlay_->isEntered_ && 
+                                 !videoPlay_->isExited_);
+        
+        if (currentVideoPath_ == targetPath && videoThreadExists)
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Already playing the same video, skipping: %s", uri);
             return true; // 返回true表示"成功",因为不需要切换
         }
         
+        // 如果视频线程不存在,即使路径相同也要强制切换
+        if (currentVideoPath_ == targetPath && !videoThreadExists)
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Video thread not exists, force switching even if path is same: %s", uri);
+        }
+        
         // 设置切换视频标志,防止屏幕状态通知暂停播放
         g_isSwitchingVideo = true;
         
index 6cea8cc..e0660c3 100644 (file)
@@ -1590,15 +1590,26 @@ extern "C" {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TimeDisplayCallback: %s", currentTime.c_str());
         }
         
-        // 处理常亮屏刷新定时器(每50分钟刷新一次,避免1小时超时)
+        // 处理常亮屏刷新定时器(每5分钟刷新一次,避免1小时超时)
         if (m_alwaysOnRefreshActive) {
             m_alwaysOnRefreshTime++;
-            // 50分钟 = 3000秒
-            if (m_alwaysOnRefreshTime >= 600) {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimeDisplayCallback: Refreshing screen always-on (50 minutes elapsed)");
+            // TimeDisplayCallback每秒调用一次,300次=300秒=5分钟
+            if (m_alwaysOnRefreshTime >= 300) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TimeDisplayCallback: Refreshing screen always-on (45 minutes elapsed)");
+                //如果息屏则先亮屏
+                if (uapi_get_screen_state() == 0) {
+                    uapi_set_screen_on_api();
+                }        
+                // 先取消常亮屏(设置为0)
                 ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
-                LOS_Msleep(1000);
+                
+                // 等待足够的时间,确保取消操作完成(异步操作需要时间)
+                // 由于 set_screen_set_keepon_timeout 是异步的,需要等待更长时间
+                LOS_Msleep(2000);
+                
+                // 重新设置常亮屏
                 ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+                
                 m_alwaysOnRefreshTime = 0; // 重置计数器
             }
         }
@@ -2030,6 +2041,45 @@ extern "C" {
             view->UpdateBatteryProcess();
         }
         
+        // 检查视频线程是否存在,如果不存在则切换到眨眼表情
+        if (view != nullptr) {
+            bool videoThreadExists = (view->videoPlay_ != nullptr && 
+                                     view->videoPlay_->isEntered_ && 
+                                     !view->videoPlay_->isExited_);
+            
+            if (!videoThreadExists) {
+                // 视频线程不存在
+                if (!m_videoThreadRecoveryInProgress) {
+                    // 第一次检测到视频线程不存在,切换到眨眼表情
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StatusCallback: Video thread not exists, switching to winking expression");
+                    SwitchToWinkingExpression();
+                    
+                    // 开始恢复流程
+                    m_videoThreadRecoveryInProgress = true;
+                    m_videoThreadRecoveryAttempts = 0;
+                } else {
+                    // 正在恢复过程中,检查视频线程是否已恢复
+                    m_videoThreadRecoveryAttempts++;
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusCallback: Video thread recovery attempt %d/3", m_videoThreadRecoveryAttempts);
+                    
+                    if (m_videoThreadRecoveryAttempts >= 3) {
+                        // 达到最大尝试次数,停止恢复
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StatusCallback: Video thread recovery failed after 3 attempts, stopping recovery");
+                        m_videoThreadRecoveryInProgress = false;
+                        m_videoThreadRecoveryAttempts = 0;
+                    }
+                }
+            } else {
+                // 视频线程存在
+                if (m_videoThreadRecoveryInProgress) {
+                    // 视频线程已恢复,重置恢复标志
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StatusCallback: Video thread recovered");
+                    m_videoThreadRecoveryInProgress = false;
+                    m_videoThreadRecoveryAttempts = 0;
+                }
+            }
+        }
+        
         // 通知Presenter进行状态处理
         if (ThunderBirdPresenter::GetInstance() != nullptr) {
             ThunderBirdPresenter::GetInstance()->timer_callback_toui_proc();