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