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