• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #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 "on_screen_client.h"
30 #include "socket_client.h"
31 #include "stationary_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 GetDevicePostureDataSync(DevicePostureData &data);
47     int32_t RegisterCoordinationListener(
48         std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
49     int32_t UnregisterCoordinationListener(
50         std::shared_ptr<ICoordinationListener> listener, bool isCompatible = false);
51     int32_t PrepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible = false);
52     int32_t UnprepareCoordination(CooperateMsgInfoCallback callback, bool isCompatible = false);
53     int32_t ActivateCoordination(const std::string &remoteNetworkId, int32_t startDeviceId,
54         CooperateMsgInfoCallback callback, bool isCompatible = false);
55     int32_t ActivateCooperateWithOptions(const std::string &remoteNetworkId,
56         int32_t startDeviceId, CooperateMsgInfoCallback callback, const CooperateOptions &options);
57     int32_t DeactivateCoordination(bool isUnchained, CooperateMsgInfoCallback callback, bool isCompatible = false);
58     int32_t GetCoordinationState(const std::string &networkId, std::function<void(bool)> callback,
59         bool isCompatible = false);
60     int32_t GetCoordinationState(const std::string &udId, bool &state);
61     int32_t RegisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener);
62     int32_t UnregisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener = nullptr);
63     int32_t SetDamplingCoefficient(uint32_t direction, double coefficient);
64     int32_t UpdateDragStyle(DragCursorStyle style, int32_t eventId = -1);
65     int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
66     int32_t StopDrag(const DragDropResult &dropResult);
67     int32_t GetDragTargetPid();
68     int32_t GetUdKey(std::string &udKey);
69     int32_t AddDraglistener(DragListenerPtr listener, bool isJsCaller = false);
70     int32_t RemoveDraglistener(DragListenerPtr listener, bool isJsCaller = false);
71     int32_t AddSubscriptListener(SubscriptListenerPtr listener);
72     int32_t RemoveSubscriptListener(SubscriptListenerPtr listener);
73     int32_t SetDragWindowVisible(
74         bool visible, bool isForce = false, const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
75     int32_t GetShadowOffset(ShadowOffset &shadowOffset);
76     int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
77     int32_t GetDragData(DragData &dragData);
78     int32_t GetDragState(DragState &dragState);
79     int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
80     int32_t RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener = nullptr);
81     int32_t UpdatePreviewStyle(const PreviewStyle &previewStyle);
82     int32_t UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle, const PreviewAnimation &animation);
83     int32_t RotateDragWindowSync(const std::shared_ptr<Rosen::RSTransaction>& rsTransaction = nullptr);
84     int32_t GetDragSummary(std::map<std::string, int64_t> &summarys, bool isJsCaller = false);
85     int32_t SetDragSwitchState(bool enable, bool isJsCaller = false);
86     int32_t SetAppDragSwitchState(bool enable, const std::string &pkgName, bool isJsCaller = false);
87     int32_t EnterTextEditorArea(bool enable);
88     int32_t GetDragAction(DragAction &dragAction);
89     int32_t GetExtraInfo(std::string &extraInfo);
90     int32_t AddPrivilege();
91     int32_t EraseMouseIcon();
92     int32_t SetDragWindowScreenId(uint64_t displayId, uint64_t screenId);
93     int32_t SetMouseDragMonitorState(bool state);
94     int32_t SubscribeCallback(BoomerangType type, std::string bundleName, sptr<IRemoteBoomerangCallback> callback);
95     int32_t UnsubscribeCallback(BoomerangType type, std::string bundleName, sptr<IRemoteBoomerangCallback> callback);
96     int32_t NotifyMetadataBindingEvent(std::string bundleName, sptr<IRemoteBoomerangCallback> callback);
97     int32_t SubmitMetadata(std::string metadata);
98     int32_t BoomerangEncodeImage(std::shared_ptr<Media::PixelMap> pixelMap, std::string matedata,
99         sptr<IRemoteBoomerangCallback> callback);
100     int32_t BoomerangDecodeImage(std::shared_ptr<Media::PixelMap> pixelMap, sptr<IRemoteBoomerangCallback> callback);
101     void OnConnected();
102     void OnDisconnected();
103     int32_t SetDraggableState(bool state);
104     int32_t GetAppDragSwitchState(bool &state);
105     void SetDraggableStateAsync(bool state, int64_t downTime);
106     int32_t GetDragBundleInfo(DragBundleInfo &dragBundleInfo);
107     int32_t EnableInternalDropAnimation(const std::string &animationInfo);
108     bool IsDragStart();
109     int32_t GetPageContent(const OnScreen::ContentOption& option, OnScreen::PageContent& pageContent);
110     int32_t SendControlEvent(const OnScreen::ControlEvent& event);
111     int32_t GetDragSummaryInfo(DragSummaryInfo &dragSummaryInfo);
112 
113 private:
114     void InitClient();
115     void InitMsgHandler();
116 
117     std::mutex mutex_;
118     std::unique_ptr<SocketClient> client_ { nullptr };
119     CooperateClient cooperate_;
120     DragClient drag_;
121     StationaryClient stationary_;
122     BoomerangClient boomerang_;
123     OnScreen::OnScreenClient onScreen_;
124     bool isScreenRotation_ { false };
125     std::vector<std::string> foldRotatePolicys_ {};
126 };
127 
128 #define INTER_MGR_IMPL OHOS::Singleton<IntentionManager>::GetInstance()
129 } // namespace DeviceStatus
130 } // namespace Msdp
131 } // namespace OHOS
132 #endif // INTENTION_MANAGER_H
133