Merge #1988 into sdk650pathc0423 from refs/changes/1988/head 1997/target/1
author袁清梦 <3449750381@qq.com>
Tue, 22 Jul 2025 05:55:53 +0000 (05:55 +0000)
committer袁清梦 <3449750381@qq.com>
Tue, 22 Jul 2025 05:55:53 +0000 (05:55 +0000)
Code review from 袁清梦

* refs/changes/1988/head: (2 commits squashed)

  - 修复息屏处理的notify

  - 校验运动数据

Signed-off-by: Caisking <3449750381@qq.com>
Merged-by: Caisking <3449750381@qq.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1988
code/sdk/application/wearable/fd230/nativeapp/nativeui/screennotify/include/ui_screennotify.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/screennotify/src/ui_screennotify.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingModel.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingModel.cpp

index 39399a4..6d6077f 100644 (file)
@@ -26,7 +26,6 @@ void notify_screen_on_event(void);
 void notify_screen_off_event(void);
 void notify_screen_aod_on_event(void);
 void notify_screen_aod_off_event(void);
-
 /**
  * @brief 设置灭屏后slice的存活期,需要在slice对应的Presentor的OnStart方法中调用
  * 默认存活期是5秒,灭屏超过5秒后再次亮屏会跳回主界面
@@ -36,11 +35,14 @@ void set_back_to_home_interval(uint32_t time_sec);
 
 /**
  * @brief 获取灭屏后slice的存活期,需要在slice对应的Presentor的OnStart方法中调用
- * 默认存活期是5秒,灭屏超过5秒后再次亮屏会跳回主界面
+ * 默认存活期是5秒,灭屏超过10秒后再次亮屏会跳回主界面
  * @param time_sec 获取的slice灭屏后的存活期时间
  */
 uint32_t get_back_to_home_interval(void);
 
+void handleLockEnabled(uint16_t current_slice_id);
+void handleLockDisabled(uint16_t current_slice_id);
+
 #ifdef __cplusplus
 }
 #endif
index 784c4c4..307f99e 100644 (file)
@@ -1,3 +1,4 @@
+
 #include <list>
 #include <cstdio>
 #include "ability_state.h"
 #include "components/root_view.h"
 #include "notification_manager.h"
 #include "DialBinTypesV2.h"
+#include <unordered_set>
+#include "ConfigModel.h"
+#include <cstdint>
+
+extern "C" void uapi_dev_runtime_set_lock_status(uint8_t status);
+extern "C" uint8_t uapi_dev_runtime_get_lock_status(void);
 
 #ifdef __cplusplus
 extern "C" {
 #endif
-static uint32_t g_back_to_home_interval = 5;
 
-// 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面
-uint16_t ignore_slice_ids[] = {
+static uint32_t g_back_to_home_interval = 3;           // 超时时间 3秒
+static const uint32_t g_screen_off_time_interval = 10; // 超时时间 10秒
+//息屏不上锁
+const uint16_t ignore_slice_ids[] = {
     VIEW_INVALID,
-    VIEW_SETTING,
-    VIEW_UISAMPLE,
-#ifdef SUPPORT_ALIPAY_SEC
-    VIEW_MAIN_ALIPAY,
-#endif
+    VIEW_SAVEBAT,      // 省电模式
+    VIEW_TRAININGCRAD, // 训练卡片
+};
+//息屏10秒回到主界面
+const uint16_t special_slice_ids[] = {
+    VIEW_ADD_CARD,   //卡片管理
+    VIEW_SET_DIAL,   //表盘管理
+    VIEW_HEART_CHART //心率检测
 };
 
-static std::list<ScreenStatusNotifyCallback> g_callback;
+static std::unordered_set<ScreenStatusNotifyCallback> g_callbacks;
 
-static void ChangeToHomeView(void)
-{
-    screen_context_t *sc = power_display_get_screen_context();
-    uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
-    for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) {
-        if (ignore_slice_ids[i] == current_slice_id) {
-            return;
-        }
-    }
-    if (sc->screen_off_time_interval > g_back_to_home_interval) {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
-                      sc->screen_off_time_interval);
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
-                      OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
-        if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) {
-            if (current_slice_id != VIEW_MAIN) { // 主表盘
-                OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-            } else {
-                if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) {
-                    // 当前页面为主表盘的其他页面时,切换回主表盘页面
-                    OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
-                }
-            }
-        }
+static bool isSliceIgnored(uint16_t slice_id) {
+  for (uint16_t id : ignore_slice_ids) {
+    if (id == slice_id) {
+      return true;
     }
+  }
+  return false;
 }
+static void GuiEnterAod(bool entry) {
+  using namespace OHOS;
+  DisplayState newState = entry ? DisplayState::AOD : DisplayState::NORMAL;
 
-static void GuiEnterAod(bool entry)
-{
-    using namespace OHOS;
-    DisplayState newState = entry ? DisplayState::AOD : DisplayState::NORMAL;
-
-    uint16_t current_slice_id = NativeAbility::GetInstance().GetCurSliceId();
-    for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) {
-        if (ignore_slice_ids[i] == current_slice_id) {
-            return;
-        }
+  uint16_t current_slice_id = NativeAbility::GetInstance().GetCurSliceId();
+  for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) {
+    if (ignore_slice_ids[i] == current_slice_id) {
+      return;
     }
-    if (NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) {
-        if (newState == DisplayState::AOD) {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "enter aod");
-            NativeAbility::GetInstance().ChangeSlice(VIEW_AOD);
-        } else {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "exit aod");
-            NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-        }
+  }
+  if (NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) {
+    if (newState == DisplayState::AOD) {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "enter aod");
+      NativeAbility::GetInstance().ChangeSlice(VIEW_AOD);
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "exit aod");
+      NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
     }
-};
+  }
+}
+static void ChangeToHomeView(void) {
+  screen_context_t *sc = power_display_get_screen_context();
+  uint16_t current_slice_id =
+      OHOS::NativeAbility::GetInstance().GetCurSliceId();
 
-void notify_screen_on_event(void)
-{
-    for (auto callback : g_callback) {
-        callback(SCREEN_STATUS_ON);
-    }
-    ChangeToHomeView();
-    if (GraphicService::GetInstance()->IsNativeRunning() && !OHOS::NotificationManager::GetInstance()->HasNotifyShowing()) {
-        OHOS::NativeAbility::GetInstance().ResumeSlice(); // ensure that don't resume twice if switch to home
+  if (isSliceIgnored(current_slice_id)) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Current slice ID %u is ignored.",
+                  current_slice_id);
+    return;
+  }
+
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen off time interval = %u %u",
+                sc->screen_off_time_interval, g_back_to_home_interval);
+
+  if (sc->screen_off_time_interval > g_back_to_home_interval) {
+    int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int(
+        OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH);
+
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate);
+
+    if (lockstate == 1) {
+      handleLockEnabled(current_slice_id);
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "Lock state is not enabled (lockstate != 1).");
     }
+  }
+  if (sc->screen_off_time_interval > g_screen_off_time_interval) {
+    handleLockDisabled(current_slice_id);
+  }
 }
 
-void notify_screen_off_event(void)
-{
-    for (auto callback : g_callback) {
-        callback(SCREEN_STATUS_OFF);
-    }
-    if (GraphicService::GetInstance()->IsNativeRunning()) {
-        OHOS::NativeAbility::GetInstance().StopSliceTransition(); // make sure to end slice transition before turning screen off.
-        OHOS::NativeAbility::GetInstance().PauseSlice();
+void handleLockEnabled(uint16_t current_slice_id) {
+  if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() ==
+      STATE_ACTIVE) {
+    if (uapi_dev_runtime_get_lock_status() == 0) {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "Device is unlocked (lock status == 0).");
+      OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+      uapi_dev_runtime_set_lock_status(1); // 上锁
+      OHOS::MainModel::GetInstance().setDialState(OHOS::DialState::LOCK, true);
+    } else if (current_slice_id == VIEW_CODED_LOCK) {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "Device is locked (lock status == 1) and current slice is "
+                    "VIEW_CODED_LOCK.");
+      OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+    } else {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                    "Device is in an inactive lock state or current slice is "
+                    "not VIEW_CODED_LOCK.");
     }
+  } else {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "Native ability state is not active.");
+  }
 }
 
+void handleLockDisabled(uint16_t current_slice_id) {
+  int lockstate = OHOS::ConfigModel::GetInstance()->get_configData_int(
+      OHOS::ConfigModel::CONFIGMODEL_ITEM_PASSWORD_SWITCH);
+
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lockstate = %d", lockstate);
+
+  if (lockstate == 0) {
+    for (uint16_t id : special_slice_ids) {
+      if (id == current_slice_id) {
+        OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+        return;
+      }
+    }
+  }
+}
 void notify_screen_aod_on_event(void)
 {
     GuiEnterAod(true);
@@ -112,31 +152,37 @@ void notify_screen_aod_off_event(void)
 {
     GuiEnterAod(false);
 }
+void notify_screen_on_event(void) {
+  for (auto callback : g_callbacks) {
+    callback(SCREEN_STATUS_ON);
+  }
+  ChangeToHomeView();
+}
 
-void set_back_to_home_interval(uint32_t time_sec)
-{
-    g_back_to_home_interval = time_sec;
+void notify_screen_off_event(void) {
+  for (auto callback : g_callbacks) {
+    callback(SCREEN_STATUS_OFF);
+  }
 }
 
-uint32_t get_back_to_home_interval(void)
-{
-    return g_back_to_home_interval;
+void set_back_to_home_interval(uint32_t time_sec) {
+  g_back_to_home_interval = time_sec;
 }
 
-void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-{
-    if (callback != nullptr) {
-        g_callback.push_back(callback);
-    }
+uint32_t get_back_to_home_interval(void) { return g_back_to_home_interval; }
+
+void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback) {
+  if (callback != nullptr) {
+    g_callbacks.insert(callback);
+  }
 }
 
-void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-{
-    if (callback != nullptr) {
-        g_callback.remove(callback);
-    }
+void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback) {
+  if (callback != nullptr) {
+    g_callbacks.erase(callback);
+  }
 }
 
 #ifdef __cplusplus
 }
-#endif
+#endif
\ No newline at end of file
index db9ddb5..e0a35bc 100644 (file)
 #include "traing/Training_UiConfig.h"
 #include "ui_resource_string.h"
 
-// #include "cywee_hal.h"
-// #include "cywee_service.h"
+#ifdef SUPPORT_CYWEE_SERVICE
+#include "cywee_service.h"
+#include "cywee_hal.h"
+#endif
 
 #include <cmath>
 #include <iostream>
@@ -98,7 +100,6 @@ int write_Trainingdata_data(Trainingdata data);
 void ble_training_init(void);
 #endif
 
-
 #ifdef __cplusplus
 }
 #endif
@@ -131,8 +132,6 @@ namespace OHOS {
 
 #define MAXSPORTID 176
 
-
-
 // 运动状态
 enum class ExerciseState {
   End = 0,
@@ -267,11 +266,11 @@ public:
   LoadDataFormJson(std::vector<SportData> &sportDataVector); /*加载json文件*/
   void RecordSportData();                                    /*保存数据*/
 
-  // 训练数据相关配置
-  #ifdef CYWEE_ACTIVITY_ENABLE
+// 训练数据相关配置
+#ifdef SUPPORT_CYWEE_SERVICE
   void AnalysisData(act_result_t *cyweeInfo); /*解析传输过来的数据*/
   void AnalysisExtraData(act_ext_result_t *cyweeInfo); /*解析运动额外数据*/
-  #endif
+#endif
 
   void AnalysisHeartData(uint8_t hrs);              /*解析运动心率数据*/
   SportData *GetSportdata();                        /*获取训练数据*/
index 8fc620c..0e025c2 100644 (file)
@@ -37,6 +37,7 @@
 #endif
 
 #ifdef SUPPORT_CYWEE_SERVICE
+#include "cywee_hal.h"
 #include "cywee_service.h"
 #endif
 
@@ -133,7 +134,7 @@ void TraingUnsubscribeTopic(Topic topic) {
 }
 int flag = 0;
 static void Training_Notify(void *args, const Topic topic, Request *request) {
-#ifdef CYWEE_ACTIVITY_ENABLE
+#ifdef SUPPORT_CYWEE_SERVICE
   UNUSED(args);
   UNUSED(topic);
   if (request == NULL) {
@@ -150,10 +151,9 @@ static void Training_Notify(void *args, const Topic topic, Request *request) {
                     "memcpy_s act_result_t fail  ret = %d", rets);
       return;
     }
-    // GraphicService::GetInstance()->PostGraphicEvent(
-    // std::bind(&TraingCardPresenter::send_sport_cmd,
-    //           TraingCardPresenter::GetInstance(), traingbleInfo));
+#ifdef BLE_SERVER_ENABLE
     TraingCardPresenter::GetInstance()->send_sport_cmd(traingbleInfo);
+#endif
     delete traingbleInfo;
   }
   //增加训练runtime控制
@@ -507,10 +507,19 @@ double CalculateAverageHeartRate(const std::vector<int> &heartRates) {
 
   return sum / sortedHeartRates.size(); // 返回平均值
 }
-#ifdef CYWEE_ACTIVITY_ENABLE
+#ifdef SUPPORT_CYWEE_SERVICE
 /*分析数据*/
 void TraingModel::AnalysisData(act_result_t *cyweeInfo) {
+  if (cyweeInfo == NULL)
+    return;
+
   // 不同的运动类型解析不同的数据
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                "AnalysisData:[steps %d, distance %d,calories %d, pace %d, "
+                "step_frequency %d, step_length %d]",
+                cyweeInfo->steps, cyweeInfo->distance, cyweeInfo->calories,
+                cyweeInfo->pace, cyweeInfo->step_frequency,
+                cyweeInfo->step_length);
   // 通用数据
   sportdata->steps = cyweeInfo->steps;
   sportdata->distance = cyweeInfo->distance;
@@ -570,10 +579,15 @@ void TraingModel::AnalysisData(act_result_t *cyweeInfo) {
 #endif
 
 /*分析activity extra info数据*/
-#ifdef CYWEE_ACTIVITY_ENABLE
+#ifdef SUPPORT_CYWEE_SERVICE
 void TraingModel::AnalysisExtraData(act_ext_result_t *cyweeInfo) {
 
-  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[apc:%d fpc:%d cdc:%d std:%d]",
+  //判断是否为特殊训练
+  if (isspecialsport_ == false) {
+    return;
+  }
+
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[apc:%d fpc:%d cdc:%d std:%d]",
                 cyweeInfo->avg_pace, cyweeInfo->max_pace,
                 cyweeInfo->avg_step_freq, cyweeInfo->avg_step_len);
   //平均配速
@@ -1500,16 +1514,13 @@ bool TraingModel::AddHeartRateData(uint32_t timestamp, uint8_t heartRate) {
   // 检查重复时间戳
   for (const auto &entry : heartRateTable) {
     if (entry.timestamp == timestamp) {
-      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
-                    "时间戳重复无法添加数据 AddHeartRateData is error!");
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"时间戳重复无法添加数据 AddHeartRateData is error!");
       return false; // 返回重复
     }
   }
 
   if (heartRateTable.size() >= MAX_ENTRIES) {
-    WEARABLE_LOGE(
-        WEARABLE_LOG_MODULE_APP,
-        "达到最大心率数据条目限制 无法添加新的数据 AddHeartRateData is error!");
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"达到最大心率数据条目限制 无法添加新的数据 AddHeartRateData is error!");
     return false; // 返回条目满了
   }
 
@@ -1764,8 +1775,6 @@ std::string TraingModel::DisplayMotionDuration() {
   if (g_motionTimes > 0) {
     sportdata->duration = g_motionTimes; // 设置训练时长
 
-    // 每分钟进行配速和心率数据存储
-    StoreDataIfMinutePassed();
   }
 
   return motionDuration; // 返回格式化的运动时长
@@ -1796,7 +1805,7 @@ void TraingModel::StoreDataIfMinutePassed() {
     }
   }
 
-  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "duration:[%d] g_motionTimes[%d]\r\n",
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "duration:[%d] g_motionTimes[%d]\r\n",
                 sportdata->duration, g_motionTimes);
 }
 
@@ -1825,10 +1834,8 @@ void TraingTimerCallback(void) {
     pauseStartTimestamp = sportdata->starttime;
   }
 
-  uint32_t currentTimestamp =
-      OHOS::TraingModel::GetInstance()->get_current_time(); // 获取当前时间戳
-  g_motionTimes = (currentTimestamp - pauseStartTimestamp) +
-                  totalPausedDuration; // 更新运动时间
+  uint32_t currentTimestamp =OHOS::TraingModel::GetInstance()->get_current_time(); // 获取当前时间戳
+  g_motionTimes = (currentTimestamp - pauseStartTimestamp) + totalPausedDuration; // 更新运动时间
   sportdata->duration = g_motionTimes; // 更新持续时间
 
   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,
@@ -2374,17 +2381,17 @@ static void sport_data_callbackProc(int data) {
     return;
   }
   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "sport_data_callbackProc");
-#ifdef CYWEE_ACTIVITY_ENABLE
+#ifdef SUPPORT_CYWEE_SERVICE
   act_result_t cyweeInfo;
   cywee_get_act_data(&cyweeInfo);
-  TraingModel::GetInstance()->AnalysisData(cyweeInfo);
+  TraingModel::GetInstance()->AnalysisData(&cyweeInfo);
   // 更新其他目标完成度
   TraingModel::GetInstance()->CheckSportTag();
 
   act_ext_result_t cyweeInfo_ext;
 
   cywee_get_act_ext_data(&cyweeInfo_ext);
-  TraingModel::GetInstance()->AnalysisExtraData(cyweeInfo_ext);
+  TraingModel::GetInstance()->AnalysisExtraData(&cyweeInfo_ext);
 #endif
   //训练心率
   uint8_t hrs = 0;