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 "memory/rs_memory_flow_control.h"
33 #include "pipeline/render_thread/rs_base_render_util.h"
34 #include "pipeline/main_thread/rs_main_thread.h"
35 #include "pipeline/rs_uni_render_judgement.h"
36 #include "platform/common/rs_log.h"
37 #include "transaction/rs_ashmem_helper.h"
38 #include "transaction/rs_unmarshal_thread.h"
39 #include "render/rs_typeface_cache.h"
40 #include "rs_trace.h"
41 #include "rs_profiler.h"
42
43 namespace OHOS {
44 namespace Rosen {
45 namespace {
46 constexpr size_t MAX_DATA_SIZE_FOR_UNMARSHALLING_IN_PLACE = 1024 * 15; // 15kB
47 constexpr size_t FILE_DESCRIPTOR_LIMIT = 15;
48 constexpr size_t MAX_OBJECTNUM = 512;
49 constexpr size_t MAX_DATA_SIZE = 1024 * 1024; // 1MB
50 static constexpr int MAX_SECURITY_EXEMPTION_LIST_NUMBER = 1024; // securityExemptionList size not exceed 1024
51 #ifdef RES_SCHED_ENABLE
52 const uint32_t RS_IPC_QOS_LEVEL = 7;
53 constexpr const char* RS_BUNDLE_NAME = "render_service";
54 #endif
55 static constexpr std::array descriptorCheckList = {
56 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FOCUS_APP_INFO),
57 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DEFAULT_SCREEN_ID),
58 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_SCREEN_ID),
59 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ALL_SCREEN_IDS),
60 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VIRTUAL_SCREEN),
61 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PHYSICAL_SCREEN_RESOLUTION),
62 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_RESOLUTION),
63 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SURFACE),
64 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_BLACKLIST),
65 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::ADD_VIRTUAL_SCREEN_BLACKLIST),
66 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN_BLACKLIST),
67 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST),
68 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SECURITY_MASK),
69 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_MIRROR_SCREEN_VISIBLE_RECT),
70 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN),
71 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CHANGE_CALLBACK),
72 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_MODE),
73 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_REFRESH_RATE),
74 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_REFRESH_RATE_MODE),
75 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SYNC_FRAME_RATE_RANGE),
76 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_FRAME_RATE_LINKER),
77 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CURRENT_REFRESH_RATE),
78 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_CURRENT_REFRESH_RATE_MODE),
79 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_REFRESH_RATES),
80 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SHOW_REFRESH_RATE_ENABLED),
81 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SHOW_REFRESH_RATE_ENABLED),
82 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REALTIME_REFRESH_RATE),
83 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::MARK_POWER_OFF_NEED_PROCESS_ONE_FRAME),
84 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPAINT_EVERYTHING),
85 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::FORCE_REFRESH_ONE_FRAME_WITH_NEXT_VSYNC),
86 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DISABLE_RENDER_CONTROL_SCREEN),
87 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DISPLAY_IDENTIFICATION_DATA),
88 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
89 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_POINTER_COLOR_INVERSION_CONFIG),
90 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_POINTER_COLOR_INVERSION_ENABLED),
91 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_POINTER_LUMINANCE_CALLBACK),
92 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_POINTER_LUMINANCE_CALLBACK),
93 #endif
94 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_POWER_STATUS),
95 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_BACK_LIGHT),
96 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_ACTIVE_MODE),
97 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_MODES),
98 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CAPABILITY),
99 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_POWER_STATUS),
100 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_BACK_LIGHT),
101 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_DATA),
102 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_VIRTUAL_SCREEN_RESOLUTION),
103 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER),
104 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER),
105 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_GAMUTS),
106 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_METADATAKEYS),
107 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT),
108 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT),
109 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT_MAP),
110 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CORRECTION),
111 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION),
112 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE),
113 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_GLOBAL_DARK_COLOR_MODE),
114 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT_MAP),
115 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE),
116 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_CAPABILITY),
117 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PIXEL_FORMAT),
118 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXEL_FORMAT),
119 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_HDR_FORMATS),
120 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_FORMAT),
121 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_HDR_FORMAT),
122 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_COLORSPACES),
123 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_COLORSPACE),
124 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_COLORSPACE),
125 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_TYPE),
126 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SKIP_FRAME_INTERVAL),
127 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_REFRESH_RATE),
128 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_RECT),
129 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_OCCLUSION_CHANGE_CALLBACK),
130 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_APP_WINDOW_NUM),
131 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SYSTEM_ANIMATED_SCENES),
132 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WATERMARK),
133 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SHOW_WATERMARK),
134 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::RESIZE_VIRTUAL_SCREEN),
135 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC),
136 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHICS),
137 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_TOTAL_APP_MEM_SIZE),
138 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_JANK_STATS),
139 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_BITMAP),
140 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP),
141 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::EXECUTE_SYNCHRONOUS_TASK),
142 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_LIGHT_FACTOR_STATUS),
143 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PACKAGE_EVENT),
144 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_REFRESH_RATE_EVENT),
145 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_SOFT_VSYNC_EVENT),
146 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_RESPONSE),
147 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_COMPLETE),
148 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_JANK_FRAME),
149 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_RS_SCENE_JANK_START),
150 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_RS_SCENE_JANK_END),
151 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_GAMESTATE),
152 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_TOUCH_EVENT),
153 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_DYNAMIC_MODE_EVENT),
154 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_HGMCONFIG_EVENT),
155 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HARDWARE_ENABLED),
156 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HIDE_PRIVACY_CONTENT),
157 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK),
158 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK),
159 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_HGM_CFG_CALLBACK),
160 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ROTATION_CACHE_ENABLED),
161 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_SCREEN_SWITCHED),
162 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_TP_FEATURE_CONFIG),
163 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_USING_STATUS),
164 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_MODE_CHANGE_CALLBACK),
165 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CURTAIN_SCREEN_USING_STATUS),
166 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DROP_FRAME_BY_PID),
167 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_TYPEFACE),
168 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_TYPEFACE),
169 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_UPDATE_CALLBACK),
170 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK),
171 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_DIRTY_REGION_INFO),
172 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_GLOBAL_DIRTY_REGION_INFO),
173 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_LAYER_COMPOSE_INFO),
174 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW),
175 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_UIEXTENSION_CALLBACK),
176 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VMA_CACHE_STATUS),
177 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_STATUS),
178 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ANCO_FORCE_DO_DIRECT),
179 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NEED_REGISTER_TYPEFACE),
180 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_DISPLAY_NODE),
181 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FREE_MULTI_WINDOW_STATUS),
182 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_BUFFER_CALLBACK),
183 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_BUFFER_CALLBACK),
184 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_LAYER_TOP),
185 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WINDOW_CONTAINER),
186 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SELF_DRAWING_NODE_RECT_CHANGE_CALLBACK),
187 #ifdef RS_ENABLE_OVERLAY_DISPLAY
188 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_OVERLAY_DISPLAY_MODE),
189 #endif
190 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PAGE_NAME),
191 static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TEST_LOAD_FILE_SUB_TREE),
192 };
193
CopyFileDescriptor(MessageParcel & old,MessageParcel & copied)194 void CopyFileDescriptor(MessageParcel& old, MessageParcel& copied)
195 {
196 binder_size_t* object = reinterpret_cast<binder_size_t*>(old.GetObjectOffsets());
197 binder_size_t* copiedObject = reinterpret_cast<binder_size_t*>(copied.GetObjectOffsets());
198
199 size_t objectNum = old.GetOffsetsSize();
200
201 uintptr_t data = old.GetData();
202 uintptr_t copiedData = copied.GetData();
203
204 for (size_t i = 0; i < objectNum; i++) {
205 const flat_binder_object* flat = reinterpret_cast<flat_binder_object*>(data + object[i]);
206 flat_binder_object* copiedFlat = reinterpret_cast<flat_binder_object*>(copiedData + copiedObject[i]);
207
208 if (flat->hdr.type == BINDER_TYPE_FD && flat->handle >= 0) {
209 int32_t val = dup(flat->handle);
210 if (val < 0) {
211 ROSEN_LOGW("CopyFileDescriptor dup failed, fd:%{public}d, handle:%{public}" PRIu32, val,
212 static_cast<uint32_t>(flat->handle));
213 }
214 copiedFlat->handle = static_cast<uint32_t>(val);
215 }
216 }
217 }
218
CopyParcelIfNeed(MessageParcel & old,pid_t callingPid)219 std::shared_ptr<MessageParcel> CopyParcelIfNeed(MessageParcel& old, pid_t callingPid)
220 {
221 if (RSSystemProperties::GetCacheEnabledForRotation() &&
222 RSMainThread::Instance()->GetDesktopPidForRotationScene() != callingPid) {
223 return nullptr;
224 }
225 auto dataSize = old.GetDataSize();
226 if (dataSize <= MAX_DATA_SIZE_FOR_UNMARSHALLING_IN_PLACE && old.GetOffsetsSize() < FILE_DESCRIPTOR_LIMIT) {
227 return nullptr;
228 }
229 if (dataSize > MAX_DATA_SIZE) {
230 return nullptr;
231 }
232 if (dataSize == 0) {
233 return nullptr;
234 }
235
236 if (old.GetOffsetsSize() > MAX_OBJECTNUM) {
237 ROSEN_LOGW("RSRenderServiceConnectionStub::CopyParcelIfNeed failed, parcel fdCnt: %{public}zu is too large",
238 old.GetOffsetsSize());
239 return nullptr;
240 }
241
242 RS_TRACE_NAME("CopyParcelForUnmarsh: size:" + std::to_string(dataSize));
243 void* base = malloc(dataSize);
244 if (base == nullptr) {
245 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed malloc failed");
246 return nullptr;
247 }
248 if (memcpy_s(base, dataSize, reinterpret_cast<void*>(old.GetData()), dataSize) != 0) {
249 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed copy parcel data failed");
250 free(base);
251 return nullptr;
252 }
253
254 auto parcelCopied = RS_PROFILER_COPY_PARCEL(old);
255 if (!parcelCopied->ParseFrom(reinterpret_cast<uintptr_t>(base), dataSize)) {
256 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed ParseFrom failed");
257 free(base);
258 return nullptr;
259 }
260
261 auto objectNum = old.GetOffsetsSize();
262 if (objectNum != 0) {
263 parcelCopied->InjectOffsets(old.GetObjectOffsets(), objectNum);
264 CopyFileDescriptor(old, *parcelCopied);
265 }
266 if (parcelCopied->ReadInt32() != 0) {
267 RS_LOGE("RSRenderServiceConnectionStub::CopyParcelIfNeed parcel data not match");
268 return nullptr;
269 }
270 return parcelCopied;
271 }
272
CheckCreateNodeAndSurface(pid_t pid,RSSurfaceNodeType nodeType,SurfaceWindowType windowType)273 bool CheckCreateNodeAndSurface(pid_t pid, RSSurfaceNodeType nodeType, SurfaceWindowType windowType)
274 {
275 constexpr int nodeTypeMin = static_cast<int>(RSSurfaceNodeType::DEFAULT);
276 constexpr int nodeTypeMax = static_cast<int>(RSSurfaceNodeType::UI_EXTENSION_SECURE_NODE);
277
278 int typeNum = static_cast<int>(nodeType);
279 if (typeNum < nodeTypeMin || typeNum > nodeTypeMax) {
280 RS_LOGW("CREATE_NODE_AND_SURFACE invalid RSSurfaceNodeType");
281 return false;
282 }
283 if (windowType != SurfaceWindowType::DEFAULT_WINDOW && windowType != SurfaceWindowType::SYSTEM_SCB_WINDOW) {
284 RS_LOGW("CREATE_NODE_AND_SURFACE invalid SurfaceWindowType");
285 return false;
286 }
287
288 bool isTokenTypeValid = true;
289 bool isNonSystemAppCalling = false;
290 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemAppCalling);
291 if (isNonSystemAppCalling) {
292 if (nodeType != RSSurfaceNodeType::DEFAULT &&
293 nodeType != RSSurfaceNodeType::APP_WINDOW_NODE &&
294 nodeType != RSSurfaceNodeType::SELF_DRAWING_NODE &&
295 nodeType != RSSurfaceNodeType::UI_EXTENSION_COMMON_NODE) {
296 RS_LOGW("CREATE_NODE_AND_SURFACE NonSystemAppCalling invalid RSSurfaceNodeType %{public}d, pid %d",
297 typeNum, pid);
298 return false;
299 }
300 if (windowType != SurfaceWindowType::DEFAULT_WINDOW) {
301 RS_LOGW("CREATE_NODE_AND_SURFACE NonSystemAppCalling invalid SurfaceWindowType %{public}d, pid %d",
302 static_cast<int>(windowType), pid);
303 return false;
304 }
305 }
306
307 return true;
308 }
309
IsValidCallingPid(pid_t pid,pid_t callingPid)310 bool IsValidCallingPid(pid_t pid, pid_t callingPid)
311 {
312 return (callingPid == getpid()) || (callingPid == pid);
313 }
314
TypefaceXcollieCallback(void * arg)315 static void TypefaceXcollieCallback(void* arg)
316 {
317 if (arg) {
318 bool* isTrigger = static_cast<bool*>(arg);
319 *isTrigger = true;
320 }
321 }
322 }
323
SetQos()324 void RSRenderServiceConnectionStub::SetQos()
325 {
326 #ifdef RES_SCHED_ENABLE
327 std::string strBundleName = RS_BUNDLE_NAME;
328 std::string strPid = std::to_string(getpid());
329 std::string strTid = std::to_string(gettid());
330 std::string strQos = std::to_string(RS_IPC_QOS_LEVEL);
331 std::unordered_map<std::string, std::string> mapPayload;
332 mapPayload["pid"] = strPid;
333 mapPayload[strTid] = strQos;
334 mapPayload["bundleName"] = strBundleName;
335 OHOS::ResourceSchedule::ResSchedClient::GetInstance().ReportData(
336 OHOS::ResourceSchedule::ResType::RES_TYPE_THREAD_QOS_CHANGE, 0, mapPayload);
337 struct sched_param param = {0};
338 param.sched_priority = 1;
339 if (sched_setscheduler(0, SCHED_FIFO, ¶m) != 0) {
340 RS_LOGE("RSRenderServiceConnectionStub Couldn't set SCHED_FIFO.");
341 } else {
342 RS_LOGI("RSRenderServiceConnectionStub set SCHED_FIFO succeed.");
343 }
344 #endif
345 }
346
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)347 int RSRenderServiceConnectionStub::OnRemoteRequest(
348 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
349 {
350 uint32_t parcelNumber = RS_PROFILER_ON_REMOTE_REQUEST(this, code, data, reply, option);
351
352 AshmemFdContainer::SetIsUnmarshalThread(false);
353 pid_t callingPid = GetCallingPid();
354 RSMarshallingHelper::SetCallingPid(callingPid);
355 auto tid = gettid();
356 {
357 std::lock_guard<std::mutex> lock(mutex_);
358 if (tids_.find(tid) == tids_.end()) {
359 SetQos();
360 tids_.insert(tid);
361 }
362 }
363 if (std::find(std::cbegin(descriptorCheckList), std::cend(descriptorCheckList), code) !=
364 std::cend(descriptorCheckList)) {
365 auto token = data.ReadInterfaceToken();
366 if (token != RSIRenderServiceConnection::GetDescriptor()) {
367 if (code == static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE)) {
368 if (!reply.WriteInt32(0)) {
369 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest Write failed.");
370 return ERR_INVALID_REPLY;
371 }
372 }
373 return ERR_INVALID_STATE;
374 }
375 }
376 auto accessible = securityManager_.IsInterfaceCodeAccessible(code);
377 if (!accessible && code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SURFACE_CAPTURE) &&
378 code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC) &&
379 code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REFRESH_INFO) &&
380 code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER) &&
381 code != static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER)) {
382 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission code:%{public}d", code);
383 return ERR_INVALID_STATE;
384 }
385 int ret = ERR_NONE;
386 switch (code) {
387 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::COMMIT_TRANSACTION): {
388 bool isTokenTypeValid = true;
389 bool isNonSystemAppCalling = false;
390 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemAppCalling);
391 if (!isTokenTypeValid) {
392 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION invalid token type");
393 return ERR_INVALID_STATE;
394 }
395 if (isNonSystemAppCalling) {
396 RsCommandVerifyHelper::GetInstance().RegisterNonSystemPid(callingPid);
397 }
398 RS_TRACE_NAME_FMT("Recv Parcel Size:%zu, fdCnt:%zu", data.GetDataSize(), data.GetOffsetsSize());
399 static bool isUniRender = RSUniRenderJudgement::IsUniRender();
400 std::shared_ptr<MessageParcel> parsedParcel;
401 std::unique_ptr<AshmemFdWorker> ashmemFdWorker = nullptr;
402 std::shared_ptr<AshmemFlowControlUnit> ashmemFlowControlUnit = nullptr;
403 if (data.ReadInt32() == 0) { // indicate normal parcel
404 if (isUniRender) {
405 // in uni render mode, if parcel size over threshold,
406 // Unmarshalling task will be post to RSUnmarshalThread,
407 // copy the origin parcel to maintain the parcel lifetime
408 parsedParcel = CopyParcelIfNeed(data, callingPid);
409 }
410 if (parsedParcel == nullptr) {
411 // no need to copy or copy failed, use original parcel
412 // execute Unmarshalling immediately
413 auto transactionData = RSBaseRenderUtil::ParseTransactionData(data, parcelNumber);
414 if (transactionData && isNonSystemAppCalling) {
415 const auto& nodeMap = RSMainThread::Instance()->GetContext().GetNodeMap();
416 if (!transactionData->IsCallingPidValid(callingPid, nodeMap)) {
417 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION IsCallingPidValid check failed");
418 }
419 }
420 CommitTransaction(transactionData);
421 break;
422 }
423 } else {
424 // indicate ashmem parcel
425 // should be parsed to normal parcel before Unmarshalling
426 parsedParcel = RSAshmemHelper::ParseFromAshmemParcel(&data, ashmemFdWorker, ashmemFlowControlUnit,
427 callingPid);
428 if (parsedParcel) {
429 parcelNumber = RS_PROFILER_ON_REMOTE_REQUEST(this, code, *parsedParcel, reply, option);
430 }
431 }
432 if (parsedParcel == nullptr) {
433 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION failed: parsed parcel is nullptr");
434 return ERR_INVALID_DATA;
435 }
436 if (isUniRender) {
437 // post Unmarshalling task to RSUnmarshalThread
438 RSUnmarshalThread::Instance().RecvParcel(parsedParcel, isNonSystemAppCalling, callingPid,
439 std::move(ashmemFdWorker), ashmemFlowControlUnit, parcelNumber);
440 } else {
441 // execute Unmarshalling immediately
442 auto transactionData = RSBaseRenderUtil::ParseTransactionData(*parsedParcel, parcelNumber);
443 if (transactionData && isNonSystemAppCalling) {
444 const auto& nodeMap = RSMainThread::Instance()->GetContext().GetNodeMap();
445 if (!transactionData->IsCallingPidValid(callingPid, nodeMap)) {
446 RS_LOGE("RSRenderServiceConnectionStub::COMMIT_TRANSACTION IsCallingPidValid check failed");
447 }
448 }
449 CommitTransaction(transactionData);
450 }
451 break;
452 }
453 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_UNI_RENDER_ENABLED): {
454 bool enable;
455 if (GetUniRenderEnabled(enable) != ERR_OK || !reply.WriteBool(enable)) {
456 RS_LOGE("RSRenderServiceConnectionStub::GET_UNI_RENDER_ENABLED read enable failed!");
457 ret = ERR_INVALID_REPLY;
458 }
459 break;
460 }
461 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE): {
462 uint64_t nodeId{0};
463 if (!data.ReadUint64(nodeId)) {
464 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE read nodeId failed!");
465 ret = ERR_INVALID_DATA;
466 break;
467 }
468 bool isNonSystemCalling = false;
469 bool isTokenTypeValid = true;
470 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemCalling);
471 if (isNonSystemCalling && !IsValidCallingPid(ExtractPid(nodeId), callingPid)) {
472 RS_LOGW("CREATE_NODE invalid nodeId[%{public}" PRIu64 "] pid[%{public}d]", nodeId, callingPid);
473 ret = ERR_INVALID_DATA;
474 break;
475 }
476 RS_PROFILER_PATCH_NODE_ID(data, nodeId);
477 std::string surfaceName;
478 if (!data.ReadString(surfaceName)) {
479 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE read surfaceName failed!");
480 ret = ERR_INVALID_DATA;
481 break;
482 }
483 RSSurfaceRenderNodeConfig config = {.id = nodeId, .name = surfaceName};
484 bool success;
485 if (CreateNode(config, success) != ERR_OK || !reply.WriteBool(success)) {
486 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE Write success failed!");
487 ret = ERR_INVALID_REPLY;
488 }
489 break;
490 }
491 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_NODE_AND_SURFACE): {
492 uint64_t nodeId{0};
493 if (!data.ReadUint64(nodeId)) {
494 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE_AND_SURFACE read nodeId failed!");
495 ret = ERR_INVALID_DATA;
496 break;
497 }
498 if (!IsValidCallingPid(ExtractPid(nodeId), callingPid)) {
499 RS_LOGW("CREATE_NODE_AND_SURFACE invalid nodeId[%" PRIu64 "] pid[%d]", nodeId, callingPid);
500 ret = ERR_INVALID_DATA;
501 break;
502 }
503 RS_PROFILER_PATCH_NODE_ID(data, nodeId);
504 std::string surfaceName;
505 uint8_t type { 0 };
506 bool isTextureExportNode { false };
507 bool isSync { false };
508 uint8_t surfaceWindowType { 0 };
509 bool unobscured { false };
510 if (!data.ReadString(surfaceName) || !data.ReadUint8(type) || !data.ReadBool(isTextureExportNode) ||
511 !data.ReadBool(isSync) || !data.ReadUint8(surfaceWindowType) || !data.ReadBool(unobscured)) {
512 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE_AND_SURFACE read surfaceRenderNodeConfig failed!");
513 ret = ERR_INVALID_DATA;
514 break;
515 }
516 if (!CheckCreateNodeAndSurface(callingPid, static_cast<RSSurfaceNodeType>(type),
517 static_cast<SurfaceWindowType>(surfaceWindowType))) {
518 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE_AND_SURFACE CheckCreateNodeAndSurface failed!");
519 ret = ERR_INVALID_DATA;
520 break;
521 }
522 RSSurfaceRenderNodeConfig config = { .id = nodeId,
523 .name = surfaceName,
524 .nodeType = static_cast<RSSurfaceNodeType>(type),
525 .isTextureExportNode = isTextureExportNode,
526 .isSync = isSync,
527 .surfaceWindowType = static_cast<SurfaceWindowType>(surfaceWindowType) };
528 sptr<Surface> surface = nullptr;
529 ErrCode err = CreateNodeAndSurface(config, surface, unobscured);
530 if ((err != ERR_OK) || (surface == nullptr)) {
531 ret = ERR_NULL_OBJECT;
532 break;
533 }
534 auto producer = surface->GetProducer();
535 if (!reply.WriteRemoteObject(producer->AsObject())) {
536 RS_LOGE("RSRenderServiceConnectionStub::CREATE_NODE_AND_SURFACE read RemoteObject failed!");
537 ret = ERR_INVALID_REPLY;
538 }
539 break;
540 }
541 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FOCUS_APP_INFO): {
542 int32_t pid{0};
543 if (!data.ReadInt32(pid)) {
544 RS_LOGE("RSRenderServiceConnectionStub::SET_FOCUS_APP_INFO read pid failed!");
545 ret = ERR_INVALID_DATA;
546 break;
547 }
548 RS_PROFILER_PATCH_PID(data, pid);
549 int32_t uid{0};
550 std::string bundleName;
551 std::string abilityName;
552 uint64_t focusNodeId{0};
553 if (!data.ReadInt32(uid) || !data.ReadString(bundleName) ||
554 !data.ReadString(abilityName) || !data.ReadUint64(focusNodeId)) {
555 RS_LOGE("RSRenderServiceConnectionStub::SET_FOCUS_APP_INFO read parcel failed!");
556 ret = ERR_INVALID_DATA;
557 break;
558 }
559 RS_PROFILER_PATCH_NODE_ID(data, focusNodeId);
560 int32_t status = SetFocusAppInfo(pid, uid, bundleName, abilityName, focusNodeId);
561 if (!reply.WriteInt32(status)) {
562 RS_LOGE("RSRenderServiceConnectionStub::SET_FOCUS_APP_INFO Write status failed!");
563 ret = ERR_INVALID_REPLY;
564 }
565 break;
566 }
567 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DEFAULT_SCREEN_ID): {
568 ScreenId id = GetDefaultScreenId();
569 if (!reply.WriteUint64(id)) {
570 RS_LOGE("RSRenderServiceConnectionStub::GET_DEFAULT_SCREEN_ID Write id failed!");
571 ret = ERR_INVALID_REPLY;
572 }
573 break;
574 }
575 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_SCREEN_ID): {
576 ScreenId id = GetActiveScreenId();
577 if (!reply.WriteUint64(id)) {
578 RS_LOGE("RSRenderServiceConnectionStub::GET_ACTIVE_SCREEN_ID Write id failed!");
579 ret = ERR_INVALID_REPLY;
580 }
581 break;
582 }
583 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ALL_SCREEN_IDS): {
584 std::vector<ScreenId> ids = GetAllScreenIds();
585 if (!reply.WriteUint32(ids.size())) {
586 RS_LOGE("RSRenderServiceConnectionStub::GET_ALL_SCREEN_IDS Write idsSize failed!");
587 ret = ERR_INVALID_REPLY;
588 break;
589 }
590 for (uint32_t i = 0; i < ids.size(); i++) {
591 if (!reply.WriteUint64(ids[i])) {
592 RS_LOGE("RSRenderServiceConnectionStub::GET_ALL_SCREEN_IDS Write ids failed!");
593 ret = ERR_INVALID_REPLY;
594 break;
595 }
596 }
597 break;
598 }
599 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VIRTUAL_SCREEN): {
600 // read the parcel data.
601 std::string name;
602 uint32_t width{0};
603 uint32_t height{0};
604 bool useSurface{false};
605 if (!data.ReadString(name) || !data.ReadUint32(width) ||
606 !data.ReadUint32(height) || !data.ReadBool(useSurface)) {
607 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VIRTUAL_SCREEN read parcel failed!");
608 ret = ERR_INVALID_DATA;
609 break;
610 }
611 sptr<Surface> surface = nullptr;
612 if (useSurface) {
613 auto remoteObject = data.ReadRemoteObject();
614 if (remoteObject != nullptr) {
615 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
616 surface = Surface::CreateSurfaceAsProducer(bufferProducer);
617 }
618 }
619 ScreenId mirrorId{INVALID_SCREEN_ID};
620 int32_t flags{0};
621 std::vector<NodeId> whiteList;
622 if (!data.ReadUint64(mirrorId) || !data.ReadInt32(flags) || !data.ReadUInt64Vector(&whiteList)) {
623 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VIRTUAL_SCREEN read ScreenId failed!");
624 ret = ERR_INVALID_DATA;
625 break;
626 }
627 ScreenId id = CreateVirtualScreen(name, width, height, surface, mirrorId, flags, whiteList);
628 if (!reply.WriteUint64(id)) {
629 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VIRTUAL_SCREEN Write id failed!");
630 ret = ERR_INVALID_REPLY;
631 }
632 break;
633 }
634 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_BLACKLIST): {
635 // read the parcel data.
636 ScreenId id{INVALID_SCREEN_ID};
637 std::vector<NodeId> blackListVector;
638 if (!data.ReadUint64(id) || !data.ReadUInt64Vector(&blackListVector)) {
639 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_BLACKLIST read parcel failed!");
640 ret = ERR_INVALID_DATA;
641 break;
642 }
643 int32_t status = SetVirtualScreenBlackList(id, blackListVector);
644 if (!reply.WriteInt32(status)) {
645 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_BLACKLIST Write status failed!");
646 ret = ERR_INVALID_REPLY;
647 }
648 break;
649 }
650 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::ADD_VIRTUAL_SCREEN_BLACKLIST): {
651 // read the parcel data.
652 ScreenId id{INVALID_SCREEN_ID};
653 std::vector<NodeId> blackListVector;
654 if (!data.ReadUint64(id) || !data.ReadUInt64Vector(&blackListVector)) {
655 RS_LOGE("RSRenderServiceConnectionStub::ADD_VIRTUAL_SCREEN_BLACKLIST read parcel failed!");
656 ret = ERR_INVALID_DATA;
657 break;
658 }
659 int32_t repCode;
660 AddVirtualScreenBlackList(id, blackListVector, repCode);
661 if (!reply.WriteInt32(repCode)) {
662 RS_LOGE("RSRenderServiceConnectionStub::ADD_VIRTUAL_SCREEN_BLACKLIST Write repCode failed!");
663 ret = ERR_INVALID_REPLY;
664 }
665 break;
666 }
667 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN_BLACKLIST): {
668 // read the parcel data.
669 ScreenId id{INVALID_SCREEN_ID};
670 std::vector<NodeId> blackListVector;
671 if (!data.ReadUint64(id) || !data.ReadUInt64Vector(&blackListVector)) {
672 RS_LOGE("RSRenderServiceConnectionStub::ADD_VIRTUAL_SCREEN_BLACKLIST read parcel failed!");
673 ret = ERR_INVALID_DATA;
674 break;
675 }
676 int32_t repCode;
677 RemoveVirtualScreenBlackList(id, blackListVector, repCode);
678 if (!reply.WriteInt32(repCode)) {
679 RS_LOGE("RSRenderServiceConnectionStub::REMOVE_VIRTUAL_SCREEN_BLACKLIST Write repCode failed!");
680 ret = ERR_INVALID_REPLY;
681 }
682 break;
683 }
684 case static_cast<uint32_t>(
685 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST): {
686 // read the parcel data.
687 ScreenId id{INVALID_SCREEN_ID};
688 std::vector<NodeId> securityExemptionList;
689 if (!data.ReadUint64(id) || !data.ReadUInt64Vector(&securityExemptionList)) {
690 RS_LOGE(
691 "RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST read parcel failed!");
692 ret = ERR_INVALID_DATA;
693 break;
694 }
695 if (securityExemptionList.size() > MAX_SECURITY_EXEMPTION_LIST_NUMBER) {
696 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST"
697 " failed: too many lists.");
698 ret = ERR_INVALID_DATA;
699 break;
700 }
701 int32_t status = SetVirtualScreenSecurityExemptionList(id, securityExemptionList);
702 if (!reply.WriteInt32(status)) {
703 RS_LOGE(
704 "RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_SECURITY_EXEMPTION_LIST Write status failed!");
705 ret = ERR_INVALID_REPLY;
706 }
707 break;
708 }
709 case static_cast<uint32_t>(
710 RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SECURITY_MASK): {
711 // read the parcel data.
712 ScreenId id{INVALID_SCREEN_ID};
713 bool enable{false};
714 if (!data.ReadUint64(id) || !data.ReadBool(enable)) {
715 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_SECURITY_MASK read parcel failed!");
716 ret = ERR_INVALID_DATA;
717 break;
718 }
719 std::shared_ptr<Media::PixelMap> securityMask{nullptr};
720 if (enable) {
721 securityMask = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
722 }
723 int32_t result = SetScreenSecurityMask(id, std::move(securityMask));
724 if (!reply.WriteInt32(result)) {
725 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_SECURITY_MASK Write result failed!");
726 ret = ERR_INVALID_REPLY;
727 }
728 break;
729 }
730 case static_cast<uint32_t>(
731 RSIRenderServiceConnectionInterfaceCode::SET_MIRROR_SCREEN_VISIBLE_RECT): {
732 // read the parcel data.
733 ScreenId id = INVALID_SCREEN_ID;
734 if (!data.ReadUint64(id)) {
735 RS_LOGE("RSRenderServiceConnectionStub::SET_MIRROR_SCREEN_VISIBLE_RECT Read id failed!");
736 ret = ERR_INVALID_REPLY;
737 break;
738 }
739 int32_t x = -1;
740 int32_t y = -1;
741 int32_t w = -1;
742 int32_t h = -1;
743 if (!data.ReadInt32(x) || !data.ReadInt32(y) ||
744 !data.ReadInt32(w) || !data.ReadInt32(h)) {
745 RS_LOGE("RSRenderServiceConnectionStub::SET_MIRROR_SCREEN_VISIBLE_RECT Read parcel failed!");
746 ret = ERR_INVALID_REPLY;
747 break;
748 }
749 auto mainScreenRect = Rect {
750 .x = x,
751 .y = y,
752 .w = w,
753 .h = h
754 };
755 bool supportRotation{false};
756 if (!data.ReadBool(supportRotation)) {
757 RS_LOGE("RSRenderServiceConnectionStub::SET_MIRROR_SCREEN_VISIBLE_RECT Read supportRotation failed!");
758 ret = ERR_INVALID_DATA;
759 break;
760 }
761 int32_t status = SetMirrorScreenVisibleRect(id, mainScreenRect, supportRotation);
762 if (!reply.WriteInt32(status)) {
763 RS_LOGE("RSRenderServiceConnectionStub::SET_MIRROR_SCREEN_VISIBLE_RECT Write status failed!");
764 ret = ERR_INVALID_REPLY;
765 }
766 break;
767 }
768 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW): {
769 // read the parcel data.
770 ScreenId id{INVALID_SCREEN_ID};
771 bool enable{false};
772 if (!data.ReadUint64(id) || !data.ReadBool(enable)) {
773 RS_LOGE("RSRenderServiceConnectionStub::SET_CAST_SCREEN_ENABLE_SKIP_WINDOW Read parcel failed!");
774 ret = ERR_INVALID_DATA;
775 break;
776 }
777 int32_t result = SetCastScreenEnableSkipWindow(id, enable);
778 if (!reply.WriteInt32(result)) {
779 RS_LOGE("RSRenderServiceConnectionStub::SET_MIRROR_SCREEN_VISIBLE_RECT Write result failed!");
780 ret = ERR_INVALID_REPLY;
781 }
782 break;
783 }
784 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_SURFACE): {
785 // read the parcel data.
786 ScreenId id{INVALID_SCREEN_ID};
787 if (!data.ReadUint64(id)) {
788 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_SURFACE Read parcel failed!");
789 ret = ERR_INVALID_DATA;
790 break;
791 }
792 auto remoteObject = data.ReadRemoteObject();
793 if (remoteObject == nullptr) {
794 ret = ERR_NULL_OBJECT;
795 break;
796 }
797 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
798 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
799 if (surface == nullptr) {
800 ret = ERR_NULL_OBJECT;
801 break;
802 }
803 int32_t status = SetVirtualScreenSurface(id, surface);
804 if (!reply.WriteInt32(status)) {
805 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_SURFACE Write status failed!");
806 ret = ERR_INVALID_REPLY;
807 }
808 break;
809 }
810 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REMOVE_VIRTUAL_SCREEN): {
811 ScreenId id{INVALID_SCREEN_ID};
812 if (!data.ReadUint64(id)) {
813 RS_LOGE("RSRenderServiceConnectionStub::REMOVE_VIRTUAL_SCREEN Read parcel failed!");
814 ret = ERR_INVALID_DATA;
815 break;
816 }
817 RemoveVirtualScreen(id);
818 break;
819 }
820 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CHANGE_CALLBACK): {
821 auto remoteObject = data.ReadRemoteObject();
822 if (remoteObject == nullptr) {
823 ret = ERR_NULL_OBJECT;
824 break;
825 }
826 sptr<RSIScreenChangeCallback> cb = iface_cast<RSIScreenChangeCallback>(remoteObject);
827 if (cb == nullptr) {
828 ret = ERR_NULL_OBJECT;
829 break;
830 }
831 int32_t status = SetScreenChangeCallback(cb);
832 if (!reply.WriteInt32(status)) {
833 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_CHANGE_CALLBACK Write status failed!");
834 ret = ERR_INVALID_REPLY;
835 }
836 break;
837 }
838 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
839 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_POINTER_COLOR_INVERSION_CONFIG): {
840 float darkBuffer { 0.f };
841 float brightBuffer { 0.f };
842 int64_t interval { 0 };
843 int32_t rangeSize { 0 };
844 if (!data.ReadFloat(darkBuffer) || !data.ReadFloat(brightBuffer) || !data.ReadInt64(interval) ||
845 !data.ReadInt32(rangeSize)) {
846 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_COLOR_INVERSION_CONFIG read parcel failed!");
847 ret = ERR_INVALID_DATA;
848 break;
849 }
850 int32_t status = SetPointerColorInversionConfig(darkBuffer, brightBuffer, interval, rangeSize);
851 if (!reply.WriteInt32(status)) {
852 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_COLOR_INVERSION_CONFIG Write status failed!");
853 ret = ERR_INVALID_REPLY;
854 }
855 break;
856 }
857 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_POINTER_COLOR_INVERSION_ENABLED): {
858 bool enable { false };
859 if (!data.ReadBool(enable)) {
860 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_COLOR_INVERSION_ENABLED read enable failed!");
861 ret = ERR_INVALID_DATA;
862 break;
863 }
864 int32_t status = SetPointerColorInversionEnabled(enable);
865 if (!reply.WriteInt32(status)) {
866 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_COLOR_INVERSION_ENABLED Write status failed!");
867 ret = ERR_INVALID_REPLY;
868 }
869 break;
870 }
871 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_POINTER_LUMINANCE_CALLBACK): {
872 auto remoteObject = data.ReadRemoteObject();
873 if (remoteObject == nullptr) {
874 ret = ERR_NULL_OBJECT;
875 break;
876 }
877 sptr<RSIPointerLuminanceChangeCallback> cb = iface_cast<RSIPointerLuminanceChangeCallback>(remoteObject);
878 if (cb == nullptr) {
879 ret = ERR_NULL_OBJECT;
880 break;
881 }
882 int32_t status = RegisterPointerLuminanceChangeCallback(cb);
883 if (!reply.WriteInt32(status)) {
884 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_POINTER_LUMINANCE_CALLBACK Write status failed!");
885 ret = ERR_INVALID_REPLY;
886 }
887 break;
888 }
889 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_POINTER_LUMINANCE_CALLBACK): {
890 int32_t status = UnRegisterPointerLuminanceChangeCallback();
891 if (!reply.WriteInt32(status)) {
892 RS_LOGE("RSRenderServiceConnectionStub::UNREGISTER_POINTER_LUMINANCE_CALLBACK Write status failed!");
893 ret = ERR_INVALID_REPLY;
894 }
895 break;
896 }
897 #endif
898 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_MODE): {
899 ScreenId id{INVALID_SCREEN_ID};
900 uint32_t modeId{0};
901 if (!data.ReadUint64(id) || !data.ReadUint32(modeId)) {
902 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_ACTIVE_MODE Read parcel failed!");
903 ret = ERR_INVALID_DATA;
904 break;
905 }
906 SetScreenActiveMode(id, modeId);
907 break;
908 }
909 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_REFRESH_RATE): {
910 ScreenId id{INVALID_SCREEN_ID};
911 int32_t sceneId{0};
912 int32_t rate{0};
913 if (!data.ReadUint64(id) || !data.ReadInt32(sceneId) || !data.ReadInt32(rate)) {
914 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_REFRESH_RATE Read parcel failed!");
915 ret = ERR_INVALID_DATA;
916 break;
917 }
918 SetScreenRefreshRate(id, sceneId, rate);
919 break;
920 }
921 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_REFRESH_RATE_MODE): {
922 int32_t mode{0};
923 if (!data.ReadInt32(mode)) {
924 RS_LOGE("RSRenderServiceConnectionStub::SET_REFRESH_RATE_MODE Read parcel failed!");
925 ret = ERR_INVALID_DATA;
926 break;
927 }
928 SetRefreshRateMode(mode);
929 break;
930 }
931 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SYNC_FRAME_RATE_RANGE): {
932 FrameRateLinkerId id{0};
933 if (!data.ReadUint64(id)) {
934 RS_LOGE("RSRenderServiceConnectionStub::SYNC_FRAME_RATE_RANGE Read id failed!");
935 ret = ERR_INVALID_DATA;
936 break;
937 }
938 if (ExtractPid(id) != callingPid) {
939 RS_LOGW("The SyncFrameRateRange isn't legal, frameRateLinkerId: %{public}" PRIu64
940 ", callingPid:%{public}d", id, callingPid);
941 ret = ERR_INVALID_DATA;
942 break;
943 }
944 uint32_t min{0};
945 uint32_t max{0};
946 uint32_t preferred{0};
947 uint32_t type{0};
948 uint32_t componentScene{0};
949 int32_t animatorExpectedFrameRate{0};
950 if (!data.ReadUint32(min) || !data.ReadUint32(max) || !data.ReadUint32(preferred) ||
951 !data.ReadUint32(type) || !data.ReadUint32(componentScene) ||
952 !data.ReadInt32(animatorExpectedFrameRate)) {
953 RS_LOGE("RSRenderServiceConnectionStub::SYNC_FRAME_RATE_RANGE Read parcel failed!");
954 ret = ERR_INVALID_DATA;
955 break;
956 }
957 SyncFrameRateRange(id, {min, max, preferred, type, static_cast<ComponentScene>(componentScene)},
958 animatorExpectedFrameRate);
959 break;
960 }
961 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_FRAME_RATE_LINKER): {
962 FrameRateLinkerId id{0};
963 if (!data.ReadUint64(id)) {
964 RS_LOGE("RSRenderServiceConnectionStub::UNREGISTER_FRAME_RATE_LINKER Read id failed!");
965 ret = ERR_INVALID_DATA;
966 break;
967 }
968 if (ExtractPid(id) != callingPid) {
969 RS_LOGW("The UnregisterFrameRateLinker isn't legal, frameRateLinkerId: %{public}" PRIu64
970 ", callingPid:%{public}d", id, callingPid);
971 ret = ERR_INVALID_DATA;
972 break;
973 }
974 UnregisterFrameRateLinker(id);
975 break;
976 }
977 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CURRENT_REFRESH_RATE): {
978 ScreenId id{INVALID_SCREEN_ID};
979 if (!data.ReadUint64(id)) {
980 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_CURRENT_REFRESH_RATE Read id failed!");
981 ret = ERR_INVALID_DATA;
982 break;
983 }
984 uint32_t refreshRate = GetScreenCurrentRefreshRate(id);
985 if (!reply.WriteUint32(refreshRate)) {
986 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_CURRENT_REFRESH_RATE Write refreshRate failed!");
987 ret = ERR_INVALID_REPLY;
988 }
989 break;
990 }
991 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_CURRENT_REFRESH_RATE_MODE): {
992 int32_t refreshRateMode = GetCurrentRefreshRateMode();
993 if (!reply.WriteInt32(refreshRateMode)) {
994 RS_LOGE("RSRenderServiceConnectionStub::GET_CURRENT_REFRESH_RATE_MODE Write refreshRateMode failed!");
995 ret = ERR_INVALID_REPLY;
996 }
997 break;
998 }
999 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_REFRESH_RATES): {
1000 ScreenId id{INVALID_SCREEN_ID};
1001 if (!data.ReadUint64(id)) {
1002 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_REFRESH_RATES Read id failed!");
1003 ret = ERR_INVALID_DATA;
1004 break;
1005 }
1006 std::vector<int32_t> rates = GetScreenSupportedRefreshRates(id);
1007 if (!reply.WriteUint64(static_cast<uint64_t>(rates.size()))) {
1008 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_REFRESH_RATES Write rates failed!");
1009 ret = ERR_INVALID_REPLY;
1010 break;
1011 }
1012 for (auto ratesIter : rates) {
1013 if (!reply.WriteInt32(ratesIter)) {
1014 RS_LOGE(
1015 "RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_REFRESH_RATES Write ratesIter failed!");
1016 ret = ERR_INVALID_REPLY;
1017 break;
1018 }
1019 }
1020 break;
1021 }
1022 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SHOW_REFRESH_RATE_ENABLED): {
1023 bool enabled = GetShowRefreshRateEnabled();
1024 if (!reply.WriteBool(enabled)) {
1025 RS_LOGE("RSRenderServiceConnectionStub::GET_SHOW_REFRESH_RATE_ENABLED Write enabled failed!");
1026 ret = ERR_INVALID_REPLY;
1027 }
1028 break;
1029 }
1030 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SHOW_REFRESH_RATE_ENABLED): {
1031 bool enabled{false};
1032 int32_t type{0};
1033 if (!data.ReadBool(enabled) || !data.ReadInt32(type)) {
1034 RS_LOGE("RSRenderServiceConnectionStub::GET_SHOW_REFRESH_RATE_ENABLED Read parcel failed!");
1035 ret = ERR_INVALID_DATA;
1036 break;
1037 }
1038 SetShowRefreshRateEnabled(enabled, type);
1039 break;
1040 }
1041 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REALTIME_REFRESH_RATE): {
1042 ScreenId id{INVALID_SCREEN_ID};
1043 if (!data.ReadUint64(id)) {
1044 RS_LOGE("RSRenderServiceConnectionStub::GET_REALTIME_REFRESH_RATE Read id failed!");
1045 ret = ERR_INVALID_DATA;
1046 break;
1047 }
1048 uint32_t refreshRate = GetRealtimeRefreshRate(id);
1049 if (!reply.WriteUint32(refreshRate)) {
1050 RS_LOGE("RSRenderServiceConnectionStub::GET_REALTIME_REFRESH_RATE Read refreshRate failed!");
1051 ret = ERR_INVALID_REPLY;
1052 }
1053 break;
1054 }
1055 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_REFRESH_INFO): {
1056 auto token = data.ReadInterfaceToken();
1057 if (token != RSIRenderServiceConnection::GetDescriptor()) {
1058 ret = ERR_INVALID_STATE;
1059 break;
1060 }
1061 int32_t pid{0};
1062 if (!data.ReadInt32(pid)) {
1063 RS_LOGE("RSRenderServiceConnectionStub::GET_REFRESH_INFO Read pid failed!");
1064 ret = ERR_INVALID_DATA;
1065 break;
1066 }
1067 if (!IsValidCallingPid(pid, callingPid)) {
1068 RS_LOGW("GET_REFRESH_INFO invalid pid[%{public}d]", callingPid);
1069 ret = ERR_INVALID_DATA;
1070 break;
1071 }
1072 std::string refreshInfo;
1073 if (GetRefreshInfo(pid, refreshInfo) != ERR_OK || !reply.WriteString(refreshInfo)) {
1074 RS_LOGE("RSRenderServiceConnectionStub::GET_REFRESH_INFO Write refreshInfo failed!");
1075 ret = ERR_INVALID_REPLY;
1076 }
1077 break;
1078 }
1079 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PHYSICAL_SCREEN_RESOLUTION): {
1080 ScreenId id{INVALID_SCREEN_ID};
1081 uint32_t width{0};
1082 uint32_t height{0};
1083 if (!data.ReadUint64(id) || !data.ReadUint32(width) || !data.ReadUint32(height)) {
1084 RS_LOGE("RSRenderServiceConnectionStub::SET_PHYSICAL_SCREEN_RESOLUTION Read parcel failed!");
1085 ret = ERR_INVALID_DATA;
1086 break;
1087 }
1088 int32_t status = SetPhysicalScreenResolution(id, width, height);
1089 if (!reply.WriteInt32(status)) {
1090 RS_LOGE("RSRenderServiceConnectionStub::SET_PHYSICAL_SCREEN_RESOLUTION Write status failed!");
1091 ret = ERR_INVALID_REPLY;
1092 }
1093 break;
1094 }
1095 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_RESOLUTION): {
1096 ScreenId id{INVALID_SCREEN_ID};
1097 uint32_t width{0};
1098 uint32_t height{0};
1099 if (!data.ReadUint64(id) || !data.ReadUint32(width) || !data.ReadUint32(height)) {
1100 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_RESOLUTION Read parcel failed!");
1101 ret = ERR_INVALID_DATA;
1102 break;
1103 }
1104 int32_t status = SetVirtualScreenResolution(id, width, height);
1105 if (!reply.WriteInt32(status)) {
1106 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_RESOLUTION Write status failed!");
1107 ret = ERR_INVALID_REPLY;
1108 }
1109 break;
1110 }
1111 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_DISPLAY_IDENTIFICATION_DATA): {
1112 ScreenId id{INVALID_SCREEN_ID};
1113 uint8_t outPort{0};
1114 std::vector<uint8_t> edidData{};
1115 if (!data.ReadUint64(id)) {
1116 RS_LOGE("RSRenderServiceConnectionStub::GET_DISPLAY_IDENTIFICATION_DATA Read parcel failed!");
1117 ret = ERR_INVALID_DATA;
1118 break;
1119 }
1120 int32_t result = GetDisplayIdentificationData(id, outPort, edidData);
1121 if (!reply.WriteUint8(result)) {
1122 RS_LOGE("RSRenderServiceConnectionStub::GET_DISPLAY_IDENTIFICATION_DATA Write result failed!");
1123 ret = IPC_STUB_WRITE_PARCEL_ERR;
1124 break;
1125 }
1126 if (result != SUCCESS) {
1127 break;
1128 }
1129 if (!reply.WriteUint8(outPort) ||
1130 !reply.WriteUint32(static_cast<uint32_t>(edidData.size())) ||
1131 !reply.WriteBuffer(edidData.data(), edidData.size())) {
1132 RS_LOGE("RSRenderServiceConnectionStub::GET_DISPLAY_IDENTIFICATION_DATA Write parcel failed!");
1133 ret = IPC_STUB_WRITE_PARCEL_ERR;
1134 }
1135 break;
1136 }
1137 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::MARK_POWER_OFF_NEED_PROCESS_ONE_FRAME): {
1138 MarkPowerOffNeedProcessOneFrame();
1139 break;
1140 }
1141 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPAINT_EVERYTHING): {
1142 RepaintEverything();
1143 break;
1144 }
1145 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::FORCE_REFRESH_ONE_FRAME_WITH_NEXT_VSYNC): {
1146 ForceRefreshOneFrameWithNextVSync();
1147 break;
1148 }
1149 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DISABLE_RENDER_CONTROL_SCREEN): {
1150 ScreenId id{INVALID_SCREEN_ID};
1151 if (!data.ReadUint64(id)) {
1152 RS_LOGE("RSRenderServiceConnectionStub::DISABLE_RENDER_CONTROL_SCREEN Read id failed!");
1153 ret = ERR_INVALID_DATA;
1154 break;
1155 }
1156 DisablePowerOffRenderControl(id);
1157 break;
1158 }
1159 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_POWER_STATUS): {
1160 ScreenId id{INVALID_SCREEN_ID};
1161 uint32_t status{0};
1162 if (!data.ReadUint64(id) || !data.ReadUint32(status)) {
1163 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_POWER_STATUS Read parcel failed!");
1164 ret = ERR_INVALID_DATA;
1165 break;
1166 }
1167 SetScreenPowerStatus(id, static_cast<ScreenPowerStatus>(status));
1168 break;
1169 }
1170 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SURFACE_CAPTURE): {
1171 NodeId id{0};
1172 if (!data.ReadUint64(id)) {
1173 RS_LOGE("RSRenderServiceConnectionStub::TAKE_SURFACE_CAPTURE Read parcel failed!");
1174 ret = ERR_INVALID_DATA;
1175 break;
1176 }
1177 RS_PROFILER_PATCH_NODE_ID(data, id);
1178 auto remoteObject = data.ReadRemoteObject();
1179 if (remoteObject == nullptr) {
1180 ret = ERR_NULL_OBJECT;
1181 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture remoteObject is nullptr");
1182 break;
1183 }
1184 sptr<RSISurfaceCaptureCallback> cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
1185 if (cb == nullptr) {
1186 ret = ERR_NULL_OBJECT;
1187 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture cb is nullptr");
1188 break;
1189 }
1190 RSSurfaceCaptureConfig captureConfig;
1191 RSSurfaceCaptureBlurParam blurParam;
1192 Drawing::Rect specifiedAreaRect;
1193 if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
1194 ret = ERR_INVALID_DATA;
1195 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture read captureConfig failed");
1196 break;
1197 }
1198 if (!ReadSurfaceCaptureBlurParam(blurParam, data)) {
1199 ret = ERR_INVALID_DATA;
1200 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture read blurParam failed");
1201 break;
1202 }
1203 if (!ReadSurfaceCaptureAreaRect(specifiedAreaRect, data)) {
1204 ret = ERR_INVALID_DATA;
1205 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture read specifiedAreaRect failed");
1206 break;
1207 }
1208 RSSurfaceCapturePermissions permissions;
1209 permissions.screenCapturePermission = accessible;
1210 permissions.isSystemCalling = RSInterfaceCodeAccessVerifierBase::IsSystemCalling(
1211 RSIRenderServiceConnectionInterfaceCodeAccessVerifier::codeEnumTypeName_ + "::TAKE_SURFACE_CAPTURE");
1212 // Since GetCallingPid interface always returns 0 in asynchronous binder in Linux kernel system,
1213 // we temporarily add a white list to avoid abnormal functionality or abnormal display.
1214 // The white list will be removed after GetCallingPid interface can return real PID.
1215 permissions.selfCapture = (ExtractPid(id) == callingPid || callingPid == 0);
1216 TakeSurfaceCapture(id, cb, captureConfig, blurParam, specifiedAreaRect, permissions);
1217 break;
1218 }
1219 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TAKE_SELF_SURFACE_CAPTURE): {
1220 NodeId id{0};
1221 if (!data.ReadUint64(id)) {
1222 ret = ERR_INVALID_DATA;
1223 break;
1224 }
1225 if (ExtractPid(id) != callingPid) {
1226 RS_LOGW("RSRenderServiceConnectionStub::TakeSelfSurfaceCapture failed, nodeId:[%{public}" PRIu64
1227 "], callingPid:[%{public}d], pid:[%{public}d]", id, callingPid, ExtractPid(id));
1228 ret = ERR_INVALID_DATA;
1229 break;
1230 }
1231 RS_PROFILER_PATCH_NODE_ID(data, id);
1232 auto remoteObject = data.ReadRemoteObject();
1233 if (remoteObject == nullptr) {
1234 ret = ERR_NULL_OBJECT;
1235 RS_LOGE("RSRenderServiceConnectionStub::TakeSelfSurfaceCapture remoteObject is nullptr");
1236 break;
1237 }
1238 sptr<RSISurfaceCaptureCallback> cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
1239 if (cb == nullptr) {
1240 ret = ERR_NULL_OBJECT;
1241 RS_LOGE("RSRenderServiceConnectionStub::TakeSelfSurfaceCapture cb is nullptr");
1242 break;
1243 }
1244 RSSurfaceCaptureConfig captureConfig;
1245 if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
1246 ret = ERR_INVALID_DATA;
1247 RS_LOGE("RSRenderServiceConnectionStub::TakeSelfSurfaceCapture read captureConfig failed");
1248 break;
1249 }
1250 TakeSelfSurfaceCapture(id, cb, captureConfig);
1251 break;
1252 }
1253 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WINDOW_FREEZE_IMMEDIATELY): {
1254 NodeId id{0};
1255 if (!data.ReadUint64(id)) {
1256 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY Read id failed!");
1257 ret = ERR_INVALID_DATA;
1258 break;
1259 }
1260 RS_PROFILER_PATCH_NODE_ID(data, id);
1261 bool isFreeze{false};
1262 if (!data.ReadBool(isFreeze)) {
1263 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY Read isFreeze failed!");
1264 ret = ERR_INVALID_DATA;
1265 break;
1266 }
1267 sptr<RSISurfaceCaptureCallback> cb;
1268 RSSurfaceCaptureConfig captureConfig;
1269 RSSurfaceCaptureBlurParam blurParam;
1270 if (isFreeze) {
1271 auto remoteObject = data.ReadRemoteObject();
1272 if (remoteObject == nullptr) {
1273 ret = ERR_NULL_OBJECT;
1274 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY remoteObject is nullptr");
1275 break;
1276 }
1277 cb = iface_cast<RSISurfaceCaptureCallback>(remoteObject);
1278 if (cb == nullptr) {
1279 ret = ERR_NULL_OBJECT;
1280 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY cb is nullptr");
1281 break;
1282 }
1283 if (!ReadSurfaceCaptureConfig(captureConfig, data)) {
1284 ret = ERR_INVALID_DATA;
1285 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_FREEZE_IMMEDIATELY write captureConfig failed");
1286 break;
1287 }
1288 if (!ReadSurfaceCaptureBlurParam(blurParam, data)) {
1289 ret = ERR_INVALID_DATA;
1290 RS_LOGE("RSRenderServiceConnectionStub::TakeSurfaceCapture read blurParam failed");
1291 break;
1292 }
1293 }
1294 SetWindowFreezeImmediately(id, isFreeze, cb, captureConfig, blurParam);
1295 break;
1296 }
1297 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_POINTER_POSITION): {
1298 NodeId id { 0 };
1299 if (!data.ReadUint64(id)) {
1300 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_POSITION read nodeId failed!");
1301 break;
1302 }
1303 RS_PROFILER_PATCH_NODE_ID(data, id);
1304 float positionX { 0.f };
1305 float positionY { 0.f };
1306 float positionZ { 0.f };
1307 float positionW { 0.f };
1308 if (!data.ReadFloat(positionX) || !data.ReadFloat(positionY) || !data.ReadFloat(positionZ) ||
1309 !data.ReadFloat(positionW)) {
1310 RS_LOGE("RSRenderServiceConnectionStub::SET_POINTER_POSITION read position failed!");
1311 ret = ERR_INVALID_DATA;
1312 break;
1313 }
1314 SetHwcNodeBounds(id, positionX, positionY, positionZ, positionW);
1315 break;
1316 }
1317 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_APPLICATION_AGENT): {
1318 pid_t pid = GetCallingPid();
1319 RS_PROFILER_PATCH_PID(data, pid);
1320 auto remoteObject = data.ReadRemoteObject();
1321 if (remoteObject == nullptr) {
1322 ret = ERR_NULL_OBJECT;
1323 break;
1324 }
1325 sptr<IApplicationAgent> app = iface_cast<IApplicationAgent>(remoteObject);
1326 if (app == nullptr) {
1327 ret = ERR_NULL_OBJECT;
1328 break;
1329 }
1330 RegisterApplicationAgent(pid, app);
1331 break;
1332 }
1333 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_VIRTUAL_SCREEN_RESOLUTION): {
1334 ScreenId id{INVALID_SCREEN_ID};
1335 if (!data.ReadUint64(id)) {
1336 RS_LOGE("RSRenderServiceConnectionStub::GET_VIRTUAL_SCREEN_RESOLUTION Read id failed!");
1337 ret = ERR_INVALID_DATA;
1338 break;
1339 }
1340 RSVirtualScreenResolution virtualScreenResolution = GetVirtualScreenResolution(id);
1341 if (!reply.WriteParcelable(&virtualScreenResolution)) {
1342 RS_LOGE("RSRenderServiceConnectionStub::GET_VIRTUAL_SCREEN_RESOLUTION Write virtualScreenResolution "
1343 "failed!");
1344 ret = ERR_INVALID_REPLY;
1345 }
1346 break;
1347 }
1348 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_ACTIVE_MODE): {
1349 ScreenId id{INVALID_SCREEN_ID};
1350 if (!data.ReadUint64(id)) {
1351 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_ACTIVE_MODE Read id failed!");
1352 ret = ERR_INVALID_DATA;
1353 break;
1354 }
1355 RSScreenModeInfo screenModeInfo = GetScreenActiveMode(id);
1356 if (!reply.WriteParcelable(&screenModeInfo)) {
1357 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_ACTIVE_MODE Write screenModeInfo failed!");
1358 ret = ERR_INVALID_REPLY;
1359 }
1360 break;
1361 }
1362 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_MODES): {
1363 ScreenId id{INVALID_SCREEN_ID};
1364 if (!data.ReadUint64(id)) {
1365 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_MODES Read id failed!");
1366 ret = ERR_INVALID_DATA;
1367 break;
1368 }
1369 std::vector<RSScreenModeInfo> screenSupportedModes = GetScreenSupportedModes(id);
1370 if (!reply.WriteUint64(static_cast<uint64_t>(screenSupportedModes.size()))) {
1371 RS_LOGE(
1372 "RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_MODES Write screenSupportedModesSize failed!");
1373 ret = ERR_INVALID_REPLY;
1374 break;
1375 }
1376 for (uint32_t modeIndex = 0; modeIndex < screenSupportedModes.size(); modeIndex++) {
1377 if (!reply.WriteParcelable(&screenSupportedModes[modeIndex])) {
1378 RS_LOGE(
1379 "RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_MODES Write screenSupportedModes failed!");
1380 ret = ERR_INVALID_REPLY;
1381 break;
1382 }
1383 }
1384 break;
1385 }
1386 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHIC): {
1387 int32_t pid{0};
1388 if (!data.ReadInt32(pid)) {
1389 RS_LOGE("RSRenderServiceConnectionStub::GET_MEMORY_GRAPHIC Read pid failed!");
1390 ret = ERR_INVALID_DATA;
1391 break;
1392 }
1393 RS_PROFILER_PATCH_PID(data, pid);
1394 if (!IsValidCallingPid(pid, callingPid)) {
1395 RS_LOGW("GET_MEMORY_GRAPHIC invalid pid[%{public}d]", callingPid);
1396 ret = ERR_INVALID_DATA;
1397 break;
1398 }
1399 MemoryGraphic memoryGraphic;
1400 if (GetMemoryGraphic(pid, memoryGraphic) != ERR_OK || !reply.WriteParcelable(&memoryGraphic)) {
1401 RS_LOGE("RSRenderServiceConnectionStub::GET_MEMORY_GRAPHIC Write memoryGraphic failed!");
1402 ret = ERR_INVALID_REPLY;
1403 }
1404 break;
1405 }
1406 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_MEMORY_GRAPHICS): {
1407 std::vector<MemoryGraphic> memoryGraphics;
1408 if (GetMemoryGraphics(memoryGraphics) != ERR_OK ||
1409 !reply.WriteUint64(static_cast<uint64_t>(memoryGraphics.size()))) {
1410 RS_LOGE("RSRenderServiceConnectionStub::GET_MEMORY_GRAPHIC Write memoryGraphicsSize failed!");
1411 ret = ERR_INVALID_REPLY;
1412 break;
1413 }
1414 for (uint32_t index = 0; index < memoryGraphics.size(); index++) {
1415 if (!reply.WriteParcelable(&memoryGraphics[index])) {
1416 RS_LOGE("RSRenderServiceConnectionStub::GET_MEMORY_GRAPHIC Write memoryGraphics failed!");
1417 ret = ERR_INVALID_REPLY;
1418 break;
1419 }
1420 }
1421 break;
1422 }
1423 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_TOTAL_APP_MEM_SIZE): {
1424 float cpuMemSize = 0.f;
1425 float gpuMemSize = 0.f;
1426 bool success;
1427 if (GetTotalAppMemSize(cpuMemSize, gpuMemSize, success) != ERR_OK || !success ||
1428 !reply.WriteFloat(cpuMemSize) || !reply.WriteFloat(gpuMemSize)) {
1429 RS_LOGE("RSRenderServiceConnectionStub::GET_TOTAL_APP_MEM_SIZE Write parcel failed!");
1430 ret = ERR_INVALID_REPLY;
1431 }
1432 break;
1433 }
1434 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_CAPABILITY): {
1435 ScreenId id{INVALID_SCREEN_ID};
1436 if (!data.ReadUint64(id)) {
1437 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_CAPABILITY Read id failed!");
1438 ret = ERR_INVALID_DATA;
1439 break;
1440 }
1441 RSScreenCapability screenCapability = GetScreenCapability(id);
1442 if (!reply.WriteParcelable(&screenCapability)) {
1443 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_CAPABILITY Write screenCapability failed!");
1444 ret = ERR_INVALID_REPLY;
1445 }
1446 break;
1447 }
1448 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_POWER_STATUS): {
1449 ScreenId id{INVALID_SCREEN_ID};
1450 if (!data.ReadUint64(id)) {
1451 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_POWER_STATUS Read id failed!");
1452 ret = ERR_INVALID_DATA;
1453 break;
1454 }
1455 ScreenPowerStatus status = GetScreenPowerStatus(id);
1456 if (!reply.WriteUint32(static_cast<uint32_t>(status))) {
1457 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_POWER_STATUS Write status failed!");
1458 ret = ERR_INVALID_REPLY;
1459 }
1460 break;
1461 }
1462 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_DATA): {
1463 ScreenId id{INVALID_SCREEN_ID};
1464 if (!data.ReadUint64(id)) {
1465 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_DATA Read id failed!");
1466 ret = ERR_INVALID_DATA;
1467 break;
1468 }
1469 RSScreenData screenData = GetScreenData(id);
1470 if (!reply.WriteParcelable(&screenData)) {
1471 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_DATA Write screenData failed!");
1472 ret = ERR_INVALID_REPLY;
1473 }
1474 break;
1475 }
1476 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_BACK_LIGHT): {
1477 ScreenId id{INVALID_SCREEN_ID};
1478 if (!data.ReadUint64(id)) {
1479 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_BACK_LIGHT Read id failed!");
1480 ret = ERR_INVALID_DATA;
1481 break;
1482 }
1483 int32_t level = GetScreenBacklight(id);
1484 if (!reply.WriteInt32(level)) {
1485 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_BACK_LIGHT Write level failed!");
1486 ret = ERR_INVALID_REPLY;
1487 }
1488 break;
1489 }
1490 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_BACK_LIGHT): {
1491 ScreenId id{INVALID_SCREEN_ID};
1492 uint32_t level{0};
1493 if (!data.ReadUint64(id) || !data.ReadUint32(level)) {
1494 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_BACK_LIGHT Read parcel failed!");
1495 ret = ERR_INVALID_DATA;
1496 break;
1497 }
1498 SetScreenBacklight(id, level);
1499 break;
1500 }
1501 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_AVAILABLE_LISTENER): {
1502 NodeId id{0};
1503 if (!data.ReadUint64(id)) {
1504 RS_LOGE("RSRenderServiceConnectionStub::SET_BUFFER_AVAILABLE_LISTENER Read id failed!");
1505 ret = ERR_INVALID_DATA;
1506 break;
1507 }
1508 if (!accessible && (ExtractPid(id) != callingPid)) {
1509 RS_LOGW("The SetBufferAvailableListener isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1510 id, callingPid);
1511 break;
1512 }
1513 RS_PROFILER_PATCH_NODE_ID(data, id);
1514 auto remoteObject = data.ReadRemoteObject();
1515 bool isFromRenderThread{false};
1516 if (!data.ReadBool(isFromRenderThread)) {
1517 RS_LOGE("RSRenderServiceConnectionStub::SET_BUFFER_AVAILABLE_LISTENER read isFromRenderThread failed!");
1518 ret = ERR_INVALID_DATA;
1519 break;
1520 }
1521 if (remoteObject == nullptr) {
1522 ret = ERR_NULL_OBJECT;
1523 break;
1524 }
1525 sptr<RSIBufferAvailableCallback> cb = iface_cast<RSIBufferAvailableCallback>(remoteObject);
1526 if (cb == nullptr) {
1527 ret = ERR_NULL_OBJECT;
1528 break;
1529 }
1530 RegisterBufferAvailableListener(id, cb, isFromRenderThread);
1531 break;
1532 }
1533 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_BUFFER_CLEAR_LISTENER): {
1534 NodeId id{0};
1535 if (!data.ReadUint64(id)) {
1536 RS_LOGE("RSRenderServiceConnectionStub::SET_BUFFER_CLEAR_LISTENER Read id failed!");
1537 ret = ERR_INVALID_DATA;
1538 break;
1539 }
1540 if (!accessible && (ExtractPid(id) != callingPid)) {
1541 RS_LOGW("The SetBufferClearListener isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
1542 id, callingPid);
1543 break;
1544 }
1545 RS_PROFILER_PATCH_NODE_ID(data, id);
1546 auto remoteObject = data.ReadRemoteObject();
1547 if (remoteObject == nullptr) {
1548 ret = ERR_NULL_OBJECT;
1549 break;
1550 }
1551 sptr<RSIBufferClearCallback> cb = iface_cast<RSIBufferClearCallback>(remoteObject);
1552 if (cb == nullptr) {
1553 ret = ERR_NULL_OBJECT;
1554 break;
1555 }
1556 RegisterBufferClearListener(id, cb);
1557 break;
1558 }
1559 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_GAMUTS): {
1560 ScreenId id{INVALID_SCREEN_ID};
1561 if (!data.ReadUint64(id)) {
1562 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_GAMUTS Read id failed!");
1563 ret = ERR_INVALID_DATA;
1564 break;
1565 }
1566 std::vector<uint32_t> modeSend;
1567 std::vector<ScreenColorGamut> mode;
1568 int32_t result = GetScreenSupportedColorGamuts(id, mode);
1569 if (!reply.WriteInt32(result)) {
1570 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_GAMUTS Write result failed!");
1571 ret = ERR_INVALID_REPLY;
1572 break;
1573 }
1574 if (result != StatusCode::SUCCESS) {
1575 ret = ERR_UNKNOWN_REASON;
1576 break;
1577 }
1578 std::copy(mode.begin(), mode.end(), std::back_inserter(modeSend));
1579 if (!reply.WriteUInt32Vector(modeSend)) {
1580 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_GAMUTS Write modeSend failed!");
1581 ret = ERR_INVALID_REPLY;
1582 }
1583 break;
1584 }
1585 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_METADATAKEYS): {
1586 ScreenId id{INVALID_SCREEN_ID};
1587 if (!data.ReadUint64(id)) {
1588 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_METADATAKEYS Read id failed!");
1589 ret = ERR_INVALID_DATA;
1590 break;
1591 }
1592 std::vector<uint32_t> keySend;
1593 std::vector<ScreenHDRMetadataKey> keys;
1594 int32_t result = GetScreenSupportedMetaDataKeys(id, keys);
1595 if (!reply.WriteInt32(result)) {
1596 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_METADATAKEYS Write result failed!");
1597 ret = ERR_INVALID_REPLY;
1598 break;
1599 }
1600 if (result != StatusCode::SUCCESS) {
1601 ret = ERR_UNKNOWN_REASON;
1602 break;
1603 }
1604 for (auto i : keys) {
1605 keySend.push_back(i);
1606 }
1607 if (!reply.WriteUInt32Vector(keySend)) {
1608 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_METADATAKEYS Write keySend failed!");
1609 ret = ERR_INVALID_REPLY;
1610 }
1611 break;
1612 }
1613 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT): {
1614 ScreenId id{INVALID_SCREEN_ID};
1615 if (!data.ReadUint64(id)) {
1616 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT Read id failed!");
1617 ret = ERR_INVALID_DATA;
1618 break;
1619 }
1620 ScreenColorGamut mode;
1621 int32_t result = GetScreenColorGamut(id, mode);
1622 if (!reply.WriteInt32(result)) {
1623 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT Write result failed!");
1624 ret = ERR_INVALID_REPLY;
1625 break;
1626 }
1627 if (result != StatusCode::SUCCESS) {
1628 ret = ERR_UNKNOWN_REASON;
1629 break;
1630 }
1631 if (!reply.WriteUint32(mode)) {
1632 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT Write mode failed!");
1633 ret = ERR_INVALID_REPLY;
1634 }
1635 break;
1636 }
1637 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT): {
1638 ScreenId id{INVALID_SCREEN_ID};
1639 int32_t modeIdx{0};
1640 if (!data.ReadUint64(id) || !data.ReadInt32(modeIdx)) {
1641 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_GAMUT Read parcel failed!");
1642 ret = ERR_INVALID_DATA;
1643 break;
1644 }
1645 int32_t result = SetScreenColorGamut(id, modeIdx);
1646 if (!reply.WriteInt32(result)) {
1647 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_GAMUT Write result failed!");
1648 ret = ERR_INVALID_REPLY;
1649 }
1650 break;
1651 }
1652 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_GAMUT_MAP): {
1653 ScreenId id{INVALID_SCREEN_ID};
1654 int32_t mode{0};
1655 if (!data.ReadUint64(id) || !data.ReadInt32(mode)) {
1656 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_GAMUT_MAP Read parcel failed!");
1657 ret = ERR_INVALID_DATA;
1658 break;
1659 }
1660 int32_t result = SetScreenGamutMap(id, static_cast<ScreenGamutMap>(mode));
1661 if (!reply.WriteInt32(result)) {
1662 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_GAMUT_MAP Write parcel failed!");
1663 ret = ERR_INVALID_REPLY;
1664 }
1665 break;
1666 }
1667 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_CORRECTION): {
1668 ScreenId id{INVALID_SCREEN_ID};
1669 int32_t screenRotation{0};
1670 if (!data.ReadUint64(id) || !data.ReadInt32(screenRotation)) {
1671 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_CORRECTION Read parcel failed!");
1672 ret = ERR_INVALID_DATA;
1673 break;
1674 }
1675 int32_t result = SetScreenCorrection(id, static_cast<ScreenRotation>(screenRotation));
1676 if (!reply.WriteInt32(result)) {
1677 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_CORRECTION Write parcel failed!");
1678 ret = ERR_INVALID_REPLY;
1679 }
1680 break;
1681 }
1682 case static_cast<uint32_t>(
1683 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION): {
1684 ScreenId id{INVALID_SCREEN_ID};
1685 bool canvasRotation{false};
1686 if (!data.ReadUint64(id) || !data.ReadBool(canvasRotation)) {
1687 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION Read parcel failed!");
1688 ret = ERR_INVALID_DATA;
1689 break;
1690 }
1691 bool result = SetVirtualMirrorScreenCanvasRotation(id, canvasRotation);
1692 if (!reply.WriteBool(result)) {
1693 RS_LOGE(
1694 "RSRenderServiceConnectionStub::SET_VIRTUAL_MIRROR_SCREEN_CANVAS_ROTATION Write parcel failed!");
1695 ret = ERR_INVALID_REPLY;
1696 }
1697 break;
1698 }
1699 case static_cast<uint32_t>(
1700 RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE): {
1701 ScreenId id{INVALID_SCREEN_ID};
1702 uint32_t scaleMode{0};
1703 if (!data.ReadUint64(id) || !data.ReadUint32(scaleMode)) {
1704 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE Read parcel failed!");
1705 ret = ERR_INVALID_DATA;
1706 break;
1707 }
1708 bool result = SetVirtualMirrorScreenScaleMode(id, static_cast<ScreenScaleMode>(scaleMode));
1709 if (!reply.WriteBool(result)) {
1710 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_MIRROR_SCREEN_SCALE_MODE Write parcel failed!");
1711 ret = ERR_INVALID_REPLY;
1712 }
1713 break;
1714 }
1715 case static_cast<uint32_t>(
1716 RSIRenderServiceConnectionInterfaceCode::SET_GLOBAL_DARK_COLOR_MODE): {
1717 bool isDark{false};
1718 if (!data.ReadBool(isDark)) {
1719 RS_LOGE("RSRenderServiceConnectionStub::SET_GLOBAL_DARK_COLOR_MODE Read parcel failed!");
1720 ret = ERR_INVALID_DATA;
1721 break;
1722 }
1723 bool result = SetGlobalDarkColorMode(isDark);
1724 if (!reply.WriteBool(result)) {
1725 RS_LOGE("RSRenderServiceConnectionStub::SET_GLOBAL_DARK_COLOR_MODE Write result failed!");
1726 ret = ERR_INVALID_REPLY;
1727 }
1728 break;
1729 }
1730 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_GAMUT_MAP): {
1731 ScreenId id{INVALID_SCREEN_ID};
1732 if (!data.ReadUint64(id)) {
1733 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT_MAP Read parcel failed!");
1734 ret = ERR_INVALID_DATA;
1735 break;
1736 }
1737 ScreenGamutMap mode;
1738 int32_t result = GetScreenGamutMap(id, mode);
1739 if (!reply.WriteInt32(result)) {
1740 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT_MAP Write result failed!");
1741 ret = ERR_INVALID_REPLY;
1742 break;
1743 }
1744 if (result != StatusCode::SUCCESS) {
1745 ret = ERR_UNKNOWN_REASON;
1746 break;
1747 }
1748 if (!reply.WriteUint32(mode)) {
1749 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_GAMUT_MAP Write mode failed!");
1750 ret = ERR_INVALID_REPLY;
1751 }
1752 break;
1753 }
1754 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_VSYNC_CONNECTION): {
1755 std::string name;
1756 if (!data.ReadString(name)) {
1757 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VSYNC_CONNECTION read name failed!");
1758 ret = ERR_INVALID_DATA;
1759 break;
1760 }
1761 auto remoteObj = data.ReadRemoteObject();
1762 uint64_t id{0};
1763 NodeId windowNodeID{0};
1764 if (!data.ReadUint64(id) || !data.ReadUint64(windowNodeID)) {
1765 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VSYNC_CONNECTION read parcel failed!");
1766 ret = ERR_INVALID_DATA;
1767 break;
1768 }
1769 if (remoteObj == nullptr) {
1770 ret = ERR_NULL_OBJECT;
1771 break;
1772 }
1773 if (!remoteObj->IsProxyObject()) {
1774 ret = ERR_UNKNOWN_OBJECT;
1775 break;
1776 }
1777 auto token = iface_cast<VSyncIConnectionToken>(remoteObj);
1778 if (token == nullptr) {
1779 ret = ERR_UNKNOWN_OBJECT;
1780 break;
1781 }
1782 sptr<IVSyncConnection> conn = CreateVSyncConnection(name, token, id, windowNodeID);
1783 if (conn == nullptr) {
1784 ret = ERR_NULL_OBJECT;
1785 break;
1786 }
1787 #ifdef ENABLE_IPC_SECURITY_ACCESS_COUNTER
1788 securityUtils_.IncreaseAccessCounter(code);
1789 #endif
1790 if (!reply.WriteRemoteObject(conn->AsObject())) {
1791 RS_LOGE("RSRenderServiceConnectionStub::CREATE_VSYNC_CONNECTION Write Object failed!");
1792 ret = ERR_INVALID_REPLY;
1793 }
1794 break;
1795 }
1796 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP_BY_PROCESSID): {
1797 uint64_t pid;
1798 if (!data.ReadUint64(pid)) {
1799 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXELMAP_BY_PROCESSID Read pid failed!");
1800 ret = ERR_INVALID_DATA;
1801 break;
1802 }
1803 std::vector<PixelMapInfo> pixelMapInfoVector;
1804 int32_t repCode;
1805 if (GetPixelMapByProcessId(pixelMapInfoVector, static_cast<pid_t>(pid), repCode) != ERR_OK ||
1806 !reply.WriteInt32(repCode)) {
1807 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXELMAP_BY_PROCESSID Write repCode failed!");
1808 ret = ERR_INVALID_REPLY;
1809 break;
1810 }
1811 if (!RSMarshallingHelper::MarshallingVec(reply, pixelMapInfoVector)) {
1812 ret = ERR_INVALID_REPLY;
1813 break;
1814 }
1815 break;
1816 }
1817 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_PIXEL_MAP_FROM_SURFACE): {
1818 auto remoteObject = data.ReadRemoteObject();
1819 if (remoteObject == nullptr) {
1820 if (!reply.WriteInt32(0)) {
1821 RS_LOGE("RSRenderServiceConnectionStub::CREATE_PIXEL_MAP_FROM_SURFACE Write Object failed!");
1822 ret = ERR_INVALID_REPLY;
1823 break;
1824 }
1825 ret = ERR_NULL_OBJECT;
1826 break;
1827 }
1828 auto bufferProducer = iface_cast<IBufferProducer>(remoteObject);
1829 sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bufferProducer);
1830 if (surface == nullptr) {
1831 if (!reply.WriteInt32(0)) {
1832 RS_LOGE("RSRenderServiceConnectionStub::CREATE_PIXEL_MAP_FROM_SURFACE Write parcel failed!");
1833 ret = ERR_INVALID_REPLY;
1834 break;
1835 }
1836 ret = ERR_NULL_OBJECT;
1837 break;
1838 }
1839 int32_t x = 0;
1840 int32_t y = 0;
1841 int32_t w = 0;
1842 int32_t h = 0;
1843 if (!data.ReadInt32(x) || !data.ReadInt32(y) || !data.ReadInt32(w) || !data.ReadInt32(h)) {
1844 RS_LOGE("RSRenderServiceConnectionStub::CREATE_PIXEL_MAP_FROM_SURFACE Read parcel failed!");
1845 ret = ERR_INVALID_DATA;
1846 break;
1847 }
1848 auto srcRect = Rect {
1849 .x = x,
1850 .y = y,
1851 .w = w,
1852 .h = h
1853 };
1854 std::shared_ptr<Media::PixelMap> pixelMap = nullptr;
1855 CreatePixelMapFromSurface(surface, srcRect, pixelMap);
1856 if (pixelMap) {
1857 if (!reply.WriteBool(true)) {
1858 RS_LOGE("RSRenderServiceConnectionStub::CREATE_PIXEL_MAP_FROM_SURFACE Read parcel failed");
1859 ret = ERR_INVALID_REPLY;
1860 break;
1861 }
1862 if (!pixelMap->Marshalling(reply)) {
1863 RS_LOGE("pixelMap Marshalling fail");
1864 ret = ERR_INVALID_REPLY;
1865 }
1866 } else {
1867 if (!reply.WriteBool(false)) {
1868 RS_LOGE("RSRenderServiceConnectionStub::CREATE_PIXEL_MAP_FROM_SURFACE Read parcel failed!");
1869 ret = ERR_INVALID_REPLY;
1870 break;
1871 }
1872 }
1873 break;
1874 }
1875 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_CAPABILITY): {
1876 ScreenId id{INVALID_SCREEN_ID};
1877 if (!data.ReadUint64(id)) {
1878 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_CAPABILITY Read id failed!");
1879 ret = ERR_INVALID_DATA;
1880 break;
1881 }
1882 RSScreenHDRCapability screenHDRCapability;
1883 int32_t result = GetScreenHDRCapability(id, screenHDRCapability);
1884 if (!reply.WriteInt32(result)) {
1885 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_CAPABILITY Write result failed!");
1886 ret = ERR_INVALID_REPLY;
1887 break;
1888 }
1889 if (result != StatusCode::SUCCESS) {
1890 ret = ERR_UNKNOWN_REASON;
1891 break;
1892 }
1893 if (!reply.WriteParcelable(&screenHDRCapability)) {
1894 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_CAPABILITY Write screenHDRCapability failed!");
1895 ret = ERR_INVALID_REPLY;
1896 }
1897 break;
1898 }
1899 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXEL_FORMAT): {
1900 ScreenId id{INVALID_SCREEN_ID};
1901 if (!data.ReadUint64(id)) {
1902 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXEL_FORMAT Read id failed!");
1903 ret = ERR_INVALID_DATA;
1904 break;
1905 }
1906 GraphicPixelFormat pixelFormat;
1907 int32_t resCode;
1908 GetPixelFormat(id, pixelFormat, resCode);
1909 if (!reply.WriteInt32(resCode)) {
1910 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXEL_FORMAT Write result failed!");
1911 ret = ERR_INVALID_REPLY;
1912 break;
1913 }
1914 if (resCode != StatusCode::SUCCESS) {
1915 break;
1916 }
1917 if (!reply.WriteUint32(static_cast<uint32_t>(pixelFormat))) {
1918 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXEL_FORMAT Write pixelFormat failed!");
1919 ret = ERR_INVALID_REPLY;
1920 }
1921 break;
1922 }
1923 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_PIXEL_FORMAT): {
1924 ScreenId id{INVALID_SCREEN_ID};
1925 if (!data.ReadUint64(id)) {
1926 RS_LOGE("RSRenderServiceConnectionStub::SET_PIXEL_FORMAT Read id failed!");
1927 ret = ERR_INVALID_DATA;
1928 break;
1929 }
1930 int32_t pixel{0};
1931 if (!data.ReadInt32(pixel)) {
1932 RS_LOGE("RSRenderServiceConnectionStub::SET_PIXEL_FORMAT read pixelFormat failed!");
1933 ret = ERR_INVALID_DATA;
1934 break;
1935 }
1936 GraphicPixelFormat pixelFormat = static_cast<GraphicPixelFormat>(pixel);
1937 int32_t resCode;
1938 SetPixelFormat(id, pixelFormat, resCode);
1939 if (!reply.WriteInt32(resCode)) {
1940 RS_LOGE("RSRenderServiceConnectionStub::SET_PIXEL_FORMAT Write result failed!");
1941 ret = ERR_INVALID_REPLY;
1942 }
1943 break;
1944 }
1945 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_HDR_FORMATS): {
1946 ScreenId id{INVALID_SCREEN_ID};
1947 if (!data.ReadUint64(id)) {
1948 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_HDR_FORMATS Read id failed!");
1949 ret = ERR_INVALID_DATA;
1950 break;
1951 }
1952 std::vector<uint32_t> hdrFormatsSend;
1953 std::vector<ScreenHDRFormat> hdrFormats;
1954 int32_t resCode;
1955 GetScreenSupportedHDRFormats(id, hdrFormats, resCode);
1956 if (!reply.WriteInt32(resCode)) {
1957 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_HDR_FORMATS Write result failed!");
1958 ret = ERR_INVALID_REPLY;
1959 break;
1960 }
1961 if (resCode != StatusCode::SUCCESS) {
1962 break;
1963 }
1964 std::copy(hdrFormats.begin(), hdrFormats.end(), std::back_inserter(hdrFormatsSend));
1965 if (!reply.WriteUInt32Vector(hdrFormatsSend)) {
1966 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_HDR_FORMATS Write hdrFormatsSend failed!");
1967 ret = ERR_INVALID_REPLY;
1968 }
1969 break;
1970 }
1971 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_HDR_FORMAT): {
1972 ScreenId id{INVALID_SCREEN_ID};
1973 if (!data.ReadUint64(id)) {
1974 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_FORMAT Read id failed!");
1975 ret = ERR_INVALID_DATA;
1976 break;
1977 }
1978 ScreenHDRFormat hdrFormat;
1979 int32_t resCode;
1980 GetScreenHDRFormat(id, hdrFormat, resCode);
1981 if (!reply.WriteInt32(resCode)) {
1982 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_FORMAT Write resCode failed!");
1983 ret = ERR_INVALID_REPLY;
1984 break;
1985 }
1986 if (resCode != StatusCode::SUCCESS) {
1987 break;
1988 }
1989 if (!reply.WriteUint32(hdrFormat)) {
1990 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_HDR_FORMAT Write hdrFormat failed!");
1991 ret = ERR_INVALID_REPLY;
1992 }
1993 break;
1994 }
1995 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_HDR_FORMAT): {
1996 ScreenId id{INVALID_SCREEN_ID};
1997 int32_t modeIdx{0};
1998 if (!data.ReadUint64(id) || !data.ReadInt32(modeIdx)) {
1999 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_HDR_FORMAT Read parcel failed!");
2000 ret = ERR_INVALID_DATA;
2001 break;
2002 }
2003 int32_t resCode;
2004 SetScreenHDRFormat(id, modeIdx, resCode);
2005 if (!reply.WriteInt32(resCode)) {
2006 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_HDR_FORMAT Write resCode failed!");
2007 ret = ERR_INVALID_REPLY;
2008 }
2009 break;
2010 }
2011 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_SUPPORTED_COLORSPACES): {
2012 ScreenId id{INVALID_SCREEN_ID};
2013 if (!data.ReadUint64(id)) {
2014 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_COLORSPACES Read parcel failed!");
2015 ret = ERR_INVALID_DATA;
2016 break;
2017 }
2018 std::vector<uint32_t> colorSpacesSend;
2019 std::vector<GraphicCM_ColorSpaceType> colorSpaces;
2020 int32_t resCode;
2021 GetScreenSupportedColorSpaces(id, colorSpaces, resCode);
2022 if (!reply.WriteInt32(resCode)) {
2023 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_COLORSPACES Write resCode failed!");
2024 ret = ERR_INVALID_REPLY;
2025 break;
2026 }
2027 if (resCode != StatusCode::SUCCESS) {
2028 break;
2029 }
2030 std::copy(colorSpaces.begin(), colorSpaces.end(), std::back_inserter(colorSpacesSend));
2031 if (!reply.WriteUInt32Vector(colorSpacesSend)) {
2032 RS_LOGE(
2033 "RSRenderServiceConnectionStub::GET_SCREEN_SUPPORTED_COLORSPACES Write colorSpacesSend failed!");
2034 ret = ERR_INVALID_REPLY;
2035 }
2036 break;
2037 }
2038 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_COLORSPACE): {
2039 ScreenId id{INVALID_SCREEN_ID};
2040 if (!data.ReadUint64(id)) {
2041 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_COLORSPACE Read parcel failed!");
2042 ret = ERR_INVALID_DATA;
2043 break;
2044 }
2045 GraphicCM_ColorSpaceType colorSpace;
2046 int32_t resCode;
2047 GetScreenColorSpace(id, colorSpace, resCode);
2048 if (!reply.WriteInt32(resCode)) {
2049 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_COLORSPACE Write result failed!");
2050 ret = ERR_INVALID_REPLY;
2051 break;
2052 }
2053 if (resCode != StatusCode::SUCCESS) {
2054 break;
2055 }
2056 if (!reply.WriteUint32(colorSpace)) {
2057 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_COLORSPACE Write colorSpace failed!");
2058 ret = ERR_INVALID_REPLY;
2059 }
2060 break;
2061 }
2062 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_COLORSPACE): {
2063 ScreenId id{INVALID_SCREEN_ID};
2064 if (!data.ReadUint64(id)) {
2065 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_COLORSPACE Read id failed!");
2066 ret = ERR_INVALID_DATA;
2067 break;
2068 }
2069 int32_t color{0};
2070 if (!data.ReadInt32(color)) {
2071 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_COLORSPACE read colorSpace failed!");
2072 ret = ERR_INVALID_DATA;
2073 break;
2074 }
2075 GraphicCM_ColorSpaceType colorSpace = static_cast<GraphicCM_ColorSpaceType>(color);
2076 int32_t resCode;
2077 SetScreenColorSpace(id, colorSpace, resCode);
2078 if (!reply.WriteInt32(resCode)) {
2079 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_COLORSPACE Write result failed!");
2080 ret = ERR_INVALID_REPLY;
2081 }
2082 break;
2083 }
2084 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_SCREEN_TYPE): {
2085 ScreenId id{INVALID_SCREEN_ID};
2086 if (!data.ReadUint64(id)) {
2087 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_TYPE Read id failed!");
2088 ret = ERR_INVALID_DATA;
2089 break;
2090 }
2091 RSScreenType type;
2092 int32_t result = GetScreenType(id, type);
2093 if (!reply.WriteInt32(result)) {
2094 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_TYPE Write result failed!");
2095 ret = ERR_INVALID_REPLY;
2096 break;
2097 }
2098 if (result != StatusCode::SUCCESS) {
2099 ret = ERR_UNKNOWN_REASON;
2100 break;
2101 }
2102 if (!reply.WriteUint32(type)) {
2103 RS_LOGE("RSRenderServiceConnectionStub::GET_SCREEN_TYPE Write type failed!");
2104 ret = ERR_INVALID_REPLY;
2105 }
2106 break;
2107 }
2108 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_BITMAP): {
2109 NodeId id{0};
2110 if (!data.ReadUint64(id)) {
2111 RS_LOGE("RSRenderServiceConnectionStub::GET_BITMAP Read id failed!");
2112 ret = ERR_INVALID_DATA;
2113 break;
2114 }
2115 if (!IsValidCallingPid(ExtractPid(id), callingPid)) {
2116 RS_LOGW("The GetBitmap isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
2117 id, callingPid);
2118 break;
2119 }
2120 RS_PROFILER_PATCH_NODE_ID(data, id);
2121 Drawing::Bitmap bm;
2122 bool success;
2123 if (GetBitmap(id, bm, success) != ERR_OK || !reply.WriteBool(success)) {
2124 RS_LOGE("RSRenderServiceConnectionStub::GET_BITMAP Write success failed!");
2125 ret = ERR_INVALID_REPLY;
2126 break;
2127 }
2128 if (success) {
2129 RSMarshallingHelper::Marshalling(reply, bm);
2130 }
2131 break;
2132 }
2133 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_PIXELMAP): {
2134 NodeId id{0};
2135 if (!data.ReadUint64(id)) {
2136 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXELMAP Read id failed!");
2137 ret = ERR_INVALID_DATA;
2138 break;
2139 }
2140 if (!IsValidCallingPid(ExtractPid(id), callingPid)) {
2141 RS_LOGW("The GetPixelmap isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
2142 id, callingPid);
2143 break;
2144 }
2145 RS_PROFILER_PATCH_NODE_ID(data, id);
2146 std::shared_ptr<Media::PixelMap> pixelmap =
2147 std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
2148 Drawing::Rect rect;
2149 RSMarshallingHelper::Unmarshalling(data, rect);
2150 std::shared_ptr<Drawing::DrawCmdList> drawCmdList;
2151 RSMarshallingHelper::Unmarshalling(data, drawCmdList);
2152 bool success;
2153 if (GetPixelmap(id, pixelmap, &rect, drawCmdList, success) != ERR_OK ||
2154 !reply.WriteBool(success)) {
2155 RS_LOGE("RSRenderServiceConnectionStub::GET_PIXELMAP Write id failed!");
2156 ret = ERR_INVALID_REPLY;
2157 break;
2158 }
2159 if (success) {
2160 RSMarshallingHelper::Marshalling(reply, pixelmap);
2161 }
2162 break;
2163 }
2164 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NEED_REGISTER_TYPEFACE): {
2165 bool result = false;
2166 uint64_t uniqueId{0};
2167 uint32_t hash{0};
2168 if (!data.ReadUint64(uniqueId) || !data.ReadUint32(hash)) {
2169 RS_LOGE("RSRenderServiceConnectionStub::NEED_REGISTER_TYPEFACE read parcel failed!");
2170 ret = ERR_INVALID_DATA;
2171 break;
2172 }
2173 RS_PROFILER_PATCH_TYPEFACE_GLOBALID(data, uniqueId);
2174 if (IsValidCallingPid(ExtractPid(uniqueId), callingPid)) {
2175 result = !RSTypefaceCache::Instance().HasTypeface(uniqueId, hash);
2176 } else {
2177 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] "
2178 "no permission NEED_REGISTER_TYPEFACE", callingPid);
2179 }
2180 if (!reply.WriteBool(result)) {
2181 RS_LOGE("RSRenderServiceConnectionStub::NEED_REGISTER_TYPEFACE Write result failed!");
2182 ret = ERR_INVALID_REPLY;
2183 }
2184 break;
2185 }
2186 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_TYPEFACE): {
2187 bool xcollieFlag = false;
2188 bool result = false;
2189 std::shared_ptr<Drawing::Typeface> typeface = nullptr;
2190 {
2191 // timer: 3s
2192 OHOS::Rosen::RSXCollie registerTypefaceXCollie("registerTypefaceXCollie_" +
2193 std::to_string(callingPid), 3, TypefaceXcollieCallback, &xcollieFlag, 0);
2194 uint64_t uniqueId{0};
2195 uint32_t hash{0};
2196 if (!data.ReadUint64(uniqueId) || !data.ReadUint32(hash)) {
2197 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_TYPEFACE read parcel failed!");
2198 ret = ERR_INVALID_DATA;
2199 break;
2200 }
2201 // safe check
2202 if (IsValidCallingPid(ExtractPid(uniqueId), callingPid)) {
2203 result = RSMarshallingHelper::Unmarshalling(data, typeface);
2204 if (result && typeface) {
2205 typeface->SetHash(hash);
2206 RS_PROFILER_PATCH_TYPEFACE_GLOBALID(data, uniqueId);
2207 RegisterTypeface(uniqueId, typeface);
2208 }
2209 } else {
2210 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] "
2211 "no permission REGISTER_TYPEFACE", callingPid);
2212 }
2213 }
2214 if (xcollieFlag && typeface) {
2215 RS_LOGW("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] typeface[%{public}s] "
2216 "size[%{public}u], too big.", callingPid, typeface->GetFamilyName().c_str(), typeface->GetSize());
2217 }
2218 if (!reply.WriteBool(result)) {
2219 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_TYPEFACE Write result failed!");
2220 ret = ERR_INVALID_REPLY;
2221 }
2222 break;
2223 }
2224 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_TYPEFACE): {
2225 uint64_t uniqueId{0};
2226 if (!data.ReadUint64(uniqueId)) {
2227 RS_LOGE("RSRenderServiceConnectionStub::UNREGISTER_TYPEFACE read uniqueId failed!");
2228 ret = ERR_INVALID_DATA;
2229 break;
2230 }
2231 // safe check
2232 if (IsValidCallingPid(ExtractPid(uniqueId), callingPid)) {
2233 RS_PROFILER_PATCH_TYPEFACE_GLOBALID(data, uniqueId);
2234 UnRegisterTypeface(uniqueId);
2235 } else {
2236 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest callingPid[%{public}d] "
2237 "no permission UNREGISTER_TYPEFACE", callingPid);
2238 }
2239 break;
2240 }
2241 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_SKIP_FRAME_INTERVAL): {
2242 if (!securityManager_.IsInterfaceCodeAccessible(code)) {
2243 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest no permission to access"\
2244 "SET_SCREEN_SKIP_FRAME_INTERVAL");
2245 return ERR_INVALID_STATE;
2246 }
2247 ScreenId id{INVALID_SCREEN_ID};
2248 uint32_t skipFrameInterval{0};
2249 if (!data.ReadUint64(id) || !data.ReadUint32(skipFrameInterval)) {
2250 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_SKIP_FRAME_INTERVAL Read parcel failed!");
2251 ret = ERR_INVALID_DATA;
2252 break;
2253 }
2254 int32_t result = SetScreenSkipFrameInterval(id, skipFrameInterval);
2255 if (!reply.WriteInt32(result)) {
2256 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_SKIP_FRAME_INTERVAL Write result failed!");
2257 ret = ERR_INVALID_REPLY;
2258 }
2259 break;
2260 }
2261 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_REFRESH_RATE): {
2262 ScreenId id = 0;
2263 uint32_t maxRefreshRate = 0;
2264 if (!data.ReadUint64(id) || !data.ReadUint32(maxRefreshRate)) {
2265 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_REFRESH_RATE Read parcel failed!");
2266 ret = ERR_INVALID_DATA;
2267 break;
2268 }
2269 uint32_t actualRefreshRate = 0;
2270 int32_t result = SetVirtualScreenRefreshRate(id, maxRefreshRate, actualRefreshRate);
2271 if (!reply.WriteInt32(result)) {
2272 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_REFRESH_RATE Write result failed!");
2273 return ERR_INVALID_REPLY;
2274 }
2275 if (!reply.WriteUint32(actualRefreshRate)) {
2276 RS_LOGE(
2277 "RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_REFRESH_RATE Write actualRefreshRate failed!");
2278 return ERR_INVALID_REPLY;
2279 }
2280 break;
2281 }
2282 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_SCREEN_ACTIVE_RECT): {
2283 ScreenId id{INVALID_SCREEN_ID};
2284 int32_t x{0};
2285 int32_t y{0};
2286 int32_t w{0};
2287 int32_t h{0};
2288 if (!data.ReadUint64(id) || !data.ReadInt32(x) || !data.ReadInt32(y) ||
2289 !data.ReadInt32(w) || !data.ReadInt32(h)) {
2290 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_ACTIVE_RECT Read parcel failed!");
2291 ret = ERR_INVALID_DATA;
2292 break;
2293 }
2294 Rect activeRect {
2295 .x = x,
2296 .y = y,
2297 .w = w,
2298 .h = h
2299 };
2300 uint32_t result = SetScreenActiveRect(id, activeRect);
2301 if (!reply.WriteUint32(result)) {
2302 RS_LOGE("RSRenderServiceConnectionStub::SET_SCREEN_ACTIVE_RECT Write result failed!");
2303 return ERR_INVALID_REPLY;
2304 }
2305 break;
2306 }
2307 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_OCCLUSION_CHANGE_CALLBACK): {
2308 auto remoteObject = data.ReadRemoteObject();
2309 if (remoteObject == nullptr) {
2310 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_OCCLUSION_CHANGE_CALLBACK Read remoteObject failed!");
2311 ret = ERR_NULL_OBJECT;
2312 break;
2313 }
2314 sptr<RSIOcclusionChangeCallback> callback = iface_cast<RSIOcclusionChangeCallback>(remoteObject);
2315 if (callback == nullptr) {
2316 ret = ERR_NULL_OBJECT;
2317 break;
2318 }
2319 int32_t status = RegisterOcclusionChangeCallback(callback);
2320 if (!reply.WriteInt32(status)) {
2321 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_OCCLUSION_CHANGE_CALLBACK Write status failed!");
2322 ret = ERR_INVALID_REPLY;
2323 }
2324 break;
2325 }
2326 case static_cast<uint32_t>(
2327 RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK): {
2328 NodeId id{0};
2329 if (!data.ReadUint64(id)) {
2330 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Read id failed!");
2331 ret = ERR_INVALID_DATA;
2332 break;
2333 }
2334 RS_PROFILER_PATCH_NODE_ID(data, id);
2335 if (!IsValidCallingPid(ExtractPid(id), callingPid)) {
2336 RS_LOGW("The RegisterSurfaceOcclusionChangeCallback isn't legal, nodeId:%{public}" PRIu64 ", "
2337 "callingPid:%{public}d", id, callingPid);
2338 ret = ERR_INVALID_DATA;
2339 break;
2340 }
2341 auto remoteObject = data.ReadRemoteObject();
2342 if (remoteObject == nullptr) {
2343 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Read remoteObject "
2344 "failed!");
2345 ret = ERR_NULL_OBJECT;
2346 break;
2347 }
2348 sptr<RSISurfaceOcclusionChangeCallback> callback =
2349 iface_cast<RSISurfaceOcclusionChangeCallback>(remoteObject);
2350 if (callback == nullptr) {
2351 ret = ERR_NULL_OBJECT;
2352 break;
2353 }
2354 std::vector<float> partitionPoints;
2355 if (!data.ReadFloatVector(&partitionPoints)) {
2356 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Read "
2357 "partitionPoints failed!");
2358 ret = ERR_TRANSACTION_FAILED;
2359 break;
2360 }
2361 int32_t status = RegisterSurfaceOcclusionChangeCallback(id, callback, partitionPoints);
2362 if (!reply.WriteInt32(status)) {
2363 RS_LOGE(
2364 "RSRenderServiceConnectionStub::REGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Write status failed!");
2365 ret = ERR_INVALID_REPLY;
2366 }
2367 break;
2368 }
2369 case static_cast<uint32_t>(
2370 RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK): {
2371 NodeId id{0};
2372 if (!data.ReadUint64(id)) {
2373 RS_LOGE("RSRenderServiceConnectionStub::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Read id failed!");
2374 ret = ERR_INVALID_DATA;
2375 break;
2376 }
2377 RS_PROFILER_PATCH_NODE_ID(data, id);
2378 if (!IsValidCallingPid(ExtractPid(id), callingPid)) {
2379 RS_LOGW("The UnRegisterSurfaceOcclusionChangeCallback isn't legal, nodeId:%{public}" PRIu64 ", "
2380 "callingPid:%{public}d", id, callingPid);
2381 ret = ERR_INVALID_DATA;
2382 break;
2383 }
2384 int32_t status = UnRegisterSurfaceOcclusionChangeCallback(id);
2385 if (!reply.WriteInt32(status)) {
2386 RS_LOGE(
2387 "RSRenderServiceConnectionStub::UNREGISTER_SURFACE_OCCLUSION_CHANGE_CALLBACK Write status failed!");
2388 ret = ERR_INVALID_REPLY;
2389 }
2390 break;
2391 }
2392 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_APP_WINDOW_NUM): {
2393 uint32_t num{0};
2394 if (!data.ReadUint32(num)) {
2395 RS_LOGE("RSRenderServiceConnectionStub::SET_APP_WINDOW_NUM Read num failed!");
2396 ret = ERR_INVALID_DATA;
2397 break;
2398 }
2399 SetAppWindowNum(num);
2400 break;
2401 }
2402 case static_cast<uint32_t>(
2403 RSIRenderServiceConnectionInterfaceCode::SET_SYSTEM_ANIMATED_SCENES): {
2404 uint32_t systemAnimatedScenes{0};
2405 bool isRegularAnimation{false};
2406 if (!data.ReadUint32(systemAnimatedScenes) || !data.ReadBool(isRegularAnimation)) {
2407 RS_LOGE("RSRenderServiceConnectionStub::SET_SYSTEM_ANIMATED_SCENES Read parcel failed!");
2408 ret = ERR_INVALID_DATA;
2409 break;
2410 }
2411 bool result = SetSystemAnimatedScenes(
2412 static_cast<SystemAnimatedScenes>(systemAnimatedScenes), isRegularAnimation);
2413 if (!reply.WriteBool(result)) {
2414 RS_LOGE("RSRenderServiceConnectionStub::SET_SYSTEM_ANIMATED_SCENES Write result failed!");
2415 ret = ERR_INVALID_REPLY;
2416 }
2417 break;
2418 }
2419 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WATERMARK): {
2420 if (!RSSystemProperties::GetSurfaceNodeWatermarkEnabled()) {
2421 RS_LOGI("Current disenable water mark");
2422 break;
2423 }
2424 std::string name;
2425 if (!data.ReadString(name)) {
2426 RS_LOGE("RSRenderServiceConnectionStub::SET_WATERMARK Read name failed!");
2427 ret = ERR_INVALID_DATA;
2428 break;
2429 }
2430 auto watermark = std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
2431 if (watermark == nullptr) {
2432 ret = ERR_NULL_OBJECT;
2433 RS_LOGE("RSRenderServiceConnectionStub::std::shared_ptr<Media::PixelMap> watermark == nullptr");
2434 break;
2435 }
2436 bool success;
2437 if (SetWatermark(name, watermark, success) != ERR_OK || !success) {
2438 RS_LOGE("RSRenderServiceConnectionStub::SetWatermark failed");
2439 }
2440 break;
2441 }
2442 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SHOW_WATERMARK): {
2443 std::shared_ptr<Media::PixelMap> watermarkImg =
2444 std::shared_ptr<Media::PixelMap>(data.ReadParcelable<Media::PixelMap>());
2445 bool isShow{false};
2446 if (!data.ReadBool(isShow)) {
2447 RS_LOGE("RSRenderServiceConnectionStub::SHOW_WATERMARK Read isShow failed!");
2448 ret = ERR_INVALID_DATA;
2449 break;
2450 }
2451 ShowWatermark(watermarkImg, isShow);
2452 break;
2453 }
2454 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::RESIZE_VIRTUAL_SCREEN): {
2455 ScreenId id{INVALID_SCREEN_ID};
2456 uint32_t width{0};
2457 uint32_t height{0};
2458 if (!data.ReadUint64(id) || !data.ReadUint32(width) || !data.ReadUint32(height)) {
2459 RS_LOGE("RSRenderServiceConnectionStub::RESIZE_VIRTUAL_SCREEN Read parcel failed!");
2460 ret = ERR_INVALID_DATA;
2461 break;
2462 }
2463 int32_t status = ResizeVirtualScreen(id, width, height);
2464 if (!reply.WriteInt32(status)) {
2465 RS_LOGE("RSRenderServiceConnectionStub::RESIZE_VIRTUAL_SCREEN Write status failed!");
2466 ret = ERR_INVALID_REPLY;
2467 }
2468 break;
2469 }
2470 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_JANK_STATS): {
2471 ReportJankStats();
2472 break;
2473 }
2474 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_RESPONSE): {
2475 DataBaseRs info;
2476 if (!ReadDataBaseRs(info, data)) {
2477 ret = ERR_INVALID_DATA;
2478 break;
2479 }
2480 ReportEventResponse(info);
2481 break;
2482 }
2483 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_COMPLETE): {
2484 DataBaseRs info;
2485 if (!ReadDataBaseRs(info, data)) {
2486 ret = ERR_INVALID_DATA;
2487 break;
2488 }
2489 ReportEventComplete(info);
2490 break;
2491 }
2492 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_JANK_FRAME): {
2493 DataBaseRs info;
2494 if (!ReadDataBaseRs(info, data)) {
2495 ret = ERR_INVALID_DATA;
2496 break;
2497 }
2498 ReportEventJankFrame(info);
2499 break;
2500 }
2501 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_RS_SCENE_JANK_START): {
2502 AppInfo info;
2503 if (!ReadAppInfo(info, data)) {
2504 ret = ERR_INVALID_DATA;
2505 break;
2506 }
2507 ReportRsSceneJankStart(info);
2508 break;
2509 }
2510 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_RS_SCENE_JANK_END): {
2511 AppInfo info;
2512 if (!ReadAppInfo(info, data)) {
2513 ret = ERR_INVALID_DATA;
2514 break;
2515 }
2516 ReportRsSceneJankEnd(info);
2517 break;
2518 }
2519 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REPORT_EVENT_GAMESTATE): {
2520 GameStateData info;
2521 if (!ReadGameStateDataRs(info, data)) {
2522 ret = ERR_INVALID_DATA;
2523 break;
2524 }
2525 ReportGameStateData(info);
2526 break;
2527 }
2528 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::EXECUTE_SYNCHRONOUS_TASK): {
2529 int16_t type{0};
2530 int16_t subType{0};
2531 if (!data.ReadInt16(type) || !data.ReadInt16(subType)) {
2532 RS_LOGE("RSRenderServiceConnectionStub::EXECUTE_SYNCHRONOUS_TASK Read parcel failed!");
2533 ret = ERR_INVALID_STATE;
2534 break;
2535 }
2536 if (type != RS_NODE_SYNCHRONOUS_READ_PROPERTY && type != RS_NODE_SYNCHRONOUS_GET_VALUE_FRACTION) {
2537 ret = ERR_INVALID_STATE;
2538 break;
2539 }
2540 auto func = RSCommandFactory::Instance().GetUnmarshallingFunc(type, subType);
2541 if (func == nullptr) {
2542 ret = ERR_INVALID_STATE;
2543 break;
2544 }
2545 auto command = static_cast<RSSyncTask*>((*func)(data));
2546 if (command == nullptr) {
2547 ret = ERR_INVALID_STATE;
2548 break;
2549 }
2550 std::shared_ptr<RSSyncTask> task(command);
2551 const auto& nodeMap = RSMainThread::Instance()->GetContext().GetNodeMap();
2552 if (!task->IsCallingPidValid(callingPid, nodeMap)) {
2553 ret = ERR_INVALID_STATE;
2554 break;
2555 }
2556 ExecuteSynchronousTask(task);
2557 if (!task->Marshalling(reply)) {
2558 ret = ERR_INVALID_STATE;
2559 }
2560 break;
2561 }
2562 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HARDWARE_ENABLED) : {
2563 uint64_t id{0};
2564 if (!data.ReadUint64(id)) {
2565 RS_LOGE("RSRenderServiceConnectionStub::SET_HARDWARE_ENABLED Read id failed!");
2566 ret = ERR_INVALID_DATA;
2567 break;
2568 }
2569 if (!IsValidCallingPid(ExtractPid(id), callingPid)) {
2570 RS_LOGW("The SetHardwareEnabled isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
2571 id, callingPid);
2572 break;
2573 }
2574 bool isEnabled{false};
2575 uint8_t selfDrawingType{static_cast<uint8_t>(SelfDrawingNodeType::DEFAULT)};
2576 bool dynamicHardwareEnable{false};
2577 if (!data.ReadBool(isEnabled) ||
2578 !data.ReadUint8(selfDrawingType) ||
2579 !data.ReadBool(dynamicHardwareEnable)) {
2580 RS_LOGE("RSRenderServiceConnectionStub::SET_HARDWARE_ENABLED Read parcel failed!");
2581 ret = ERR_INVALID_DATA;
2582 break;
2583 }
2584 SetHardwareEnabled(id, isEnabled, static_cast<SelfDrawingNodeType>(selfDrawingType), dynamicHardwareEnable);
2585 break;
2586 }
2587 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_HIDE_PRIVACY_CONTENT) : {
2588 uint64_t id{0};
2589 if (!data.ReadUint64(id)) {
2590 RS_LOGE("RSRenderServiceConnectionStub::SET_HIDE_PRIVACY_CONTENT Read id failed!");
2591 ret = ERR_INVALID_DATA;
2592 break;
2593 }
2594 auto isSystemCalling = RSInterfaceCodeAccessVerifierBase::IsSystemCalling(
2595 RSIRenderServiceConnectionInterfaceCodeAccessVerifier::codeEnumTypeName_ +
2596 "::SET_HIDE_PRIVACY_CONTENT");
2597 if (!isSystemCalling) {
2598 if (!reply.WriteUint32(static_cast<uint32_t>(RSInterfaceErrorCode::NONSYSTEM_CALLING))) {
2599 RS_LOGE("RSRenderServiceConnectionStub::SET_HIDE_PRIVACY_CONTENT Write isSystemCalling failed!");
2600 ret = ERR_INVALID_REPLY;
2601 }
2602 break;
2603 }
2604 if (ExtractPid(id) != callingPid) {
2605 RS_LOGW("The SetHidePrivacyContent isn't legal, nodeId:%{public}" PRIu64 ", callingPid:%{public}d",
2606 id, callingPid);
2607 if (!reply.WriteUint32(static_cast<uint32_t>(RSInterfaceErrorCode::NOT_SELF_CALLING))) {
2608 RS_LOGE("RSRenderServiceConnectionStub::SET_HIDE_PRIVACY_CONTENT Write ErrorCode failed!");
2609 ret = ERR_INVALID_REPLY;
2610 }
2611 break;
2612 }
2613 bool needHidePrivacyContent{false};
2614 if (!data.ReadBool(needHidePrivacyContent)) {
2615 RS_LOGE("RSRenderServiceConnectionStub::SET_HIDE_PRIVACY_CONTENT read needHidePrivacyContent failed!");
2616 ret = ERR_INVALID_DATA;
2617 break;
2618 }
2619 uint32_t resCode;
2620 if (SetHidePrivacyContent(id, needHidePrivacyContent, resCode) != ERR_OK ||
2621 !reply.WriteUint32(resCode)) {
2622 RS_LOGE("RSRenderServiceConnectionStub::SET_HIDE_PRIVACY_CONTENT Write resCode failed!");
2623 ret = ERR_INVALID_REPLY;
2624 }
2625 break;
2626 }
2627 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_LIGHT_FACTOR_STATUS) : {
2628 int32_t lightFactorStatus{0};
2629 if (!data.ReadInt32(lightFactorStatus)) {
2630 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_LIGHT_FACTOR_STATUS Read lightFactorStatus failed!");
2631 ret = ERR_INVALID_DATA;
2632 break;
2633 }
2634 NotifyLightFactorStatus(lightFactorStatus);
2635 break;
2636 }
2637 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PACKAGE_EVENT) : {
2638 uint32_t listSize{0};
2639 if (!data.ReadUint32(listSize)) {
2640 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_PACKAGE_EVENT Read listSize failed!");
2641 ret = ERR_INVALID_DATA;
2642 break;
2643 }
2644 const uint32_t MAX_LIST_SIZE = 50;
2645 if (listSize > MAX_LIST_SIZE) {
2646 ret = ERR_INVALID_STATE;
2647 break;
2648 }
2649 std::vector<std::string> packageList;
2650 bool errFlag{false};
2651 for (uint32_t i = 0; i < listSize; i++) {
2652 std::string package;
2653 if (!data.ReadString(package)) {
2654 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_PACKAGE_EVENT Read package failed!");
2655 errFlag = true;
2656 break;
2657 }
2658 packageList.push_back(package);
2659 }
2660 if (errFlag) {
2661 ret = ERR_INVALID_DATA;
2662 break;
2663 }
2664 NotifyPackageEvent(listSize, packageList);
2665 break;
2666 }
2667 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_APP_STRATEGY_CONFIG_CHANGE_EVENT) : {
2668 std::string pkgName;
2669 uint32_t listSize{0};
2670 if (!data.ReadString(pkgName) || !data.ReadUint32(listSize)) {
2671 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_APP_STRATEGY_CONFIG_CHANGE_EVENT Read parcel failed!");
2672 ret = ERR_INVALID_DATA;
2673 break;
2674 }
2675 const uint32_t MAX_LIST_SIZE = 50;
2676 if (listSize > MAX_LIST_SIZE) {
2677 ret = ERR_INVALID_STATE;
2678 break;
2679 }
2680
2681 std::vector<std::pair<std::string, std::string>> newConfig;
2682 bool errFlag{false};
2683 for (uint32_t i = 0; i < listSize; i++) {
2684 std::string key;
2685 std::string value;
2686 if (!data.ReadString(key) || !data.ReadString(value)) {
2687 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_APP_STRATEGY_CONFIG_CHANGE_EVENT Read newConfig "
2688 "failed!");
2689 errFlag = true;
2690 break;
2691 }
2692 newConfig.push_back(make_pair(key, value));
2693 }
2694 if (errFlag) {
2695 ret = ERR_INVALID_STATE;
2696 break;
2697 }
2698 NotifyAppStrategyConfigChangeEvent(pkgName, listSize, newConfig);
2699 }
2700 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_REFRESH_RATE_EVENT) : {
2701 std::string eventName;
2702 bool eventStatus{false};
2703 uint32_t minRefreshRate{0};
2704 uint32_t maxRefreshRate{0};
2705 std::string description;
2706 if (!data.ReadString(eventName) || !data.ReadBool(eventStatus) || !data.ReadUint32(minRefreshRate) ||
2707 !data.ReadUint32(maxRefreshRate) || !data.ReadString(description)) {
2708 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_REFRESH_RATE_EVENT Read parcel failed!");
2709 ret = ERR_INVALID_DATA;
2710 break;
2711 }
2712 EventInfo eventInfo = {
2713 eventName, eventStatus, minRefreshRate, maxRefreshRate, description
2714 };
2715 NotifyRefreshRateEvent(eventInfo);
2716 break;
2717 }
2718 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_SOFT_VSYNC_EVENT) : {
2719 uint32_t pid{0};
2720 uint32_t rateDiscount{0};
2721 if (!data.ReadUint32(pid) || !data.ReadUint32(rateDiscount)) {
2722 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_SOFT_VSYNC_EVENT Read parcel failed!");
2723 ret = ERR_INVALID_DATA;
2724 break;
2725 }
2726 NotifySoftVsyncEvent(pid, rateDiscount);
2727 break;
2728 }
2729 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_DYNAMIC_MODE_EVENT) : {
2730 bool enableDynamicMode{false};
2731 if (!data.ReadBool(enableDynamicMode)) {
2732 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_DYNAMIC_MODE_EVENT Read parcel failed!");
2733 ret = ERR_INVALID_DATA;
2734 break;
2735 }
2736 NotifyDynamicModeEvent(enableDynamicMode);
2737 break;
2738 }
2739 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_TOUCH_EVENT) : {
2740 int32_t touchStatus{0};
2741 int32_t touchCnt{0};
2742 if (!data.ReadInt32(touchStatus) || !data.ReadInt32(touchCnt)) {
2743 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_TOUCH_EVENT Read parcel failed!");
2744 ret = ERR_INVALID_DATA;
2745 break;
2746 }
2747 NotifyTouchEvent(touchStatus, touchCnt);
2748 break;
2749 }
2750 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_HGMCONFIG_EVENT) : {
2751 std::string eventName;
2752 bool state{false};
2753 if (!data.ReadString(eventName) || !data.ReadBool(state)) {
2754 RS_LOGE("RSRenderServiceConnectionStub::NOTIFY_HGMCONFIG_EVENT Read parcel failed!");
2755 ret = ERR_INVALID_DATA;
2756 break;
2757 }
2758 NotifyHgmConfigEvent(eventName, state);
2759 break;
2760 }
2761 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_HGM_CFG_CALLBACK) : {
2762 auto remoteObject = data.ReadRemoteObject();
2763 if (remoteObject == nullptr) {
2764 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_HGM_CFG_CALLBACK Read remoteObject failed!");
2765 ret = ERR_NULL_OBJECT;
2766 break;
2767 }
2768 sptr<RSIHgmConfigChangeCallback> callback = iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
2769 if (callback == nullptr) {
2770 ret = ERR_NULL_OBJECT;
2771 break;
2772 }
2773 int32_t status = RegisterHgmConfigChangeCallback(callback);
2774 if (!reply.WriteInt32(status)) {
2775 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_HGM_CFG_CALLBACK Write status failed!");
2776 ret = ERR_INVALID_REPLY;
2777 }
2778 break;
2779 }
2780 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_MODE_CHANGE_CALLBACK) : {
2781 auto remoteObject = data.ReadRemoteObject();
2782 if (remoteObject == nullptr) {
2783 RS_LOGE("RSRenderServiceConnectionStub::REFRESH_RATE_MODE_CHANGE_CALLBACK Read remoteObject failed!");
2784 ret = ERR_NULL_OBJECT;
2785 break;
2786 }
2787 sptr<RSIHgmConfigChangeCallback> callback =
2788 iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
2789 if (callback == nullptr) {
2790 ret = ERR_NULL_OBJECT;
2791 break;
2792 }
2793 int32_t status = RegisterHgmRefreshRateModeChangeCallback(callback);
2794 if (!reply.WriteInt32(status)) {
2795 RS_LOGE("RSRenderServiceConnectionStub::REFRESH_RATE_MODE_CHANGE_CALLBACK Write status failed!");
2796 ret = ERR_INVALID_REPLY;
2797 }
2798 break;
2799 }
2800 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REFRESH_RATE_UPDATE_CALLBACK) : {
2801 sptr<RSIHgmConfigChangeCallback> callback = nullptr;
2802 sptr<IRemoteObject> remoteObject = nullptr;
2803 bool readRemoteObject{false};
2804 if (!data.ReadBool(readRemoteObject)) {
2805 RS_LOGE("RSRenderServiceConnectionStub::REFRESH_RATE_UPDATE_CALLBACK Read remoteObject failed!");
2806 ret = ERR_INVALID_DATA;
2807 break;
2808 }
2809 if (readRemoteObject) {
2810 remoteObject = data.ReadRemoteObject();
2811 }
2812 if (remoteObject != nullptr) {
2813 callback = iface_cast<RSIHgmConfigChangeCallback>(remoteObject);
2814 }
2815 int32_t status = RegisterHgmRefreshRateUpdateCallback(callback);
2816 if (!reply.WriteInt32(status)) {
2817 RS_LOGE("RSRenderServiceConnectionStub::REFRESH_RATE_UPDATE_CALLBACK Write status failed!");
2818 ret = ERR_INVALID_REPLY;
2819 }
2820 break;
2821 }
2822 case static_cast<uint32_t>(
2823 RSIRenderServiceConnectionInterfaceCode::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK) : {
2824 sptr<RSIFrameRateLinkerExpectedFpsUpdateCallback> callback = nullptr;
2825 sptr<IRemoteObject> remoteObject = nullptr;
2826 int32_t dstPid{0};
2827 bool readRemoteObject{false};
2828 if (!data.ReadInt32(dstPid) || !data.ReadBool(readRemoteObject)) {
2829 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK Read parcel "
2830 "failed!");
2831 ret = ERR_INVALID_DATA;
2832 break;
2833 }
2834 if (readRemoteObject) {
2835 remoteObject = data.ReadRemoteObject();
2836 }
2837 if (remoteObject != nullptr) {
2838 callback = iface_cast<RSIFrameRateLinkerExpectedFpsUpdateCallback>(remoteObject);
2839 }
2840 int32_t status = RegisterFrameRateLinkerExpectedFpsUpdateCallback(dstPid, callback);
2841 if (!reply.WriteInt32(status)) {
2842 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_FRAME_RATE_LINKER_EXPECTED_FPS_CALLBACK Write status "
2843 "failed!");
2844 ret = ERR_INVALID_REPLY;
2845 }
2846 break;
2847 }
2848 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ROTATION_CACHE_ENABLED) : {
2849 bool isEnabled = false;
2850 if (!data.ReadBool(isEnabled)) {
2851 RS_LOGE("RSRenderServiceConnectionStub::SET_ROTATION_CACHE_ENABLED Read isEnabled failed!");
2852 ret = IPC_STUB_INVALID_DATA_ERR;
2853 break;
2854 }
2855 SetCacheEnabledForRotation(isEnabled);
2856 break;
2857 }
2858 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_ACTIVE_DIRTY_REGION_INFO) : {
2859 const auto& activeDirtyRegionInfos = GetActiveDirtyRegionInfo();
2860 if (!reply.WriteInt32(activeDirtyRegionInfos.size())) {
2861 RS_LOGE("RSRenderServiceConnectionStub::GET_ACTIVE_DIRTY_REGION_INFO Write activeDirtyRegionInfosSize "
2862 "failed!");
2863 ret = ERR_INVALID_REPLY;
2864 break;
2865 }
2866 for (const auto& activeDirtyRegionInfo : activeDirtyRegionInfos) {
2867 if (!reply.WriteInt64(activeDirtyRegionInfo.activeDirtyRegionArea) ||
2868 !reply.WriteInt32(activeDirtyRegionInfo.activeFramesNumber) ||
2869 !reply.WriteInt32(activeDirtyRegionInfo.pidOfBelongsApp) ||
2870 !reply.WriteString(activeDirtyRegionInfo.windowName)) {
2871 RS_LOGE("RSRenderServiceConnectionStub::GET_ACTIVE_DIRTY_REGION_INFO Write activeDirtyRegionInfos "
2872 "failed!");
2873 ret = ERR_INVALID_REPLY;
2874 break;
2875 }
2876 }
2877 break;
2878 }
2879 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_GLOBAL_DIRTY_REGION_INFO) : {
2880 const auto& globalDirtyRegionInfo = GetGlobalDirtyRegionInfo();
2881 if (!reply.WriteInt64(globalDirtyRegionInfo.globalDirtyRegionAreas) ||
2882 !reply.WriteInt32(globalDirtyRegionInfo.globalFramesNumber) ||
2883 !reply.WriteInt32(globalDirtyRegionInfo.skipProcessFramesNumber) ||
2884 !reply.WriteInt32(globalDirtyRegionInfo.mostSendingPidWhenDisplayNodeSkip)) {
2885 RS_LOGE(
2886 "RSRenderServiceConnectionStub::GET_GLOBAL_DIRTY_REGION_INFO Write globalDirtyRegionInfo failed!");
2887 ret = ERR_INVALID_REPLY;
2888 }
2889 break;
2890 }
2891 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_LAYER_COMPOSE_INFO) : {
2892 const auto& LayerComposeInfo = GetLayerComposeInfo();
2893 if (!reply.WriteInt32(LayerComposeInfo.uniformRenderFrameNumber) ||
2894 !reply.WriteInt32(LayerComposeInfo.offlineComposeFrameNumber) ||
2895 !reply.WriteInt32(LayerComposeInfo.redrawFrameNumber)) {
2896 RS_LOGE("RSRenderServiceConnectionStub::GET_LAYER_COMPOSE_INFO Write LayerComposeInfo failed!");
2897 ret = ERR_INVALID_REPLY;
2898 }
2899 break;
2900 }
2901 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::
2902 GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO) : {
2903 const auto& hwcDisabledReasonInfos = GetHwcDisabledReasonInfo();
2904 if (!reply.WriteInt32(hwcDisabledReasonInfos.size())) {
2905 RS_LOGE("RSRenderServiceConnectionStub::GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO Write "
2906 "hwcDisabledReasonInfos failed!");
2907 ret = ERR_INVALID_REPLY;
2908 break;
2909 }
2910 for (const auto& hwcDisabledReasonInfo : hwcDisabledReasonInfos) {
2911 for (const auto& disabledReasonCount : hwcDisabledReasonInfo.disabledReasonStatistics) {
2912 if (!reply.WriteInt32(disabledReasonCount)) {
2913 RS_LOGE("RSRenderServiceConnectionStub::GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO Write "
2914 "disabledReasonCount failed!");
2915 ret = ERR_INVALID_REPLY;
2916 break;
2917 }
2918 }
2919 if (ret == ERR_INVALID_REPLY) {
2920 break;
2921 }
2922 if (!reply.WriteInt32(hwcDisabledReasonInfo.pidOfBelongsApp) ||
2923 !reply.WriteString(hwcDisabledReasonInfo.nodeName)) {
2924 RS_LOGE("RSRenderServiceConnectionStub::GET_HARDWARE_COMPOSE_DISABLED_REASON_INFO Write "
2925 "hwcDisabledReasonInfo failed!");
2926 ret = ERR_INVALID_REPLY;
2927 break;
2928 }
2929 }
2930 break;
2931 }
2932 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::GET_HDR_ON_DURATION) : {
2933 int64_t hdrOnDuration = 0;
2934 auto errCode = GetHdrOnDuration(hdrOnDuration);
2935 if (errCode != ERR_OK || !reply.WriteInt64(hdrOnDuration)) {
2936 RS_LOGE("RSRenderServiceConnectionStub::GET_HDR_ON_DURATION Write "
2937 "hdrOnDuration failed!");
2938 ret = ERR_INVALID_REPLY;
2939 }
2940 break;
2941 }
2942 #ifdef TP_FEATURE_ENABLE
2943 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_TP_FEATURE_CONFIG) : {
2944 int32_t feature{0};
2945 if (!data.ReadInt32(feature)) {
2946 RS_LOGE("RSRenderServiceConnectionStub::SET_TP_FEATURE_CONFIG Read feature failed!");
2947 ret = ERR_INVALID_DATA;
2948 break;
2949 }
2950 auto config = data.ReadCString();
2951 if (config == nullptr) {
2952 RS_LOGE("RSRenderServiceConnectionStub::SET_TP_FEATURE_CONFIG Read config failed!");
2953 ret = ERR_INVALID_DATA;
2954 break;
2955 }
2956 uint8_t tpFeatureConfigType{0};
2957 if (!data.ReadUint8(tpFeatureConfigType)) {
2958 RS_LOGE("RSRenderServiceConnectionStub::SET_TP_FEATURE_CONFIG Read tpFeatureConfigType failed!");
2959 ret = ERR_INVALID_DATA;
2960 break;
2961 }
2962 SetTpFeatureConfig(feature, config, static_cast<TpFeatureConfigType>(tpFeatureConfigType));
2963 break;
2964 }
2965 #endif
2966 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_USING_STATUS) : {
2967 bool isVirtualScreenUsingStatus{false};
2968 if (!data.ReadBool(isVirtualScreenUsingStatus)) {
2969 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_USING_STATUS Read "
2970 "isVirtualScreenUsingStatus failed!");
2971 ret = ERR_INVALID_DATA;
2972 break;
2973 }
2974 SetVirtualScreenUsingStatus(isVirtualScreenUsingStatus);
2975 break;
2976 }
2977
2978 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_CURTAIN_SCREEN_USING_STATUS) : {
2979 bool isCurtainScreenOn{false};
2980 if (!data.ReadBool(isCurtainScreenOn)) {
2981 RS_LOGE("RSRenderServiceConnectionStub::SET_CURTAIN_SCREEN_USING_STATUS Read "
2982 "isCurtainScreenOn failed!");
2983 ret = ERR_INVALID_DATA;
2984 break;
2985 }
2986 SetCurtainScreenUsingStatus(isCurtainScreenOn);
2987 break;
2988 }
2989 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::DROP_FRAME_BY_PID) : {
2990 std::vector<int32_t> pidList;
2991 if (!data.ReadInt32Vector(&pidList)) {
2992 RS_LOGE("RSRenderServiceConnectionStub::DROP_FRAME_BY_PID Read "
2993 "pidList failed!");
2994 ret = ERR_INVALID_REPLY;
2995 break;
2996 }
2997 DropFrameByPid(pidList);
2998 break;
2999 }
3000 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_UIEXTENSION_CALLBACK): {
3001 uint64_t userId{0};
3002 if (!data.ReadUint64(userId)) {
3003 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_UIEXTENSION_CALLBACK Read "
3004 "userId failed!");
3005 ret = ERR_INVALID_DATA;
3006 break;
3007 }
3008 auto remoteObject = data.ReadRemoteObject();
3009 if (remoteObject == nullptr) {
3010 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_UIEXTENSION_CALLBACK Read remoteObject failed!");
3011 ret = ERR_NULL_OBJECT;
3012 break;
3013 }
3014 sptr<RSIUIExtensionCallback> callback = iface_cast<RSIUIExtensionCallback>(remoteObject);
3015 if (callback == nullptr) {
3016 ret = ERR_NULL_OBJECT;
3017 break;
3018 }
3019 bool unobscured{false};
3020 if (!data.ReadBool(unobscured)) {
3021 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_UIEXTENSION_CALLBACK Read unobscured failed!");
3022 ret = ERR_INVALID_DATA;
3023 break;
3024 }
3025 int32_t status = RegisterUIExtensionCallback(userId, callback, unobscured);
3026 if (!reply.WriteInt32(status)) {
3027 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_UIEXTENSION_CALLBACK Write status failed!");
3028 ret = ERR_INVALID_REPLY;
3029 }
3030 break;
3031 }
3032 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VIRTUAL_SCREEN_STATUS) : {
3033 ScreenId id{INVALID_SCREEN_ID};
3034 uint8_t screenStatus{0};
3035 if (!data.ReadUint64(id) || !data.ReadUint8(screenStatus)) {
3036 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_STATUS Read parcel failed!");
3037 ret = ERR_INVALID_DATA;
3038 break;
3039 }
3040 bool result = SetVirtualScreenStatus(id, static_cast<VirtualScreenStatus>(screenStatus));
3041 if (!reply.WriteBool(result)) {
3042 RS_LOGE("RSRenderServiceConnectionStub::SET_VIRTUAL_SCREEN_STATUS Write result failed!");
3043 ret = ERR_INVALID_REPLY;
3044 }
3045 break;
3046 }
3047 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_PAGE_NAME) : {
3048 std::string packageName;
3049 std::string pageName;
3050 bool isEnter{false};
3051 if (!data.ReadString(packageName) || !data.ReadString(pageName) || !data.ReadBool(isEnter)) {
3052 RS_LOGE("NOTIFY_PAGE_NAME read data err.");
3053 ret = ERR_INVALID_DATA;
3054 break;
3055 }
3056 NotifyPageName(packageName, pageName, isEnter);
3057 break;
3058 }
3059 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_VMA_CACHE_STATUS) : {
3060 bool flag{false};
3061 if (!data.ReadBool(flag)) {
3062 RS_LOGE("RSRenderServiceConnectionStub::SET_VMA_CACHE_STATUS read flag failed!");
3063 ret = ERR_INVALID_DATA;
3064 break;
3065 }
3066 SetVmaCacheStatus(flag);
3067 break;
3068 }
3069 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_ANCO_FORCE_DO_DIRECT) : {
3070 bool direct{false};
3071 if (!data.ReadBool(direct)) {
3072 RS_LOGE("RSRenderServiceConnectionStub::SET_ANCO_FORCE_DO_DIRECT Read direct failed!");
3073 ret = ERR_INVALID_DATA;
3074 break;
3075 }
3076 bool res;
3077 if (SetAncoForceDoDirect(direct, res) != ERR_OK || !reply.WriteBool(res)) {
3078 RS_LOGE("RSRenderServiceConnectionStub::SET_ANCO_FORCE_DO_DIRECT Write result failed!");
3079 ret = ERR_INVALID_REPLY;
3080 }
3081 break;
3082 }
3083 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::CREATE_DISPLAY_NODE) : {
3084 uint64_t id{0};
3085 if (!data.ReadUint64(id)) {
3086 RS_LOGE("RSRenderServiceConnectionStub::CREATE_DISPLAY_NODE Read id failed!");
3087 ret = ERR_INVALID_DATA;
3088 break;
3089 }
3090 bool isNonSystemCalling = false;
3091 bool isTokenTypeValid = true;
3092 RSInterfaceCodeAccessVerifierBase::GetAccessType(isTokenTypeValid, isNonSystemCalling);
3093 if (isNonSystemCalling && !IsValidCallingPid(ExtractPid(id), callingPid)) {
3094 RS_LOGW("CREATE_DISPLAY_NODE invalid nodeId[%{public}" PRIu64 "] pid[%{public}d]", id, callingPid);
3095 ret = ERR_INVALID_DATA;
3096 break;
3097 }
3098 uint64_t mirrorId{0};
3099 uint64_t screenId{0};
3100 bool isMirrored{false};
3101 if (!data.ReadUint64(mirrorId) ||
3102 !data.ReadUint64(screenId) ||
3103 !data.ReadBool(isMirrored)) {
3104 RS_LOGE("RSRenderServiceConnectionStub::CREATE_DISPLAY_NODE Read config failed!");
3105 ret = ERR_INVALID_DATA;
3106 break;
3107 }
3108 RSDisplayNodeConfig config = {
3109 .screenId = screenId,
3110 .isMirrored = isMirrored,
3111 .mirrorNodeId = mirrorId,
3112 .isSync = true,
3113 };
3114 bool success;
3115 if (CreateNode(config, id, success) != ERR_OK || reply.WriteBool(success)) {
3116 RS_LOGE("RSRenderServiceConnectionStub::CREATE_DISPLAY_NODE Write success failed!");
3117 ret = ERR_INVALID_REPLY;
3118 }
3119 break;
3120 }
3121 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_FREE_MULTI_WINDOW_STATUS) : {
3122 bool enable{false};
3123 if (!data.ReadBool(enable)) {
3124 RS_LOGE("RSRenderServiceConnectionStub::SET_FREE_MULTI_WINDOW_STATUS Read enable failed!");
3125 ret = ERR_INVALID_DATA;
3126 break;
3127 }
3128 SetFreeMultiWindowStatus(enable);
3129 break;
3130 }
3131 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::REGISTER_SURFACE_BUFFER_CALLBACK) : {
3132 int32_t pid{0};
3133 uint64_t uid{0};
3134 if (!data.ReadInt32(pid) ||
3135 !data.ReadUint64(uid)) {
3136 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SURFACE_BUFFER_CALLBACK Read parcel failed!");
3137 ret = ERR_INVALID_DATA;
3138 break;
3139 }
3140 if (!IsValidCallingPid(pid, callingPid)) {
3141 RS_LOGW("REGISTER_SURFACE_BUFFER_CALLBACK invalid pid[%{public}d]", callingPid);
3142 ret = ERR_INVALID_DATA;
3143 break;
3144 }
3145 auto remoteObject = data.ReadRemoteObject();
3146 if (remoteObject == nullptr) {
3147 ret = ERR_NULL_OBJECT;
3148 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest remoteObject == nullptr");
3149 break;
3150 }
3151 sptr<RSISurfaceBufferCallback> callback = iface_cast<RSISurfaceBufferCallback>(remoteObject);
3152 if (callback == nullptr) {
3153 ret = ERR_NULL_OBJECT;
3154 RS_LOGE("RSRenderServiceConnectionStub::OnRemoteRequest remoteObject cast error");
3155 break;
3156 }
3157 RegisterSurfaceBufferCallback(pid, uid, callback);
3158 break;
3159 }
3160 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::UNREGISTER_SURFACE_BUFFER_CALLBACK) : {
3161 int32_t pid{0};
3162 uint64_t uid{0};
3163 if (!data.ReadInt32(pid) ||
3164 !data.ReadUint64(uid)) {
3165 RS_LOGE("RSRenderServiceConnectionStub::UNREGISTER_SURFACE_BUFFER_CALLBACK Read parcel failed!");
3166 ret = ERR_INVALID_DATA;
3167 break;
3168 }
3169 if (!IsValidCallingPid(pid, callingPid)) {
3170 RS_LOGW("UNREGISTER_SURFACE_BUFFER_CALLBACK invalid pid[%{public}d]", callingPid);
3171 ret = ERR_INVALID_DATA;
3172 break;
3173 }
3174 UnregisterSurfaceBufferCallback(pid, uid);
3175 break;
3176 }
3177 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_LAYER_TOP) : {
3178 std::string nodeIdStr;
3179 bool isTop{false};
3180 if (!data.ReadString(nodeIdStr) ||
3181 !data.ReadBool(isTop)) {
3182 RS_LOGE("RSRenderServiceConnectionStub::SET_LAYER_TOP Read parcel failed!");
3183 ret = ERR_INVALID_DATA;
3184 break;
3185 }
3186 SetLayerTop(nodeIdStr, isTop);
3187 break;
3188 }
3189 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::NOTIFY_SCREEN_SWITCHED) : {
3190 NotifyScreenSwitched();
3191 break;
3192 }
3193 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_WINDOW_CONTAINER) : {
3194 NodeId nodeId = {};
3195 bool isEnabled = {};
3196 if (!data.ReadUint64(nodeId) || !data.ReadBool(isEnabled)) {
3197 RS_LOGE("RSRenderServiceConnectionStub::SET_WINDOW_CONTAINER Read parcel failed!");
3198 ret = ERR_INVALID_DATA;
3199 break;
3200 }
3201 if (!IsValidCallingPid(ExtractPid(nodeId), callingPid)) {
3202 RS_LOGW("SET_WINDOW_CONTAINER invalid nodeId[%{public}" PRIu64 "] pid[%{public}d]", nodeId, callingPid);
3203 ret = ERR_INVALID_DATA;
3204 break;
3205 }
3206 SetWindowContainer(nodeId, isEnabled);
3207 break;
3208 }
3209 case static_cast<uint32_t>(
3210 RSIRenderServiceConnectionInterfaceCode::REGISTER_SELF_DRAWING_NODE_RECT_CHANGE_CALLBACK): {
3211 auto remoteObject = data.ReadRemoteObject();
3212 if (remoteObject == nullptr) {
3213 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SELF_DRAWING_NODE_RECT_CHANGE_CALLBACK Read "
3214 "remoteObject failed!");
3215 ret = ERR_NULL_OBJECT;
3216 break;
3217 }
3218 sptr<RSISelfDrawingNodeRectChangeCallback> callback =
3219 iface_cast<RSISelfDrawingNodeRectChangeCallback>(remoteObject);
3220 if (callback == nullptr) {
3221 ret = ERR_NULL_OBJECT;
3222 break;
3223 }
3224 int32_t status = RegisterSelfDrawingNodeRectChangeCallback(callback);
3225 if (!reply.WriteInt32(status)) {
3226 RS_LOGE("RSRenderServiceConnectionStub::REGISTER_SELF_DRAWING_NODE_RECT_CHANGE_CALLBACK Write status "
3227 "failed!");
3228 ret = ERR_INVALID_REPLY;
3229 }
3230 break;
3231 }
3232 #ifdef RS_ENABLE_OVERLAY_DISPLAY
3233 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::SET_OVERLAY_DISPLAY_MODE) : {
3234 RS_LOGI("RSRenderServicrConnectionStub::OnRemoteRequest SET_OVERLAY_DISPLAY_MODE");
3235 int32_t mode{0};
3236 if (!data.ReadInt32(mode)) {
3237 RS_LOGE("RSRenderServiceConnectionStub::SET_OVERLAY_DISPLAY_MODE Read mode failed!");
3238 ret = ERR_INVALID_DATA;
3239 break;
3240 }
3241 int32_t result = SetOverlayDisplayMode(mode);
3242 if (!reply.WriteInt32(result)) {
3243 RS_LOGE("RSRenderServiceConnectionStub::SET_OVERLAY_DISPLAY_MODE Write status failed!");
3244 ret = ERR_INVALID_REPLY;
3245 }
3246 break;
3247 }
3248 #endif
3249 case static_cast<uint32_t>(RSIRenderServiceConnectionInterfaceCode::TEST_LOAD_FILE_SUB_TREE) : {
3250 NodeId nodeId = {};
3251 std::string filePath;
3252 if (!data.ReadUint64(nodeId) || !data.ReadString(filePath)) {
3253 RS_LOGE("RSRenderServiceConnectionStub::TEST_LOAD_FILE_SUB_TREE Read parcel failed!");
3254 ret = ERR_INVALID_DATA;
3255 break;
3256 }
3257 RS_PROFILER_TEST_LOAD_FILE_SUB_TREE(nodeId, filePath);
3258 break;
3259 }
3260 default: {
3261 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
3262 }
3263 }
3264
3265 return ret;
3266 }
3267
ReadDataBaseRs(DataBaseRs & info,MessageParcel & data)3268 bool RSRenderServiceConnectionStub::ReadDataBaseRs(DataBaseRs& info, MessageParcel& data)
3269 {
3270 if (!data.ReadInt32(info.appPid) || !data.ReadInt32(info.eventType) ||
3271 !data.ReadInt32(info.versionCode) || !data.ReadInt64(info.uniqueId) ||
3272 !data.ReadInt64(info.inputTime) || !data.ReadInt64(info.beginVsyncTime) ||
3273 !data.ReadInt64(info.endVsyncTime) || !data.ReadBool(info.isDisplayAnimator) ||
3274 !data.ReadString(info.sceneId) || !data.ReadString(info.versionName) ||
3275 !data.ReadString(info.bundleName) || !data.ReadString(info.processName) ||
3276 !data.ReadString(info.abilityName) ||!data.ReadString(info.pageUrl) ||
3277 !data.ReadString(info.sourceType) || !data.ReadString(info.note)) {
3278 RS_LOGE("RSRenderServiceConnectionStub::ReadDataBaseRs Read parcel failed!");
3279 return false;
3280 }
3281 return true;
3282 }
3283
ReadAppInfo(AppInfo & info,MessageParcel & data)3284 bool RSRenderServiceConnectionStub::ReadAppInfo(AppInfo& info, MessageParcel& data)
3285 {
3286 if (!data.ReadInt64(info.startTime)) {
3287 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read startTime failed!");
3288 return false;
3289 }
3290 if (!data.ReadInt64(info.endTime)) {
3291 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read endTime failed!");
3292 return false;
3293 }
3294 if (!data.ReadInt32(info.pid)) {
3295 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read pid failed!");
3296 return false;
3297 }
3298 if (!data.ReadString(info.versionName)) {
3299 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read versionName failed!");
3300 return false;
3301 }
3302 if (!data.ReadInt32(info.versionCode)) {
3303 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read versionCode failed!");
3304 return false;
3305 }
3306 if (!data.ReadString(info.bundleName)) {
3307 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read bundleName failed!");
3308 return false;
3309 }
3310 if (!data.ReadString(info.processName)) {
3311 RS_LOGE("RSRenderServiceConnectionStub::ReadAppInfo Read processName failed!");
3312 return false;
3313 }
3314 return true;
3315 }
3316
ReadGameStateDataRs(GameStateData & info,MessageParcel & data)3317 bool RSRenderServiceConnectionStub::ReadGameStateDataRs(GameStateData& info, MessageParcel& data)
3318 {
3319 if (!data.ReadInt32(info.pid) || !data.ReadInt32(info.uid) ||
3320 !data.ReadInt32(info.state) || !data.ReadInt32(info.renderTid) ||
3321 !data.ReadString(info.bundleName)) {
3322 RS_LOGE("RSRenderServiceConnectionStub::ReadGameStateDataRs Read parcel failed!");
3323 return false;
3324 }
3325 return true;
3326 }
3327
ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig & captureConfig,MessageParcel & data)3328 bool RSRenderServiceConnectionStub::ReadSurfaceCaptureConfig(RSSurfaceCaptureConfig& captureConfig, MessageParcel& data)
3329 {
3330 uint8_t captureType { 0 };
3331 if (!data.ReadFloat(captureConfig.scaleX) || !data.ReadFloat(captureConfig.scaleY) ||
3332 !data.ReadBool(captureConfig.useDma) || !data.ReadBool(captureConfig.useCurWindow) ||
3333 !data.ReadUint8(captureType) || !data.ReadBool(captureConfig.isSync) ||
3334 !data.ReadFloat(captureConfig.mainScreenRect.left_) ||
3335 !data.ReadFloat(captureConfig.mainScreenRect.top_) ||
3336 !data.ReadFloat(captureConfig.mainScreenRect.right_) ||
3337 !data.ReadFloat(captureConfig.mainScreenRect.bottom_)) {
3338 RS_LOGE("RSRenderServiceConnectionStub::ReadSurfaceCaptureConfig Read captureType failed!");
3339 return false;
3340 }
3341 captureConfig.captureType = static_cast<SurfaceCaptureType>(captureType);
3342 return true;
3343 }
3344
ReadSurfaceCaptureBlurParam(RSSurfaceCaptureBlurParam & blurParam,MessageParcel & data)3345 bool RSRenderServiceConnectionStub::ReadSurfaceCaptureBlurParam(
3346 RSSurfaceCaptureBlurParam& blurParam, MessageParcel& data)
3347 {
3348 if (!data.ReadBool(blurParam.isNeedBlur) || !data.ReadFloat(blurParam.blurRadius)) {
3349 RS_LOGE("RSRenderServiceConnectionStub::ReadSurfaceCaptureBlurParam Read blurParam failed!");
3350 return false;
3351 }
3352 return true;
3353 }
3354
ReadSurfaceCaptureAreaRect(Drawing::Rect & specifiedAreaRect,MessageParcel & data)3355 bool RSRenderServiceConnectionStub::ReadSurfaceCaptureAreaRect(
3356 Drawing::Rect& specifiedAreaRect, MessageParcel& data)
3357 {
3358 if (!data.ReadFloat(specifiedAreaRect.left_) || !data.ReadFloat(specifiedAreaRect.top_) ||
3359 !data.ReadFloat(specifiedAreaRect.right_) || !data.ReadFloat(specifiedAreaRect.bottom_)) {
3360 RS_LOGE("RSRenderServiceConnectionStub::ReadSurfaceCaptureAreaRect Read specifiedAreaRect failed!");
3361 return false;
3362 }
3363 return true;
3364 }
3365
3366 const RSInterfaceCodeSecurityManager RSRenderServiceConnectionStub::securityManager_ = \
3367 RSInterfaceCodeSecurityManager::CreateInstance<RSIRenderServiceConnectionInterfaceCodeAccessVerifier>();
3368 } // namespace Rosen
3369 } // namespace OHOS
3370