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 #include "drag_client.h"
17
18 #include "default_params.h"
19 #include "drag_params.h"
20 #include "devicestatus_define.h"
21 #include "devicestatus_func_callback.h"
22 #include "proto.h"
23
24 namespace OHOS {
25 namespace Msdp {
26 namespace DeviceStatus {
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragClient" };
29 } // namespace
30
StartDrag(ITunnelClient & tunnel,const DragData & dragData,std::shared_ptr<IStartDragListener> listener)31 int32_t DragClient::StartDrag(ITunnelClient &tunnel,
32 const DragData &dragData, std::shared_ptr<IStartDragListener> listener)
33 {
34 CALL_DEBUG_ENTER;
35 CHKPR(listener, RET_ERR);
36 for (const auto& shadowInfo : dragData.shadowInfos) {
37 CHKPR(shadowInfo.pixelMap, RET_ERR);
38 if ((shadowInfo.x > 0) || (shadowInfo.y > 0) ||
39 (shadowInfo.x < -shadowInfo.pixelMap->GetWidth()) ||
40 (shadowInfo.y < -shadowInfo.pixelMap->GetHeight())) {
41 FI_HILOGE("Invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d",
42 shadowInfo.x, shadowInfo.y);
43 return RET_ERR;
44 }
45 }
46 if ((dragData.dragNum <= 0) || (dragData.buffer.size() > MAX_BUFFER_SIZE) ||
47 (dragData.displayX < 0) || (dragData.displayY < 0)) {
48 FI_HILOGE("Start drag, invalid argument, dragNum:%{public}d, bufferSize:%{public}zu, "
49 "displayX:%{public}d, displayY:%{public}d",
50 dragData.dragNum, dragData.buffer.size(), dragData.displayX, dragData.displayY);
51 return RET_ERR;
52 }
53 {
54 std::lock_guard<std::mutex> guard(mtx_);
55 startDragListener_ = listener;
56 }
57 StartDragParam param { dragData };
58 DefaultReply reply {};
59
60 int32_t ret = tunnel.Start(Intention::DRAG, param, reply);
61 if (ret != RET_OK) {
62 FI_HILOGE("ITunnelClient::Start fail");
63 }
64 return ret;
65 }
66
StopDrag(ITunnelClient & tunnel,const DragDropResult & dropResult)67 int32_t DragClient::StopDrag(ITunnelClient &tunnel, const DragDropResult &dropResult)
68 {
69 CALL_DEBUG_ENTER;
70 StopDragParam param(dropResult);
71 DefaultReply reply;
72
73 int32_t ret = tunnel.Stop(Intention::DRAG, param, reply);
74 if (ret != RET_OK) {
75 FI_HILOGE("ITunnelClient::Start fail");
76 }
77 return ret;
78 }
79
AddDraglistener(ITunnelClient & tunnel,DragListenerPtr listener)80 int32_t DragClient::AddDraglistener(ITunnelClient &tunnel, DragListenerPtr listener)
81 {
82 CALL_DEBUG_ENTER;
83 CHKPR(listener, RET_ERR);
84 std::lock_guard<std::mutex> guard(mtx_);
85 if (std::any_of(dragListener_.cbegin(), dragListener_.cend(),
86 [listener](DragListenerPtr tListener) {
87 return (tListener == listener);
88 })) {
89 return RET_OK;
90 }
91 if (!hasRegistered_) {
92 DefaultParam param {};
93 DefaultReply reply {};
94
95 int32_t ret = tunnel.AddWatch(Intention::DRAG, DragRequestID::ADD_DRAG_LISTENER, param, reply);
96 if (ret != RET_OK) {
97 FI_HILOGE("ITunnelClient::AddWatch fail");
98 return ret;
99 }
100 hasRegistered_ = true;
101 }
102 dragListener_.push_back(listener);
103 return RET_OK;
104 }
105
RemoveDraglistener(ITunnelClient & tunnel,DragListenerPtr listener)106 int32_t DragClient::RemoveDraglistener(ITunnelClient &tunnel, DragListenerPtr listener)
107 {
108 CALL_DEBUG_ENTER;
109 std::lock_guard<std::mutex> guard(mtx_);
110 if (listener == nullptr) {
111 dragListener_.clear();
112 } else {
113 dragListener_.erase(std::remove_if(dragListener_.begin(), dragListener_.end(),
114 [listener] (auto lIter) {
115 return lIter == listener;
116 })
117 );
118 }
119 if (hasRegistered_ && dragListener_.empty()) {
120 hasRegistered_ = false;
121 DefaultParam param {};
122 DefaultReply reply {};
123
124 int32_t ret = tunnel.RemoveWatch(Intention::DRAG, DragRequestID::REMOVE_DRAG_LISTENER, param, reply);
125 if (ret != RET_OK) {
126 FI_HILOGE("ITunnelClient::RemoveWatch fail");
127 return ret;
128 }
129 }
130 return RET_OK;
131 }
132
AddSubscriptListener(ITunnelClient & tunnel,SubscriptListenerPtr listener)133 int32_t DragClient::AddSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener)
134 {
135 return RET_ERR;
136 }
137
RemoveSubscriptListener(ITunnelClient & tunnel,SubscriptListenerPtr listener)138 int32_t DragClient::RemoveSubscriptListener(ITunnelClient &tunnel, SubscriptListenerPtr listener)
139 {
140 return RET_ERR;
141 }
142
SetDragWindowVisible(ITunnelClient & tunnel,bool visible)143 int32_t DragClient::SetDragWindowVisible(ITunnelClient &tunnel, bool visible)
144 {
145 return RET_ERR;
146 }
147
UpdateDragStyle(ITunnelClient & tunnel,DragCursorStyle style)148 int32_t DragClient::UpdateDragStyle(ITunnelClient &tunnel, DragCursorStyle style)
149 {
150 return RET_ERR;
151 }
152
UpdateShadowPic(ITunnelClient & tunnel,const ShadowInfo & shadowInfo)153 int32_t DragClient::UpdateShadowPic(ITunnelClient &tunnel, const ShadowInfo &shadowInfo)
154 {
155 CALL_DEBUG_ENTER;
156 CHKPR(shadowInfo.pixelMap, RET_ERR);
157 if ((shadowInfo.x > 0) || (shadowInfo.y > 0) ||
158 (shadowInfo.x < -shadowInfo.pixelMap->GetWidth()) ||
159 (shadowInfo.y < -shadowInfo.pixelMap->GetHeight())) {
160 FI_HILOGE("Invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d",
161 shadowInfo.x, shadowInfo.y);
162 return RET_ERR;
163 }
164 UpdateShadowPicParam param { shadowInfo };
165 DefaultReply reply {};
166
167 int32_t ret = tunnel.SetParam(Intention::DRAG, DragRequestID::UPDATE_SHADOW_PIC, param, reply);
168 if (ret != RET_OK) {
169 FI_HILOGE("ITunnelClient::SetParam fail");
170 }
171 return ret;
172 }
173
GetDragTargetPid(ITunnelClient & tunnel)174 int32_t DragClient::GetDragTargetPid(ITunnelClient &tunnel)
175 {
176 return RET_ERR;
177 }
178
GetUdKey(ITunnelClient & tunnel,std::string & udKey)179 int32_t DragClient::GetUdKey(ITunnelClient &tunnel, std::string &udKey)
180 {
181 return RET_ERR;
182 }
183
GetShadowOffset(ITunnelClient & tunnel,int32_t & offsetX,int32_t & offsetY,int32_t & width,int32_t & height)184 int32_t DragClient::GetShadowOffset(ITunnelClient &tunnel,
185 int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height)
186 {
187 return RET_ERR;
188 }
189
GetDragData(ITunnelClient & tunnel,DragData & dragData)190 int32_t DragClient::GetDragData(ITunnelClient &tunnel, DragData &dragData)
191 {
192 CALL_DEBUG_ENTER;
193 DefaultParam param {};
194 GetDragDataReply reply { dragData };
195
196 int32_t ret = tunnel.GetParam(Intention::DRAG, DragRequestID::GET_DRAG_DATA, param, reply);
197 if (ret != RET_OK) {
198 FI_HILOGE("ITunnelClient::GetParam fail");
199 }
200 return ret;
201 }
202
UpdatePreviewStyle(ITunnelClient & tunnel,const PreviewStyle & previewStyle)203 int32_t DragClient::UpdatePreviewStyle(ITunnelClient &tunnel, const PreviewStyle &previewStyle)
204 {
205 return RET_ERR;
206 }
207
UpdatePreviewStyleWithAnimation(ITunnelClient & tunnel,const PreviewStyle & previewStyle,const PreviewAnimation & animation)208 int32_t DragClient::UpdatePreviewStyleWithAnimation(ITunnelClient &tunnel,
209 const PreviewStyle &previewStyle, const PreviewAnimation &animation)
210 {
211 return RET_ERR;
212 }
213
GetDragSummary(ITunnelClient & tunnel,std::map<std::string,int64_t> & summarys)214 int32_t DragClient::GetDragSummary(ITunnelClient &tunnel, std::map<std::string, int64_t> &summarys)
215 {
216 return RET_ERR;
217 }
218
GetDragState(ITunnelClient & tunnel,DragState & dragState)219 int32_t DragClient::GetDragState(ITunnelClient &tunnel, DragState &dragState)
220 {
221 return RET_ERR;
222 }
223
EnterTextEditorArea(ITunnelClient & tunnel,bool enable)224 int32_t DragClient::EnterTextEditorArea(ITunnelClient &tunnel, bool enable)
225 {
226 return RET_ERR;
227 }
228
GetDragAction(ITunnelClient & tunnel,DragAction & dragAction)229 int32_t DragClient::GetDragAction(ITunnelClient &tunnel, DragAction &dragAction)
230 {
231 return RET_ERR;
232 }
233
GetExtraInfo(ITunnelClient & tunnel,std::string & extraInfo)234 int32_t DragClient::GetExtraInfo(ITunnelClient &tunnel, std::string &extraInfo)
235 {
236 return RET_ERR;
237 }
238
AddPrivilege(ITunnelClient & tunnel)239 int32_t DragClient::AddPrivilege(ITunnelClient &tunnel)
240 {
241 return RET_ERR;
242 }
243
OnNotifyResult(const StreamClient & client,NetPacket & pkt)244 int32_t DragClient::OnNotifyResult(const StreamClient &client, NetPacket &pkt)
245 {
246 return RET_ERR;
247 }
248
OnNotifyHideIcon(const StreamClient & client,NetPacket & pkt)249 int32_t DragClient::OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt)
250 {
251 return RET_ERR;
252 }
253
OnStateChangedMessage(const StreamClient & client,NetPacket & pkt)254 int32_t DragClient::OnStateChangedMessage(const StreamClient &client, NetPacket &pkt)
255 {
256 return RET_ERR;
257 }
258
OnDragStyleChangedMessage(const StreamClient & client,NetPacket & pkt)259 int32_t DragClient::OnDragStyleChangedMessage(const StreamClient &client, NetPacket &pkt)
260 {
261 return RET_ERR;
262 }
263 } // namespace DeviceStatus
264 } // namespace Msdp
265 } // namespace OHOS
266