1 /* 2 * Copyright (c) 2023 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_CHILD_MAIN_THREAD_H 17 #define OHOS_ABILITY_RUNTIME_CHILD_MAIN_THREAD_H 18 19 #include <string> 20 #include <vector> 21 #include <memory> 22 23 #include "app_mgr_interface.h" 24 #include "bundle_info.h" 25 #include "bundle_mgr_interface.h" 26 #include "child_scheduler_interface.h" 27 #include "child_scheduler_stub.h" 28 #include "child_process_info.h" 29 #include "event_handler.h" 30 #include "ipc_singleton.h" 31 #include "js_runtime.h" 32 33 namespace OHOS { 34 namespace AppExecFwk { 35 class ChildMainThread : public ChildSchedulerStub { 36 DECLARE_DELAYED_IPCSINGLETON(ChildMainThread); 37 38 public: 39 static void Start(const ChildProcessInfo &processInfo); 40 bool ScheduleLoadJs() override; 41 bool ScheduleExitProcessSafely() override; 42 43 private: 44 bool Init(const std::shared_ptr<EventRunner> &runner, const ChildProcessInfo &processInfo); 45 bool Attach(); 46 void HandleLoadJs(); 47 void InitNativeLib(const BundleInfo &bundleInfo); 48 void HandleExitProcessSafely(); 49 void ExitProcessSafely(); 50 void GetNativeLibPath(const BundleInfo &bundleInfo, AppLibPathMap &appLibPaths); 51 void GetHapSoPath(const HapModuleInfo &hapInfo, AppLibPathMap &appLibPaths, bool isPreInstallApp); 52 std::string GetLibPath(const std::string &hapPath, bool isPreInstallApp); 53 54 sptr<IAppMgr> appMgr_ = nullptr; 55 std::shared_ptr<EventHandler> mainHandler_ = nullptr; 56 std::shared_ptr<BundleInfo> bundleInfo_ = nullptr; 57 std::shared_ptr<ChildProcessInfo> processInfo_ = nullptr; 58 std::unique_ptr<AbilityRuntime::Runtime> runtime_ = nullptr; 59 60 DISALLOW_COPY_AND_MOVE(ChildMainThread); 61 }; 62 } // namespace AppExecFwk 63 } // namespace OHOS 64 #endif // OHOS_ABILITY_RUNTIME_CHILD_MAIN_THREAD_H 65