From 242f0335c9a38af9fb6fa47e6bf5ac24b0101d55 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 25 Mar 2025 16:02:04 +0800 Subject: [PATCH] =?utf8?q?nativelauncher=E6=96=87=E4=BB=B6=E5=A4=B9?= =?utf8?q?=E5=90=88=E5=B9=B6=EF=BC=8C=E5=BC=80=E6=9C=BAlog=E4=B8=8E?= =?utf8?q?=E5=8A=A8=E7=94=BB=E6=96=87=E4=BB=B6=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230/nativeabilityfwk/include/Ability.h | 136 ++++++- .../include/utils/utils_list.h | 340 +++++++++--------- .../fd230/nativeabilityfwk/src/Ability.cpp | 16 + .../nativeabilityfwk/src/NativeAbility.cpp | 12 +- .../nativeabilityfwk/src/StartNative.cpp | 3 +- .../nativelauncher/include/NativeLauncher.h | 7 +- .../nativelauncher/src/NativeLauncher.cpp | 2 +- .../include/service/graphic_service_wrapper.h | 6 + .../service/src/graphic_service_wrapper.cpp | 307 +++++++++++++++- 9 files changed, 642 insertions(+), 187 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h index 9606728be..7231902fb 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h @@ -24,9 +24,17 @@ #include "gfx_utils/vector.h" #include "graphic_mutex.h" +#include "utils/utils_list.h" +#include +#include "TransitionType.h" +#include "soc_osal.h" +#include "stack" +#include "AppViewIDs.h" namespace OHOS { -const static uint16_t gSliceInvalid = 0; +const static uint16_t gSliceInvalid = 0; const static uint16_t gSliceDefaultPriority = 4; // 页面默认是最低优先级 +const static uint16_t gMaxHistorySlices = 10; // 默认最多保存三个历史记录 + class Ability { public: void AddSliceProxy(const uint16_t sliceId, SliceProxy* proxy); @@ -65,6 +73,130 @@ public: void StopPrevSlice(); void StopSliceTransition(); void BackToPreSlice(); + + /* -------------------------------------------------------------------------- */ + /// @brief 当从一个切片(Slice)进入另一个切片时被调用。 + /// @param sliceId sliceId + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 + void EnterSlice(uint16_t sliceId,const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + const uint16_t priority = gSliceDefaultPriority) { + // 获取当前SliceID + uint16_t curSliceId = GetCurSliceId(); + if (curSliceId != defaultSliceId_) { // 假定defaultSliceId_是“主页”或启动Slice的ID + backStack_.push(curSliceId); + } + ChangeSlice(sliceId,transitionId,priority); // 切换到新的Slice + } + + uint16_t GettopSliceId(void) { + if (!backStack_.empty() ) { + return backStack_.top(); + } + return 0; + } + + + // 处理后退操作 + + /// @brief 处理后退操作。 + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 + bool Back(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + const uint16_t priority = gSliceDefaultPriority) { + + if (!backStack_.empty()) { + uint16_t preSlice = backStack_.top(); + backStack_.pop(); + ChangeSlice(preSlice,transitionId,priority); + return true; + } + else + { + backStack_.push(defaultSliceId_); // 将默认主界面的 ID 推入栈中 + // 退回到defaultSliceId_ + ChangeSlice(defaultSliceId_, transitionId, priority); + return false; // 返回false表示无前一个slice,退回到默认slice + } + } + + /// @brief 处理后退多级切片的操作。 + /// @param count 指定的后退级数 + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 + bool BackCountSlice(int count,const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + const uint16_t priority = gSliceDefaultPriority) { + //如果指定的后退级数 count 为 0 ,直接返回 false 。 + // if(count == 0) { + // return false; + // } + while(!backStack_.empty() && count != 0) //当 count 不为 0 且 backStack_ 栈不为空时,弹出栈顶元素 count 次。 + { + backStack_.pop(); + count--; + } + if(!backStack_.empty()) + { + // 如果此时 backStack_ 栈不为空,取出栈顶的切片 ID ,并调用 ChangeSlice 切换到该切片,返回 true 。 + uint16_t preSlice = backStack_.top(); + ChangeSlice(preSlice,transitionId,priority); + backStack_.pop(); + return true; + } + else + { + //如果 backStack_ 栈为空,切换到默认切片,返回 false 。 + ChangeSlice(defaultSliceId_, transitionId, priority); + return false; // 返回false表示无前一个slice,退回到默认slice + } + } + //仅用于打电话结束恢复时使用 + bool Back_CountSlice_make_phone(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + const uint16_t priority = gSliceDefaultPriority); + + + bool make_phone_push(uint16_t preSlice) { + if(backStack_.empty()) + { + backStack_.push(preSlice); + } + else + { + uint8_t top_id= backStack_.top(); + if(top_id!=preSlice) + backStack_.push(preSlice); + } + + return false; + } + + /*清空后退栈*/ + void ClearSliceIdStack(void) + { + while(!backStack_.empty()) + { + backStack_.pop(); + } + if (backStack_.empty()) { + backStack_.push(defaultSliceId_); // 将默认主界面的 ID 推入栈中 + } + } + + /*打印栈中元素*/ + void showsStackSliceId() + { + printf("\n%d\n",backStack_.size()); + std::stack tempStack = backStack_; + printf("\n["); + while(!tempStack.empty()) + { + printf("%d,",tempStack.top()); + tempStack.pop(); + } + printf("]\n"); + printf("\n%d\n",backStack_.size()); + } + /* -------------------------------------------------------------------------- */ protected: Ability() = default; @@ -94,6 +226,8 @@ protected: void PostChangeSlice(const uint16_t targetSliceId, TransitionType type, const uint16_t priority, bool enableSlideBack); Ability::ProxyStruct* Find(const uint16_t sliceId); +private: + std::stack backStack_;//这个栈会在每次进入一个新的Slice时将其ID压入栈顶,当用户请求后退时,栈顶的Slice ID会被弹出,以此来访问前一个Slice。 }; } #endif // NATIVEABILITYFWK_ABILITY_H diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/utils/utils_list.h b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/utils/utils_list.h index 10e721f7b..56df1045d 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/utils/utils_list.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/utils/utils_list.h @@ -1,170 +1,170 @@ -/* - * Copyright (c) CompanyNameMagicTag. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NATIVEABILITYFWK_UTILS_LIST_H -#define NATIVEABILITYFWK_UTILS_LIST_H - -#include - -namespace OHOS { -template -class ListsNode { -public: - ListsNode() = default; - ListsNode(T value) : value_(value), next_(nullptr), prev_(nullptr) {} - - T value_; - ListsNode *next_; - ListsNode *prev_; -}; - -template -class Lists { -public: - Lists() : count_(0) - { - head_ = new ListsNode(); - head_->next_ = head_; - head_->prev_ = head_; - } - - ~Lists() - { - RemoveAll(); - delete head_; - head_ = nullptr; - } - - const T Front() const - { - if (count_ == 0) { - return head_->value_; - } - - return head_->next_->value_; - } - - void PushFront(T value) - { - auto node = new ListsNode(value); - if (node == nullptr) { - return; - } - - node->prev_ = head_; - node->next_ = head_->next_; - head_->next_->prev_ = node; - head_->next_ = node; - count_++; - } - - void PopFront() - { - if (count_ == 0) { - return; - } - - ListsNode *node = head_->next_; - node->next_->prev_ = head_; - head_->next_ = node->next_; - delete node; - count_--; - } - - const T Back() const - { - if (count_ == 0) { - return head_->value_; - } - - return head_->prev_->value_; - } - - void PushBack(T value) - { - auto node = new ListsNode(value); - - node->next_ = head_; - node->prev_ = head_->prev_; - head_->prev_->next_ = node; - head_->prev_ = node; - count_++; - } - - void PopBack() - { - if (count_ == 0) { - return; - } - - ListsNode *node = head_->prev_; - node->prev_->next_ = head_; - head_->prev_ = node->prev_; - delete node; - count_--; - } - - void Remove(ListsNode *node) - { - if ((count_ == 0) || (node == nullptr)) { - return; - } - - node->prev_->next_ = node->next_; - node->next_->prev_ = node->prev_; - - delete node; - count_--; - } - - void RemoveAll() - { - ListsNode *node = head_->next_; - while (node != head_) { - ListsNode *temp = node; - node = node->next_; - delete temp; - } - head_->next_ = head_; - head_->prev_ = head_; - count_ = 0; - } - - ListsNode *Begin() const - { - return head_->next_; - } - - const ListsNode *End() const - { - return head_; - } - - uint16_t Size() const - { - return count_; - } - - bool IsEmpty() const - { - return count_ == 0; - } - -private: - ListsNode *head_; - uint16_t count_; -}; -} // namespace OHOS -#endif // NATIVEABILITYFWK_UTILS_LIST_H +/* + * Copyright (c) CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NATIVEABILITYFWK_UTILS_LIST_H +#define NATIVEABILITYFWK_UTILS_LIST_H + +#include + +namespace OHOS { +template +class ListsNode { +public: + ListsNode() = default; + ListsNode(T value) : value_(value), next_(nullptr), prev_(nullptr) {} + + T value_; + ListsNode *next_; + ListsNode *prev_; +}; + +template +class Lists { +public: + Lists() : count_(0) + { + head_ = new ListsNode(); + head_->next_ = head_; + head_->prev_ = head_; + } + + ~Lists() + { + RemoveAll(); + delete head_; + head_ = nullptr; + } + + const T Front() const + { + if (count_ == 0) { + return head_->value_; + } + + return head_->next_->value_; + } + + void PushFront(T value) + { + auto node = new ListsNode(value); + if (node == nullptr) { + return; + } + + node->prev_ = head_; + node->next_ = head_->next_; + head_->next_->prev_ = node; + head_->next_ = node; + count_++; + } + + void PopFront() + { + if (count_ == 0) { + return; + } + + ListsNode *node = head_->next_; + node->next_->prev_ = head_; + head_->next_ = node->next_; + delete node; + count_--; + } + + const T Back() const + { + if (count_ == 0) { + return head_->value_; + } + + return head_->prev_->value_; + } + + void PushBack(T value) + { + auto node = new ListsNode(value); + + node->next_ = head_; + node->prev_ = head_->prev_; + head_->prev_->next_ = node; + head_->prev_ = node; + count_++; + } + + void PopBack() + { + if (count_ == 0) { + return; + } + + ListsNode *node = head_->prev_; + node->prev_->next_ = head_; + head_->prev_ = node->prev_; + delete node; + count_--; + } + + void Remove(ListsNode *node) + { + if ((count_ == 0) || (node == nullptr)) { + return; + } + + node->prev_->next_ = node->next_; + node->next_->prev_ = node->prev_; + + delete node; + count_--; + } + + void RemoveAll() + { + ListsNode *node = head_->next_; + while (node != head_) { + ListsNode *temp = node; + node = node->next_; + delete temp; + } + head_->next_ = head_; + head_->prev_ = head_; + count_ = 0; + } + + ListsNode *Begin() const + { + return head_->next_; + } + + const ListsNode *End() const + { + return head_; + } + + uint16_t Size() const + { + return count_; + } + + bool IsEmpty() const + { + return count_ == 0; + } + +private: + ListsNode *head_; + uint16_t count_; +}; +} // namespace OHOS +#endif // NATIVEABILITYFWK_UTILS_LIST_H diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/Ability.cpp index 9b5ed1d85..9fb24f468 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/Ability.cpp @@ -123,6 +123,22 @@ void Ability::ChangeSlice(const uint16_t targetSliceId, TransitionType type, } FreeElement(elementName); #endif + if (targetSliceId == VIEW_MAIN) + { + ClearSliceIdStack(); /*凡是回到主界面都要清空栈*/ + } + + if (targetSliceId == VIEW_INCOMING_CALL) + { + uint16_t id=GetCurSliceId(); + if(id==VIEW_REBOOTANDSHUTDOWN && VIEW_INCOMING_CALL==GettopSliceId() ) + { + ClearSliceIdStack(); + } + + if(id!=VIEW_INCOMING_CALL && id!=VIEW_BLUETOOTH_EARPHONE) + make_phone_push(id); + } TransitionTarget target; target.sliceInfo = targetSliceId | (priority << 16); bool runImmed = PageTransitionMgr::GetInstance().BeginTransition(TransitionCaller::CHANGE_SLICE, target, diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/NativeAbility.cpp b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/NativeAbility.cpp index 12a9cb143..f48866475 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/NativeAbility.cpp +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/NativeAbility.cpp @@ -24,7 +24,7 @@ #include "notification_manager.h" #include "PageTransitionMgr.h" #include "hal_tick.h" - +#include "custom_runtime.h" #ifdef __cplusplus extern "C" { @@ -53,7 +53,15 @@ void NativeAbility::InstallAbility(void) InstallNativeAbility(nullptr, this); // 初始化Launcher - NativeLauncher::GetInstance().InitNativeLauncher(); + if(uapi_dev_runtime_get_safemode_flag()) + { + NativeLauncher::GetInstance().InitNativeLauncher(LaunchMode::SAFE_MODE); + } + else + { + NativeLauncher::GetInstance().InitNativeLauncher(LaunchMode::NORMAL_MODE); + } + HideGraphicLogo(); return; } diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp index e463c097f..a18028a81 100644 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp @@ -5,8 +5,9 @@ #include "adapter.h" void StartNative() { - OHOS::NativeLauncher::GetInstance().InitNativeLauncher(); + OHOS::NativeLauncher::GetInstance().InitNativeLauncher(OHOS::LaunchMode::NORMAL_MODE); HideGraphicLogo(); + HideGraphicOtaLogo(); Want *info = static_cast(AdapterMalloc(sizeof(Want))); memset_s(info, sizeof(Want), 0, sizeof(Want)); OHOS::NativeAbility::GetInstance().OnActive(*info); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/NativeLauncher.h index 1fc741df7..3f297f139 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/NativeLauncher.h @@ -18,10 +18,15 @@ #include "AppViewIDs.h" namespace OHOS { +enum class LaunchMode +{ + NORMAL_MODE, // 普通模式 + SAFE_MODE // 安全模式 +}; class NativeLauncher { public: static NativeLauncher &GetInstance(void); - void InitNativeLauncher(void); + void InitNativeLauncher(LaunchMode mode); private: void InitAllNativeSlices(void); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/src/NativeLauncher.cpp index 279d59df5..5b92f3b9d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -44,7 +44,7 @@ NativeLauncher &NativeLauncher::GetInstance(void) return instance; } -void NativeLauncher::InitNativeLauncher() +void NativeLauncher::InitNativeLauncher(LaunchMode mode) { #ifdef JS_ENABLE ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h index 363ee0890..002cc4bfd 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h @@ -88,6 +88,12 @@ void GpuResetStart(void); */ void GpuResetEnd(void); + +/* -------------------------------------------------------------------------- */ +void ShowGraphicOTALogo(void); +void HideGraphicOtaLogo(void); +/* -------------------------------------------------------------------------- */ + #ifdef __cplusplus }; #endif diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp index 5e72603db..51e4b05cf 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp @@ -24,6 +24,11 @@ #include "common/screen.h" #include "components/root_view.h" #include "components/ui_image_view.h" +#include "thread_init.h" +#include "custom_utils.h" +#include "components/ui_image_animator.h" +#include "wearable_log.h" +#include "uicomponents/UIComponents.h" #ifdef __cplusplus extern "C" { @@ -41,6 +46,31 @@ static bool g_showLogo = false; static OHOS::UIImageView* g_logo = nullptr; static OHOS::ImageInfo* g_imgInfo = nullptr; +static bool g_showOtaLogo = false; +static OHOS::UIImageView* g_ota_logo = nullptr; +static OHOS::ImageInfo* g_ota_imgInfo = nullptr; +static uint32_t *g_boot_animation_task_handle = NULL; +static OHOS::UIViewGroup* group=nullptr; +static OHOS::UIViewGroup* boot_group=nullptr; +static OHOS::UIImageAnimatorView* ReBootImageAnimatorView=nullptr; +#ifdef CUSTOM_Z1 +static const char *ReBootPaths = "/user/res/RebootAndShutDown/ReBoot/"; //开机图片路径 +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 30; // 图片帧数 +#else +static const char *ReBootPaths = "/user/res/RebootAndShutDown/ReBoot/"; //开机图片路径 +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 36; // 图片帧数 +#endif +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_TIME = 150; // 图片更新间隔 +static OHOS::ImageAnimatorInfo ReBootImageInfo[REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 开机图像的信息 +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_X = 0; +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_Y = 0; +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_W = 466; +static constexpr int16_t REBOOT_IMAGE_ANIMATOR_VIEW_H = 466; +const OHOS::ImageInfo **ReBootPathsArray{nullptr}; // 开机图片路径数组 +static OHOS::UIImageAnimatorView::AnimatorStopListener *bootStoplistener{nullptr}; +static bool boot_animation_flag = false; +static app_task_definition_t taskcfg={0}; + #ifdef QSPI_DISPLAY #define IMAGE_OPEN_LOGO_PATH "/user/res/OPEN_LOGO_QSPI.bin" #else @@ -54,6 +84,156 @@ static OHOS::ImageInfo* g_imgInfo = nullptr; #endif #endif +#ifdef CUSTOM_Z1 +#ifdef IMAGE_OPEN_LOGO_PATH +#undef IMAGE_OPEN_LOGO_PATH +#endif +#ifdef SINGLE_USER_PARTITION +#define IMAGE_OPEN_LOGO_PATH "/user/system/z1bootlogo.bin" +#else +#define IMAGE_OPEN_LOGO_PATH "/system/z1bootlogo.bin" +#endif +#endif + + +static void FreeImagePathsArray(const char **imagePaths, const int numImages) +{ + for (int i = 0; i < numImages; i++) + { + delete imagePaths[i]; + imagePaths[i] = nullptr; + } +} + +static void ClearAll(void) +{ + if(group!=nullptr) + { + OHOS::RootView::GetInstance()->Remove(group); + group->RemoveAll(); + + if (ReBootImageAnimatorView != nullptr) + { + delete ReBootImageAnimatorView; + ReBootImageAnimatorView = nullptr; + } + + if(bootStoplistener!=nullptr) + { + delete bootStoplistener; + bootStoplistener = nullptr; + } + + // FreeImagePathsArray(ReBootPathsArray, REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + OHOS::FreeImageInfoArray(ReBootPathsArray, ReBootPaths, REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + + delete group; + group = nullptr; + } +} + +class BootAnimatorListener:public OHOS::UIImageAnimatorView::AnimatorStopListener +{ +public: +BootAnimatorListener(){} +~BootAnimatorListener(){} + +private: + void OnAnimatorStop(OHOS::UIView &view) + { + boot_animation_flag = true; + + ClearAll(); + + //boot_group->SetVisible(false); + OHOS::RootView::GetInstance()->Remove(boot_group); + delete boot_group; + boot_group = nullptr; + } + +}; + + +static const char ** CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) +{ + const char **imagePaths = new const char *[numImages]; + char buffer[256]; + for (int i = 0; i < numImages; i++) + { +#ifdef CUSTOM_Z1 + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, numImages - i , fileExtension); +#else + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1 , fileExtension); +#endif + + imagePaths[i] = strdup(buffer); + } + return imagePaths; +} + +bool ShowReBootAnimatorView() +{ + ReBootPathsArray = OHOS::CreateImageInfoArray(ReBootPaths, REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + + if (ReBootImageAnimatorView == nullptr) + { + ReBootImageAnimatorView = new OHOS::UIImageAnimatorView(); + if (ReBootImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new ReBootImageAnimatorView fail"); + return false; + } + for (uint8_t i = 0; i < REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + ReBootImageInfo[i].imageInfo = (ReBootPathsArray[i]); + ReBootImageInfo[i].imageType = OHOS::IMG_SRC_IMAGE_INFO; + ReBootImageInfo[i].pos.x = REBOOT_IMAGE_ANIMATOR_VIEW_X; + ReBootImageInfo[i].pos.y = REBOOT_IMAGE_ANIMATOR_VIEW_Y; + ReBootImageInfo[i].width = REBOOT_IMAGE_ANIMATOR_VIEW_W; + ReBootImageInfo[i].height = REBOOT_IMAGE_ANIMATOR_VIEW_H; + } + ReBootImageAnimatorView->SetPosition(REBOOT_IMAGE_ANIMATOR_VIEW_X, REBOOT_IMAGE_ANIMATOR_VIEW_Y, REBOOT_IMAGE_ANIMATOR_VIEW_W, REBOOT_IMAGE_ANIMATOR_VIEW_H); + ReBootImageAnimatorView->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffffffff); + ReBootImageAnimatorView->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff); + ReBootImageAnimatorView->SetImageAnimatorSrc(ReBootImageInfo, REBOOT_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, 100); + ReBootImageAnimatorView->SetRepeat(false); + ReBootImageAnimatorView->SetRepeatTimes(1); + + bootStoplistener = static_cast(new BootAnimatorListener()); + if (bootStoplistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create bootStoplistener!!"); + return false; + } + ReBootImageAnimatorView->SetAnimatorStopListener(bootStoplistener); + } + + + return true; +} + +OHOS::UIViewGroup* ReBootAnimatorViewInit(void) +{ + bool ret; + group = new OHOS::UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP," group new fail"); + return nullptr; + } + group->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); + group->SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE); + ret = ShowReBootAnimatorView(); + + if (ret == false) + { + return nullptr; + } + + group->Add(ReBootImageAnimatorView); + return group; +} + static void UikitRTCCallBack(uintptr_t data) { (void)(data); @@ -164,7 +344,73 @@ void InitGraphicService(void) g_initialized = true; } -void ShowGraphicLogo() +void HideGraphicLogo() +{ + if (!g_showLogo) { + return; + } + + g_showLogo = false; + GraphicService::GetInstance()->PostGraphicEvent( + [] { + if (g_logo != nullptr) { + OHOS::RootView::GetInstance()->Remove(g_logo); + delete g_logo; + g_logo = nullptr; + OHOS::ImageCacheManager::GetInstance().UnloadSingleRes(IMAGE_OPEN_LOGO_PATH); + g_imgInfo = nullptr; + } + }); +} + +void HideGraphicOtaLogo() +{ + if (!g_showOtaLogo) { + return; + } + g_showOtaLogo = false; + GraphicService::GetInstance()->PostGraphicEvent( + [] { + if (g_ota_logo != nullptr) { + OHOS::RootView::GetInstance()->Remove(g_ota_logo); + delete g_ota_logo; + g_ota_logo = nullptr; + OHOS::ImageCacheManager::GetInstance().UnloadSingleRes(IMAGE_OTA_LOGO_PATH); + g_ota_imgInfo = nullptr; + } + }); +} + +static void boot_animation_task(void *arg) +{ + unused(arg); + + boot_group = ReBootAnimatorViewInit(); + if (boot_group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP," boot_group nullptr fail"); + return; + } + HideGraphicLogo(); + HideGraphicOtaLogo(); + OHOS::GraphicEventHandler::GetInstance()->PostGraphicEvent( + [] { + OHOS::RootView::GetInstance()->Add(boot_group); + ReBootImageAnimatorView->Start(); + }, + false); + +} + +void wait_animation_stop(void) +{ + while(boot_animation_flag == false) + { + LOS_Msleep(1000); + } +} + +void ShowGraphicLogo(void) { if (g_showLogo) { return; @@ -181,26 +427,65 @@ void ShowGraphicLogo() OHOS::RootView::GetInstance()->Add(g_logo); OHOS::RootView::GetInstance()->Invalidate(); }); + LOS_Msleep(500); } -void HideGraphicLogo() +void ShowGraphicOTALogo(void) { - if (!g_showLogo) { + + if (g_showOtaLogo) { return; } - g_showLogo = false; + g_showOtaLogo = true; + g_ota_logo = new OHOS::UIImageView(); + g_ota_logo->SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight()); + g_ota_logo->SetAutoEnable(false); + g_ota_logo->SetResizeMode(OHOS::UIImageView::CENTER); + g_ota_imgInfo = OHOS::ImageCacheManager::GetInstance().LoadSingleRes(IMAGE_OTA_LOGO_PATH); + g_ota_logo->SetSrc(g_ota_imgInfo); GraphicService::GetInstance()->PostGraphicEvent( [] { - if (g_logo != nullptr) { - OHOS::RootView::GetInstance()->Remove(g_logo); - delete g_logo; - g_logo = nullptr; - OHOS::ImageCacheManager::GetInstance().UnloadSingleRes(IMAGE_OPEN_LOGO_PATH); - g_imgInfo = nullptr; - } + OHOS::RootView::GetInstance()->Add(g_ota_logo); + OHOS::RootView::GetInstance()->Invalidate(); }); + LOS_Msleep(500); + +} + +void boot_animation_init_deinit(void) +{ + errcode_t ret = uapi_terminate_thread(taskcfg.task_handle); + + if(ret != ERRCODE_SUCC) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task failed %d!",ret); + else + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"kill boot_animation_task succed !"); + + if(taskcfg.attr.stack_mem != NULL) + { + free(taskcfg.attr.stack_mem); + taskcfg.attr.stack_mem = NULL; + } + if(taskcfg.task_handle != NULL) + taskcfg.task_handle = NULL; } +void boot_animation_init(void) +{ + taskcfg.task_handle = g_boot_animation_task_handle; + taskcfg.attr.name="boot_animation_service"; + taskcfg.attr.priority = TASK_PRIORITY_APP; + taskcfg.attr.stack_size = 0x1000; + taskcfg.func = boot_animation_task; + taskcfg.use_mem = USE_EXTEND_MEM; + + errcode_t ret=uapi_create_osThread_custom(&taskcfg); + if(ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create boot_animation_task failed %d!",ret); + return ; + } +} void PostGraphicEvent(GraphicEventCb eventCb, void* userData) { GraphicService::GetInstance()->PostGraphicEvent( -- 2.17.1