1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ABILITY_RUNTIME_EXT_NATIVE_STARTUP_MANAGER_H 17 #define OHOS_ABILITY_RUNTIME_EXT_NATIVE_STARTUP_MANAGER_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "ext_native_startup_task.h" 27 #include "nocopyable.h" 28 #include "startup_task.h" 29 30 namespace OHOS { 31 namespace AbilityRuntime { 32 enum class SchedulerPhase { 33 PostLaunchApplication, 34 }; 35 class ExtNativeStartupManager : public NoCopyable { 36 public: 37 static ExtNativeStartupManager &GetInstance(); 38 39 static void LoadExtStartupTask(); 40 41 static int32_t BuildExtStartupTask(const std::shared_ptr<ExtNativeStartupTask> &extNativeStartupTask, 42 std::shared_ptr<StartupTask> &startupTask); 43 44 static int32_t RunNativeStartupTask(const std::map<std::string, std::shared_ptr<StartupTask>> &nativeStartupTask); 45 46 int32_t RegisterExtStartupTask( 47 const std::shared_ptr<ExtNativeStartupTask> &extNativeStartupTask, const SchedulerPhase phase); 48 49 int32_t RunPhaseTasks(const SchedulerPhase phase); 50 51 private: 52 ExtNativeStartupManager(); 53 54 ~ExtNativeStartupManager() override; 55 56 std::mutex mutex_; 57 std::unordered_map<SchedulerPhase, std::vector<std::shared_ptr<ExtNativeStartupTask>>> extNativeStartupTasks_; 58 }; 59 } // namespace AbilityRuntime 60 } // namespace OHOS 61 #endif // OHOS_ABILITY_RUNTIME_EXT_NATIVE_STARTUP_MANAGER_H 62