• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 #ifndef INTERACTION_MANAGER_H
17 #define INTERACTION_MANAGER_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "nocopyable.h"
23 
24 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
25 #include "coordination_message.h"
26 #endif // OHOS_BUILD_ENABLE_ARKUI_X
27 #include "drag_data.h"
28 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
29 #include "i_coordination_listener.h"
30 #include "i_drag_listener.h"
31 #include "i_event_listener.h"
32 #include "i_hotarea_listener.h"
33 #include "i_start_drag_listener.h"
34 #include "i_subscript_listener.h"
35 #include "transaction/rs_transaction.h"
36 #else
37 #include "pointer_event.h"
38 #include "virtual_rs_window.h"
39 #endif // OHOS_BUILD_ENABLE_ARKUI_X
40 
41 namespace OHOS {
42 namespace Msdp {
43 namespace DeviceStatus {
44 class InteractionManager {
45 public:
46 
47     static InteractionManager *GetInstance();
48     virtual ~InteractionManager() = default;
49 
50 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
51     /**
52      * @brief Registers a listener for screen hopping events of the mouse pointer.
53      * @param listener Indicates the listener for screen hopping events of the mouse pointer.
54      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
55      * @since 9
56      */
57     int32_t RegisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
58         bool isCompatible = false);
59 
60     /**
61      * @brief Unregisters a listener for screen hopping events of the mouse pointer.
62      * @param listener Indicates the listener for screen hopping events of the mouse pointer.
63      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
64      * @since 9
65      */
66     int32_t UnregisterCoordinationListener(std::shared_ptr<ICoordinationListener> listener,
67         bool isCompatible = false);
68 
69     /**
70      * @brief Prepares for screen hopping.
71      * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping.
72      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
73      * @since 9
74      */
75     int32_t PrepareCoordination(std::function<void(const std::string&, const CoordinationMsgInfo&)> callback,
76         bool isCompatible = false);
77 
78     /**
79      * @brief Cancels the preparation for screen hopping.
80      * @param callback Indicates the callback used to receive the result of enabling or disabling screen hopping.
81      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
82      * @since 9
83      */
84     int32_t UnprepareCoordination(std::function<void(const std::string&, const CoordinationMsgInfo&)> callback,
85         bool isCompatible = false);
86 
87     /**
88      * @brief Starts screen hopping for the mouse pointer.
89      * @param s remoteNetworkId Indicates the descriptor of the target input device (network ID) for screen hopping.
90      * @param startDeviceId Indicates the ID of the source input device (device ID handle) for screen hopping.
91      * @param callback Indicates the callback used to receive the result of starting screen hopping.
92      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
93      * @since 9
94      */
95     int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
96         std::function<void(const std::string&, const CoordinationMsgInfo&)> callback, bool isCompatible = false);
97 
98     /**
99      * @brief Starts screen hopping for the mouse pointer.
100      * @param remoteNetworkId Indicates the descriptor of the target input device (network ID) for screen hopping.
101      * @param startDeviceId Indicates the ID of the source input device (device ID handle) for screen hopping.
102      * @param callback Indicates the callback used to receive the result of starting screen hopping.
103      * @param cooperateOptions cooperation options for peer device.
104      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
105      * @since 9
106      */
107     int32_t ActivateCooperateWithOptions(const std::string &remoteNetworkId, int32_t startDeviceId, std::function
108         <void(const std::string&, const CoordinationMsgInfo&)> callback, const CooperateOptions &cooperateOptions);
109 
110     /**
111      * @brief Stops screen hopping for the mouse pointer.
112      * @param isUnchained Specifies Whether to disable the cross-device link.
113      * The value <b>true</b> means to disable the cross-device link, and <b>false</b> means the opposite.
114      * @param callback Indicates the callback used to receive the result of stopping screen hopping.
115      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
116      * @since 9
117      */
118     int32_t DeactivateCoordination(bool isUnchained,
119         std::function<void(const std::string&, const CoordinationMsgInfo&)> callback, bool isCompatible = false);
120 
121     /**
122      * @brief Obtains the screen hopping status of a mouse pointer.
123      * @param networkId Indicates the descriptor of the input device.
124      * @param callback Indicates the callback used to receive the screen hopping status.
125      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
126      * @since 9
127      */
128     int32_t GetCoordinationState(const std::string &networkId, std::function<void(bool)> callback,
129         bool isCompatible = false);
130 
131     /**
132      * @brief Obtains the screen hopping status of a mouse pointer.
133      * @param udId Indicates the descriptor of the input device.
134      * @param state Indicates the state of crossing switch.
135      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
136      * @since 12
137      */
138     int32_t GetCoordinationState(const std::string &udId, bool &state);
139 
140     /**
141      * @brief Registers a listener for mouse pointer position information on the specified device.
142      * @param networkId Indicates the descriptor of the input device.
143      * @param listener Indicates the listener for mouse pointer position information on the specified device.
144      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
145      * @since 9
146      */
147     int32_t RegisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener);
148 
149     /**
150      * @brief Unregisters a listener for mouse pointer position information on the specified device.
151      * @param networkId Indicates the descriptor of the input device.
152      * @param listener Indicates the listener mouse pointer position information on the specified device.
153      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
154      * @since 9
155      */
156     int32_t UnregisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener = nullptr);
157 
158     int32_t SetDamplingCoefficient(uint32_t direction, double coefficient);
159 
160     /**
161      * @brief Starts dragging.
162      * @param dragData Indicates additional data used for dragging.
163      * @param listener Indicates the listener used to notify dragging result etc.
164      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
165      * @since 10
166      */
167     int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
168 #else
169     /**
170      * @brief Starts dragging.
171      * @param dragData Indicates additional data used for dragging.
172      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
173      * @since 12
174      */
175     int32_t StartDrag(const DragData &dragData);
176 #endif // OHOS_BUILD_ENABLE_ARKUI_X
177     /**
178      * @brief Stops dragging.
179      * @param result Indicates the dragging result. The value <b>0</b> means that the dragging operation is successful;
180      * <b>1</b> means that the dragging operation is failed; <b>2</b> means that the dragging operation is canceled.
181      * @param hasCustomAnimation Specifies whether a custom animation is played when the dragging is successful.
182      * The value <b>true</b> means that a custom animation is played,
183      * and <b>false</b> means that the default animation is played.
184      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
185      * @since 10
186      */
187     int32_t StopDrag(const DragDropResult &dropResult);
188 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
189     /**
190      * @brief Updates the mouse pointer style used for dragging.
191      * @param style Indicates the new mouse pointer style.
192      * @param eventId Indicates the descriptor of the event.
193      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
194      * @since 10
195      */
196     int32_t UpdateDragStyle(DragCursorStyle style, int32_t eventId = -1);
197 #else
198     /**
199      * @brief Updates the mouse pointer style used for dragging.
200      * @param style Indicates the new mouse pointer style.
201      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
202      * @since 10
203      */
204     int32_t UpdateDragStyle(DragCursorStyle style);
205 #endif // OHOS_BUILD_ENABLE_ARKUI_X
206     /**
207      * @brief Obtains the PID of the target window.
208      * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid.
209      * @since 10
210      */
211     int32_t GetDragTargetPid();
212 
213     /**
214      * @brief Obtains the unified data key of the target window.
215      * @param UdKey Indicates the unified data key of the target window.
216      * @return Returns a value greater than or equal to 0 in normal cases; returns <b>-1</b> if the PID is invalid.
217      * @since 10
218      */
219     int32_t GetUdKey(std::string &udKey);
220 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
221     /**
222      * @brief Registers a listener for dragging status changes.
223      * @param listener Indicates the listener for dragging status changes.
224      * @param isJsCaller Indicates whether to add checking.
225      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
226      * @since 10
227      */
228     int32_t AddDraglistener(std::shared_ptr<IDragListener> listener, bool isJsCaller = false);
229 
230     /**
231      * @brief Unregisters a listener for dragging status changes.
232      * @param listener Indicates the listener for dragging status changes.
233      * If no value is passed, all listeners are canceled.
234      * @param isJsCaller Indicates whether to add checking.
235      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
236      * @since 10
237      */
238     int32_t RemoveDraglistener(std::shared_ptr<IDragListener> listener = nullptr, bool isJsCaller = false);
239 
240     /**
241      * @brief Register a listener for dragging corner style changes.
242      * @param listener Indicates the listener for dragging corner style changes.
243      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
244      * @since 10
245      */
246     int32_t AddSubscriptListener(std::shared_ptr<ISubscriptListener> listener);
247 
248     /**
249      * @brief Unregisters a listener for dragging corner style changes.
250      * @param listener Indicates the listener for dragging corner style changes.
251      * If no value is passed, all listeners are canceled.
252      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
253      * @since 10
254      */
255     int32_t RemoveSubscriptListener(std::shared_ptr<ISubscriptListener> listener);
256 #endif // OHOS_BUILD_ENABLE_ARKUI_X
257 
258     /**
259      * @brief Displays or hides the dragging window.
260      * @param visible Specifies whether to display the dragging window.
261      * The value <b>true</b> means to display the dragging window, and <b>false</b> means to hide the window.
262      * @param isForce Specifies Enforce the visibility of the drag window, which is applied to this drag.
263      * For example, if you set the drag window to Hidden and isForce to true during a drag, the setting does not
264      * take effect when the drag window is displayed and isForce is false, and the setting becomes invalid at the
265      * end of the current drag.
266      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
267      * @since 10
268      */
269     int32_t SetDragWindowVisible(bool visible, bool isForce = false);
270 
271     /**
272      * @brief Obtains the position of the touch point or mouse pointer relative to
273      * the upper left corner of the shadow thumbnail.
274      * @param offsetX Indicates the x coordinate.
275      * @param offsetY Indicates the y coordinate.
276      * @param width Indicates the width of the shadow thumbnail.
277      * @param height Indicates the height of the shadow thumbnail.
278      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
279      * @since 10
280      */
281     int32_t GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height);
282 
283     /**
284      * @brief Updates the shadow thumbnail information used for dragging.
285      * @param shadowInfo Indicates the new shadow thumbnail information.
286      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
287      * @since 10
288      */
289     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
290 
291     /**
292      * @brief Obtains the dragging data.
293      * @param dragData Indicates the dragging data.
294      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
295      * @since 10
296      */
297     int32_t GetDragData(DragData &dragData);
298 
299     /**
300      * @brief Obtains the current droping type.
301      * @param dragAction dropping type while user pressed ctrl or not.
302      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
303      * @since 10
304      */
305     int32_t GetDragAction(DragAction &dragAction);
306 
307     /**
308      * @brief Obtains the 'extraInfo' field in the drag data.
309      * @param extraInfo Indicates the 'extraInfo' field in the drag data, mainly to save whether to allow drag across
310      * the device "drag_allow_distributed" field.
311      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
312      * @since 10
313      */
314     int32_t GetExtraInfo(std::string &extraInfo);
315 #ifndef  OHOS_BUILD_ENABLE_ARKUI_X
316     /**
317      * @brief Registers a listener for screen hot area of the mouse pointer.
318      * @param listener Indicates the listener for screen hot area of the mouse pointer.
319      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
320      * @since 11
321      */
322     int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
323 #endif // OHOS_BUILD_ENABLE_ARKUI_X
324     /**
325      * @brief Obtains the dragging state.
326      * @param dragState Dragging state.
327      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
328      * @since 10
329      */
330     int32_t GetDragState(DragState &dragState);
331 #ifndef  OHOS_BUILD_ENABLE_ARKUI_X
332     /**
333      * @brief Unregisters a listener for screen hot area of the mouse pointer.
334      * @param listener Indicates the listener for screen hot area of the mouse pointer.
335      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
336      * @since 9
337      */
338     int32_t RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener = nullptr);
339 #endif // OHOS_BUILD_ENABLE_ARKUI_X
340 
341     /**
342      * @brief Update preview style when dragging.
343      * @param previewStyle Indicates the preview style param for dragged item.
344      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
345      * @since 11
346      */
347     int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
348 
349     /**
350      * @brief Update preview style with animation when dragging.
351      * @param previewStyle Indicates the preview style param for dragged item.
352      * @param animation Indicates the animation param for dragged item.
353      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
354      * @since 11
355      */
356     int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
357 
358 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
359     /**
360      * @brief Rotate drag window sync.
361      * @param rsTransaction Indicates utterances rotate the sync handle.
362      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
363      * @since 12
364      */
365     int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
366 
367     /**
368      * @brief Obtains data summary of the drag object.
369      * @param summarys Indicates data summary of the drag object.
370      * @param isJsCaller Indicates whether to add checking.
371      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
372      * @since 11
373      */
374     int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller = false);
375 
376     /**
377      * @brief Sets the master switch for enhancing the drag capability.
378      * @param enable Switch state.
379      * @param isJsCaller Indicates whether to add checking.
380      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
381      * @since 15
382      */
383     int32_t SetDragSwitchState(bool enable, bool isJsCaller = false);
384 
385     /**
386      * @brief Sets the app switch for enhancing the drag capability.
387      * @param enable Switch state.
388      * @param pkgName App package name.
389      * @param isJsCaller Indicates whether to add checking.
390      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
391      * @since 15
392      */
393     int32_t SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller = false);
394 #else
395     /**
396      * @brief Obtains data summary of the drag object.
397      * @param summarys Indicates data summary of the drag object.
398      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
399      * @since 12
400      */
401     int32_t GetDragSummary(std::map<std::string, int64_t> &summarys);
402 #endif // OHOS_BUILD_ENABLE_ARKUI_X
403 
404     /**
405      * @brief Specifies whether to implement 8dp movement in the text editor area.
406      * @param enable Indicates whether to enable 8dp movement.
407      * The value <b>true</b> means to enable 8dp movement, and the value <b>false</b> means the opposite.
408      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
409      * @since 11
410      */
411     int32_t EnterTextEditorArea(bool enable);
412 
413 #ifndef OHOS_BUILD_ENABLE_ARKUI_X
414     int32_t AddPrivilege();
415 
416     int32_t EraseMouseIcon();
417 
418     int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId);
419 
420     int32_t SetMouseDragMonitorState(bool state);
421 
422     /**
423      * @brief Add an image to the drag list.
424      * @param pixelMap Add Selected image information.
425      * @param callback Indicates the callback used to notify addSelectedPixelMap result.
426      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
427      * @since 12
428      */
429     int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, std::function<void(bool)> callback);
430 
431     /**
432      * @brief Set drag state.
433      * @param state drag state, if application can drag, set true, else set false.
434      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
435      * @since 15
436      */
437     int32_t SetDraggableState(bool state);
438 
439     /**
440      * @brief Get the app switch for enhancing the drag capability.
441      * @param state Switch state.
442      * @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
443      * @since 15
444      */
445     int32_t GetAppDragSwitchState(bool &state);
446 
447     /**
448      * @brief Set drag state asynchronous.
449      * @param state drag state, if application can drag, set true, else set false.
450      * @param downTime input down time.
451      * @return
452      * @since 15
453      */
454     void SetDraggableStateAsync(bool state, int64_t downTime);
455 #else
456     /**
457      * @brief convert relative pointerEvent action to PULL_MOVE or PULL_UP.
458      * @param pointerEvent the normal input event need to deal with.
459      * @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
460      * @since 12
461      */
462     int32_t UpdatePointerAction(std::shared_ptr<MMI::PointerEvent> pointerEvent);
463 
464     /**
465      * @brief set window.
466      * @param window drag drawing needs window.
467      * @return
468      * @since 12
469      */
470     void SetDragWindow(std::shared_ptr<OHOS::Rosen::Window> window);
471 
472     /**
473      * @brief set callback to destroy window.
474      * @param cb callback function.
475      * @return
476      * @since 12
477      */
478     void RegisterDragWindow(std::function<void()> cb);
479 
480     /**
481      * @brief set VSG file path.
482      * @param filePath save SVG file path.
483      * @return
484      * @since 12
485      */
486     void SetSVGFilePath(const std::string &filePath);
487 #endif // OHOS_BUILD_ENABLE_ARKUI_X
488 
489 private:
490     InteractionManager() = default;
491     DISALLOW_COPY_AND_MOVE(InteractionManager);
492     static InteractionManager *instance_;
493 };
494 } // namespace DeviceStatus
495 } // namespace Msdp
496 } // namespace OHOS
497 
498 #define INTERACTION_MGR OHOS::Msdp::DeviceStatus::InteractionManager::GetInstance()
499 
500 #endif // INTERACTION_MANAGER_H
501