1 /*
2 * Copyright (c) 2024 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 #include "app_running_record.h"
17 #include "render_record.h"
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AppExecFwk {
RenderRecord(pid_t hostPid,const std::string & renderParam,FdGuard && ipcFd,FdGuard && sharedFd,FdGuard && crashFd,const std::shared_ptr<AppRunningRecord> & host)22 RenderRecord::RenderRecord(pid_t hostPid, const std::string &renderParam,
23 FdGuard &&ipcFd, FdGuard &&sharedFd, FdGuard &&crashFd,
24 const std::shared_ptr<AppRunningRecord> &host)
25 : hostPid_(hostPid), ipcFd_(std::move(ipcFd)), sharedFd_(std::move(sharedFd)),
26 crashFd_(std::move(crashFd)), host_(host), renderParam_(renderParam) {}
27
~RenderRecord()28 RenderRecord::~RenderRecord()
29 {}
30
CreateRenderRecord(pid_t hostPid,const std::string & renderParam,FdGuard && ipcFd,FdGuard && sharedFd,FdGuard && crashFd,const std::shared_ptr<AppRunningRecord> & host)31 std::shared_ptr<RenderRecord> RenderRecord::CreateRenderRecord(
32 pid_t hostPid, const std::string &renderParam,
33 FdGuard &&ipcFd, FdGuard &&sharedFd, FdGuard &&crashFd,
34 const std::shared_ptr<AppRunningRecord> &host)
35 {
36 if (hostPid <= 0 || renderParam.empty() || ipcFd.Get() <= 0 || sharedFd.Get() <= 0 ||
37 crashFd.Get() <= 0 || !host) {
38 return nullptr;
39 }
40
41 auto renderRecord = std::make_shared<RenderRecord>(
42 hostPid, renderParam, std::move(ipcFd), std::move(sharedFd), std::move(crashFd), host);
43 renderRecord->SetHostUid(host->GetUid());
44 renderRecord->SetHostBundleName(host->GetBundleName());
45 renderRecord->SetProcessName(host->GetProcessName());
46 return renderRecord;
47 }
48
SetPid(pid_t pid)49 void RenderRecord::SetPid(pid_t pid)
50 {
51 pid_ = pid;
52 }
53
GetPid() const54 pid_t RenderRecord::GetPid() const
55 {
56 return pid_;
57 }
58
GetHostPid() const59 pid_t RenderRecord::GetHostPid() const
60 {
61 return hostPid_;
62 }
63
SetUid(int32_t uid)64 void RenderRecord::SetUid(int32_t uid)
65 {
66 uid_ = uid;
67 }
68
GetUid() const69 int32_t RenderRecord::GetUid() const
70 {
71 return uid_;
72 }
73
SetHostUid(const int32_t hostUid)74 void RenderRecord::SetHostUid(const int32_t hostUid)
75 {
76 hostUid_ = hostUid;
77 }
78
GetHostUid() const79 int32_t RenderRecord::GetHostUid() const
80 {
81 return hostUid_;
82 }
83
SetHostBundleName(const std::string & hostBundleName)84 void RenderRecord::SetHostBundleName(const std::string &hostBundleName)
85 {
86 hostBundleName_ = hostBundleName;
87 }
88
GetHostBundleName() const89 std::string RenderRecord::GetHostBundleName() const
90 {
91 return hostBundleName_;
92 }
93
SetProcessName(const std::string & processName)94 void RenderRecord::SetProcessName(const std::string &processName)
95 {
96 processName_ = processName;
97 }
98
GetProcessName() const99 std::string RenderRecord::GetProcessName() const
100 {
101 return processName_;
102 }
103
GetRenderParam() const104 std::string RenderRecord::GetRenderParam() const
105 {
106 return renderParam_;
107 }
108
GetIpcFd() const109 int32_t RenderRecord::GetIpcFd() const
110 {
111 return ipcFd_.Get();
112 }
113
GetSharedFd() const114 int32_t RenderRecord::GetSharedFd() const
115 {
116 return sharedFd_.Get();
117 }
118
GetCrashFd() const119 int32_t RenderRecord::GetCrashFd() const
120 {
121 return crashFd_.Get();
122 }
123
GetProcessType() const124 ProcessType RenderRecord::GetProcessType() const
125 {
126 return processType_;
127 }
128
GetHostRecord() const129 std::shared_ptr<AppRunningRecord> RenderRecord::GetHostRecord() const
130 {
131 return host_.lock();
132 }
133
GetScheduler() const134 sptr<IRenderScheduler> RenderRecord::GetScheduler() const
135 {
136 return renderScheduler_;
137 }
138
SetScheduler(const sptr<IRenderScheduler> & scheduler)139 void RenderRecord::SetScheduler(const sptr<IRenderScheduler> &scheduler)
140 {
141 renderScheduler_ = scheduler;
142 }
143
SetDeathRecipient(const sptr<AppDeathRecipient> recipient)144 void RenderRecord::SetDeathRecipient(const sptr<AppDeathRecipient> recipient)
145 {
146 deathRecipient_ = recipient;
147 }
148
RegisterDeathRecipient()149 void RenderRecord::RegisterDeathRecipient()
150 {
151 if (renderScheduler_ && deathRecipient_) {
152 auto obj = renderScheduler_->AsObject();
153 if (!obj || !obj->AddDeathRecipient(deathRecipient_)) {
154 TAG_LOGE(AAFwkTag::APPMGR, "AddDeathRecipient failed");
155 }
156 }
157 }
158
SetProcessType(ProcessType type)159 void RenderRecord::SetProcessType(ProcessType type)
160 {
161 processType_ = type;
162 }
163
SetState(int32_t state)164 void RenderRecord::SetState(int32_t state)
165 {
166 state_ = state;
167 }
168
GetState() const169 int32_t RenderRecord::GetState() const
170 {
171 return state_;
172 }
173 } // namespace AppExecFwk
174 } // namespace OHOS
175