From b802cad354dadcb5827fb84ed02fddb2fa6a43c3 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 21 Mar 2025 10:24:10 +0800 Subject: [PATCH] =?utf8?q?nativeabilityfwk=20=E6=96=87=E4=BB=B6=E5=A4=B9?= =?utf8?q?=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 | 142 +++++++- .../nativeabilityfwk/include/TransitionType.h | 2 +- .../fd230/nativeabilityfwk/include/View.h | 4 +- .../include/utils/utils_list.h | 340 +++++++++--------- .../fd230/nativeabilityfwk/src/Ability.cpp | 16 + .../nativeabilityfwk/src/NativeAbility.cpp | 12 +- .../nativeabilityfwk/src/StartNative.cpp | 6 +- 7 files changed, 342 insertions(+), 180 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..caa1614cd 100755 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h @@ -15,18 +15,27 @@ #ifndef NATIVEABILITYFWK_ABILITY_H #define NATIVEABILITYFWK_ABILITY_H +#include "utils/utils_list.h" +#include "gfx_utils/vector.h" #include +#include + #include "SliceProxy.h" #include "Slice.h" + #include "wearable_log.h" #include "TransitionType.h" #include "soc_osal.h" -#include "gfx_utils/vector.h" +#include "stack" +#include "wearable_log.h" +#include "AppViewIDs.h" #include "graphic_mutex.h" - +#include "gfx_utils/vector.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 +74,131 @@ 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 +228,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/TransitionType.h b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/TransitionType.h index 0e894b4c6..f12d6c16e 100755 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/TransitionType.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/TransitionType.h @@ -44,4 +44,4 @@ typedef union { #endif } TransitionTarget; } -#endif \ No newline at end of file +#endif diff --git a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/View.h b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/View.h index 1243e46b1..5e7a93856 100755 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/include/View.h +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/include/View.h @@ -41,7 +41,7 @@ public: * @brief Scheduled by slice after funtion SetupView and before transition animator starts if exits. * * You should override it to prepare your own views and add them into root container - * A simple examle is as follow: + * A simple examle is as follow: * void OnStart() override * { * label_ = new UILabel(); @@ -55,7 +55,7 @@ public: * @brief Scheduled by slice after function TearDownView. * * You can override it or override function of Destructor function to destroy ui views - * A simple examle is as follow: + * A simple examle is as follow: * void OnStop() override * { * DELETE_IF_NOT_NULL(label_); 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 100755 --- 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 100755 --- 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 100755 --- 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..b0a95c844 100755 --- a/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp +++ b/code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp @@ -4,9 +4,11 @@ #include "graphic_service_wrapper.h" #include "adapter.h" -void StartNative() { - OHOS::NativeLauncher::GetInstance().InitNativeLauncher(); +void StartNative() +{ + 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); -- 2.17.1