nativeabilityfwk 文件夹合并 1697/1 1697/head 1699/target/1
authorluozheng <1732036298@qq.com>
Fri, 21 Mar 2025 02:24:10 +0000 (10:24 +0800)
committerluozheng <1732036298@qq.com>
Fri, 21 Mar 2025 02:24:10 +0000 (10:24 +0800)
code/sdk/application/wearable/fd230/nativeabilityfwk/include/Ability.h
code/sdk/application/wearable/fd230/nativeabilityfwk/include/TransitionType.h
code/sdk/application/wearable/fd230/nativeabilityfwk/include/View.h
code/sdk/application/wearable/fd230/nativeabilityfwk/include/utils/utils_list.h
code/sdk/application/wearable/fd230/nativeabilityfwk/src/Ability.cpp
code/sdk/application/wearable/fd230/nativeabilityfwk/src/NativeAbility.cpp
code/sdk/application/wearable/fd230/nativeabilityfwk/src/StartNative.cpp

index 9606728..caa1614 100755 (executable)
 
 #ifndef NATIVEABILITYFWK_ABILITY_H
 #define NATIVEABILITYFWK_ABILITY_H
+#include "utils/utils_list.h"
+#include "gfx_utils/vector.h"
 #include <cstdint>
+#include <vector>
+
 #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<uint16_t> 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<uint16_t> backStack_;//这个栈会在每次进入一个新的Slice时将其ID压入栈顶,当用户请求后退时,栈顶的Slice ID会被弹出,以此来访问前一个Slice。
 };
 }
 #endif // NATIVEABILITYFWK_ABILITY_H
index 1243e46..5e7a938 100755 (executable)
@@ -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_);
index 10e721f..56df104 100755 (executable)
-/*\r
- * Copyright (c) CompanyNameMagicTag.\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-#ifndef NATIVEABILITYFWK_UTILS_LIST_H\r
-#define NATIVEABILITYFWK_UTILS_LIST_H\r
-\r
-#include <cstdint>\r
-\r
-namespace OHOS {\r
-template<typename T>\r
-class ListsNode {\r
-public:\r
-    ListsNode() = default;\r
-    ListsNode(T value) : value_(value), next_(nullptr), prev_(nullptr) {}\r
-\r
-    T value_;\r
-    ListsNode<T> *next_;\r
-    ListsNode<T> *prev_;\r
-};\r
-\r
-template<typename T>\r
-class Lists {\r
-public:\r
-    Lists() : count_(0)\r
-    {\r
-        head_ = new ListsNode<T>();\r
-        head_->next_ = head_;\r
-        head_->prev_ = head_;\r
-    }\r
-\r
-    ~Lists()\r
-    {\r
-        RemoveAll();\r
-        delete head_;\r
-        head_ = nullptr;\r
-    }\r
-\r
-    const T Front() const\r
-    {\r
-        if (count_ == 0) {\r
-            return head_->value_;\r
-        }\r
-\r
-        return head_->next_->value_;\r
-    }\r
-\r
-    void PushFront(T value)\r
-    {\r
-        auto node = new ListsNode<T>(value);\r
-        if (node == nullptr) {\r
-            return;\r
-        }\r
-\r
-        node->prev_ = head_;\r
-        node->next_ = head_->next_;\r
-        head_->next_->prev_ = node;\r
-        head_->next_ = node;\r
-        count_++;\r
-    }\r
-\r
-    void PopFront()\r
-    {\r
-        if (count_ == 0) {\r
-            return;\r
-        }\r
-\r
-        ListsNode<T> *node = head_->next_;\r
-        node->next_->prev_ = head_;\r
-        head_->next_ = node->next_;\r
-        delete node;\r
-        count_--;\r
-    }\r
-\r
-    const T Back() const\r
-    {\r
-        if (count_ == 0) {\r
-            return head_->value_;\r
-        }\r
-\r
-        return head_->prev_->value_;\r
-    }\r
-\r
-    void PushBack(T value)\r
-    {\r
-        auto node = new ListsNode<T>(value);\r
-\r
-        node->next_ = head_;\r
-        node->prev_ = head_->prev_;\r
-        head_->prev_->next_ = node;\r
-        head_->prev_ = node;\r
-        count_++;\r
-    }\r
-\r
-    void PopBack()\r
-    {\r
-        if (count_ == 0) {\r
-            return;\r
-        }\r
-\r
-        ListsNode<T> *node = head_->prev_;\r
-        node->prev_->next_ = head_;\r
-        head_->prev_ = node->prev_;\r
-        delete node;\r
-        count_--;\r
-    }\r
-\r
-    void Remove(ListsNode<T> *node)\r
-    {\r
-        if ((count_ == 0) || (node == nullptr)) {\r
-            return;\r
-        }\r
-\r
-        node->prev_->next_ = node->next_;\r
-        node->next_->prev_ = node->prev_;\r
-\r
-        delete node;\r
-        count_--;\r
-    }\r
-\r
-    void RemoveAll()\r
-    {\r
-        ListsNode<T> *node = head_->next_;\r
-        while (node != head_) {\r
-            ListsNode<T> *temp = node;\r
-            node = node->next_;\r
-            delete temp;\r
-        }\r
-        head_->next_ = head_;\r
-        head_->prev_ = head_;\r
-        count_ = 0;\r
-    }\r
-\r
-    ListsNode<T> *Begin() const\r
-    {\r
-        return head_->next_;\r
-    }\r
-\r
-    const ListsNode<T> *End() const\r
-    {\r
-        return head_;\r
-    }\r
-\r
-    uint16_t Size() const\r
-    {\r
-        return count_;\r
-    }\r
-\r
-    bool IsEmpty() const\r
-    {\r
-        return count_ == 0;\r
-    }\r
-\r
-private:\r
-    ListsNode<T> *head_;\r
-    uint16_t count_;\r
-};\r
-} // namespace OHOS\r
-#endif  // NATIVEABILITYFWK_UTILS_LIST_H\r
+/*
+ * 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 <cstdint>
+
+namespace OHOS {
+template<typename T>
+class ListsNode {
+public:
+    ListsNode() = default;
+    ListsNode(T value) : value_(value), next_(nullptr), prev_(nullptr) {}
+
+    T value_;
+    ListsNode<T> *next_;
+    ListsNode<T> *prev_;
+};
+
+template<typename T>
+class Lists {
+public:
+    Lists() : count_(0)
+    {
+        head_ = new ListsNode<T>();
+        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<T>(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<T> *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<T>(value);
+
+        node->next_ = head_;
+        node->prev_ = head_->prev_;
+        head_->prev_->next_ = node;
+        head_->prev_ = node;
+        count_++;
+    }
+
+    void PopBack()
+    {
+        if (count_ == 0) {
+            return;
+        }
+
+        ListsNode<T> *node = head_->prev_;
+        node->prev_->next_ = head_;
+        head_->prev_ = node->prev_;
+        delete node;
+        count_--;
+    }
+
+    void Remove(ListsNode<T> *node)
+    {
+        if ((count_ == 0) || (node == nullptr)) {
+            return;
+        }
+
+        node->prev_->next_ = node->next_;
+        node->next_->prev_ = node->prev_;
+
+        delete node;
+        count_--;
+    }
+
+    void RemoveAll()
+    {
+        ListsNode<T> *node = head_->next_;
+        while (node != head_) {
+            ListsNode<T> *temp = node;
+            node = node->next_;
+            delete temp;
+        }
+        head_->next_ = head_;
+        head_->prev_ = head_;
+        count_ = 0;
+    }
+
+    ListsNode<T> *Begin() const
+    {
+        return head_->next_;
+    }
+
+    const ListsNode<T> *End() const
+    {
+        return head_;
+    }
+
+    uint16_t Size() const
+    {
+        return count_;
+    }
+
+    bool IsEmpty() const
+    {
+        return count_ == 0;
+    }
+
+private:
+    ListsNode<T> *head_;
+    uint16_t count_;
+};
+} // namespace OHOS
+#endif  // NATIVEABILITYFWK_UTILS_LIST_H
index 9b5ed1d..9fb24f4 100755 (executable)
@@ -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,
index 12a9cb1..f488664 100755 (executable)
@@ -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;
 }
index e463c09..b0a95c8 100755 (executable)
@@ -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<Want *>(AdapterMalloc(sizeof(Want)));
     memset_s(info, sizeof(Want), 0, sizeof(Want));
     OHOS::NativeAbility::GetInstance().OnActive(*info);