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 "base_shared_bundle_info.h" 25 #include "bundle_info.h" 26 #include "bundle_mgr_interface.h" 27 #include "child_scheduler_interface.h" 28 #include "child_scheduler_stub.h" 29 #include "child_process_info.h" 30 #include "event_handler.h" 31 #include "ipc_singleton.h" 32 #include "js_runtime.h" 33 34 namespace OHOS { 35 namespace AppExecFwk { 36 using HspList = std::vector<BaseSharedBundleInfo>; 37 class ChildMainThread : public ChildSchedulerStub { 38 DECLARE_DELAYED_IPCSINGLETON(ChildMainThread); 39 40 public: 41 static void Start(const std::map<std::string, int32_t> &fds); 42 void SetFds(const std::map<std::string, int32_t> &fds); 43 bool ScheduleLoadChild() override; 44 bool ScheduleExitProcessSafely() override; 45 bool ScheduleRunNativeProc(const sptr<IRemoteObject> &mainProcessCb) override; 46 47 private: 48 static int32_t GetChildProcessInfo(ChildProcessInfo &info); 49 bool Init(const std::shared_ptr<EventRunner> &runner, const ChildProcessInfo &processInfo); 50 bool Attach(); 51 void HandleLoadJs(); 52 void HandleLoadArkTs(); 53 void HandleLoadNative(); 54 void InitNativeLib(const BundleInfo &bundleInfo); 55 void HandleExitProcessSafely(); 56 void ExitProcessSafely(); 57 void GetNativeLibPath(const BundleInfo &bundleInfo, const HspList &hspList, AppLibPathMap &appLibPaths); 58 void HandleRunNativeProc(const sptr<IRemoteObject> &mainProcessCb); 59 void UpdateNativeChildLibModuleName(const AppLibPathMap &appLibPaths, bool isSystemApp); 60 61 sptr<IAppMgr> appMgr_ = nullptr; 62 std::shared_ptr<EventHandler> mainHandler_ = nullptr; 63 std::shared_ptr<BundleInfo> bundleInfo_ = nullptr; 64 std::shared_ptr<ChildProcessInfo> processInfo_ = nullptr; 65 std::unique_ptr<AbilityRuntime::Runtime> runtime_ = nullptr; 66 std::string nativeLibModuleName_; 67 std::shared_ptr<ChildProcessArgs> processArgs_ = nullptr; 68 69 DISALLOW_COPY_AND_MOVE(ChildMainThread); 70 }; 71 } // namespace AppExecFwk 72 } // namespace OHOS 73 #endif // OHOS_ABILITY_RUNTIME_CHILD_MAIN_THREAD_H 74