1 /*
2 * Copyright (c) 2025 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 "oh_window_pip.h"
17
18 #include "oh_window_comm.h"
19 #include "web_picture_in_picture_controller_interface.h"
20 #include "window_manager_hilog.h"
21
22 using namespace OHOS::Rosen;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t MAX_CONTROL_TYPE_NUM = 8;
28 constexpr uint32_t MAX_CONTROL_STATUS_NUM = 1;
29 std::shared_mutex idMapMutex_;
30 std::map<uint32_t, sptr<WebPictureInPictureControllerInterface>> g_ControllerIds;
31 }
32
IsIdMapFull()33 inline bool IsIdMapFull()
34 {
35 std::shared_lock<std::shared_mutex> lock(idMapMutex_);
36 if (g_ControllerIds.size() >= static_cast<size_t>(UINT32_MAX - 1)) {
37 return true;
38 }
39 return false;
40 }
41
FindNextAvailableId()42 inline uint32_t FindNextAvailableId()
43 {
44 if (IsIdMapFull()) {
45 return 0;
46 }
47 uint32_t nextId = 0;
48 std::unique_lock<std::shared_mutex> lock(idMapMutex_);
49 while (nextId < UINT32_MAX && g_ControllerIds.find(nextId) != g_ControllerIds.end()) {
50 nextId++;
51 }
52 return nextId;
53 }
54
GetControllerFromId(uint32_t controllerId)55 inline sptr<WebPictureInPictureControllerInterface> GetControllerFromId(uint32_t controllerId)
56 {
57 std::shared_lock<std::shared_mutex> lock(idMapMutex_);
58 if (g_ControllerIds.find(controllerId) == g_ControllerIds.end()) {
59 return nullptr;
60 }
61 return g_ControllerIds.at(controllerId);
62 }
63 } // namespace Rosen
64 } // namespace OHOS
65
66 namespace {
67 /*
68 * Used to map from WMError to WindowManager_ErrorCode.
69 */
70 const std::unordered_map<WMError, WindowManager_ErrorCode> OH_WINDOW_TO_ERROR_CODE_MAP {
71 { WMError::WM_OK, WindowManager_ErrorCode::OK },
72 { WMError::WM_ERROR_INVALID_PARAM, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM },
73 { WMError::WM_ERROR_DEVICE_NOT_SUPPORT, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_DEVICE_NOT_SUPPORTED },
74 { WMError::WM_ERROR_PIP_DESTROY_FAILED, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_DESTROY_FAILED },
75 { WMError::WM_ERROR_PIP_STATE_ABNORMALLY, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_STATE_ABNORMAL },
76 { WMError::WM_ERROR_PIP_CREATE_FAILED, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_CREATE_FAILED },
77 { WMError::WM_ERROR_PIP_INTERNAL_ERROR, WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_INTERNAL_ERROR },
78 { WMError::WM_ERROR_PIP_REPEAT_OPERATION,
79 WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_REPEATED_OPERATION },
80 };
81
GetErrorCodeFromWMError(WMError error)82 inline WindowManager_ErrorCode GetErrorCodeFromWMError(WMError error)
83 {
84 if (OH_WINDOW_TO_ERROR_CODE_MAP.find(error) == OH_WINDOW_TO_ERROR_CODE_MAP.end()) {
85 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_INTERNAL_ERROR;
86 }
87 return OH_WINDOW_TO_ERROR_CODE_MAP.at(error);
88 }
89 } //namespace
90
OH_PictureInPicture_CreatePipConfig(PictureInPicture_PipConfig * pipConfig)91 int32_t OH_PictureInPicture_CreatePipConfig(PictureInPicture_PipConfig* pipConfig)
92 {
93 if (pipConfig == nullptr) {
94 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
95 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
96 }
97 PiPConfig* config = new PiPConfig();
98 *pipConfig = reinterpret_cast<PictureInPicture_PipConfig>(config);
99 TLOGI(WmsLogTag::WMS_PIP, "pipConfig created");
100 return WindowManager_ErrorCode::OK;
101 }
102
OH_PictureInPicture_DestroyPipConfig(PictureInPicture_PipConfig * pipConfig)103 int32_t OH_PictureInPicture_DestroyPipConfig(PictureInPicture_PipConfig* pipConfig)
104 {
105 if (pipConfig == nullptr) {
106 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
107 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
108 }
109 auto config = reinterpret_cast<PiPConfig*>(*pipConfig);
110 if (config == nullptr) {
111 TLOGE(WmsLogTag::WMS_PIP, "config is nullptr");
112 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
113 }
114 delete config;
115 *pipConfig = nullptr;
116 TLOGI(WmsLogTag::WMS_PIP, "pipConfig destroyed");
117 return WindowManager_ErrorCode::OK;
118 }
119
OH_PictureInPicture_SetPipMainWindowId(PictureInPicture_PipConfig pipConfig,uint32_t mainWindowId)120 int32_t OH_PictureInPicture_SetPipMainWindowId(PictureInPicture_PipConfig pipConfig, uint32_t mainWindowId)
121 {
122 if (pipConfig == nullptr) {
123 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
124 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
125 }
126 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
127 config->mainWindowId = mainWindowId;
128 return WindowManager_ErrorCode::OK;
129 }
130
OH_PictureInPicture_SetPipTemplateType(PictureInPicture_PipConfig pipConfig,PictureInPicture_PipTemplateType pipTemplateType)131 int32_t OH_PictureInPicture_SetPipTemplateType(PictureInPicture_PipConfig pipConfig,
132 PictureInPicture_PipTemplateType pipTemplateType)
133 {
134 if (pipConfig == nullptr) {
135 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
136 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
137 }
138 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
139 config->pipTemplateType = static_cast<uint32_t>(pipTemplateType);
140 return WindowManager_ErrorCode::OK;
141 }
142
OH_PictureInPicture_SetPipRect(PictureInPicture_PipConfig pipConfig,uint32_t width,uint32_t height)143 int32_t OH_PictureInPicture_SetPipRect(PictureInPicture_PipConfig pipConfig, uint32_t width, uint32_t height)
144 {
145 if (pipConfig == nullptr) {
146 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
147 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
148 }
149 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
150 config->width = width;
151 config->height = height;
152 return WindowManager_ErrorCode::OK;
153 }
154
OH_PictureInPicture_SetPipControlGroup(PictureInPicture_PipConfig pipConfig,PictureInPicture_PipControlGroup * controlGroup,uint8_t controlGroupLength)155 int32_t OH_PictureInPicture_SetPipControlGroup(PictureInPicture_PipConfig pipConfig,
156 PictureInPicture_PipControlGroup* controlGroup, uint8_t controlGroupLength)
157 {
158 if (pipConfig == nullptr) {
159 TLOGE(WmsLogTag::WMS_PIP, "pipConfig is nullptr");
160 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
161 }
162 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
163 if (controlGroup != nullptr) {
164 config->controlGroup = std::vector<uint32_t>(controlGroup, controlGroup + controlGroupLength);
165 } else {
166 config->controlGroup = {};
167 }
168 return WindowManager_ErrorCode::OK;
169 }
170
OH_PictureInPicture_SetPipNapiEnv(PictureInPicture_PipConfig pipConfig,void * env)171 int32_t OH_PictureInPicture_SetPipNapiEnv(PictureInPicture_PipConfig pipConfig, void* env)
172 {
173 if (pipConfig == nullptr || env == nullptr) {
174 TLOGE(WmsLogTag::WMS_PIP, "pipConfig or env is nullptr");
175 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
176 }
177 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
178 config->env = reinterpret_cast<napi_env>(env);
179 return WindowManager_ErrorCode::OK;
180 }
181
OH_PictureInPicture_CreatePip(PictureInPicture_PipConfig pipConfig,uint32_t * controllerId)182 int32_t OH_PictureInPicture_CreatePip(PictureInPicture_PipConfig pipConfig, uint32_t* controllerId)
183 {
184 if (pipConfig == nullptr || controllerId == nullptr) {
185 TLOGE(WmsLogTag::WMS_PIP, "pipConfig or controllerId is nullptr");
186 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
187 }
188 if (IsIdMapFull()) {
189 TLOGE(WmsLogTag::WMS_PIP, "all IDs are used");
190 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_PIP_INTERNAL_ERROR;
191 }
192 auto config = reinterpret_cast<PiPConfig*>(pipConfig);
193 auto webPipControllerInterface = OHOS::sptr<WebPictureInPictureControllerInterface>::MakeSptr();
194 auto errCode = webPipControllerInterface->Create(*config);
195 if (errCode != WMError::WM_OK) {
196 TLOGE(WmsLogTag::WMS_PIP, "pipInterface create failed");
197 return GetErrorCodeFromWMError(errCode);
198 }
199 uint32_t id = FindNextAvailableId();
200 *controllerId = id;
201 std::unique_lock<std::shared_mutex> lock(idMapMutex_);
202 g_ControllerIds[id] = webPipControllerInterface;
203 TLOGI(WmsLogTag::WMS_PIP, "create success! controllerId: %{public}u", id);
204 return WindowManager_ErrorCode::OK;
205 }
206
OH_PictureInPicture_DeletePip(uint32_t controllerId)207 int32_t OH_PictureInPicture_DeletePip(uint32_t controllerId)
208 {
209 auto pipController = GetControllerFromId(controllerId);
210 if (pipController == nullptr) {
211 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
212 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
213 }
214 if (pipController->IsStarted()) {
215 TLOGE(WmsLogTag::WMS_PIP, "could not delete before stopPip: %{public}d", controllerId);
216 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
217 }
218 std::unique_lock<std::shared_mutex> lock(idMapMutex_);
219 g_ControllerIds.erase(controllerId);
220 return WindowManager_ErrorCode::OK;
221 }
222
OH_PictureInPicture_StartPip(uint32_t controllerId)223 int32_t OH_PictureInPicture_StartPip(uint32_t controllerId)
224 {
225 auto pipController = GetControllerFromId(controllerId);
226 if (pipController == nullptr) {
227 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
228 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
229 }
230 return GetErrorCodeFromWMError(pipController->StartPip(controllerId));
231 }
232
OH_PictureInPicture_StopPip(uint32_t controllerId)233 int32_t OH_PictureInPicture_StopPip(uint32_t controllerId)
234 {
235 auto pipController = GetControllerFromId(controllerId);
236 if (pipController == nullptr) {
237 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
238 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
239 }
240 return GetErrorCodeFromWMError(pipController->StopPip());
241 }
242
OH_PictureInPicture_UpdatePipContentSize(uint32_t controllerId,uint32_t width,uint32_t height)243 int32_t OH_PictureInPicture_UpdatePipContentSize(uint32_t controllerId, uint32_t width, uint32_t height)
244 {
245 auto pipController = GetControllerFromId(controllerId);
246 if (pipController == nullptr) {
247 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
248 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
249 }
250 return GetErrorCodeFromWMError(pipController->UpdateContentSize(width, height));
251 }
252
OH_PictureInPicture_UpdatePipControlStatus(uint32_t controllerId,PictureInPicture_PipControlType controlType,PictureInPicture_PipControlStatus status)253 int32_t OH_PictureInPicture_UpdatePipControlStatus(uint32_t controllerId, PictureInPicture_PipControlType controlType,
254 PictureInPicture_PipControlStatus status)
255 {
256 auto typeNum = static_cast<uint32_t>(controlType);
257 auto statusNum = static_cast<uint32_t>(status);
258 if (typeNum > MAX_CONTROL_TYPE_NUM || statusNum > MAX_CONTROL_STATUS_NUM) {
259 TLOGE(WmsLogTag::WMS_PIP, "param error. controlType: %{public}d, status: %{public}d", typeNum, statusNum);
260 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
261 }
262 auto pipController = GetControllerFromId(controllerId);
263 if (pipController == nullptr) {
264 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
265 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
266 }
267 return GetErrorCodeFromWMError(pipController->UpdatePiPControlStatus(static_cast<PiPControlType>(controlType),
268 static_cast<PiPControlStatus>(status)));
269 }
270
OH_PictureInPicture_SetPipControlEnabled(uint32_t controllerId,PictureInPicture_PipControlType controlType,bool enabled)271 int32_t OH_PictureInPicture_SetPipControlEnabled(uint32_t controllerId, PictureInPicture_PipControlType controlType,
272 bool enabled)
273 {
274 auto typeNum = static_cast<uint32_t>(controlType);
275 if (typeNum > MAX_CONTROL_TYPE_NUM) {
276 TLOGE(WmsLogTag::WMS_PIP, "param error. controlType: %{public}d", typeNum);
277 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
278 }
279 auto pipController = GetControllerFromId(controllerId);
280 if (pipController == nullptr) {
281 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
282 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
283 }
284 return GetErrorCodeFromWMError(pipController->setPiPControlEnabled(static_cast<PiPControlType>(controlType),
285 enabled));
286 }
287
OH_PictureInPicture_SetPipInitialSurfaceRect(uint32_t controllerId,int32_t positionX,int32_t positionY,uint32_t width,uint32_t height)288 int32_t OH_PictureInPicture_SetPipInitialSurfaceRect(uint32_t controllerId, int32_t positionX, int32_t positionY,
289 uint32_t width, uint32_t height)
290 {
291 auto pipController = GetControllerFromId(controllerId);
292 if (pipController == nullptr) {
293 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
294 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
295 }
296 return GetErrorCodeFromWMError(pipController->SetPipInitialSurfaceRect(positionX, positionY, width, height));
297 }
298
OH_PictureInPicture_UnsetPipInitialSurfaceRect(uint32_t controllerId)299 int32_t OH_PictureInPicture_UnsetPipInitialSurfaceRect(uint32_t controllerId)
300 {
301 auto pipController = GetControllerFromId(controllerId);
302 if (pipController == nullptr) {
303 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
304 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
305 }
306 return GetErrorCodeFromWMError(pipController->UnsetPipInitialSurfaceRect());
307 }
308
OH_PictureInPicture_RegisterStartPipCallback(uint32_t controllerId,WebPipStartPipCallback callback)309 int32_t OH_PictureInPicture_RegisterStartPipCallback(uint32_t controllerId, WebPipStartPipCallback callback)
310 {
311 auto pipController = GetControllerFromId(controllerId);
312 if (pipController == nullptr) {
313 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
314 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
315 }
316 return GetErrorCodeFromWMError(pipController->RegisterStartPipListener(callback));
317 }
318
OH_PictureInPicture_UnregisterStartPipCallback(uint32_t controllerId,WebPipStartPipCallback callback)319 int32_t OH_PictureInPicture_UnregisterStartPipCallback(uint32_t controllerId, WebPipStartPipCallback callback)
320 {
321 auto pipController = GetControllerFromId(controllerId);
322 if (pipController == nullptr) {
323 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
324 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
325 }
326 if (callback == nullptr) {
327 TLOGE(WmsLogTag::WMS_PIP, "callback is nullptr");
328 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
329 }
330 return GetErrorCodeFromWMError(pipController->UnregisterStartPipListener(callback));
331 }
332
OH_PictureInPicture_UnregisterAllStartPipCallbacks(uint32_t controllerId)333 int32_t OH_PictureInPicture_UnregisterAllStartPipCallbacks(uint32_t controllerId)
334 {
335 auto pipController = GetControllerFromId(controllerId);
336 if (pipController == nullptr) {
337 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
338 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
339 }
340 return GetErrorCodeFromWMError(pipController->UnregisterAllPiPStart());
341 }
342
OH_PictureInPicture_RegisterLifecycleListener(uint32_t controllerId,WebPipLifecycleCallback callback)343 int32_t OH_PictureInPicture_RegisterLifecycleListener(uint32_t controllerId, WebPipLifecycleCallback callback)
344 {
345 auto pipController = GetControllerFromId(controllerId);
346 if (pipController == nullptr) {
347 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
348 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
349 }
350 return GetErrorCodeFromWMError(pipController->RegisterLifeCycleListener(
351 reinterpret_cast<OHOS::Rosen::NativePipLifeCycleCallback>(callback)));
352 }
353
OH_PictureInPicture_UnregisterLifecycleListener(uint32_t controllerId,WebPipLifecycleCallback callback)354 int32_t OH_PictureInPicture_UnregisterLifecycleListener(uint32_t controllerId, WebPipLifecycleCallback callback)
355 {
356 auto pipController = GetControllerFromId(controllerId);
357 if (pipController == nullptr) {
358 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
359 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
360 }
361 if (callback == nullptr) {
362 TLOGE(WmsLogTag::WMS_PIP, "callback is nullptr");
363 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
364 }
365 return GetErrorCodeFromWMError(pipController->UnregisterLifeCycleListener(
366 reinterpret_cast<OHOS::Rosen::NativePipLifeCycleCallback>(callback)));
367 }
368
OH_PictureInPicture_UnregisterAllLifecycleListeners(uint32_t controllerId)369 int32_t OH_PictureInPicture_UnregisterAllLifecycleListeners(uint32_t controllerId)
370 {
371 auto pipController = GetControllerFromId(controllerId);
372 if (pipController == nullptr) {
373 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
374 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
375 }
376 return GetErrorCodeFromWMError(pipController->UnregisterAllPiPLifecycle());
377 }
378
OH_PictureInPicture_RegisterControlEventListener(uint32_t controllerId,WebPipControlEventCallback callback)379 int32_t OH_PictureInPicture_RegisterControlEventListener(uint32_t controllerId, WebPipControlEventCallback callback)
380 {
381 auto pipController = GetControllerFromId(controllerId);
382 if (pipController == nullptr) {
383 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
384 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
385 }
386 return GetErrorCodeFromWMError(pipController->RegisterControlEventListener(
387 reinterpret_cast<OHOS::Rosen::NativePipControlEventCallback>(callback)));
388 }
389
OH_PictureInPicture_UnregisterControlEventListener(uint32_t controllerId,WebPipControlEventCallback callback)390 int32_t OH_PictureInPicture_UnregisterControlEventListener(uint32_t controllerId, WebPipControlEventCallback callback)
391 {
392 auto pipController = GetControllerFromId(controllerId);
393 if (pipController == nullptr) {
394 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
395 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
396 }
397 if (callback == nullptr) {
398 TLOGE(WmsLogTag::WMS_PIP, "callback is nullptr");
399 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
400 }
401 return GetErrorCodeFromWMError(pipController->UnregisterControlEventListener(
402 reinterpret_cast<OHOS::Rosen::NativePipControlEventCallback>(callback)));
403 }
404
OH_PictureInPicture_UnregisterAllControlEventListeners(uint32_t controllerId)405 int32_t OH_PictureInPicture_UnregisterAllControlEventListeners(uint32_t controllerId)
406 {
407 auto pipController = GetControllerFromId(controllerId);
408 if (pipController == nullptr) {
409 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
410 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
411 }
412 return GetErrorCodeFromWMError(pipController->UnregisterAllPiPControlObserver());
413 }
414
OH_PictureInPicture_RegisterResizeListener(uint32_t controllerId,WebPipResizeCallback callback)415 int32_t OH_PictureInPicture_RegisterResizeListener(uint32_t controllerId, WebPipResizeCallback callback)
416 {
417 auto pipController = GetControllerFromId(controllerId);
418 if (pipController == nullptr) {
419 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
420 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
421 }
422 return GetErrorCodeFromWMError(pipController->RegisterResizeListener(callback));
423 }
424
OH_PictureInPicture_UnregisterResizeListener(uint32_t controllerId,WebPipResizeCallback callback)425 int32_t OH_PictureInPicture_UnregisterResizeListener(uint32_t controllerId, WebPipResizeCallback callback)
426 {
427 auto pipController = GetControllerFromId(controllerId);
428 if (pipController == nullptr) {
429 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
430 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
431 }
432 if (callback == nullptr) {
433 TLOGE(WmsLogTag::WMS_PIP, "callback is nullptr");
434 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
435 }
436 return GetErrorCodeFromWMError(pipController->UnregisterResizeListener(callback));
437 }
438
OH_PictureInPicture_UnregisterAllResizeListeners(uint32_t controllerId)439 int32_t OH_PictureInPicture_UnregisterAllResizeListeners(uint32_t controllerId)
440 {
441 auto pipController = GetControllerFromId(controllerId);
442 if (pipController == nullptr) {
443 TLOGE(WmsLogTag::WMS_PIP, "controllerId not found: %{public}d", controllerId);
444 return WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INCORRECT_PARAM;
445 }
446 return GetErrorCodeFromWMError(pipController->UnregisterAllPiPWindowSize());
447 }