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