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