From: luozheng <1732036298@qq.com> Date: Tue, 19 Mar 2024 09:24:42 +0000 (+0800) Subject: 实现长按四秒关机功能,关机动画还未设置 X-Git-Tag: release_V1.2.70_20241020_135402~1296^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=5e504d9e23edbb738d42f5a1220081f1118b1153;p=mirrors%2FFD230.git 实现长按四秒关机功能,关机动画还未设置 --- diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index d85469baa..89692fef9 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -113,6 +113,7 @@ #include "dialupdate/include/DialUpdateView.h" #include "config/include/ConfigModel.h" +#include "rebootdevice/include/RebootModel.h" #include "phone/include/PhoneView.h" #include "phone/include/PhonePresenter.h" @@ -261,6 +262,8 @@ namespace OHOS // 初始化默认首页 ScreenModels::GetInstance()->PreLoadAppimages(); NativeAbility::GetInstance().SetDefaultSliceId(VIEW_MAIN); + //注册长按重启或关机事件 + RebootModel::GetInstance()->RegisterLongPressEvents(); } void NativeLauncher::InitAllNativeSlices(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp index e14bad8ff..1a73f16f7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp @@ -217,9 +217,9 @@ namespace OHOS { for (int i = 0; i < numImages; i++) { - free((void *)imagePaths[i]); + delete imagePaths[i]; + imagePaths[i] = nullptr; } - delete[] imagePaths; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h index dd0a6c38e..5c14f77a5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootModel.h @@ -25,7 +25,7 @@ public: void SetSelectViewId(int16_t value); bool GetExitsView(void); void SetExitsView(bool value); - + bool RegisterLongPressEvents(void); private: RebootModel(); int16_t selectView{0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp index 735064a55..1b2c15d31 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp @@ -4,36 +4,84 @@ * Create: 2022-04-28 */ -#include "RebootModel.h" +#include "rebootdevice/include/RebootModel.h" +#include "wearable_log.h" +#include "NativeAbility.h" +#include "errcode.h" +namespace OHOS +{ + RebootModel::RebootModel() {} -namespace OHOS { -RebootModel::RebootModel() {} + RebootModel::~RebootModel() {} -RebootModel::~RebootModel() {} + RebootModel *RebootModel::GetInstance(void) + { + static RebootModel instance; + return &instance; + } -RebootModel *RebootModel::GetInstance(void) -{ - static RebootModel instance; - return &instance; -} + int16_t RebootModel::GetSelectView(void) + { + return selectView; + } -int16_t RebootModel::GetSelectView(void) -{ - return selectView; -} + void RebootModel::SetSelectViewId(int16_t value) + { + selectView = value; + } -void RebootModel::SetSelectViewId(int16_t value) -{ - selectView = value; -} + bool RebootModel::GetExitsView(void) + { + return exitsView; + } -bool RebootModel::GetExitsView(void) -{ - return exitsView; -} + void RebootModel::SetExitsView(bool value) + { + exitsView = value; + } -void RebootModel::SetExitsView(bool value) -{ - exitsView = value; -} +#ifdef __cplusplus + extern "C" + { +#endif + +#include "input_app.h" +#ifdef __cplusplus + } +#endif +#include +#include +#include "power_display_service.h" + /* + * @brief 长按四秒关机回调函数 + */ + static void OnKeyLongPress4s_Callback(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnKeyLongPress4s_Callback"); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + //切换到关机/重启卡片 + NativeAbility::GetInstance().ChangeSlice(VIEW_SHUTDOWN_OR_REBOOT); + + return; + } + + /* + * @brief 注册长按监听事件 + * @return 注册成功返回true,反之返回false + */ + bool RebootModel::RegisterLongPressEvents(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootModel::RegisterLongPressEvents"); + int32_t ret = uapi_button_register_event_cb(OnKeyLongPress4s_Callback, BUTTON_PWR_LONGPRESS_4S); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register LongPress Events err,ret = %d", ret); + return false; + } + return true; + } } \ No newline at end of file