1 /*
2  * Copyright (c) 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 INTENTION_MANAGER_H
17 #define INTENTION_MANAGER_H
18 
19 #include <mutex>
20 
21 #include "singleton.h"
22 
23 #include "cooperate_client.h"
24 #include "drag_client.h"
25 #include "drag_data.h"
26 #include "drag_manager_impl.h"
27 #include "i_event_listener.h"
28 #include "socket_client.h"
29 #include "stationary_client.h"
30 #include "tunnel_client.h"
31 
32 namespace OHOS {
33 namespace Msdp {
34 namespace DeviceStatus {
35 class IntentionManager {
36     DECLARE_SINGLETON(IntentionManager);
37     using CooperateMsgInfoCallback = std::function<void(const std::string&, const CoordinationMsgInfo&)>;
38 
39 public:
40     DISALLOW_MOVE(IntentionManager);
41     int32_t SubscribeCallback(Type type, ActivityEvent event, ReportLatencyNs latency,
42         sptr<IRemoteDevStaCallback> callback);
43     int32_t UnsubscribeCallback(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback);
44     Data GetDeviceStatusData(const Type type);
45     int32_t RegisterCoordinationListener(
46         std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
47     int32_t UnregisterCoordinationListener(
48         std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
49     int32_t PrepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible = false);
50     int32_t UnprepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible = false);
51     int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
52         CooperateMsgInfoCallback callback, bool isCompatible = false);
53     int32_t DeactivateCoordination(bool isUnchained, CooperateMsgInfoCallback callback, bool isCompatible = false);
54     int32_t GetCoordinationState(const std::string &networkId, std::function<void(bool)> callback,
55         bool isCompatible = false);
56     int32_t GetCoordinationState(const std::string &udId, bool &state);
57     int32_t RegisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener);
58     int32_t UnregisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener = nullptr);
59     int32_t SetDamplingCoefficient(uint32_t direction, double coefficient);
60     int32_t UpdateDragStyle(DragCursorStyle style, int32_t eventId = -1);
61     int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
62     int32_t StopDrag(const DragDropResult &dropResult);
63     int32_t GetDragTargetPid();
64     int32_t GetUdKey(std::string &udKey);
65     int32_t AddDraglistener(DragListenerPtr listener, bool isJsCaller = false);
66     int32_t RemoveDraglistener(DragListenerPtr listener, bool isJsCaller = false);
67     int32_t AddSubscriptListener(SubscriptListenerPtr listener);
68     int32_t RemoveSubscriptListener(SubscriptListenerPtr listener);
69     int32_t SetDragWindowVisible(bool visible, bool isForce = false);
70     int32_t GetShadowOffset(ShadowOffset &shadowOffset);
71     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
72     int32_t GetDragData(DragData &dragData);
73     int32_t GetDragState(DragState &dragState);
74     int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
75     int32_t RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener = nullptr);
76     int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
77     int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
78     int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
79     int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller = false);
80     int32_t EnterTextEditorArea(bool enable);
81     int32_t GetDragAction(DragAction &dragAction);
82     int32_t GetExtraInfo(std::string &extraInfo);
83     int32_t AddPrivilege();
84     int32_t EraseMouseIcon();
85     int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId);
86     int32_t SetMouseDragMonitorState(bool state);
87     int32_t AddSelectedPixelMap(std::shared_ptr<OHOS::Media::PixelMap> pixelMap, std::function<void(bool)> callback);
88     void OnConnected();
89     void OnDisconnected();
90 
91 private:
92     void InitClient();
93     void InitMsgHandler();
94 
95     std::mutex mutex_;
96     std::shared_ptr<TunnelClient> tunnel_ { nullptr };
97     std::unique_ptr<SocketClient> client_ { nullptr };
98     CooperateClient cooperate_;
99     DragClient drag_;
100     StationaryClient stationary_;
101     bool isScreenRotation_ { false };
102     std::vector<std::string> foldRotatePolicys_ {};
103 };
104 
105 #define INTER_MGR_IMPL OHOS::Singleton<IntentionManager>::GetInstance()
106 } // namespace DeviceStatus
107 } // namespace Msdp
108 } // namespace OHOS
109 #endif // INTENTION_MANAGER_H
110