1 /*
2 * Copyright (c) 2021-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 #include "rs_render_service_connection_stub.h"
17 #include <memory>
18 #include <mutex>
19 #include "ivsync_connection.h"
20 #ifdef RES_SCHED_ENABLE
21 #include "res_sched_client.h"
22 #include "res_type.h"
23 #include <sched.h>
24 #endif
25 #include "securec.h"
26 #include "sys_binder.h"
27
28 #include "command/rs_command_factory.h"
29 #include "command/rs_command_verify_helper.h"
30 #include "common/rs_xcollie.h"
31 #include "hgm_frame_rate_manager.h"
32 #include "pipeline/rs_base_render_util.h"
33 #include "pipeline/rs_main_thread.h"
34 #include "pipeline/rs_uni_render_judgement.h"
35 #include "pipeline/rs_unmarshal_thread.h"
36 #include "platform/common/rs_log.h"
37 #include "transaction/rs_ashmem_helper.h"
38 #include "render/rs_typeface_cache.h"
39 #include "rs_trace.h"
40 #include "rs_profiler.h"
41
42 namespace OHOS {
43 namespace Rosen {
44 namespace {
45 constexpr size_t MAX_DATA_SIZE_FOR_UNMARSHALLING_IN_PLACE = 1024 * 15; // 15kB
46 constexpr size_t FILE_DESCRIPTOR_LIMIT = 15;
47 constexpr size_t MAX_OBJECTNUM = INT_MAX;
48 constexpr size_t MAX_DATA_SIZE = INT_MAX;
49 #ifdef RES_SCHED_ENABLE
50 const uint32_t RS_IPC_QOS_LEVEL = 7;
51 constexpr const char* RS_BUNDLE_NAME = "render_service";
52 #endif
53 static constexpr std::array descriptorCheckList = {
54 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FOCUS_APP_INFO),
55 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DEFAULT_SCREEN_ID),
56 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_SCREEN_ID),
57 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ALL_SCREEN_IDS),
58 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VIRTUAL_SCREEN),
59 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_RESOLUTION),
60 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SURFACE),
61 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_BLACKLIST),
62 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::ADD_VIRTUAL_SCREEN_BLACKLIST),
63 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN_BLACKLIST),
64 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST),
65 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN),
66 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CHANGE_CALLBACK),
67 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_MODE),
68 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_REFRESH_RATE),
69 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_REFRESH_RATE_MODE),
70 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SYNC_FRAME_RATE_RANGE),
71 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_FRAME_RATE_LINKER),
72 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CURRENT_REFRESH_RATE),
73 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_CURRENT_REFRESH_RATE_MODE),
74 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_REFRESH_RATES),
75 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SHOW_REFRESH_RATE_ENABLED),
76 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SHOW_REFRESH_RATE_ENABLED),
77 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::MARK_POWER_OFF_NEED_PROCESS_ONE_FRAME),
78 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DISABLE_RENDER_CONTROL_SCREEN),
79 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_POWER_STATUS),
80 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_BACK_LIGHT),
81 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_ACTIVE_MODE),
82 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_MODES),
83 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CAPABILITY),
84 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_POWER_STATUS),
85 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_BACK_LIGHT),
86 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_DATA),
87 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_VIRTUAL_SCREEN_RESOLUTION),
88 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER),
89 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER),
90 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_GAMUTS),
91 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_METADATAKEYS),
92 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT),
93 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT),
94 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT_MAP),
95 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CORRECTION),
96 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION),
97 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE),
98 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_GLOBAL_DARK_COLOR_MODE),
99 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT_MAP),
100 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE),
101 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_CAPABILITY),
102 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PIXEL_FORMAT),
103 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXEL_FORMAT),
104 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_HDR_FORMATS),
105 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_FORMAT),
106 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_HDR_FORMAT),
107 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_COLORSPACES),
108 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_COLORSPACE),
109 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_COLORSPACE),
110 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_TYPE),
111 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SKIP_FRAME_INTERVAL),
112 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_REFRESH_RATE),
113 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_OCCLUSION_CHANGE_CALLBACK),
114 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_APP_WINDOW_NUM),
115 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SYSTEM_ANIMATED_SCENES),
116 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SHOW_WATERMARK),
117 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::RESIZE_VIRTUAL_SCREEN),
118 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC),
119 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHICS),
120 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_TOTAL_APP_MEM_SIZE),
121 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_JANK_STATS),
122 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_BITMAP),
123 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP),
124 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::EXECUTE_SYNCHRONOUS_TASK),
125 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_LIGHT_FACTOR_STATUS),
126 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PACKAGE_EVENT),
127 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_REFRESH_RATE_EVENT),
128 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_RESPONSE),
129 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_COMPLETE),
130 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_JANK_FRAME),
131 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_GAMESTATE),
132 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_TOUCH_EVENT),
133 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_DYNAMIC_MODE_EVENT),
134 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HARDWARE_ENABLED),
135 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HIDE_PRIVACY_CONTENT),
136 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK),
137 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK),
138 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_HGM_CFG_CALLBACK),
139 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ROTATION_CACHE_ENABLED),
140 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_TP_FEATURE_CONFIG),
141 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_USING_STATUS),
142 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_MODE_CHANGE_CALLBACK),
143 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CURTAIN_SCREEN_USING_STATUS),
144 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DROP_FRAME_BY_PID),
145 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_TYPEFACE),
146 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_TYPEFACE),
147 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_UPDATE_CALLBACK),
148 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK),
149 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_DIRTY_REGION_INFO),
150 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_GLOBAL_DIRTY_REGION_INFO),
151 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_LAYER_COMPOSE_INFO),
152 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW),
153 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_UIEXTENSION_CALLBACK),
154 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VMA_CACHE_STATUS),
155 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ANCO_FORCE_DO_DIRECT),
156 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NEED_REGISTER_TYPEFACE),
157 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_BUFFER_CALLBACK),
158 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_BUFFER_CALLBACK),
159 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_DISPLAY_NODE),
160 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_LAYER_TOP),
161 };
162
CopyFileDescriptor(MessageParcel & old,MessageParcel & copied)163 void CopyFileDescriptor(MessageParcel& old, MessageParcel& copied)
164 {
165 binder_size_t* object = reinterpret_cast<binder_size_t*>(old.GetObjectOffsets());
166 binder_size_t* copiedObject = reinterpret_cast<binder_size_t*>(copied.GetObjectOffsets());
167
168 size_t objectNum = old.GetOffsetsSize();
169 if (objectNum > MAX_OBJECTNUM) {
170 return;
171 }
172
173 uintptr_t data = old.GetData();
174 uintptr_t copiedData = copied.GetData();
175
176 for (size_t i = 0; i < objectNum; i++) {
177 const flat_binder_object* flat = reinterpret_cast<flat_binder_object*>(data + object[i]);
178 flat_binder_object* copiedFlat = reinterpret_cast<flat_binder_object*>(copiedData + copiedObject[i]);
179
180 if (flat->hdr.type == BINDER_TYPE_FD && flat->handle > 0) {
181 int32_t val = dup(flat->handle);
182 if (val < 0) {
183 ROSEN_LOGW("CopyFileDescriptor dup failed, fd:%{public}d, handle:%{public}" PRIu32, val,
184 static_cast<uint32_t>(flat->handle));
185 }
186 copiedFlat->handle = static_cast<uint32_t>(val);
187 }
188 }
189 }
190
CopyParcelIfNeed(MessageParcel & old,pid_t callingPid)191 std::shared_ptr<MessageParcel> CopyParcelIfNeed(MessageParcel& old, pid_t callingPid)
192 {
193 if (RSSystemProperties::GetCacheEnabledForRotation() &&
194 RSMainThread::Instance()->GetDesktopPidForRotationScene() != callingPid) {
195 return nullptr;
196 }
197 auto dataSize = old.GetDataSize();
198 if (dataSize <= MAX_DATA_SIZE_FOR_UNMARSHALLING_IN_PLACE && old.GetOffsetsSize() < FILE_DESCRIPTOR_LIMIT) {
199 return nullptr;
200 }
201 if (dataSize > MAX_DATA_SIZE) {
202 return nullptr;
203 }
204 if (dataSize == 0) {
205 return nullptr;
206 }
207 RS_TRACE_NAME("CopyParcelForUnmarsh: size:" + std::to_string(dataSize));
208 void* base = malloc(dataSize);
209 if (base == nullptr) {
210 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed malloc failed");
211 return nullptr;
212 }
213 if (memcpy_s(base, dataSize, reinterpret_cast<void*>(old.GetData()), dataSize) != 0) {
214 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed copy parcel data failed");
215 free(base);
216 return nullptr;
217 }
218
219 auto parcelCopied = RS_PROFILER_COPY_PARCEL(old);
220 if (!parcelCopied->ParseFrom(reinterpret_cast<uintptr_t>(base), dataSize)) {
221 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed ParseFrom failed");
222 free(base);
223 return nullptr;
224 }
225
226 auto objectNum = old.GetOffsetsSize();
227 if (objectNum != 0) {
228 parcelCopied->InjectOffsets(old.GetObjectOffsets(), objectNum);
229 CopyFileDescriptor(old, *parcelCopied);
230 }
231 if (parcelCopied->ReadInt32() != 0) {
232 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed parcel data not match");
233 return nullptr;
234 }
235 return parcelCopied;
236 }
237
CheckCreateNodeAndSurface(pid_t pid,RSSurfaceNodeType nodeType,SurfaceWindowType windowType)238 bool CheckCreateNodeAndSurface(pid_t pid, RSSurfaceNodeType nodeType, SurfaceWindowType windowType)
239 {
240 constexpr int nodeTypeMin = static_cast<int>(RSSurfaceNodeType::DEFAULT);
241 constexpr int nodeTypeMax = static_cast<int>(RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE);
242
243 int typeNum = static_cast<int>(nodeType);
244 if (typeNum < nodeTypeMin || typeNum > nodeTypeMax) {
245 RS_LOGW("CREATE_NODE_AND_SURFACE invalid RSSurfaceNodeType");
246 return false;
247 }
248 if (windowType != SurfaceWindowType::DEFAULT_WINDOW && windowType != SurfaceWindowType::SYSTEM_SCB_WINDOW) {
249 RS_LOGW("CREATE_NODE_AND_SURFACE invalid SurfaceWindowType");
250 return false;
251 }
252
253 bool isTokenTypeValid = true;
254 bool isNonSystemAppCalling = false;
255 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemAppCalling);
256 if (isNonSystemAppCalling) {
257 if (nodeType != RSSurfaceNodeType::DEFAULT &&
258 nodeType != RSSurfaceNodeType::APP_WINDOW_NODE &&
259 nodeType != RSSurfaceNodeType::SELF_DRAWING_NODE &&
260 nodeType != RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE) {
261 RS_LOGW("CREATE_NODE_AND_SURFACE NonSystemAppCalling invalid RSSurfaceNodeType %{public}d, pid %d",
262 typeNum, pid);
263 return false;
264 }
265 if (windowType != SurfaceWindowType::DEFAULT_WINDOW) {
266 RS_LOGW("CREATE_NODE_AND_SURFACE NonSystemAppCalling invalid SurfaceWindowType %{public}d, pid %d",
267 static_cast<int>(windowType), pid);
268 return false;
269 }
270 }
271
272 return true;
273 }
274 }
275
SetQos()276 void RSRenderServiceConnectionStub::SetQos()
277 {
278 #ifdef RES_SCHED_ENABLE
279 std::string strBundleName = RS_BUNDLE_NAME;
280 std::string strPid = std::to_string(getpid());
281 std::string strTid = std::to_string(gettid());
282 std::string strQos = std::to_string(RS_IPC_QOS_LEVEL);
283 std::unordered_map<std::string, std::string> mapPayload;
284 mapPayload["pid"] = strPid;
285 mapPayload[strTid] = strQos;
286 mapPayload["bundleName"] = strBundleName;
287 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(
288 OHOS::ResourceSchedule::ResType::RES_TYPE_THREAD_QOS_CHANGE, 0, mapPayload);
289 struct sched_param param = {0};
290 param.sched_priority = 1;
291 if (sched_setscheduler(0, SCHED_FIFO, ¶m) != 0) {
292 RS_LOGE("RSRenderServiceConnectionStub Couldn't set SCHED_FIFO.");
293 } else {
294 RS_LOGI("RSRenderServiceConnectionStub set SCHED_FIFO succeed.");
295 }
296 #endif
297 }
298
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)299 int RSRenderServiceConnectionStub::OnRemoteRequest(
300 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
301 {
302 RS_PROFILER_ON_REMOTE_REQUEST(this, code, data, reply, option);
303 auto tid = gettid();
304 {
305 std::lock_guard<std::mutex> lock(mutex_);
306 if (tids_.find(tid) == tids_.end()) {
307 SetQos();
308 tids_.insert(tid);
309 }
310 }
311 pid_t callingPid = GetCallingPid();
312 if (std::find(std::cbegin(descriptorCheckList), std::cend(descriptorCheckList), code) !=
313 std::cend(descriptorCheckList)) {
314 auto token = data.ReadInterfaceToken();
315 if (token != RSIRenderServiceConnection::GetDescriptor()) {
316 if (code == static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE)) {
317 if (!reply.WriteInt32(0)) {
318 return ERR_INVALID_REPLY;
319 }
320 }
321 return ERR_INVALID_STATE;
322 }
323 }
324 auto accessible = securityManager_.IsInterfaceCodeAccessible(code);
325 if (!accessible && code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SURFACE_CAPTURE)) {
326 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission code:%{public}d", code);
327 return ERR_INVALID_STATE;
328 }
329 int ret = ERR_NONE;
330 switch (code) {
331 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::COMMIT_TRANSACTION): {
332 bool isTokenTypeValid = true;
333 bool isNonSystemAppCalling = false;
334 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemAppCalling);
335 if (!isTokenTypeValid) {
336 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION invalid token type");
337 return ERR_INVALID_STATE;
338 }
339 if (isNonSystemAppCalling) {
340 RsCommandVerifyHelper::GetInstance().RegisterNonSystemPid(callingPid);
341 }
342 RS_TRACE_NAME_FMT("Recv Parcel Size:%zu, fdCnt:%zu", data.GetDataSize(), data.GetOffsetsSize());
343 static bool isUniRender = RSUniRenderJudgement::IsUniRender();
344 std::shared_ptr<MessageParcel> parsedParcel;
345 if (data.ReadInt32() == 0) { // indicate normal parcel
346 if (isUniRender) {
347 // in uni render mode, if parcel size over threshold,
348 // Unmarshalling task will be post to RSUnmarshalThread,
349 // copy the origin parcel to maintain the parcel lifetime
350 parsedParcel = CopyParcelIfNeed(data, callingPid);
351 }
352 if (parsedParcel == nullptr) {
353 // no need to copy or copy failed, use original parcel
354 // execute Unmarshalling immediately
355 auto transactionData = RSBaseRenderUtil::ParseTransactionData(data);
356 if (transactionData && isNonSystemAppCalling) {
357 const auto& nodeMap = RSMainThread::Instance()->GetContext().GetNodeMap();
358 pid_t conflictCommandPid = 0;
359 std::string commandMapDesc = "";
360 if (!transactionData->IsCallingPidValid(callingPid, nodeMap, conflictCommandPid,
361 commandMapDesc)) {
362 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION non-system callingPid %{public}d"
363 " is denied to access commandPid %{public}d, commandMap = %{public}s",
364 callingPid, conflictCommandPid, commandMapDesc.c_str());
365 }
366 }
367 CommitTransaction(transactionData);
368 break;
369 }
370 } else {
371 // indicate ashmem parcel
372 // should be parsed to normal parcel before Unmarshalling
373 parsedParcel = RSAshmemHelper::ParseFromAshmemParcel(&data);
374 }
375 if (parsedParcel == nullptr) {
376 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION failed: parsed parcel is nullptr");
377 return ERR_INVALID_DATA;
378 }
379 if (isUniRender) {
380 // post Unmarshalling task to RSUnmarshalThread
381 RSUnmarshalThread::Instance().RecvParcel(parsedParcel, isNonSystemAppCalling, callingPid);
382 } else {
383 // execute Unmarshalling immediately
384 auto transactionData = RSBaseRenderUtil::ParseTransactionData(*parsedParcel);
385 if (transactionData && isNonSystemAppCalling) {
386 const auto& nodeMap = RSMainThread::Instance()->GetContext().GetNodeMap();
387 pid_t conflictCommandPid = 0;
388 std::string commandMapDesc = "";
389 if (!transactionData->IsCallingPidValid(callingPid, nodeMap, conflictCommandPid, commandMapDesc)) {
390 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION non-system callingPid %{public}d"
391 " is denied to access commandPid %{public}d, commandMap = %{public}s",
392 callingPid, conflictCommandPid, commandMapDesc.c_str());
393 }
394 }
395 CommitTransaction(transactionData);
396 }
397 break;
398 }
399 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_UNI_RENDER_ENABLED): {
400 if (!reply.WriteBool(GetUniRenderEnabled())) {
401 ret = ERR_INVALID_REPLY;
402 }
403 break;
404 }
405 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE): {
406 auto nodeId = data.ReadUint64();
407 RS_PROFILER_PATCH_NODE_ID(data, nodeId);
408 auto surfaceName = data.ReadString();
409 auto bundleName = data.ReadString();
410 RSSurfaceRenderNodeConfig config = {.id = nodeId, .name = surfaceName, .bundleName = bundleName};
411 if (!reply.WriteBool(CreateNode(config))) {
412 ret = ERR_INVALID_REPLY;
413 }
414 break;
415 }
416 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE_AND_SURFACE): {
417 auto nodeId = data.ReadUint64();
418 if (ExtractPid(nodeId) != callingPid) {
419 RS_LOGW("CREATE_NODE_AND_SURFACE invalid nodeId[%" PRIu64 "] pid[%d]", nodeId, callingPid);
420 ret = ERR_INVALID_DATA;
421 break;
422 }
423 RS_PROFILER_PATCH_NODE_ID(data, nodeId);
424 auto surfaceName = data.ReadString();
425 auto type = static_cast<RSSurfaceNodeType>(data.ReadUint8());
426 auto bundleName = data.ReadString();
427 bool isTextureExportNode = data.ReadBool();
428 bool isSync = data.ReadBool();
429 auto surfaceWindowType = static_cast<SurfaceWindowType>(data.ReadUint8());
430 if (!CheckCreateNodeAndSurface(callingPid, type, surfaceWindowType)) {
431 ret = ERR_INVALID_DATA;
432 break;
433 }
434 RSSurfaceRenderNodeConfig config = {
435 .id = nodeId, .name = surfaceName, .bundleName = bundleName, .nodeType = type,
436 .isTextureExportNode = isTextureExportNode, .isSync = isSync,
437 .surfaceWindowType = surfaceWindowType};
438 sptr<Surface> surface = CreateNodeAndSurface(config);
439 if (surface == nullptr) {
440 ret = ERR_NULL_OBJECT;
441 break;
442 }
443 auto producer = surface->GetProducer();
444 if (!reply.WriteRemoteObject(producer->AsObject())) {
445 ret = ERR_INVALID_REPLY;
446 }
447 break;
448 }
449 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FOCUS_APP_INFO): {
450 int32_t pid = data.ReadInt32();
451 RS_PROFILER_PATCH_PID(data, pid);
452 int32_t uid = data.ReadInt32();
453 std::string bundleName = data.ReadString();
454 std::string abilityName = data.ReadString();
455 uint64_t focusNodeId = data.ReadUint64();
456 RS_PROFILER_PATCH_NODE_ID(data, focusNodeId);
457 int32_t status = SetFocusAppInfo(pid, uid, bundleName, abilityName, focusNodeId);
458 if (!reply.WriteInt32(status)) {
459 ret = ERR_INVALID_REPLY;
460 }
461 break;
462 }
463 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DEFAULT_SCREEN_ID): {
464 ScreenId id = GetDefaultScreenId();
465 if (!reply.WriteUint64(id)) {
466 ret = ERR_INVALID_REPLY;
467 }
468 break;
469 }
470 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_SCREEN_ID): {
471 ScreenId id = GetActiveScreenId();
472 if (!reply.WriteUint64(id)) {
473 ret = ERR_INVALID_REPLY;
474 }
475 break;
476 }
477 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ALL_SCREEN_IDS): {
478 std::vector<ScreenId> ids = GetAllScreenIds();
479 if (!reply.WriteUint32(ids.size())) {
480 ret = ERR_INVALID_REPLY;
481 break;
482 }
483 for (uint32_t i = 0; i < ids.size(); i++) {
484 if (!reply.WriteUint64(ids[i])) {
485 ret = ERR_INVALID_REPLY;
486 break;
487 }
488 }
489 break;
490 }
491 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VIRTUAL_SCREEN): {
492 // read the parcel data.
493 std::string name = data.ReadString();
494 uint32_t width = data.ReadUint32();
495 uint32_t height = data.ReadUint32();
496 sptr<Surface> surface = nullptr;
497 if (data.ReadBool()) {
498 auto remoteObject = data.ReadRemoteObject();
499 if (remoteObject != nullptr) {
500 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
501 surface = Surface::CreateSurfaceAsProducer(bufferProducer);
502 }
503 }
504 ScreenId mirrorId = data.ReadUint64();
505 int32_t flags = data.ReadInt32();
506 std::vector<NodeId> whiteList;
507 data.ReadUInt64Vector(&whiteList);
508 ScreenId id = CreateVirtualScreen(name, width, height, surface, mirrorId, flags, whiteList);
509 if (!reply.WriteUint64(id)) {
510 ret = ERR_INVALID_REPLY;
511 }
512 break;
513 }
514 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_BLACKLIST): {
515 // read the parcel data.
516 ScreenId id = data.ReadUint64();
517 std::vector<NodeId> blackListVector;
518 data.ReadUInt64Vector(&blackListVector);
519 int32_t status = SetVirtualScreenBlackList(id, blackListVector);
520 if (!reply.WriteInt32(status)) {
521 ret = ERR_INVALID_REPLY;
522 }
523 break;
524 }
525 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::ADD_VIRTUAL_SCREEN_BLACKLIST): {
526 // read the parcel data.
527 ScreenId id = data.ReadUint64();
528 std::vector<NodeId> blackListVector;
529 if (!data.ReadUInt64Vector(&blackListVector)) {
530 ret = ERR_INVALID_REPLY;
531 break;
532 }
533 int32_t status = AddVirtualScreenBlackList(id, blackListVector);
534 if (!reply.WriteInt32(status)) {
535 ret = ERR_INVALID_REPLY;
536 }
537 break;
538 }
539 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN_BLACKLIST): {
540 // read the parcel data.
541 ScreenId id = data.ReadUint64();
542 std::vector<NodeId> blackListVector;
543 if (!data.ReadUInt64Vector(&blackListVector)) {
544 ret = ERR_INVALID_REPLY;
545 break;
546 }
547 int32_t status = RemoveVirtualScreenBlackList(id, blackListVector);
548 if (!reply.WriteInt32(status)) {
549 ret = ERR_INVALID_REPLY;
550 }
551 break;
552 }
553 case static_cast<uint32_t>(
554 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST): {
555 if (!securityManager_.IsInterfaceCodeAccessible(code)) {
556 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission"
557 "SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST");
558 return ERR_INVALID_STATE;
559 }
560 // read the parcel data.
561 ScreenId id = data.ReadUint64();
562 std::vector<NodeId> securityExemptionList;
563 if (!data.ReadUInt64Vector(&securityExemptionList)) {
564 ret = ERR_INVALID_REPLY;
565 break;
566 }
567 int32_t status = SetVirtualScreenSecurityExemptionList(id, securityExemptionList);
568 if (!reply.WriteInt32(status)) {
569 ret = ERR_INVALID_REPLY;
570 }
571 break;
572 }
573 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW): {
574 // read the parcel data.
575 ScreenId id = data.ReadUint64();
576 bool enable = data.ReadBool();
577 int32_t result = SetCastScreenEnableSkipWindow(id, enable);
578 if (!reply.WriteInt32(result)) {
579 ret = ERR_INVALID_REPLY;
580 }
581 break;
582 }
583 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SURFACE): {
584 // read the parcel data.
585 ScreenId id = data.ReadUint64();
586 auto remoteObject = data.ReadRemoteObject();
587 if (remoteObject == nullptr) {
588 ret = ERR_NULL_OBJECT;
589 break;
590 }
591 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
592 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
593 if (surface == nullptr) {
594 ret = ERR_NULL_OBJECT;
595 break;
596 }
597 int32_t status = SetVirtualScreenSurface(id, surface);
598 if (!reply.WriteInt32(status)) {
599 ret = ERR_INVALID_REPLY;
600 }
601 break;
602 }
603 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN): {
604 ScreenId id = data.ReadUint64();
605 RemoveVirtualScreen(id);
606 break;
607 }
608 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CHANGE_CALLBACK): {
609 auto remoteObject = data.ReadRemoteObject();
610 if (remoteObject == nullptr) {
611 ret = ERR_NULL_OBJECT;
612 break;
613 }
614 sptr<RSIScreenChangeCallback> cb = iface_cast<RSIScreenChangeCallback>(remoteObject);
615 if (cb == nullptr) {
616 ret = ERR_NULL_OBJECT;
617 break;
618 }
619 int32_t status = SetScreenChangeCallback(cb);
620 if (!reply.WriteInt32(status)) {
621 ret = ERR_INVALID_REPLY;
622 }
623 break;
624 }
625 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_MODE): {
626 ScreenId id = data.ReadUint64();
627 uint32_t modeId = data.ReadUint32();
628 SetScreenActiveMode(id, modeId);
629 break;
630 }
631 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_REFRESH_RATE): {
632 ScreenId id = data.ReadUint64();
633 int32_t sceneId = data.ReadInt32();
634 int32_t rate = data.ReadInt32();
635 SetScreenRefreshRate(id, sceneId, rate);
636 break;
637 }
638 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_REFRESH_RATE_MODE): {
639 int32_t mode = data.ReadInt32();
640 SetRefreshRateMode(mode);
641 break;
642 }
643 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SYNC_FRAME_RATE_RANGE): {
644 FrameRateLinkerId id = data.ReadUint64();
645 if (ExtractPid(id) != callingPid) {
646 RS_LOGW("The SyncFrameRateRange isn't legal, frameRateLinkerId: %{public}" PRIu64
647 ", callingPid:%{public}d", id, callingPid);
648 ret = ERR_INVALID_DATA;
649 break;
650 }
651 uint32_t min = data.ReadUint32();
652 uint32_t max = data.ReadUint32();
653 uint32_t preferred = data.ReadUint32();
654 uint32_t type = data.ReadUint32();
655 int32_t animatorExpectedFrameRate = data.ReadInt32();
656 SyncFrameRateRange(id, {min, max, preferred, type}, animatorExpectedFrameRate);
657 break;
658 }
659 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_FRAME_RATE_LINKER): {
660 FrameRateLinkerId id = data.ReadUint64();
661 if (ExtractPid(id) != callingPid) {
662 RS_LOGW("The UnregisterFrameRateLinker isn't legal, frameRateLinkerId: %{public}" PRIu64
663 ", callingPid:%{public}d", id, callingPid);
664 ret = ERR_INVALID_DATA;
665 break;
666 }
667 UnregisterFrameRateLinker(id);
668 break;
669 }
670 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CURRENT_REFRESH_RATE): {
671 ScreenId id = data.ReadUint64();
672 uint32_t refreshRate = GetScreenCurrentRefreshRate(id);
673 if (!reply.WriteUint32(refreshRate)) {
674 ret = ERR_INVALID_REPLY;
675 }
676 break;
677 }
678 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_CURRENT_REFRESH_RATE_MODE): {
679 int32_t refreshRateMode = GetCurrentRefreshRateMode();
680 if (!reply.WriteInt32(refreshRateMode)) {
681 ret = ERR_INVALID_REPLY;
682 }
683 break;
684 }
685 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_REFRESH_RATES): {
686 ScreenId id = data.ReadUint64();
687 std::vector<int32_t> rates = GetScreenSupportedRefreshRates(id);
688 if (!reply.WriteUint64(static_cast<uint64_t>(rates.size()))) {
689 ret = ERR_INVALID_REPLY;
690 break;
691 }
692 for (auto ratesIter : rates) {
693 if (!reply.WriteInt32(ratesIter)) {
694 ret = ERR_INVALID_REPLY;
695 break;
696 }
697 }
698 break;
699 }
700 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SHOW_REFRESH_RATE_ENABLED): {
701 bool enable = GetShowRefreshRateEnabled();
702 if (!reply.WriteBool(enable)) {
703 ret = ERR_INVALID_REPLY;
704 }
705 break;
706 }
707 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SHOW_REFRESH_RATE_ENABLED): {
708 bool enable = data.ReadBool();
709 SetShowRefreshRateEnabled(enable);
710 break;
711 }
712 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REFRESH_INFO): {
713 auto token = data.ReadInterfaceToken();
714 if (token != RSIRenderServiceConnection::GetDescriptor()) {
715 ret = ERR_INVALID_STATE;
716 break;
717 }
718 pid_t pid = data.ReadInt32();
719 std::string refreshInfo = GetRefreshInfo(pid);
720 if (!reply.WriteString(refreshInfo)) {
721 ret = ERR_INVALID_REPLY;
722 }
723 break;
724 }
725 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_RESOLUTION): {
726 ScreenId id = data.ReadUint64();
727 uint32_t width = data.ReadUint32();
728 uint32_t height = data.ReadUint32();
729 int32_t status = SetVirtualScreenResolution(id, width, height);
730 if (!reply.WriteInt32(status)) {
731 ret = ERR_INVALID_REPLY;
732 }
733 break;
734 }
735 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::MARK_POWER_OFF_NEED_PROCESS_ONE_FRAME): {
736 MarkPowerOffNeedProcessOneFrame();
737 break;
738 }
739 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DISABLE_RENDER_CONTROL_SCREEN): {
740 ScreenId id = data.ReadUint64();
741 DisablePowerOffRenderControl(id);
742 break;
743 }
744 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_POWER_STATUS): {
745 ScreenId id = data.ReadUint64();
746 uint32_t status = data.ReadUint32();
747 SetScreenPowerStatus(id, static_cast<ScreenPowerStatus>(status));
748 break;
749 }
750 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SURFACE_CAPTURE): {
751 NodeId id = data.ReadUint64();
752 RS_PROFILER_PATCH_NODE_ID(data, id);
753 auto remoteObject = data.ReadRemoteObject();
754 if (remoteObject == nullptr) {
755 ret = ERR_NULL_OBJECT;
756 break;
757 }
758 sptr<RSISurfaceCaptureCallback> cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
759 if (cb == nullptr) {
760 ret = ERR_NULL_OBJECT;
761 break;
762 }
763 RSSurfaceCaptureConfig captureConfig;
764 if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
765 ret = ERR_INVALID_DATA;
766 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture write captureConfig failed");
767 break;
768 }
769 RSSurfaceCapturePermissions permissions;
770 permissions.screenCapturePermission = accessible;
771 permissions.isSystemCalling = RSInterfaceCodeAccessVerifierBase::IsSystemCalling(
772 RSIRenderServiceConnectionInterfaceCodeAccessVerifier::codeEnumTypeName_ + "::TAKE_SURFACE_CAPTURE");
773 // Since GetCallingPid interface always returns 0 in asynchronous binder in Linux kernel system,
774 // we temporarily add a white list to avoid abnormal functionality or abnormal display.
775 // The white list will be removed after GetCallingPid interface can return real PID.
776 permissions.selfCapture = (ExtractPid(id) == callingPid || callingPid == 0);
777 TakeSurfaceCapture(id, cb, captureConfig, permissions);
778 break;
779 }
780 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WINDOW_FREEZE_IMMEDIATELY): {
781 NodeId id{0};
782 if (!data.ReadUint64(id)) {
783 ret = ERR_INVALID_DATA;
784 break;
785 }
786 RS_PROFILER_PATCH_NODE_ID(data, id);
787 bool isFreeze{false};
788 if (!data.ReadBool(isFreeze)) {
789 ret = ERR_INVALID_DATA;
790 break;
791 }
792 sptr<RSISurfaceCaptureCallback> cb;
793 RSSurfaceCaptureConfig captureConfig;
794 if (isFreeze) {
795 auto remoteObject = data.ReadRemoteObject();
796 if (remoteObject == nullptr) {
797 ret = ERR_NULL_OBJECT;
798 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY remoteObject is nullptr");
799 break;
800 }
801 cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
802 if (cb == nullptr) {
803 ret = ERR_NULL_OBJECT;
804 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY cb is nullptr");
805 break;
806 }
807 if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
808 ret = ERR_INVALID_DATA;
809 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY write captureConfig failed");
810 break;
811 }
812 }
813 SetWindowFreezeImmediately(id, isFreeze, cb, captureConfig);
814 break;
815 }
816 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_APPLICATION_AGENT): {
817 auto pid = data.ReadInt32();
818 RS_PROFILER_PATCH_PID(data, pid);
819 auto remoteObject = data.ReadRemoteObject();
820 if (remoteObject == nullptr) {
821 ret = ERR_NULL_OBJECT;
822 break;
823 }
824 sptr<IApplicationAgent> app = iface_cast<IApplicationAgent>(remoteObject);
825 if (app == nullptr) {
826 ret = ERR_NULL_OBJECT;
827 break;
828 }
829 RegisterApplicationAgent(pid, app);
830 break;
831 }
832 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_VIRTUAL_SCREEN_RESOLUTION): {
833 ScreenId id = data.ReadUint64();
834 RSVirtualScreenResolution virtualScreenResolution = GetVirtualScreenResolution(id);
835 if (!reply.WriteParcelable(&virtualScreenResolution)) {
836 ret = ERR_INVALID_REPLY;
837 }
838 break;
839 }
840 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_ACTIVE_MODE): {
841 ScreenId id = data.ReadUint64();
842 RSScreenModeInfo screenModeInfo = GetScreenActiveMode(id);
843 if (!reply.WriteParcelable(&screenModeInfo)) {
844 ret = ERR_INVALID_REPLY;
845 }
846 break;
847 }
848 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_MODES): {
849 ScreenId id = data.ReadUint64();
850 std::vector<RSScreenModeInfo> screenSupportedModes = GetScreenSupportedModes(id);
851 if (!reply.WriteUint64(static_cast<uint64_t>(screenSupportedModes.size()))) {
852 ret = ERR_INVALID_REPLY;
853 break;
854 }
855 for (uint32_t modeIndex = 0; modeIndex < screenSupportedModes.size(); modeIndex++) {
856 if (!reply.WriteParcelable(&screenSupportedModes[modeIndex])) {
857 ret = ERR_INVALID_REPLY;
858 break;
859 }
860 }
861 break;
862 }
863 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC): {
864 auto pid = data.ReadInt32();
865 RS_PROFILER_PATCH_PID(data, pid);
866 MemoryGraphic memoryGraphic = GetMemoryGraphic(pid);
867 if (!reply.WriteParcelable(&memoryGraphic)) {
868 ret = ERR_INVALID_REPLY;
869 }
870 break;
871 }
872 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHICS): {
873 std::vector<MemoryGraphic> memoryGraphics = GetMemoryGraphics();
874 if (!reply.WriteUint64(static_cast<uint64_t>(memoryGraphics.size()))) {
875 ret = ERR_INVALID_REPLY;
876 break;
877 }
878 for (uint32_t index = 0; index < memoryGraphics.size(); index++) {
879 if (!reply.WriteParcelable(&memoryGraphics[index])) {
880 ret = ERR_INVALID_REPLY;
881 break;
882 }
883 }
884 break;
885 }
886 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_TOTAL_APP_MEM_SIZE): {
887 float cpuMemSize = 0.f;
888 float gpuMemSize = 0.f;
889 GetTotalAppMemSize(cpuMemSize, gpuMemSize);
890 if (!reply.WriteFloat(cpuMemSize) || !reply.WriteFloat(gpuMemSize)) {
891 ret = ERR_INVALID_REPLY;
892 }
893 break;
894 }
895 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CAPABILITY): {
896 ScreenId id = data.ReadUint64();
897 RSScreenCapability screenCapability = GetScreenCapability(id);
898 if (!reply.WriteParcelable(&screenCapability)) {
899 ret = ERR_INVALID_REPLY;
900 }
901 break;
902 }
903 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_POWER_STATUS): {
904 ScreenId id = data.ReadUint64();
905 ScreenPowerStatus status = GetScreenPowerStatus(id);
906 if (!reply.WriteUint32(static_cast<uint32_t>(status))) {
907 ret = ERR_INVALID_REPLY;
908 }
909 break;
910 }
911 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_DATA): {
912 ScreenId id = data.ReadUint64();
913 RSScreenData screenData = GetScreenData(id);
914 if (!reply.WriteParcelable(&screenData)) {
915 ret = ERR_INVALID_REPLY;
916 }
917 break;
918 }
919 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_BACK_LIGHT): {
920 ScreenId id = data.ReadUint64();
921 int32_t level = GetScreenBacklight(id);
922 if (!reply.WriteInt32(level)) {
923 ret = ERR_INVALID_REPLY;
924 }
925 break;
926 }
927 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_BACK_LIGHT): {
928 ScreenId id = data.ReadUint64();
929 uint32_t level = data.ReadUint32();
930 SetScreenBacklight(id, level);
931 break;
932 }
933 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER): {
934 NodeId id = data.ReadUint64();
935 RS_PROFILER_PATCH_NODE_ID(data, id);
936 auto remoteObject = data.ReadRemoteObject();
937 bool isFromRenderThread = data.ReadBool();
938 if (remoteObject == nullptr) {
939 ret = ERR_NULL_OBJECT;
940 break;
941 }
942 sptr<RSIBufferAvailableCallback> cb = iface_cast<RSIBufferAvailableCallback>(remoteObject);
943 if (cb == nullptr) {
944 ret = ERR_NULL_OBJECT;
945 break;
946 }
947 RegisterBufferAvailableListener(id, cb, isFromRenderThread);
948 break;
949 }
950 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER): {
951 NodeId id = data.ReadUint64();
952 RS_PROFILER_PATCH_NODE_ID(data, id);
953 auto remoteObject = data.ReadRemoteObject();
954 if (remoteObject == nullptr) {
955 ret = ERR_NULL_OBJECT;
956 break;
957 }
958 sptr<RSIBufferClearCallback> cb = iface_cast<RSIBufferClearCallback>(remoteObject);
959 if (cb == nullptr) {
960 ret = ERR_NULL_OBJECT;
961 break;
962 }
963 RegisterBufferClearListener(id, cb);
964 break;
965 }
966 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_GAMUTS): {
967 ScreenId id = data.ReadUint64();
968 std::vector<uint32_t> modeSend;
969 std::vector<ScreenColorGamut> mode;
970 int32_t result = GetScreenSupportedColorGamuts(id, mode);
971 if (!reply.WriteInt32(result)) {
972 ret = ERR_INVALID_REPLY;
973 break;
974 }
975 if (result != StatusCode::SUCCESS) {
976 ret = ERR_UNKNOWN_REASON;
977 break;
978 }
979 std::copy(mode.begin(), mode.end(), std::back_inserter(modeSend));
980 if (!reply.WriteUInt32Vector(modeSend)) {
981 ret = ERR_INVALID_REPLY;
982 }
983 break;
984 }
985 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_METADATAKEYS): {
986 ScreenId id = data.ReadUint64();
987 std::vector<uint32_t> keySend;
988 std::vector<ScreenHDRMetadataKey> keys;
989 int32_t result = GetScreenSupportedMetaDataKeys(id, keys);
990 if (!reply.WriteInt32(result)) {
991 ret = ERR_INVALID_REPLY;
992 break;
993 }
994 if (result != StatusCode::SUCCESS) {
995 ret = ERR_UNKNOWN_REASON;
996 break;
997 }
998 for (auto i : keys) {
999 keySend.push_back(i);
1000 }
1001 if (!reply.WriteUInt32Vector(keySend)) {
1002 ret = ERR_INVALID_REPLY;
1003 }
1004 break;
1005 }
1006 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT): {
1007 ScreenId id = data.ReadUint64();
1008 ScreenColorGamut mode;
1009 int32_t result = GetScreenColorGamut(id, mode);
1010 if (!reply.WriteInt32(result)) {
1011 ret = ERR_INVALID_REPLY;
1012 break;
1013 }
1014 if (result != StatusCode::SUCCESS) {
1015 ret = ERR_UNKNOWN_REASON;
1016 break;
1017 }
1018 if (!reply.WriteUint32(mode)) {
1019 ret = ERR_INVALID_REPLY;
1020 }
1021 break;
1022 }
1023 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT): {
1024 ScreenId id = data.ReadUint64();
1025 int32_t modeIdx = data.ReadInt32();
1026 int32_t result = SetScreenColorGamut(id, modeIdx);
1027 if (!reply.WriteInt32(result)) {
1028 ret = ERR_INVALID_REPLY;
1029 }
1030 break;
1031 }
1032 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT_MAP): {
1033 ScreenId id = data.ReadUint64();
1034 ScreenGamutMap mode = static_cast<ScreenGamutMap>(data.ReadInt32());
1035 int32_t result = SetScreenGamutMap(id, mode);
1036 if (!reply.WriteInt32(result)) {
1037 ret = ERR_INVALID_REPLY;
1038 }
1039 break;
1040 }
1041 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CORRECTION): {
1042 ScreenId id = data.ReadUint64();
1043 ScreenRotation screenRotation = static_cast<ScreenRotation>(data.ReadInt32());
1044 int32_t result = SetScreenCorrection(id, screenRotation);
1045 if (!reply.WriteInt32(result)) {
1046 ret = ERR_INVALID_REPLY;
1047 }
1048 break;
1049 }
1050 case static_cast<uint32_t>(
1051 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION): {
1052 ScreenId id = data.ReadUint64();
1053 bool canvasRotation = data.ReadBool();
1054 bool result = SetVirtualMirrorScreenCanvasRotation(id, canvasRotation);
1055 if (!reply.WriteBool(result)) {
1056 ret = ERR_INVALID_REPLY;
1057 }
1058 break;
1059 }
1060 case static_cast<uint32_t>(
1061 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE): {
1062 ScreenId id = data.ReadUint64();
1063 ScreenScaleMode scaleMode = static_cast<ScreenScaleMode>(data.ReadUint32());
1064 bool result = SetVirtualMirrorScreenScaleMode(id, scaleMode);
1065 if (!reply.WriteBool(result)) {
1066 ret = ERR_INVALID_REPLY;
1067 }
1068 break;
1069 }
1070 case static_cast<uint32_t>(
1071 RSIRenderServiceConnectionInterfaceCode::SET_GLOBAL_DARK_COLOR_MODE): {
1072 bool isDark = data.ReadBool();
1073 bool result = SetGlobalDarkColorMode(isDark);
1074 if (!reply.WriteBool(result)) {
1075 ret = ERR_INVALID_REPLY;
1076 }
1077 break;
1078 }
1079 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT_MAP): {
1080 ScreenId id = data.ReadUint64();
1081 ScreenGamutMap mode;
1082 int32_t result = GetScreenGamutMap(id, mode);
1083 if (!reply.WriteInt32(result)) {
1084 ret = ERR_INVALID_REPLY;
1085 break;
1086 }
1087 if (result != StatusCode::SUCCESS) {
1088 ret = ERR_UNKNOWN_REASON;
1089 break;
1090 }
1091 if (!reply.WriteUint32(mode)) {
1092 ret = ERR_INVALID_REPLY;
1093 }
1094 break;
1095 }
1096 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VSYNC_CONNECTION): {
1097 std::string name = data.ReadString();
1098 auto remoteObj = data.ReadRemoteObject();
1099 uint64_t id = data.ReadUint64();
1100 NodeId windowNodeID = data.ReadUint64();
1101 bool fromXcomponent = data.ReadBool();
1102 if (remoteObj == nullptr) {
1103 ret = ERR_NULL_OBJECT;
1104 break;
1105 }
1106 if (!remoteObj->IsProxyObject()) {
1107 ret = ERR_UNKNOWN_OBJECT;
1108 break;
1109 }
1110 auto token = iface_cast<VSyncIConnectionToken>(remoteObj);
1111 if (token == nullptr) {
1112 ret = ERR_UNKNOWN_OBJECT;
1113 break;
1114 }
1115 sptr<IVSyncConnection> conn = CreateVSyncConnection(name, token, id, windowNodeID, fromXcomponent);
1116 if (conn == nullptr) {
1117 ret = ERR_NULL_OBJECT;
1118 break;
1119 }
1120 #ifdef ENABLE_IPC_SECURITY_ACCESS_COUNTER
1121 securityUtils_.IncreaseAccessCounter(code);
1122 #endif
1123 if (!reply.WriteRemoteObject(conn->AsObject())) {
1124 ret = ERR_INVALID_REPLY;
1125 }
1126 break;
1127 }
1128 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE): {
1129 auto remoteObject = data.ReadRemoteObject();
1130 if (remoteObject == nullptr) {
1131 if (!reply.WriteInt32(0)) {
1132 ret = ERR_INVALID_REPLY;
1133 break;
1134 }
1135 ret = ERR_NULL_OBJECT;
1136 break;
1137 }
1138 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
1139 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
1140 if (surface == nullptr) {
1141 if (!reply.WriteInt32(0)) {
1142 ret = ERR_INVALID_REPLY;
1143 break;
1144 }
1145 ret = ERR_NULL_OBJECT;
1146 break;
1147 }
1148 auto x = data.ReadInt32();
1149 auto y = data.ReadInt32();
1150 auto w = data.ReadInt32();
1151 auto h = data.ReadInt32();
1152 auto srcRect = Rect {
1153 .x = x,
1154 .y = y,
1155 .w = w,
1156 .h = h
1157 };
1158 std::shared_ptr<Media::PixelMap> pixelMap = CreatePixelMapFromSurface(surface, srcRect);
1159 if (pixelMap) {
1160 if (!reply.WriteBool(true)) {
1161 ret = ERR_INVALID_REPLY;
1162 break;
1163 }
1164 if (!pixelMap->Marshalling(reply)) {
1165 RS_LOGE("pixelMap Marshalling fail");
1166 ret = ERR_INVALID_REPLY;
1167 }
1168 } else {
1169 if (!reply.WriteBool(false)) {
1170 ret = ERR_INVALID_REPLY;
1171 break;
1172 }
1173 }
1174 break;
1175 }
1176 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_CAPABILITY): {
1177 ScreenId id = data.ReadUint64();
1178 RSScreenHDRCapability screenHDRCapability;
1179 int32_t result = GetScreenHDRCapability(id, screenHDRCapability);
1180 if (!reply.WriteInt32(result)) {
1181 ret = ERR_INVALID_REPLY;
1182 break;
1183 }
1184 if (result != StatusCode::SUCCESS) {
1185 ret = ERR_UNKNOWN_REASON;
1186 break;
1187 }
1188 if (!reply.WriteParcelable(&screenHDRCapability)) {
1189 ret = ERR_INVALID_REPLY;
1190 }
1191 break;
1192 }
1193 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXEL_FORMAT): {
1194 ScreenId id = data.ReadUint64();
1195 GraphicPixelFormat pixelFormat;
1196 int32_t result = GetPixelFormat(id, pixelFormat);
1197 if (!reply.WriteInt32(result)) {
1198 ret = ERR_INVALID_REPLY;
1199 break;
1200 }
1201 if (result != StatusCode::SUCCESS) {
1202 break;
1203 }
1204 if (!reply.WriteUint32(static_cast<uint32_t>(pixelFormat))) {
1205 ret = ERR_INVALID_REPLY;
1206 }
1207 break;
1208 }
1209 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PIXEL_FORMAT): {
1210 ScreenId id = data.ReadUint64();
1211 GraphicPixelFormat pixelFormat = static_cast<GraphicPixelFormat>(data.ReadInt32());
1212 int32_t result = SetPixelFormat(id, pixelFormat);
1213 if (!reply.WriteInt32(result)) {
1214 ret = ERR_INVALID_REPLY;
1215 }
1216 break;
1217 }
1218 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_HDR_FORMATS): {
1219 ScreenId id = data.ReadUint64();
1220 std::vector<uint32_t> hdrFormatsSend;
1221 std::vector<ScreenHDRFormat> hdrFormats;
1222 int32_t result = GetScreenSupportedHDRFormats(id, hdrFormats);
1223 if (!reply.WriteInt32(result)) {
1224 ret = ERR_INVALID_REPLY;
1225 break;
1226 }
1227 if (result != StatusCode::SUCCESS) {
1228 break;
1229 }
1230 std::copy(hdrFormats.begin(), hdrFormats.end(), std::back_inserter(hdrFormatsSend));
1231 if (!reply.WriteUInt32Vector(hdrFormatsSend)) {
1232 ret = ERR_INVALID_REPLY;
1233 }
1234 break;
1235 }
1236 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_FORMAT): {
1237 ScreenId id = data.ReadUint64();
1238 ScreenHDRFormat hdrFormat;
1239 int32_t result = GetScreenHDRFormat(id, hdrFormat);
1240 if (!reply.WriteInt32(result)) {
1241 ret = ERR_INVALID_REPLY;
1242 break;
1243 }
1244 if (result != StatusCode::SUCCESS) {
1245 break;
1246 }
1247 if (!reply.WriteUint32(hdrFormat)) {
1248 ret = ERR_INVALID_REPLY;
1249 }
1250 break;
1251 }
1252 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_HDR_FORMAT): {
1253 ScreenId id = data.ReadUint64();
1254 int32_t modeIdx = data.ReadInt32();
1255 int32_t result = SetScreenHDRFormat(id, modeIdx);
1256 if (!reply.WriteInt32(result)) {
1257 ret = ERR_INVALID_REPLY;
1258 }
1259 break;
1260 }
1261 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_COLORSPACES): {
1262 ScreenId id = data.ReadUint64();
1263 std::vector<uint32_t> colorSpacesSend;
1264 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
1265 int32_t result = GetScreenSupportedColorSpaces(id, colorSpaces);
1266 if (!reply.WriteInt32(result)) {
1267 ret = ERR_INVALID_REPLY;
1268 break;
1269 }
1270 if (result != StatusCode::SUCCESS) {
1271 break;
1272 }
1273 std::copy(colorSpaces.begin(), colorSpaces.end(), std::back_inserter(colorSpacesSend));
1274 if (!reply.WriteUInt32Vector(colorSpacesSend)) {
1275 ret = ERR_INVALID_REPLY;
1276 }
1277 break;
1278 }
1279 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_COLORSPACE): {
1280 ScreenId id = data.ReadUint64();
1281 GraphicCM_ColorSpaceType colorSpace;
1282 int32_t result = GetScreenColorSpace(id, colorSpace);
1283 if (!reply.WriteInt32(result)) {
1284 ret = ERR_INVALID_REPLY;
1285 break;
1286 }
1287 if (result != StatusCode::SUCCESS) {
1288 break;
1289 }
1290 if (!reply.WriteUint32(colorSpace)) {
1291 ret = ERR_INVALID_REPLY;
1292 }
1293 break;
1294 }
1295 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_COLORSPACE): {
1296 ScreenId id = data.ReadUint64();
1297 GraphicCM_ColorSpaceType colorSpace = static_cast<GraphicCM_ColorSpaceType>(data.ReadInt32());
1298 int32_t result = SetScreenColorSpace(id, colorSpace);
1299 if (!reply.WriteInt32(result)) {
1300 ret = ERR_INVALID_REPLY;
1301 }
1302 break;
1303 }
1304 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_TYPE): {
1305 ScreenId id = data.ReadUint64();
1306 RSScreenType type;
1307 int32_t result = GetScreenType(id, type);
1308 if (!reply.WriteInt32(result)) {
1309 ret = ERR_INVALID_REPLY;
1310 break;
1311 }
1312 if (result != StatusCode::SUCCESS) {
1313 ret = ERR_UNKNOWN_REASON;
1314 break;
1315 }
1316 if (!reply.WriteUint32(type)) {
1317 ret = ERR_INVALID_REPLY;
1318 }
1319 break;
1320 }
1321 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_BITMAP): {
1322 NodeId id = data.ReadUint64();
1323 if (ExtractPid(id) != callingPid) {
1324 RS_LOGW("The GetBitmap isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1325 id, callingPid);
1326 break;
1327 }
1328 RS_PROFILER_PATCH_NODE_ID(data, id);
1329 Drawing::Bitmap bm;
1330 bool result = GetBitmap(id, bm);
1331 if (!reply.WriteBool(result)) {
1332 ret = ERR_INVALID_REPLY;
1333 break;
1334 }
1335 if (result) {
1336 RSMarshallingHelper::Marshalling(reply, bm);
1337 }
1338 break;
1339 }
1340 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP): {
1341 NodeId id = data.ReadUint64();
1342 if (ExtractPid(id) != callingPid) {
1343 RS_LOGW("The GetPixelmap isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1344 id, callingPid);
1345 break;
1346 }
1347 RS_PROFILER_PATCH_NODE_ID(data, id);
1348 std::shared_ptr<Media::PixelMap> pixelmap =
1349 std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
1350 Drawing::Rect rect;
1351 RSMarshallingHelper::Unmarshalling(data, rect);
1352 std::shared_ptr<Drawing::DrawCmdList> drawCmdList;
1353 RSMarshallingHelper::Unmarshalling(data, drawCmdList);
1354 bool result = GetPixelmap(id, pixelmap, &rect, drawCmdList);
1355 if (!reply.WriteBool(result)) {
1356 ret = ERR_INVALID_REPLY;
1357 break;
1358 }
1359 if (result) {
1360 RSMarshallingHelper::Marshalling(reply, pixelmap);
1361 }
1362 break;
1363 }
1364 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NEED_REGISTER_TYPEFACE): {
1365 uint64_t uniqueId = data.ReadUint64();
1366 uint32_t hash = data.ReadUint32();
1367 bool ret = !RSTypefaceCache::Instance().HasTypeface(uniqueId, hash);
1368 reply.WriteBool(ret);
1369 break;
1370 }
1371 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_TYPEFACE): {
1372 // timer: 3s
1373 OHOS::Rosen::RSXCollie registerTypefaceXCollie("registerTypefaceXCollie_" + std::to_string(callingPid), 3);
1374 bool result = false;
1375 uint64_t uniqueId = data.ReadUint64();
1376 uint32_t hash = data.ReadUint32();
1377 // safe check
1378 if (ExtractPid(uniqueId) == callingPid) {
1379 std::shared_ptr<Drawing::Typeface> typeface;
1380 result = RSMarshallingHelper::Unmarshalling(data, typeface);
1381 if (result && typeface) {
1382 typeface->SetHash(hash);
1383 RegisterTypeface(uniqueId, typeface);
1384 }
1385 } else {
1386 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] "
1387 "no permission REGISTER_TYPEFACE", callingPid);
1388 }
1389 if (!reply.WriteBool(result)) {
1390 ret = ERR_INVALID_REPLY;
1391 }
1392 break;
1393 }
1394 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_TYPEFACE): {
1395 uint64_t uniqueId = data.ReadUint64();
1396 // safe check
1397 if (ExtractPid(uniqueId) == callingPid) {
1398 UnRegisterTypeface(uniqueId);
1399 } else {
1400 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] "
1401 "no permission UNREGISTER_TYPEFACE", callingPid);
1402 }
1403 break;
1404 }
1405 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SKIP_FRAME_INTERVAL): {
1406 if (!securityManager_.IsInterfaceCodeAccessible(code)) {
1407 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission to access"\
1408 "SET_SCREEN_SKIP_FRAME_INTERVAL");
1409 return ERR_INVALID_STATE;
1410 }
1411 ScreenId id = data.ReadUint64();
1412 uint32_t skipFrameInterval = data.ReadUint32();
1413 int32_t result = SetScreenSkipFrameInterval(id, skipFrameInterval);
1414 if (!reply.WriteInt32(result)) {
1415 ret = ERR_INVALID_REPLY;
1416 }
1417 break;
1418 }
1419 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_REFRESH_RATE): {
1420 ScreenId id = data.ReadUint64();
1421 uint32_t maxRefreshRate = data.ReadUint32();
1422 uint32_t actualRefreshRate = 0;
1423 int32_t result = SetVirtualScreenRefreshRate(id, maxRefreshRate, actualRefreshRate);
1424 if (!reply.WriteInt32(result)) {
1425 return ERR_INVALID_REPLY;
1426 }
1427 if (!reply.WriteUint32(actualRefreshRate)) {
1428 return ERR_INVALID_REPLY;
1429 }
1430 break;
1431 }
1432 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_OCCLUSION_CHANGE_CALLBACK): {
1433 auto remoteObject = data.ReadRemoteObject();
1434 if (remoteObject == nullptr) {
1435 ret = ERR_NULL_OBJECT;
1436 break;
1437 }
1438 sptr<RSIOcclusionChangeCallback> callback = iface_cast<RSIOcclusionChangeCallback>(remoteObject);
1439 if (callback == nullptr) {
1440 ret = ERR_NULL_OBJECT;
1441 break;
1442 }
1443 int32_t status = RegisterOcclusionChangeCallback(callback);
1444 if (!reply.WriteInt32(status)) {
1445 ret = ERR_INVALID_REPLY;
1446 }
1447 break;
1448 }
1449 case static_cast<uint32_t>(
1450 RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK): {
1451 NodeId id = data.ReadUint64();
1452 RS_PROFILER_PATCH_NODE_ID(data, id);
1453 if (ExtractPid(id) != callingPid) {
1454 RS_LOGW("The RegisterSurfaceOcclusionChangeCallback isn't legal, nodeId:%{public}" PRIu64 ", "
1455 "callingPid:%{public}d", id, callingPid);
1456 ret = ERR_INVALID_DATA;
1457 break;
1458 }
1459 auto remoteObject = data.ReadRemoteObject();
1460 if (remoteObject == nullptr) {
1461 ret = ERR_NULL_OBJECT;
1462 break;
1463 }
1464 sptr<RSISurfaceOcclusionChangeCallback> callback =
1465 iface_cast<RSISurfaceOcclusionChangeCallback>(remoteObject);
1466 if (callback == nullptr) {
1467 ret = ERR_NULL_OBJECT;
1468 break;
1469 }
1470 std::vector<float> partitionPoints;
1471 if (!data.ReadFloatVector(&partitionPoints)) {
1472 ret = ERR_TRANSACTION_FAILED;
1473 break;
1474 }
1475 int32_t status = RegisterSurfaceOcclusionChangeCallback(id, callback, partitionPoints);
1476 if (!reply.WriteInt32(status)) {
1477 ret = ERR_INVALID_REPLY;
1478 }
1479 break;
1480 }
1481 case static_cast<uint32_t>(
1482 RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK): {
1483 NodeId id = data.ReadUint64();
1484 RS_PROFILER_PATCH_NODE_ID(data, id);
1485 if (ExtractPid(id) != callingPid) {
1486 RS_LOGW("The UnRegisterSurfaceOcclusionChangeCallback isn't legal, nodeId:%{public}" PRIu64 ", "
1487 "callingPid:%{public}d", id, callingPid);
1488 ret = ERR_INVALID_DATA;
1489 break;
1490 }
1491 int32_t status = UnRegisterSurfaceOcclusionChangeCallback(id);
1492 if (!reply.WriteInt32(status)) {
1493 ret = ERR_INVALID_REPLY;
1494 }
1495 break;
1496 }
1497 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_APP_WINDOW_NUM): {
1498 uint32_t num = data.ReadUint32();
1499 SetAppWindowNum(num);
1500 break;
1501 }
1502 case static_cast<uint32_t>(
1503 RSIRenderServiceConnectionInterfaceCode::SET_SYSTEM_ANIMATED_SCENES): {
1504 uint32_t systemAnimatedScenes = data.ReadUint32();
1505 bool result = SetSystemAnimatedScenes(static_cast<SystemAnimatedScenes>(systemAnimatedScenes));
1506 if (!reply.WriteBool(result)) {
1507 ret = ERR_INVALID_REPLY;
1508 }
1509 break;
1510 }
1511 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SHOW_WATERMARK): {
1512 std::shared_ptr<Media::PixelMap> watermarkImg =
1513 std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
1514 bool isShow = data.ReadBool();
1515 ShowWatermark(watermarkImg, isShow);
1516 break;
1517 }
1518 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::RESIZE_VIRTUAL_SCREEN): {
1519 ScreenId id = data.ReadUint64();
1520 uint32_t width = data.ReadUint32();
1521 uint32_t height = data.ReadUint32();
1522 int32_t status = ResizeVirtualScreen(id, width, height);
1523 if (!reply.WriteInt32(status)) {
1524 ret = ERR_INVALID_REPLY;
1525 }
1526 break;
1527 }
1528 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_JANK_STATS): {
1529 ReportJankStats();
1530 break;
1531 }
1532 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_RESPONSE): {
1533 DataBaseRs info;
1534 ReadDataBaseRs(info, data);
1535 ReportEventResponse(info);
1536 break;
1537 }
1538 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_COMPLETE): {
1539 DataBaseRs info;
1540 ReadDataBaseRs(info, data);
1541 ReportEventComplete(info);
1542 break;
1543 }
1544 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_JANK_FRAME): {
1545 DataBaseRs info;
1546 ReadDataBaseRs(info, data);
1547 ReportEventJankFrame(info);
1548 break;
1549 }
1550 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_GAMESTATE): {
1551 GameStateData info;
1552 ReadGameStateDataRs(info, data);
1553 ReportGameStateData(info);
1554 break;
1555 }
1556 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::EXECUTE_SYNCHRONOUS_TASK): {
1557 auto type = data.ReadInt16();
1558 auto subType = data.ReadInt16();
1559 if (type != RS_NODE_SYNCHRONOUS_READ_PROPERTY && type != RS_NODE_SYNCHRONOUS_GET_VALUE_FRACTION) {
1560 ret = ERR_INVALID_STATE;
1561 break;
1562 }
1563 auto func = RSCommandFactory::Instance().GetUnmarshallingFunc(type, subType);
1564 if (func == nullptr) {
1565 ret = ERR_INVALID_STATE;
1566 break;
1567 }
1568 auto command = static_cast<RSSyncTask*>((*func)(data));
1569 if (command == nullptr) {
1570 ret = ERR_INVALID_STATE;
1571 break;
1572 }
1573 std::shared_ptr<RSSyncTask> task(command);
1574 ExecuteSynchronousTask(task);
1575 if (!task->Marshalling(reply)) {
1576 ret = ERR_INVALID_STATE;
1577 }
1578 break;
1579 }
1580 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HARDWARE_ENABLED) : {
1581 auto id = data.ReadUint64();
1582 if (ExtractPid(id) != callingPid) {
1583 RS_LOGW("The SetHardwareEnabled isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1584 id, callingPid);
1585 break;
1586 }
1587 auto isEnabled = data.ReadBool();
1588 auto selfDrawingType = static_cast<SelfDrawingNodeType>(data.ReadUint8());
1589 auto dynamicHardwareEnable = data.ReadBool();
1590 SetHardwareEnabled(id, isEnabled, selfDrawingType, dynamicHardwareEnable);
1591 break;
1592 }
1593 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HIDE_PRIVACY_CONTENT) : {
1594 auto id = data.ReadUint64();
1595 auto isSystemCalling = RSInterfaceCodeAccessVerifierBase::IsSystemCalling(
1596 RSIRenderServiceConnectionInterfaceCodeAccessVerifier::codeEnumTypeName_ +
1597 "::SET_HIDE_PRIVACY_CONTENT");
1598 if (!isSystemCalling) {
1599 if (!reply.WriteUint32(static_cast<uint32_t>(RSInterfaceErrorCode::NONSYSTEM_CALLING))) {
1600 ret = ERR_INVALID_REPLY;
1601 }
1602 break;
1603 }
1604 if (ExtractPid(id) != callingPid) {
1605 RS_LOGW("The SetHidePrivacyContent isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1606 id, callingPid);
1607 if (!reply.WriteUint32(static_cast<uint32_t>(RSInterfaceErrorCode::NOT_SELF_CALLING))) {
1608 ret = ERR_INVALID_REPLY;
1609 }
1610 break;
1611 }
1612 auto needHidePrivacyContent = data.ReadBool();
1613 if (!reply.WriteUint32(SetHidePrivacyContent(id, needHidePrivacyContent))) {
1614 ret = ERR_INVALID_REPLY;
1615 }
1616 break;
1617 }
1618 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_LIGHT_FACTOR_STATUS) : {
1619 auto isSafe = data.ReadBool();
1620 NotifyLightFactorStatus(isSafe);
1621 break;
1622 }
1623 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PACKAGE_EVENT) : {
1624 auto listSize = data.ReadUint32();
1625 const uint32_t MAX_LIST_SIZE = 50;
1626 if (listSize > MAX_LIST_SIZE) {
1627 ret = ERR_INVALID_STATE;
1628 break;
1629 }
1630 std::vector<std::string> packageList;
1631 for (uint32_t i = 0; i < listSize; i++) {
1632 packageList.push_back(data.ReadString());
1633 }
1634 NotifyPackageEvent(listSize, packageList);
1635 break;
1636 }
1637 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_REFRESH_RATE_EVENT) : {
1638 EventInfo eventInfo = {
1639 data.ReadString(), data.ReadBool(), data.ReadUint32(), data.ReadUint32(), data.ReadString(),
1640 };
1641 NotifyRefreshRateEvent(eventInfo);
1642 break;
1643 }
1644 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_DYNAMIC_MODE_EVENT) : {
1645 auto enableDynamicMode = data.ReadBool();
1646 NotifyDynamicModeEvent(enableDynamicMode);
1647 break;
1648 }
1649 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_TOUCH_EVENT) : {
1650 auto touchStatus = data.ReadInt32();
1651 auto touchCnt = data.ReadInt32();
1652 NotifyTouchEvent(touchStatus, touchCnt);
1653 break;
1654 }
1655 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_HGM_CFG_CALLBACK) : {
1656 auto remoteObject = data.ReadRemoteObject();
1657 if (remoteObject == nullptr) {
1658 ret = ERR_NULL_OBJECT;
1659 break;
1660 }
1661 sptr<RSIHgmConfigChangeCallback> callback = iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
1662 if (callback == nullptr) {
1663 ret = ERR_NULL_OBJECT;
1664 break;
1665 }
1666 int32_t status = RegisterHgmConfigChangeCallback(callback);
1667 if (!reply.WriteInt32(status)) {
1668 ret = ERR_INVALID_REPLY;
1669 }
1670 break;
1671 }
1672 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_MODE_CHANGE_CALLBACK) : {
1673 auto remoteObject = data.ReadRemoteObject();
1674 if (remoteObject == nullptr) {
1675 ret = ERR_NULL_OBJECT;
1676 break;
1677 }
1678 sptr<RSIHgmConfigChangeCallback> callback =
1679 iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
1680 if (callback == nullptr) {
1681 ret = ERR_NULL_OBJECT;
1682 break;
1683 }
1684 int32_t status = RegisterHgmRefreshRateModeChangeCallback(callback);
1685 if (!reply.WriteInt32(status)) {
1686 ret = ERR_INVALID_REPLY;
1687 }
1688 break;
1689 }
1690 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_UPDATE_CALLBACK) : {
1691 sptr<RSIHgmConfigChangeCallback> callback = nullptr;
1692 sptr<IRemoteObject> remoteObject = nullptr;
1693 if (data.ReadBool()) {
1694 remoteObject = data.ReadRemoteObject();
1695 }
1696 if (remoteObject != nullptr) {
1697 callback = iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
1698 }
1699 int32_t status = RegisterHgmRefreshRateUpdateCallback(callback);
1700 if (!reply.WriteInt32(status)) {
1701 ret = ERR_INVALID_REPLY;
1702 }
1703 break;
1704 }
1705 case static_cast<uint32_t>(
1706 RSIRenderServiceConnectionInterfaceCode::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK) : {
1707 sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback = nullptr;
1708 sptr<IRemoteObject> remoteObject = nullptr;
1709 int32_t dstPid = data.ReadInt32();
1710 if (data.ReadBool()) {
1711 remoteObject = data.ReadRemoteObject();
1712 }
1713 if (remoteObject != nullptr) {
1714 callback = iface_cast<RSIFrameRateLinkerExpectedFpsUpdateCallback>(remoteObject);
1715 }
1716 int32_t status = RegisterFrameRateLinkerExpectedFpsUpdateCallback(dstPid, callback);
1717 if (!reply.WriteInt32(status)) {
1718 ret = ERR_INVALID_REPLY;
1719 }
1720 break;
1721 }
1722 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ROTATION_CACHE_ENABLED) : {
1723 if (!securityManager_.IsInterfaceCodeAccessible(code)) {
1724 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission SET_ROTATION_CACHE_ENABLED");
1725 return ERR_INVALID_STATE;
1726 }
1727 bool isEnabled = false;
1728 if (!data.ReadBool(isEnabled)) {
1729 ret = IPC_STUB_INVALID_DATA_ERR;
1730 break;
1731 }
1732 SetCacheEnabledForRotation(isEnabled);
1733 break;
1734 }
1735 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_DIRTY_REGION_INFO) : {
1736 const auto& activeDirtyRegionInfos = GetActiveDirtyRegionInfo();
1737 if (!reply.WriteInt32(activeDirtyRegionInfos.size())) {
1738 ret = ERR_INVALID_REPLY;
1739 break;
1740 }
1741 for (const auto& activeDirtyRegionInfo : activeDirtyRegionInfos) {
1742 if (!reply.WriteInt64(activeDirtyRegionInfo.activeDirtyRegionArea) ||
1743 !reply.WriteInt32(activeDirtyRegionInfo.activeFramesNumber) ||
1744 !reply.WriteInt32(activeDirtyRegionInfo.pidOfBelongsApp) ||
1745 !reply.WriteString(activeDirtyRegionInfo.windowName)) {
1746 ret = ERR_INVALID_REPLY;
1747 break;
1748 }
1749 }
1750 break;
1751 }
1752 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_GLOBAL_DIRTY_REGION_INFO) : {
1753 const auto& globalDirtyRegionInfo = GetGlobalDirtyRegionInfo();
1754 if (!reply.WriteInt64(globalDirtyRegionInfo.globalDirtyRegionAreas) ||
1755 !reply.WriteInt32(globalDirtyRegionInfo.globalFramesNumber) ||
1756 !reply.WriteInt32(globalDirtyRegionInfo.skipProcessFramesNumber) ||
1757 !reply.WriteInt32(globalDirtyRegionInfo.mostSendingPidWhenDisplayNodeSkip)) {
1758 ret = ERR_INVALID_REPLY;
1759 }
1760 break;
1761 }
1762 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_LAYER_COMPOSE_INFO) : {
1763 const auto& LayerComposeInfo = GetLayerComposeInfo();
1764 if (!reply.WriteInt32(LayerComposeInfo.uniformRenderFrameNumber) ||
1765 !reply.WriteInt32(LayerComposeInfo.offlineComposeFrameNumber) ||
1766 !reply.WriteInt32(LayerComposeInfo.redrawFrameNumber)) {
1767 ret = ERR_INVALID_REPLY;
1768 }
1769 break;
1770 }
1771 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::
1772 GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO) : {
1773 const auto& hwcDisabledReasonInfos = GetHwcDisabledReasonInfo();
1774 if (!reply.WriteInt32(hwcDisabledReasonInfos.size())) {
1775 ret = ERR_INVALID_REPLY;
1776 break;
1777 }
1778 for (const auto& hwcDisabledReasonInfo : hwcDisabledReasonInfos) {
1779 for (const auto& disabledReasonCount : hwcDisabledReasonInfo.disabledReasonStatistics) {
1780 if (!reply.WriteInt32(disabledReasonCount)) {
1781 ret = ERR_INVALID_REPLY;
1782 break;
1783 }
1784 }
1785 if (ret == ERR_INVALID_REPLY) {
1786 break;
1787 }
1788 if (!reply.WriteInt32(hwcDisabledReasonInfo.pidOfBelongsApp) ||
1789 !reply.WriteString(hwcDisabledReasonInfo.nodeName)) {
1790 ret = ERR_INVALID_REPLY;
1791 break;
1792 }
1793 }
1794 break;
1795 }
1796 #ifdef TP_FEATURE_ENABLE
1797 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_TP_FEATURE_CONFIG) : {
1798 int32_t feature = data.ReadInt32();
1799 auto config = data.ReadCString();
1800 auto tpFeatureConfigType = static_cast<TpFeatureConfigType>(data.ReadUint8());
1801 SetTpFeatureConfig(feature, config, tpFeatureConfigType);
1802 break;
1803 }
1804 #endif
1805 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_USING_STATUS) : {
1806 auto isVirtualScreenUsingStatus = data.ReadBool();
1807 SetVirtualScreenUsingStatus(isVirtualScreenUsingStatus);
1808 break;
1809 }
1810
1811 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CURTAIN_SCREEN_USING_STATUS) : {
1812 auto isCurtainScreenOn = data.ReadBool();
1813 SetCurtainScreenUsingStatus(isCurtainScreenOn);
1814 break;
1815 }
1816 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DROP_FRAME_BY_PID) : {
1817 std::vector<int32_t> pidList;
1818 if (!data.ReadInt32Vector(&pidList)) {
1819 ret = ERR_INVALID_REPLY;
1820 break;
1821 }
1822 DropFrameByPid(pidList);
1823 break;
1824 }
1825 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_UIEXTENSION_CALLBACK): {
1826 uint64_t userId = data.ReadUint64();
1827 auto remoteObject = data.ReadRemoteObject();
1828 if (remoteObject == nullptr) {
1829 ret = ERR_NULL_OBJECT;
1830 break;
1831 }
1832 sptr<RSIUIExtensionCallback> callback = iface_cast<RSIUIExtensionCallback>(remoteObject);
1833 if (callback == nullptr) {
1834 ret = ERR_NULL_OBJECT;
1835 break;
1836 }
1837 int32_t status = RegisterUIExtensionCallback(userId, callback);
1838 if (!reply.WriteInt32(status)) {
1839 ret = ERR_INVALID_REPLY;
1840 }
1841 break;
1842 }
1843 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ANCO_FORCE_DO_DIRECT) : {
1844 bool direct = data.ReadBool();
1845 bool result = SetAncoForceDoDirect(direct);
1846 reply.WriteBool(result);
1847 break;
1848 }
1849 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VMA_CACHE_STATUS) : {
1850 bool flag = data.ReadBool();
1851 SetVmaCacheStatus(flag);
1852 break;
1853 }
1854 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_BUFFER_CALLBACK) : {
1855 auto pid = data.ReadInt32();
1856 auto uid = data.ReadUint64();
1857 auto remoteObject = data.ReadRemoteObject();
1858 if (remoteObject == nullptr) {
1859 ret = ERR_NULL_OBJECT;
1860 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest remoteObject == nullptr");
1861 break;
1862 }
1863 sptr<RSISurfaceBufferCallback> callback = iface_cast<RSISurfaceBufferCallback>(remoteObject);
1864 if (callback == nullptr) {
1865 ret = ERR_NULL_OBJECT;
1866 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest remoteObject cast error");
1867 break;
1868 }
1869 RegisterSurfaceBufferCallback(pid, uid, callback);
1870 break;
1871 }
1872 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_BUFFER_CALLBACK) : {
1873 auto pid = data.ReadInt32();
1874 auto uid = data.ReadUint64();
1875 UnregisterSurfaceBufferCallback(pid, uid);
1876 break;
1877 }
1878 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_DISPLAY_NODE) : {
1879 auto id = data.ReadUint64();
1880 auto mirrorId = data.ReadUint64();
1881 auto screenId = data.ReadUint64();
1882 auto isMirrored = data.ReadBool();
1883 RSDisplayNodeConfig config = {
1884 .screenId = screenId,
1885 .isMirrored = isMirrored,
1886 .mirrorNodeId = mirrorId,
1887 .isSync = true,
1888 };
1889 reply.WriteBool(CreateNode(config, id));
1890 break;
1891 }
1892 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_LAYER_TOP) : {
1893 std::string nodeIdStr = data.ReadString();
1894 bool isTop = data.ReadBool();
1895 SetLayerTop(nodeIdStr, isTop);
1896 break;
1897 }
1898 default: {
1899 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
1900 }
1901 }
1902
1903 return ret;
1904 }
1905
ReadDataBaseRs(DataBaseRs & info,MessageParcel & data)1906 void RSRenderServiceConnectionStub::ReadDataBaseRs(DataBaseRs& info, MessageParcel& data)
1907 {
1908 info.appPid = data.ReadInt32();
1909 info.eventType = data.ReadInt32();
1910 info.versionCode = data.ReadInt32();
1911 info.uniqueId = data.ReadInt64();
1912 info.inputTime = data.ReadInt64();
1913 info.beginVsyncTime = data.ReadInt64();
1914 info.endVsyncTime = data.ReadInt64();
1915 info.isDisplayAnimator = data.ReadBool();
1916 info.sceneId = data.ReadString();
1917 info.versionName = data.ReadString();
1918 info.bundleName = data.ReadString();
1919 info.processName = data.ReadString();
1920 info.abilityName = data.ReadString();
1921 info.pageUrl = data.ReadString();
1922 info.sourceType = data.ReadString();
1923 info.note = data.ReadString();
1924 }
1925
ReadGameStateDataRs(GameStateData & info,MessageParcel & data)1926 void RSRenderServiceConnectionStub::ReadGameStateDataRs(GameStateData& info, MessageParcel& data)
1927 {
1928 info.pid = data.ReadInt32();
1929 info.uid = data.ReadInt32();
1930 info.state = data.ReadInt32();
1931 info.renderTid = data.ReadInt32();
1932 info.bundleName = data.ReadString();
1933 }
1934
ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig & captureConfig,MessageParcel & data)1935 bool RSRenderServiceConnectionStub::ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig& captureConfig, MessageParcel& data)
1936 {
1937 uint8_t captureType { 0 };
1938 if (!data.ReadFloat(captureConfig.scaleX) || !data.ReadFloat(captureConfig.scaleY) ||
1939 !data.ReadBool(captureConfig.useDma) || !data.ReadBool(captureConfig.useCurWindow) ||
1940 !data.ReadUint8(captureType) || !data.ReadBool(captureConfig.isSync)) {
1941 return false;
1942 }
1943 captureConfig.captureType = static_cast<SurfaceCaptureType>(captureType);
1944 return true;
1945 }
1946
1947 const RSInterfaceCodeSecurityManager RSRenderServiceConnectionStub::securityManager_ = \
1948 RSInterfaceCodeSecurityManager::CreateInstance<RSIRenderServiceConnectionInterfaceCodeAccessVerifier>();
1949 } // namespace Rosen
1950 } // namespace OHOS
1951