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 virtual ~ChildProcessRecord(); 40 41 static std::shared_ptr<ChildProcessRecord> CreateChildProcessRecord(pid_t hostPid, 42 const ChildProcessRequest &request, const std::shared_ptr<AppRunningRecord> hostRecord); 43 static std::shared_ptr<ChildProcessRecord> CreateNativeChildProcessRecord(pid_t hostPid, const std::string &libName, 44 const std::shared_ptr<AppRunningRecord> hostRecord, const sptr<IRemoteObject> &mainProcessCb, 45 int32_t childProcessCount, bool isStartWithDebug); 46 47 void SetPid(pid_t pid); 48 pid_t GetPid() const; 49 pid_t GetHostPid() const; 50 void SetUid(int32_t uid); 51 int32_t GetUid() const; 52 std::string GetProcessName() const; 53 std::string GetSrcEntry() const; 54 std::string GetEntryFunc() const; 55 std::shared_ptr<AppRunningRecord> GetHostRecord() const; 56 void SetScheduler(const sptr<IChildScheduler> &scheduler); 57 sptr<IChildScheduler> GetScheduler() const; 58 void SetDeathRecipient(const sptr<AppDeathRecipient> recipient); 59 void RegisterDeathRecipient(); 60 void RemoveDeathRecipient(); 61 void ScheduleExitProcessSafely(); 62 bool isStartWithDebug(); 63 int32_t GetChildProcessType() const; 64 sptr<IRemoteObject> GetMainProcessCallback() const; 65 void ClearMainProcessCallback(); 66 void SetEntryParams(const std::string &entryParams); 67 std::string GetEntryParams() const; 68 ProcessType GetProcessType() const; 69 70 private: 71 void MakeProcessName(const std::shared_ptr<AppRunningRecord> hostRecord); 72 73 pid_t pid_ = 0; 74 pid_t hostPid_ = 0; 75 int32_t uid_ = 0; 76 int32_t childProcessCount_ = 0; 77 int32_t childProcessType_ = CHILD_PROCESS_TYPE_JS; 78 std::string processName_; 79 std::string srcEntry_; 80 std::string entryFunc_; 81 std::map<std::string, int32_t> fds_; 82 std::weak_ptr<AppRunningRecord> hostRecord_; 83 sptr<IChildScheduler> scheduler_ = nullptr; 84 sptr<AppDeathRecipient> deathRecipient_ = nullptr; 85 sptr<IRemoteObject> mainProcessCb_ = nullptr; 86 bool isStartWithDebug_; 87 std::string entryParams_; 88 ProcessType processType_ = ProcessType::CHILD; 89 }; 90 } // namespace AppExecFwk 91 } // namespace OHOS 92 #endif // OHOS_ABILITY_RUNTIME_CHILD_PROCESS_RECORD_H 93