• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 "interaction_manager.h"
17 
18 #include "devicestatus_define.h"
19 #include "drag_data.h"
20 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
21 #include "intention_manager.h"
22 #else
23 #include "drag_manager.h"
24 #endif // OHOS_BUILD_ENABLE_ARKUI_X
25 
26 namespace OHOS {
27 namespace Msdp {
28 namespace DeviceStatus {
29 
30 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
31 using CooperateMsgInfoCallback = std::function<void(const std::string&, const CoordinationMsgInfo&)>;
32 #endif // OHOS_BUILD_ENABLE_ARKUI_X
33 
34 std::shared_ptr<InteractionManager> InteractionManager::instance_ = nullptr;
35 std::mutex InteractionManager::mutex_;
36 
GetInstance()37 std::shared_ptr<InteractionManager> InteractionManager::GetInstance()
38 {
39     if (instance_ == nullptr) {
40         std::lock_guard<std::mutex> lock(mutex_);
41         if (instance_ == nullptr) {
42             instance_ = std::make_shared<InteractionManager>();
43         }
44     }
45     return instance_;
46 }
47 
48 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,bool isCompatible)49 int32_t InteractionManager::RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
50     bool isCompatible)
51 {
52     return INTER_MGR_IMPL.RegisterCoordinationListener(listener, isCompatible);
53 }
54 
UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,bool isCompatible)55 int32_t InteractionManager::UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
56     bool isCompatible)
57 {
58     return INTER_MGR_IMPL.UnregisterCoordinationListener(listener, isCompatible);
59 }
60 
PrepareCoordination(CooperateMsgInfoCallback callback,bool isCompatible)61 int32_t InteractionManager::PrepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible)
62 {
63     return INTER_MGR_IMPL.PrepareCoordination(callback, isCompatible);
64 }
65 
UnprepareCoordination(CooperateMsgInfoCallback callback,bool isCompatible)66 int32_t InteractionManager::UnprepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible)
67 {
68     return INTER_MGR_IMPL.UnprepareCoordination(callback, isCompatible);
69 }
70 
ActivateCoordination(const std::string & remoteNetworkId,int32_t startDeviceId,CooperateMsgInfoCallback callback,bool isCompatible)71 int32_t InteractionManager::ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
72     CooperateMsgInfoCallback callback, bool isCompatible)
73 {
74     return INTER_MGR_IMPL.ActivateCoordination(remoteNetworkId, startDeviceId, callback, isCompatible);
75 }
76 
ActivateCooperateWithOptions(const std::string & remoteNetworkId,int32_t startDeviceId,CooperateMsgInfoCallback callback,const CooperateOptions & cooperateOptions)77 int32_t InteractionManager::ActivateCooperateWithOptions(const std::string &remoteNetworkId, int32_t startDeviceId,
78     CooperateMsgInfoCallback callback, const CooperateOptions &cooperateOptions)
79 {
80     return INTER_MGR_IMPL.ActivateCooperateWithOptions(remoteNetworkId, startDeviceId, callback, cooperateOptions);
81 }
82 
DeactivateCoordination(bool isUnchained,CooperateMsgInfoCallback callback,bool isCompatible)83 int32_t InteractionManager::DeactivateCoordination(bool isUnchained, CooperateMsgInfoCallback callback,
84     bool isCompatible)
85 {
86     return INTER_MGR_IMPL.DeactivateCoordination(isUnchained, callback, isCompatible);
87 }
88 
SetDraggableState(bool state)89 int32_t InteractionManager::SetDraggableState(bool state)
90 {
91     return INTER_MGR_IMPL.SetDraggableState(state);
92 }
93 
GetAppDragSwitchState(bool & state)94 int32_t InteractionManager::GetAppDragSwitchState(bool &state)
95 {
96     return INTER_MGR_IMPL.GetAppDragSwitchState(state);
97 }
98 
SetDraggableStateAsync(bool state,int64_t downTime)99 void InteractionManager::SetDraggableStateAsync(bool state, int64_t downTime)
100 {
101     INTER_MGR_IMPL.SetDraggableStateAsync(state, downTime);
102 }
103 
GetCoordinationState(const std::string & networkId,std::function<void (bool)> callback,bool isCompatible)104 int32_t InteractionManager::GetCoordinationState(
105     const std::string &networkId, std::function<void(bool)> callback, bool isCompatible)
106 {
107     return INTER_MGR_IMPL.GetCoordinationState(networkId, callback, isCompatible);
108 }
109 
GetCoordinationState(const std::string & udId,bool & state)110 int32_t InteractionManager::GetCoordinationState(const std::string &udId, bool &state)
111 {
112     return INTER_MGR_IMPL.GetCoordinationState(udId, state);
113 }
114 
RegisterEventListener(const std::string & networkId,std::shared_ptr<IEventListener> listener)115 int32_t InteractionManager::RegisterEventListener(const std::string &networkId,
116     std::shared_ptr<IEventListener> listener)
117 {
118 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
119     return INTER_MGR_IMPL.RegisterEventListener(networkId, listener);
120 #else
121     return RET_OK;
122 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
123 }
124 
UnregisterEventListener(const std::string & networkId,std::shared_ptr<IEventListener> listener)125 int32_t InteractionManager::UnregisterEventListener(const std::string &networkId,
126     std::shared_ptr<IEventListener> listener)
127 {
128 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
129     return INTER_MGR_IMPL.UnregisterEventListener(networkId, listener);
130 #else
131     return RET_OK;
132 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
133 }
134 
SetDamplingCoefficient(uint32_t direction,double coefficient)135 int32_t InteractionManager::SetDamplingCoefficient(uint32_t direction, double coefficient)
136 {
137 #ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
138     return INTER_MGR_IMPL.SetDamplingCoefficient(direction, coefficient);
139 #else
140     return RET_OK;
141 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
142 }
143 
UpdateDragStyle(DragCursorStyle style,int32_t eventId)144 int32_t InteractionManager::UpdateDragStyle(DragCursorStyle style, int32_t eventId)
145 {
146     return INTER_MGR_IMPL.UpdateDragStyle(style, eventId);
147 }
148 
StartDrag(const DragData & dragData,std::shared_ptr<IStartDragListener> listener)149 int32_t InteractionManager::StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener)
150 {
151     return INTER_MGR_IMPL.StartDrag(dragData, listener);
152 }
153 
StopDrag(const DragDropResult & dropResult)154 int32_t InteractionManager::StopDrag(const DragDropResult &dropResult)
155 {
156     return INTER_MGR_IMPL.StopDrag(dropResult);
157 }
158 
GetDragTargetPid()159 int32_t InteractionManager::GetDragTargetPid()
160 {
161     return INTER_MGR_IMPL.GetDragTargetPid();
162 }
163 
GetUdKey(std::string & udKey)164 int32_t InteractionManager::GetUdKey(std::string &udKey)
165 {
166     return INTER_MGR_IMPL.GetUdKey(udKey);
167 }
168 
AddDraglistener(DragListenerPtr listener,bool isJsCaller)169 int32_t InteractionManager::AddDraglistener(DragListenerPtr listener, bool isJsCaller)
170 {
171     return INTER_MGR_IMPL.AddDraglistener(listener, isJsCaller);
172 }
173 
RemoveDraglistener(DragListenerPtr listener,bool isJsCaller)174 int32_t InteractionManager::RemoveDraglistener(DragListenerPtr listener, bool isJsCaller)
175 {
176     return INTER_MGR_IMPL.RemoveDraglistener(listener, isJsCaller);
177 }
178 
AddSubscriptListener(SubscriptListenerPtr listener)179 int32_t InteractionManager::AddSubscriptListener(SubscriptListenerPtr listener)
180 {
181     return INTER_MGR_IMPL.AddSubscriptListener(listener);
182 }
183 
RemoveSubscriptListener(SubscriptListenerPtr listener)184 int32_t InteractionManager::RemoveSubscriptListener(SubscriptListenerPtr listener)
185 {
186     return INTER_MGR_IMPL.RemoveSubscriptListener(listener);
187 }
188 
SetDragWindowVisible(bool visible,bool isForce,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)189 int32_t InteractionManager::SetDragWindowVisible(
190     bool visible, bool isForce, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
191 {
192     return INTER_MGR_IMPL.SetDragWindowVisible(visible, isForce, rsTransaction);
193 }
194 
GetShadowOffset(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height)195 int32_t InteractionManager::GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
196 {
197     ShadowOffset shadowOffset;
198     int32_t ret = INTER_MGR_IMPL.GetShadowOffset(shadowOffset);
199     offsetX = shadowOffset.offsetX;
200     offsetY = shadowOffset.offsetY;
201     width = shadowOffset.width;
202     height = shadowOffset.height;
203     return ret;
204 }
205 
UpdateShadowPic(const ShadowInfo & shadowInfo)206 int32_t InteractionManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
207 {
208     return INTER_MGR_IMPL.UpdateShadowPic(shadowInfo);
209 }
210 
GetDragData(DragData & dragData)211 int32_t InteractionManager::GetDragData(DragData &dragData)
212 {
213     return INTER_MGR_IMPL.GetDragData(dragData);
214 }
215 
GetDragState(DragState & dragState)216 int32_t InteractionManager::GetDragState(DragState &dragState)
217 {
218     return INTER_MGR_IMPL.GetDragState(dragState);
219 }
220 
AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener)221 int32_t InteractionManager::AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener)
222 {
223     return INTER_MGR_IMPL.AddHotAreaListener(listener);
224 }
225 
RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener)226 int32_t InteractionManager::RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener)
227 {
228     return INTER_MGR_IMPL.RemoveHotAreaListener(listener);
229 }
230 
UpdatePreviewStyle(const PreviewStyle & previewStyle)231 int32_t InteractionManager::UpdatePreviewStyle(const PreviewStyle &previewStyle)
232 {
233     return INTER_MGR_IMPL.UpdatePreviewStyle(previewStyle);
234 }
235 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)236 int32_t InteractionManager::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
237     const PreviewAnimation &animation)
238 {
239     return INTER_MGR_IMPL.UpdatePreviewStyleWithAnimation(previewStyle, animation);
240 }
241 
RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)242 int32_t InteractionManager::RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
243 {
244     return INTER_MGR_IMPL.RotateDragWindowSync(rsTransaction);
245 }
246 
SetDragWindowScreenId(uint64_t displayId,uint64_t screenId)247 int32_t InteractionManager::SetDragWindowScreenId(uint64_t displayId, uint64_t screenId)
248 {
249     return INTER_MGR_IMPL.SetDragWindowScreenId(displayId, screenId);
250 }
251 
GetDragSummary(std::map<std::string,int64_t> & summarys,bool isJsCaller)252 int32_t InteractionManager::GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller)
253 {
254     return INTER_MGR_IMPL.GetDragSummary(summarys, isJsCaller);
255 }
256 
GetDragSummaryInfo(DragSummaryInfo & dragSummaryInfo)257 int32_t InteractionManager::GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo)
258 {
259     return INTER_MGR_IMPL.GetDragSummaryInfo(dragSummaryInfo);
260 }
261 
SetDragSwitchState(bool enable,bool isJsCaller)262 int32_t InteractionManager::SetDragSwitchState(bool enable, bool isJsCaller)
263 {
264     return INTER_MGR_IMPL.SetDragSwitchState(enable, isJsCaller);
265 }
266 
SetAppDragSwitchState(bool enable,const std::string & pkgName,bool isJsCaller)267 int32_t InteractionManager::SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller)
268 {
269     return INTER_MGR_IMPL.SetAppDragSwitchState(enable, pkgName, isJsCaller);
270 }
271 
GetDragAction(DragAction & dragAction)272 int32_t InteractionManager::GetDragAction(DragAction &dragAction)
273 {
274     return INTER_MGR_IMPL.GetDragAction(dragAction);
275 }
276 
EnterTextEditorArea(bool enable)277 int32_t InteractionManager::EnterTextEditorArea(bool enable)
278 {
279     return INTER_MGR_IMPL.EnterTextEditorArea(enable);
280 }
281 
GetExtraInfo(std::string & extraInfo)282 int32_t InteractionManager::GetExtraInfo(std::string &extraInfo)
283 {
284     return INTER_MGR_IMPL.GetExtraInfo(extraInfo);
285 }
286 
AddPrivilege()287 int32_t InteractionManager::AddPrivilege()
288 {
289     return INTER_MGR_IMPL.AddPrivilege();
290 }
291 
EraseMouseIcon()292 int32_t InteractionManager::EraseMouseIcon()
293 {
294     return INTER_MGR_IMPL.EraseMouseIcon();
295 }
296 
SetMouseDragMonitorState(bool state)297 int32_t InteractionManager::SetMouseDragMonitorState(bool state)
298 {
299     return INTER_MGR_IMPL.SetMouseDragMonitorState(state);
300 }
301 
GetDragBundleInfo(DragBundleInfo & dragBundleInfo)302 int32_t InteractionManager::GetDragBundleInfo(DragBundleInfo &dragBundleInfo)
303 {
304     return INTER_MGR_IMPL.GetDragBundleInfo(dragBundleInfo);
305 }
306 
EnableInternalDropAnimation(const std::string & animationInfo)307 int32_t InteractionManager::EnableInternalDropAnimation(const std::string &animationInfo)
308 {
309     return INTER_MGR_IMPL.EnableInternalDropAnimation(animationInfo);
310 }
311 
IsDragStart()312 bool InteractionManager::IsDragStart()
313 {
314     return INTER_MGR_IMPL.IsDragStart();
315 }
316 
317 #else
StartDrag(const DragData & dragData)318 int32_t InteractionManager::StartDrag(const DragData &dragData)
319 {
320     return DRAG_MANAGER.StartDrag(dragData);
321 }
322 
UpdateDragStyle(DragCursorStyle style)323 int32_t InteractionManager::UpdateDragStyle(DragCursorStyle style)
324 {
325     return DRAG_MANAGER.UpdateDragStyle(style);
326 }
327 
StopDrag(const DragDropResult & dropResult)328 int32_t InteractionManager::StopDrag(const DragDropResult &dropResult)
329 {
330     return DRAG_MANAGER.StopDrag(dropResult);
331 }
332 
GetDragTargetPid()333 int32_t InteractionManager::GetDragTargetPid()
334 {
335     return DRAG_MANAGER.GetDragTargetPid();
336 }
337 
GetUdKey(std::string & udKey)338 int32_t InteractionManager::GetUdKey(std::string &udKey)
339 {
340     return DRAG_MANAGER.GetUdKey(udKey);
341 }
342 
SetDragWindowVisible(bool visible,bool isForce,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)343 int32_t InteractionManager::SetDragWindowVisible(
344     bool visible, bool isForce, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
345 {
346     return DRAG_MANAGER.OnSetDragWindowVisible(visible, isForce);
347 }
348 
GetShadowOffset(int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height)349 int32_t InteractionManager::GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
350 {
351     ShadowOffset shadowOffset;
352     int32_t ret = DRAG_MANAGER.OnGetShadowOffset(shadowOffset);
353     if (ret != 0) {
354         FI_HILOGE("shadowOffset is empty");
355         return ret;
356     }
357     offsetX = shadowOffset.offsetX;
358     offsetY = shadowOffset.offsetY;
359     width = shadowOffset.width;
360     height = shadowOffset.height;
361     return ret;
362 }
363 
UpdateShadowPic(const ShadowInfo & shadowInfo)364 int32_t InteractionManager::UpdateShadowPic(const ShadowInfo &shadowInfo)
365 {
366     return DRAG_MANAGER.UpdateShadowPic(shadowInfo);
367 }
368 
GetDragData(DragData & dragData)369 int32_t InteractionManager::GetDragData(DragData &dragData)
370 {
371     return DRAG_MANAGER.GetDragData(dragData);
372 }
373 
GetDragState(DragState & dragState)374 int32_t InteractionManager::GetDragState(DragState &dragState)
375 {
376     return DRAG_MANAGER.GetDragState(dragState);
377 }
378 
UpdatePreviewStyle(const PreviewStyle & previewStyle)379 int32_t InteractionManager::UpdatePreviewStyle(const PreviewStyle &previewStyle)
380 {
381     return DRAG_MANAGER.UpdatePreviewStyle(previewStyle);
382 }
383 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)384 int32_t InteractionManager::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
385     const PreviewAnimation &animation)
386 {
387     return DRAG_MANAGER.UpdatePreviewStyleWithAnimation(previewStyle, animation);
388 }
389 
GetDragSummary(std::map<std::string,int64_t> & summarys)390 int32_t InteractionManager::GetDragSummary(std::map<std::string, int64_t> &summarys)
391 {
392     return DRAG_MANAGER.GetDragSummary(summarys);
393 }
394 
GetDragSummaryInfo(DragSummaryInfo & dragSummaryInfo)395 int32_t InteractionManager::GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo)
396 {
397     return DRAG_MANAGER.GetDragSummaryInfo(dragSummaryInfo);
398 }
399 
GetDragAction(DragAction & dragAction)400 int32_t InteractionManager::GetDragAction(DragAction &dragAction)
401 {
402     return DRAG_MANAGER.GetDragAction(dragAction);
403 }
404 
EnterTextEditorArea(bool enable)405 int32_t InteractionManager::EnterTextEditorArea(bool enable)
406 {
407     return DRAG_MANAGER.EnterTextEditorArea(enable);
408 }
409 
GetExtraInfo(std::string & extraInfo)410 int32_t InteractionManager::GetExtraInfo(std::string &extraInfo)
411 {
412     return DRAG_MANAGER.GetExtraInfo(extraInfo);
413 }
414 
UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent)415 int32_t InteractionManager::UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent)
416 {
417     return DRAG_MANAGER.UpdatePointerAction(pointerEvent);
418 }
419 
SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window)420 void InteractionManager::SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window)
421 {
422     DRAG_MANAGER.SetDragWindow(window);
423 }
424 
RegisterDragWindow(std::function<void ()> cb)425 void InteractionManager::RegisterDragWindow(std::function<void()> cb)
426 {
427     DRAG_MANAGER.AddDragDestroy(cb);
428 }
429 
SetSVGFilePath(const std::string & filePath)430 void InteractionManager::SetSVGFilePath(const std::string &filePath)
431 {
432     DRAG_MANAGER.SetSVGFilePath(filePath);
433 }
434 
IsDragStart()435 bool InteractionManager::IsDragStart()
436 {
437     return DRAG_MANAGER.IsDragStart();
438 }
439 #endif // OHOS_BUILD_ENABLE_ARKUI_X
440 } // namespace DeviceStatus
441 } // namespace Msdp
442 } // namespace OHOS
443