• 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_PROCESS_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H
18 
19 #include <memory>
20 #include <string>
21 #include <sys/types.h>
22 
23 #include "app_death_recipient.h"
24 #include "app_mgr_constants.h"
25 #include "child_scheduler_interface.h"
26 #include "child_process_info.h"
27 #include "child_process_request.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 class AppRunningRecord;
32 
33 class ChildProcessRecord {
34 public:
35     ChildProcessRecord(pid_t hostPid, const ChildProcessRequest &request,
36         const std::shared_ptr<AppRunningRecord> hostRecord);
37     ChildProcessRecord(pid_t hostPid, const std::string &libName, const std::shared_ptr<AppRunningRecord> hostRecord,
38         const sptr<IRemoteObject> &mainProcessCb, int32_t childProcessCount, bool isStartWithDebug,
39         const std::string &customProcessName);
40     virtual ~ChildProcessRecord();
41 
42     static std::shared_ptr<ChildProcessRecord> CreateChildProcessRecord(pid_t hostPid,
43         const ChildProcessRequest &request, const std::shared_ptr<AppRunningRecord> hostRecord);
44     static std::shared_ptr<ChildProcessRecord> CreateNativeChildProcessRecord(pid_t hostPid, const std::string &libName,
45         const std::shared_ptr<AppRunningRecord> hostRecord, const sptr<IRemoteObject> &mainProcessCb,
46         int32_t childProcessCount, bool isStartWithDebug, const std::string &customProcessName);
47 
48     void SetPid(pid_t pid);
49     pid_t GetPid() const;
50     pid_t GetHostPid() const;
51     void SetUid(int32_t uid);
52     int32_t GetUid() const;
53     std::string GetProcessName() const;
54     std::string GetSrcEntry() const;
55     std::string GetEntryFunc() const;
56     std::shared_ptr<AppRunningRecord> GetHostRecord() const;
57     void SetScheduler(const sptr<IChildScheduler> &scheduler);
58     sptr<IChildScheduler> GetScheduler() const;
59     void SetDeathRecipient(const sptr<AppDeathRecipient> recipient);
60     void RegisterDeathRecipient();
61     void RemoveDeathRecipient();
62     void ScheduleExitProcessSafely();
63     bool isStartWithDebug();
64     int32_t GetChildProcessType() const;
65     sptr<IRemoteObject> GetMainProcessCallback() const;
66     void ClearMainProcessCallback();
67     void SetEntryParams(const std::string &entryParams);
68     std::string GetEntryParams() const;
69     ProcessType GetProcessType() const;
70     bool IsNativeSpawnStarted() const;
71 
72 private:
73     void MakeProcessName(const std::shared_ptr<AppRunningRecord> hostRecord, const std::string &customProcessName);
74 
75     bool isStartWithDebug_;
76     pid_t pid_ = 0;
77     pid_t hostPid_ = 0;
78     int32_t uid_ = 0;
79     int32_t childProcessCount_ = 0;
80     int32_t childProcessType_ = CHILD_PROCESS_TYPE_JS;
81     ProcessType processType_ = ProcessType::CHILD;
82     std::weak_ptr<AppRunningRecord> hostRecord_;
83     sptr<IChildScheduler> scheduler_ = nullptr;
84     sptr<AppDeathRecipient> deathRecipient_ = nullptr;
85     sptr<IRemoteObject> mainProcessCb_ = nullptr;
86     std::string srcEntry_;
87     std::string processName_;
88     std::string entryFunc_;
89     std::string entryParams_;
90 };
91 }  // namespace AppExecFwk
92 }  // namespace OHOS
93 #endif  // OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H
94