From: Caisking Date: Fri, 26 Dec 2025 10:59:05 +0000 (+0800) Subject: GPS的开关使用异步执行 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=d2b7f95362dc5977691f67b3d8dc8f885d7493ed;p=mirrors%2FFD230.git GPS的开关使用异步执行 --- diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp index 699bd3995..07fb8565c 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp @@ -3104,12 +3104,15 @@ void TraingModel::stop_heart_gps() { if (gpsopen == true) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始关闭GPS定位服务..."); - // 关闭gps - #if defined(SUPPORT_GNSS) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "调用gnss_stop()关闭GPS服务"); - gnss_stop(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gnss_stop()调用完成"); - #endif + // 关闭gps +#if defined(SUPPORT_GNSS) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "调用gnss_stop()关闭GPS服务"); + GraphicService::GetInstance()->PostGraphicEvent([]() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异步执行gnss_stop()"); + gnss_stop(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gnss_stop()调用完成"); + }); +#endif //关闭心率检测 #ifdef SUPPORT_PPG_SERVICE @@ -3144,12 +3147,15 @@ if (gps_timer_count < 2) { return; } - if (gps_timer_count == 2) { - #if defined(SUPPORT_GNSS) - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps"); - gnss_start(); - #endif - } + if (gps_timer_count == 2) { +#if defined(SUPPORT_GNSS) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps"); + GraphicService::GetInstance()->PostGraphicEvent([]() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异步执行gnss_start()"); + gnss_start(); + }); +#endif + } #if defined(SUPPORT_GNSS) gps_data_t send_gps_data = {0}; gps_data_t *gps_data = getPGPSGlobaldata(); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp index f02755c57..527a405e0 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -8,6 +8,7 @@ #include "custom_utils.h" #include "common/key_code.h" +#include #include #include #include @@ -159,6 +160,10 @@ namespace OHOS //修改为秒级定时器更新GPS定位状态 void TraingNomalPresenter::OnTickEvent() { + if(TraingNomalView::GetInstance() == nullptr) + { + return; + } /*判断是否需要GPS*/ if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false) {