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 #include "devicestatus_service.h"
17 
18 #include <unistd.h>
19 #include <vector>
20 
21 #include <ipc_skeleton.h>
22 
23 #include "hitrace_meter.h"
24 #include "hisysevent.h"
25 #include "if_system_ability_manager.h"
26 #include "iservice_registry.h"
27 #ifdef MEMMGR_ENABLE
28 #include "mem_mgr_client.h"
29 #endif
30 #include "string_ex.h"
31 #include "system_ability_definition.h"
32 
33 #include "devicestatus_common.h"
34 #include "devicestatus_hisysevent.h"
35 #include "dsoftbus_adapter.h"
36 #include "input_adapter.h"
37 #include "plugin_manager.h"
38 
39 #undef LOG_TAG
40 #define LOG_TAG "DeviceStatusService"
41 
42 namespace OHOS {
43 namespace Msdp {
44 namespace DeviceStatus {
45 namespace {
46 constexpr int32_t DEFAULT_WAIT_TIME_MS { 1000 };
47 constexpr int32_t WAIT_FOR_ONCE { 1 };
48 constexpr int32_t MAX_N_RETRIES { 100 };
49 
50 struct device_status_epoll_event {
51     int32_t fd { 0 };
52     EpollEventType event_type { EPOLL_EVENT_BEGIN };
53 };
54 
55 const bool REGISTER_RESULT =
56     SystemAbility::MakeAndRegisterAbility(DelayedSpSingleton<DeviceStatusService>::GetInstance().GetRefPtr());
57 } // namespace
58 
DeviceStatusService()59 DeviceStatusService::DeviceStatusService()
60     : SystemAbility(MSDP_DEVICESTATUS_SERVICE_ID, true)
61 {
62     input_ = std::make_unique<InputAdapter>();
63     pluginMgr_ = std::make_unique<PluginManager>(this);
64     dsoftbus_ = std::make_unique<DSoftbusAdapter>();
65 }
66 
~DeviceStatusService()67 DeviceStatusService::~DeviceStatusService()
68 {}
69 
OnDump()70 void DeviceStatusService::OnDump()
71 {}
72 
OnAddSystemAbility(int32_t saId,const std::string & deviceId)73 void DeviceStatusService::OnAddSystemAbility(int32_t saId, const std::string &deviceId)
74 {
75     FI_HILOGI("OnAddSystemAbility systemAbilityId:%{public}d added!", saId);
76 #ifdef MEMMGR_ENABLE
77     if (saId == MEMORY_MANAGER_SA_ID) {
78         Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), PROCESS_TYPE_SA, PROCESS_STATUS_STARTED,
79             MSDP_DEVICESTATUS_SERVICE_ID);
80     }
81 #endif
82 }
83 
OnStart()84 void DeviceStatusService::OnStart()
85 {
86     CALL_INFO_TRACE;
87     if (ready_) {
88         FI_HILOGE("On start is ready, nothing to do");
89         return;
90     }
91 
92     uint64_t tid = GetThisThreadId();
93     delegateTasks_.SetWorkerThreadId(tid);
94 
95     if (!Init()) {
96         FI_HILOGE("On start call init failed");
97         return;
98     }
99 #ifdef MEMMGR_ENABLE
100     AddSystemAbilityListener(MEMORY_MANAGER_SA_ID);
101 #endif
102     EnableDSoftbus();
103     intention_ = sptr<IntentionService>::MakeSptr(this);
104     if (!Publish(intention_)) {
105         FI_HILOGE("On start register to system ability manager failed");
106         return;
107     }
108     state_ = ServiceRunningState::STATE_RUNNING;
109     ready_ = true;
110     worker_ = std::thread([this] { this->OnThread(); });
111 }
112 
OnStop()113 void DeviceStatusService::OnStop()
114 {
115     CALL_INFO_TRACE;
116     if (!ready_) {
117         return;
118     }
119     ready_ = false;
120     state_ = ServiceRunningState::STATE_EXIT;
121 
122     delegateTasks_.PostAsyncTask([]() -> int32_t {
123         FI_HILOGD("No op");
124         return RET_OK;
125     });
126     if (worker_.joinable()) {
127         worker_.join();
128     }
129 #ifdef MEMMGR_ENABLE
130     Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), PROCESS_TYPE_SA, PROCESS_STATUS_DIED,
131         MSDP_DEVICESTATUS_SERVICE_ID);
132 #endif
133 }
134 
GetDelegateTasks()135 IDelegateTasks& DeviceStatusService::GetDelegateTasks()
136 {
137     return delegateTasks_;
138 }
139 
GetDeviceManager()140 IDeviceManager& DeviceStatusService::GetDeviceManager()
141 {
142     return devMgr_;
143 }
144 
GetTimerManager()145 ITimerManager& DeviceStatusService::GetTimerManager()
146 {
147     return timerMgr_;
148 }
149 
GetDragManager()150 IDragManager& DeviceStatusService::GetDragManager()
151 {
152     return dragMgr_;
153 }
154 
GetSocketSessionManager()155 ISocketSessionManager& DeviceStatusService::GetSocketSessionManager()
156 {
157     return socketSessionMgr_;
158 }
159 
GetPluginManager()160 IPluginManager& DeviceStatusService::GetPluginManager()
161 {
162     return *pluginMgr_;
163 }
164 
GetInput()165 IInputAdapter& DeviceStatusService::GetInput()
166 {
167     return *input_;
168 }
169 
GetDSoftbus()170 IDSoftbusAdapter& DeviceStatusService::GetDSoftbus()
171 {
172     return *dsoftbus_;
173 }
174 
EnableDSoftbus()175 void DeviceStatusService::EnableDSoftbus()
176 {
177     CALL_INFO_TRACE;
178     int32_t ret = dsoftbus_->Enable();
179     if (ret != RET_OK) {
180         FI_HILOGE("Failed to enable dsoftbus, try again later");
181         int32_t timerId = timerMgr_.AddTimer(DEFAULT_WAIT_TIME_MS, WAIT_FOR_ONCE,
182             [this] { this->EnableDSoftbus(); });
183         if (timerId < 0) {
184             FI_HILOGE("AddTimer failed, Failed to enable dsoftbus");
185         }
186     } else {
187         FI_HILOGI("Enable dsoftbus successfully");
188     }
189 }
190 
Dump(int32_t fd,const std::vector<std::u16string> & args)191 int32_t DeviceStatusService::Dump(int32_t fd, const std::vector<std::u16string> &args)
192 {
193     CALL_DEBUG_ENTER;
194     if (fd < 0) {
195         FI_HILOGE("fd is invalid");
196         return RET_NG;
197     }
198     if (args.empty()) {
199         FI_HILOGE("Param cannot be empty");
200         dprintf(fd, "param cannot be empty\n");
201         DS_DUMPER->DumpHelpInfo(fd);
202         return RET_NG;
203     }
204     std::vector<std::string> argList;
205     std::transform(args.begin(), args.end(), std::back_inserter(argList),
206         [](const std::u16string &arg) {
207         return Str16ToStr8(arg);
208     });
209 
210     std::vector<Data> datas;
211     for (auto type = TYPE_ABSOLUTE_STILL; type <= TYPE_LID_OPEN; type = static_cast<Type>(type + 1)) {
212         Data data = GetCache(type);
213         if (data.value != OnChangedValue::VALUE_INVALID) {
214             datas.emplace_back(data);
215         }
216     }
217     DS_DUMPER->ParseCommand(fd, argList, datas);
218     return RET_OK;
219 }
220 
Init()221 bool DeviceStatusService::Init()
222 {
223     CALL_INFO_TRACE;
224     if (devicestatusManager_ == nullptr) {
225         FI_HILOGW("devicestatusManager_ is nullptr");
226         devicestatusManager_ = std::make_shared<DeviceStatusManager>();
227     }
228     if (!devicestatusManager_->Init()) {
229         FI_HILOGE("OnStart init failed");
230         return false;
231     }
232     if (EpollCreate() != RET_OK) {
233         FI_HILOGE("Create epoll failed");
234         return false;
235     }
236     if (InitDelegateTasks() != RET_OK) {
237         FI_HILOGE("Delegate tasks init failed");
238         goto INIT_FAIL;
239     }
240     if (InitTimerMgr() != RET_OK) {
241         FI_HILOGE("TimerMgr init failed");
242         goto INIT_FAIL;
243     }
244     if (devMgr_.Init(this) != RET_OK) {
245         FI_HILOGE("DevMgr init failed");
246         goto INIT_FAIL;
247     }
248     if (dragMgr_.Init(this) != RET_OK) {
249         FI_HILOGE("Drag manager init failed");
250         goto INIT_FAIL;
251     }
252     if (DS_DUMPER->Init(this) != RET_OK) {
253         FI_HILOGE("Dump init failed");
254         goto INIT_FAIL;
255     }
256 #if defined(OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK)
257     if (socketSessionMgr_.Init() != RET_OK) {
258         FI_HILOGE("Failed to initialize socket session manager");
259         goto INIT_FAIL;
260     }
261 #elif defined(OHOS_BUILD_ENABLE_COORDINATION)
262 #endif // OHOS_BUILD_ENABLE_COORDINATION
263     return true;
264 
265 INIT_FAIL:
266     EpollClose();
267     return false;
268 }
269 
IsServiceReady() const270 bool DeviceStatusService::IsServiceReady() const
271 {
272     return ready_;
273 }
274 
Subscribe(Type type,ActivityEvent event,ReportLatencyNs latency,sptr<IRemoteDevStaCallback> callback)275 void DeviceStatusService::Subscribe(Type type, ActivityEvent event, ReportLatencyNs latency,
276     sptr<IRemoteDevStaCallback> callback)
277 {
278     FI_HILOGI("Enter event:%{public}d, latency:%{public}d", event, latency);
279     CHKPV(devicestatusManager_);
280     auto appInfo = std::make_shared<AppInfo>();
281     appInfo->uid = GetCallingUid();
282     appInfo->pid = GetCallingPid();
283     appInfo->tokenId = GetCallingTokenID();
284     devicestatusManager_->GetPackageName(appInfo->tokenId, appInfo->packageName);
285     appInfo->type = type;
286     appInfo->callback = callback;
287     DS_DUMPER->SaveAppInfo(appInfo);
288     StartTrace(HITRACE_TAG_MSDP, "serviceSubscribeStart");
289     devicestatusManager_->Subscribe(type, event, latency, callback);
290     FinishTrace(HITRACE_TAG_MSDP);
291     ReportSensorSysEvent(type, true);
292     WriteSubscribeHiSysEvent(appInfo->uid, appInfo->packageName, type);
293 }
294 
Unsubscribe(Type type,ActivityEvent event,sptr<IRemoteDevStaCallback> callback)295 void DeviceStatusService::Unsubscribe(Type type, ActivityEvent event, sptr<IRemoteDevStaCallback> callback)
296 {
297     FI_HILOGI("Enter event:%{public}d", event);
298     CHKPV(devicestatusManager_);
299     auto appInfo = std::make_shared<AppInfo>();
300     appInfo->uid = IPCSkeleton::GetCallingUid();
301     appInfo->pid = IPCSkeleton::GetCallingPid();
302     appInfo->tokenId = IPCSkeleton::GetCallingTokenID();
303     appInfo->packageName = DS_DUMPER->GetPackageName(appInfo->tokenId);
304     appInfo->type = type;
305     appInfo->callback = callback;
306     DS_DUMPER->RemoveAppInfo(appInfo);
307     StartTrace(HITRACE_TAG_MSDP, "serviceUnSubscribeStart");
308     devicestatusManager_->Unsubscribe(type, event, callback);
309     FinishTrace(HITRACE_TAG_MSDP);
310     ReportSensorSysEvent(type, false);
311     WriteUnSubscribeHiSysEvent(appInfo->uid, appInfo->packageName, type);
312 }
313 
GetCache(const Type & type)314 Data DeviceStatusService::GetCache(const Type &type)
315 {
316     CALL_DEBUG_ENTER;
317     if (devicestatusManager_ == nullptr) {
318         Data data = {type, OnChangedValue::VALUE_EXIT};
319         data.value = OnChangedValue::VALUE_INVALID;
320         FI_HILOGI("Get latest device status data func is nullptr, return default!");
321         return data;
322     }
323     return devicestatusManager_->GetLatestDeviceStatusData(type);
324 }
325 
ReportSensorSysEvent(int32_t type,bool enable)326 void DeviceStatusService::ReportSensorSysEvent(int32_t type, bool enable)
327 {
328     auto callerToken = GetCallingTokenID();
329     std::string packageName;
330     CHKPV(devicestatusManager_);
331     devicestatusManager_->GetPackageName(callerToken, packageName);
332     auto uid = GetCallingUid();
333     std::string str = enable ? "Subscribe" : "Unsubscribe";
334     int32_t ret = HiSysEventWrite(
335         OHOS::HiviewDFX::HiSysEvent::Domain::MSDP,
336         str,
337         OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,
338         "UID", uid,
339         "PKGNAME", packageName,
340         "TYPE", type);
341     if (ret != 0) {
342         FI_HILOGE("HiviewDFX write failed, ret:%{public}d", ret);
343     }
344 }
345 
AllocSocketFd(const std::string & programName,int32_t moduleType,int32_t & toReturnClientFd,int32_t & tokenType)346 int32_t DeviceStatusService::AllocSocketFd(const std::string &programName, int32_t moduleType,
347     int32_t &toReturnClientFd, int32_t &tokenType)
348 {
349     FI_HILOGI("Enter, programName:%{public}s, moduleType:%{public}d", programName.c_str(), moduleType);
350 
351     toReturnClientFd = -1;
352     int32_t serverFd = -1;
353     int32_t pid = GetCallingPid();
354     int32_t uid = GetCallingUid();
355     int32_t ret = delegateTasks_.PostSyncTask(
356         [this, programName, moduleType, uid, pid, &serverFd, &toReturnClientFd, &tokenType] {
357             return this->AddSocketPairInfo(programName, moduleType, uid, pid, serverFd,
358                 toReturnClientFd, tokenType);
359         });
360     if (ret != RET_OK) {
361         FI_HILOGE("Call Add socket pair info failed, return:%{public}d", ret);
362         return RET_ERR;
363     }
364     FI_HILOGI("Leave, programName:%{public}s, moduleType:%{public}d, alloc success",
365         programName.c_str(), moduleType);
366     return RET_OK;
367 }
368 
OnConnected(SessionPtr s)369 void DeviceStatusService::OnConnected(SessionPtr s)
370 {
371     CHKPV(s);
372     FI_HILOGI("fd:%{public}d", s->GetFd());
373 }
374 
OnDisconnected(SessionPtr s)375 void DeviceStatusService::OnDisconnected(SessionPtr s)
376 {
377     CHKPV(s);
378     FI_HILOGW("Enter, session, fd:%{public}d", s->GetFd());
379 }
380 
AddEpoll(EpollEventType type,int32_t fd)381 int32_t DeviceStatusService::AddEpoll(EpollEventType type, int32_t fd)
382 {
383     if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
384         FI_HILOGE("Invalid type:%{public}d", type);
385         return RET_ERR;
386     }
387     if (fd < 0) {
388         FI_HILOGE("Invalid fd:%{public}d", fd);
389         return RET_ERR;
390     }
391     auto eventData = static_cast<device_status_epoll_event*>(malloc(sizeof(device_status_epoll_event)));
392     if (!eventData) {
393         FI_HILOGE("Malloc failed");
394         return RET_ERR;
395     }
396     eventData->fd = fd;
397     eventData->event_type = type;
398     FI_HILOGD("EventData:[fd:%{public}d, type:%{public}d]", eventData->fd, eventData->event_type);
399 
400     struct epoll_event ev {};
401     ev.events = EPOLLIN;
402     ev.data.ptr = eventData;
403     if (EpollCtl(fd, EPOLL_CTL_ADD, ev) != RET_OK) {
404         free(eventData);
405         eventData = nullptr;
406         ev.data.ptr = nullptr;
407         FI_HILOGE("EpollCtl failed");
408         return RET_ERR;
409     }
410     return RET_OK;
411 }
412 
DelEpoll(EpollEventType type,int32_t fd)413 int32_t DeviceStatusService::DelEpoll(EpollEventType type, int32_t fd)
414 {
415     if (!(type >= EPOLL_EVENT_BEGIN && type < EPOLL_EVENT_END)) {
416         FI_HILOGE("Invalid type:%{public}d", type);
417         return RET_ERR;
418     }
419     if (fd < 0) {
420         FI_HILOGE("Invalid fd:%{public}d", fd);
421         return RET_ERR;
422     }
423     struct epoll_event ev {};
424     if (EpollCtl(fd, EPOLL_CTL_DEL, ev) != RET_OK) {
425         FI_HILOGE("DelEpoll failed");
426         return RET_ERR;
427     }
428     return RET_OK;
429 }
430 
IsRunning() const431 bool DeviceStatusService::IsRunning() const
432 {
433     return (state_ == ServiceRunningState::STATE_RUNNING);
434 }
435 
InitDelegateTasks()436 int32_t DeviceStatusService::InitDelegateTasks()
437 {
438     CALL_INFO_TRACE;
439     if (!delegateTasks_.Init()) {
440         FI_HILOGE("The delegate task init failed");
441         return RET_ERR;
442     }
443     int32_t ret = AddEpoll(EPOLL_EVENT_ETASK, delegateTasks_.GetReadFd());
444     if (ret != RET_OK) {
445         FI_HILOGE("AddEpoll error ret:%{public}d", ret);
446     }
447     FI_HILOGI("AddEpoll, epollfd:%{public}d, fd:%{public}d", epollFd_, delegateTasks_.GetReadFd());
448     return ret;
449 }
450 
InitTimerMgr()451 int32_t DeviceStatusService::InitTimerMgr()
452 {
453     CALL_INFO_TRACE;
454     int32_t ret = timerMgr_.Init(this);
455     if (ret != RET_OK) {
456         FI_HILOGE("TimerMgr init failed");
457         return ret;
458     }
459     ret = AddEpoll(EPOLL_EVENT_TIMER, timerMgr_.GetTimerFd());
460     if (ret != RET_OK) {
461         FI_HILOGE("AddEpoll for timer failed");
462     }
463     return ret;
464 }
465 
OnThread()466 void DeviceStatusService::OnThread()
467 {
468     SetThreadName(std::string("os_ds_service"));
469     uint64_t tid = GetThisThreadId();
470     delegateTasks_.SetWorkerThreadId(tid);
471     FI_HILOGD("Main worker thread start, tid:%{public}" PRId64 "", tid);
472     EnableDevMgr(MAX_N_RETRIES);
473 
474     while (state_ == ServiceRunningState::STATE_RUNNING) {
475         struct epoll_event ev[MAX_EVENT_SIZE] {};
476         int32_t count = EpollWait(MAX_EVENT_SIZE, -1, ev[0]);
477         for (int32_t i = 0; i < count && state_ == ServiceRunningState::STATE_RUNNING; i++) {
478             auto epollEvent = reinterpret_cast<device_status_epoll_event*>(ev[i].data.ptr);
479             CHKPC(epollEvent);
480             if (epollEvent->event_type == EPOLL_EVENT_SOCKET) {
481                 OnEpollEvent(ev[i]);
482             } else if (epollEvent->event_type == EPOLL_EVENT_ETASK) {
483                 OnDelegateTask(ev[i]);
484             } else if (epollEvent->event_type == EPOLL_EVENT_TIMER) {
485                 OnTimeout(ev[i]);
486             } else if (epollEvent->event_type == EPOLL_EVENT_DEVICE_MGR) {
487                 OnDeviceMgr(ev[i]);
488             } else {
489                 FI_HILOGW("Unknown epoll event type:%{public}d", epollEvent->event_type);
490             }
491         }
492     }
493     FI_HILOGD("Main worker thread stop, tid:%{public}" PRId64 "", tid);
494 }
495 
OnDelegateTask(const struct epoll_event & ev)496 void DeviceStatusService::OnDelegateTask(const struct epoll_event &ev)
497 {
498     if ((ev.events & EPOLLIN) == 0) {
499         FI_HILOGW("Not epollin");
500         return;
501     }
502     DelegateTasks::TaskData data {};
503     ssize_t res = read(delegateTasks_.GetReadFd(), &data, sizeof(data));
504     if (res == -1) {
505         FI_HILOGW("Read failed erron:%{public}d", errno);
506     }
507     FI_HILOGD("RemoteRequest notify td:%{public}" PRId64 ", std:%{public}" PRId64 ""
508         ", taskId:%{public}d", GetThisThreadId(), data.tid, data.taskId);
509     delegateTasks_.ProcessTasks();
510 }
511 
OnTimeout(const struct epoll_event & ev)512 void DeviceStatusService::OnTimeout(const struct epoll_event &ev)
513 {
514     CALL_DEBUG_ENTER;
515     if ((ev.events & EPOLLIN) == EPOLLIN) {
516         uint64_t expiration {};
517         ssize_t ret = read(timerMgr_.GetTimerFd(), &expiration, sizeof(expiration));
518         if (ret < 0) {
519             FI_HILOGE("Read expiration failed:%{public}s", strerror(errno));
520         }
521         timerMgr_.ProcessTimers();
522     } else if ((ev.events & (EPOLLHUP | EPOLLERR)) != 0) {
523         FI_HILOGE("Epoll hangup:%{public}s", strerror(errno));
524     }
525 }
526 
OnDeviceMgr(const struct epoll_event & ev)527 void DeviceStatusService::OnDeviceMgr(const struct epoll_event &ev)
528 {
529     CALL_DEBUG_ENTER;
530     if ((ev.events & EPOLLIN) == EPOLLIN) {
531         devMgr_.Dispatch(ev);
532     } else if ((ev.events & (EPOLLHUP | EPOLLERR)) != 0) {
533         FI_HILOGE("Epoll hangup:%{public}s", strerror(errno));
534     }
535 }
536 
EnableDevMgr(int32_t nRetries)537 int32_t DeviceStatusService::EnableDevMgr(int32_t nRetries)
538 {
539     CALL_INFO_TRACE;
540     static int32_t timerId { -1 };
541     int32_t ret = devMgr_.Enable();
542     if (ret != RET_OK) {
543         FI_HILOGE("Failed to enable device manager");
544         if (nRetries > 0) {
545             timerId = timerMgr_.AddTimer(DEFAULT_WAIT_TIME_MS, WAIT_FOR_ONCE,
546                 [this, nRetries] { return this->EnableDevMgr(nRetries - 1); });
547             if (timerId < 0) {
548                 FI_HILOGE("AddTimer failed, Failed to enable device manager");
549             }
550         } else {
551             FI_HILOGE("Maximum number of retries exceeded, Failed to enable device manager");
552         }
553         return ret;
554     }
555     AddEpoll(EPOLL_EVENT_DEVICE_MGR, devMgr_.GetFd());
556     if (timerId >= 0) {
557         timerMgr_.RemoveTimer(timerId);
558         timerId = -1;
559     }
560     return RET_OK;
561 }
562 
DisableDevMgr()563 void DeviceStatusService::DisableDevMgr()
564 {
565     DelEpoll(EPOLL_EVENT_DEVICE_MGR, devMgr_.GetFd());
566     devMgr_.Disable();
567 }
568 
RegisterCoordinationListener(bool isCompatible)569 int32_t DeviceStatusService::RegisterCoordinationListener(bool isCompatible)
570 {
571     CALL_DEBUG_ENTER;
572     (void)(isCompatible);
573 #ifdef OHOS_BUILD_ENABLE_COORDINATION
574 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
575     int32_t pid = GetCallingPid();
576     int32_t ret = delegateTasks_.PostSyncTask(
577         [this, pid] { return this->OnRegisterCoordinationListener(pid); });
578     if (ret != RET_OK) {
579         FI_HILOGE("On register coordination listener failed, ret:%{public}d", ret);
580         return RET_ERR;
581     }
582 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
583 #endif // OHOS_BUILD_ENABLE_COORDINATION
584     return RET_OK;
585 }
586 
UnregisterCoordinationListener(bool isCompatible)587 int32_t DeviceStatusService::UnregisterCoordinationListener(bool isCompatible)
588 {
589     CALL_DEBUG_ENTER;
590     (void)(isCompatible);
591 #ifdef OHOS_BUILD_ENABLE_COORDINATION
592 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
593     int32_t pid = GetCallingPid();
594     int32_t ret = delegateTasks_.PostSyncTask(
595         [this, pid] { return this->OnUnregisterCoordinationListener(pid); });
596     if (ret != RET_OK) {
597         FI_HILOGE("On unregister coordination listener failed, ret:%{public}d", ret);
598         return RET_ERR;
599     }
600 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
601 #endif // OHOS_BUILD_ENABLE_COORDINATION
602     return RET_OK;
603 }
604 
PrepareCoordination(int32_t userData,bool isCompatible)605 int32_t DeviceStatusService::PrepareCoordination(int32_t userData, bool isCompatible)
606 {
607     CALL_DEBUG_ENTER;
608     (void)(isCompatible);
609 #ifdef OHOS_BUILD_ENABLE_COORDINATION
610 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
611     int32_t pid = GetCallingPid();
612     int32_t ret = delegateTasks_.PostSyncTask(
613         [this, pid, userData] { return this->OnPrepareCoordination(pid, userData); });
614     if (ret != RET_OK) {
615         FI_HILOGE("On prepare coordination failed, ret:%{public}d", ret);
616         return ret;
617     }
618 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
619 #else
620     (void)(userData);
621 #endif // OHOS_BUILD_ENABLE_COORDINATION
622     return RET_OK;
623 }
624 
UnprepareCoordination(int32_t userData,bool isCompatible)625 int32_t DeviceStatusService::UnprepareCoordination(int32_t userData, bool isCompatible)
626 {
627     CALL_DEBUG_ENTER;
628     (void)(isCompatible);
629 #ifdef OHOS_BUILD_ENABLE_COORDINATION
630 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
631     int32_t pid = GetCallingPid();
632     int32_t ret = delegateTasks_.PostSyncTask(
633         [this, pid, userData] { return this->OnUnprepareCoordination(pid, userData); });
634     if (ret != RET_OK) {
635         FI_HILOGE("OnUnprepareCoordination failed, ret:%{public}d", ret);
636         return ret;
637     }
638 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
639 #else
640     (void)(userData);
641 #endif // OHOS_BUILD_ENABLE_COORDINATION
642     return RET_OK;
643 }
644 
ActivateCoordination(int32_t userData,const std::string & remoteNetworkId,int32_t startDeviceId,bool isCompatible)645 int32_t DeviceStatusService::ActivateCoordination(int32_t userData,
646     const std::string &remoteNetworkId, int32_t startDeviceId, bool isCompatible)
647 {
648     CALL_DEBUG_ENTER;
649     (void)(isCompatible);
650 #ifdef OHOS_BUILD_ENABLE_COORDINATION
651 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
652     int32_t pid = GetCallingPid();
653     int32_t ret = delegateTasks_.PostSyncTask([this, pid, userData, remoteNetworkId, startDeviceId] {
654         return this->OnActivateCoordination(pid, userData, remoteNetworkId, startDeviceId);
655     });
656     if (ret != RET_OK) {
657         FI_HILOGE("On activate coordination failed, ret:%{public}d", ret);
658         return ret;
659     }
660 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
661 #else
662     (void)(userData);
663     (void)(remoteNetworkId);
664     (void)(startDeviceId);
665 #endif // OHOS_BUILD_ENABLE_COORDINATION
666     return RET_OK;
667 }
668 
DeactivateCoordination(int32_t userData,bool isUnchained,bool isCompatible)669 int32_t DeviceStatusService::DeactivateCoordination(int32_t userData, bool isUnchained,
670     bool isCompatible)
671 {
672     CALL_DEBUG_ENTER;
673     (void)(isCompatible);
674 #ifdef OHOS_BUILD_ENABLE_COORDINATION
675 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
676     int32_t pid = GetCallingPid();
677     int32_t ret = delegateTasks_.PostSyncTask([this, pid, userData, isUnchained] {
678         return this->OnDeactivateCoordination(pid, userData, isUnchained);
679     });
680     if (ret != RET_OK) {
681         FI_HILOGE("On deactivate coordination failed, ret:%{public}d", ret);
682         return ret;
683     }
684 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
685 #else
686     (void)(userData);
687     (void)(isUnchained);
688 #endif // OHOS_BUILD_ENABLE_COORDINATION
689     return RET_OK;
690 }
691 
GetCoordinationState(int32_t userData,const std::string & networkId,bool isCompatible)692 int32_t DeviceStatusService::GetCoordinationState(int32_t userData, const std::string &networkId,
693     bool isCompatible)
694 {
695     CALL_DEBUG_ENTER;
696     (void)(isCompatible);
697 #ifdef OHOS_BUILD_ENABLE_COORDINATION
698 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
699     int32_t pid = GetCallingPid();
700     int32_t ret = delegateTasks_.PostSyncTask([this, pid, userData, networkId] {
701         return this->OnGetCoordinationState(pid, userData, networkId);
702     });
703     if (ret != RET_OK) {
704         FI_HILOGE("OnGetCoordinationState failed, ret:%{public}d", ret);
705         return ret;
706     }
707 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
708 #else
709     (void)(userData);
710     (void)(networkId);
711     FI_HILOGW("Get coordination state does not support");
712 #endif // OHOS_BUILD_ENABLE_COORDINATION
713     return RET_OK;
714 }
715 
GetCoordinationState(const std::string & udId,bool & state)716 int32_t DeviceStatusService::GetCoordinationState(const std::string &udId, bool &state)
717 {
718     CALL_DEBUG_ENTER;
719 #ifdef OHOS_BUILD_ENABLE_COORDINATION
720 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
721     int32_t ret = delegateTasks_.PostSyncTask([this, udId, &state] {
722         return this->OnGetCoordinationStateSync(pid, udId, state);
723     });
724     if (ret != RET_OK) {
725         FI_HILOGE("OnGetCoordinationStateSync failed, ret:%{public}d", ret);
726         return ret;
727     }
728 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
729 #else
730     (void)(udId);
731     FI_HILOGW("Get coordination state does not support");
732 #endif // OHOS_BUILD_ENABLE_COORDINATION
733     return RET_OK;
734 }
735 
AddDraglistener()736 int32_t DeviceStatusService::AddDraglistener()
737 {
738     CALL_DEBUG_ENTER;
739     int32_t session = GetCallingPid();
740     int32_t ret = delegateTasks_.PostSyncTask([this, session] {
741         return this->dragMgr_.AddListener(session);
742     });
743     if (ret != RET_OK) {
744         FI_HILOGE("AddListener failed, ret:%{public}d", ret);
745     }
746     return ret;
747 }
748 
RemoveDraglistener()749 int32_t DeviceStatusService::RemoveDraglistener()
750 {
751     CALL_DEBUG_ENTER;
752     int32_t session = GetCallingPid();
753     int32_t ret = delegateTasks_.PostSyncTask([this, session] {
754         return this->dragMgr_.RemoveListener(session);
755     });
756     if (ret != RET_OK) {
757         FI_HILOGE("Remove listener failed, ret:%{public}d", ret);
758     }
759     return ret;
760 }
761 
AddSubscriptListener()762 int32_t DeviceStatusService::AddSubscriptListener()
763 {
764     CALL_DEBUG_ENTER;
765     int32_t session = GetCallingPid();
766     int32_t ret = delegateTasks_.PostSyncTask([this, session] {
767         return this->dragMgr_.AddSubscriptListener(session);
768     });
769     if (ret != RET_OK) {
770         FI_HILOGE("AddListener failed, ret:%{public}d", ret);
771     }
772     return ret;
773 }
774 
RemoveSubscriptListener()775 int32_t DeviceStatusService::RemoveSubscriptListener()
776 {
777     CALL_DEBUG_ENTER;
778     int32_t session = GetCallingPid();
779     int32_t ret = delegateTasks_.PostSyncTask([this, session] {
780         return this->dragMgr_.RemoveSubscriptListener(session);
781     });
782     if (ret != RET_OK) {
783         FI_HILOGE("AddListener failed, ret:%{public}d", ret);
784     }
785     return ret;
786 }
787 
StartDrag(const DragData & dragData)788 int32_t DeviceStatusService::StartDrag(const DragData &dragData)
789 {
790     CALL_DEBUG_ENTER;
791     int32_t session = GetCallingPid();
792     int32_t ret = delegateTasks_.PostSyncTask([this, &dragData, session] {
793         return this->dragMgr_.StartDrag(std::cref(dragData), session);
794     });
795     if (ret != RET_OK) {
796         FI_HILOGE("StartDrag failed, ret:%{public}d", ret);
797     }
798     return ret;
799 }
800 
StopDrag(const DragDropResult & dropResult)801 int32_t DeviceStatusService::StopDrag(const DragDropResult &dropResult)
802 {
803     CALL_DEBUG_ENTER;
804     int32_t ret = delegateTasks_.PostSyncTask([this, dropResult] {
805         return this->dragMgr_.StopDrag(dropResult, std::string());
806     });
807     if (ret != RET_OK) {
808         FI_HILOGE("StopDrag failed, ret:%{public}d", ret);
809     }
810     return ret;
811 }
812 
SetDragWindowVisible(bool visible,bool isForce)813 int32_t DeviceStatusService::SetDragWindowVisible(bool visible, bool isForce)
814 {
815     CALL_DEBUG_ENTER;
816     int32_t ret = delegateTasks_.PostSyncTask([this, visible, isForce] {
817         return this->dragMgr_.OnSetDragWindowVisible(visible, isForce);
818     });
819     if (ret != RET_OK) {
820         FI_HILOGE("On set drag window visible failed, ret:%{public}d", ret);
821     }
822     return ret;
823 }
824 
EnterTextEditorArea(bool enable)825 int32_t DeviceStatusService::EnterTextEditorArea(bool enable)
826 {
827     CALL_DEBUG_ENTER;
828     int32_t ret = delegateTasks_.PostSyncTask([this, enable] {
829         return this->dragMgr_.EnterTextEditorArea(enable);
830     });
831     if (ret != RET_OK) {
832         FI_HILOGE("Enter Text Editor Area failed, ret:%{public}d", ret);
833     }
834     return ret;
835 }
836 
GetShadowOffset(ShadowOffset & shadowOffset)837 int32_t DeviceStatusService::GetShadowOffset(ShadowOffset &shadowOffset)
838 {
839     CALL_DEBUG_ENTER;
840     int32_t ret = delegateTasks_.PostSyncTask([this, &shadowOffset] {
841         return this->dragMgr_.OnGetShadowOffset(shadowOffset);
842     });
843     if (ret != RET_OK) {
844         FI_HILOGE("Get shadow offset failed, ret:%{public}d", ret);
845     }
846     return ret;
847 }
848 
UpdateShadowPic(const ShadowInfo & shadowInfo)849 int32_t DeviceStatusService::UpdateShadowPic(const ShadowInfo &shadowInfo)
850 {
851     CALL_DEBUG_ENTER;
852     int32_t ret = delegateTasks_.PostSyncTask([this, &shadowInfo] {
853         return this->dragMgr_.UpdateShadowPic(std::cref(shadowInfo));
854     });
855     if (ret != RET_OK) {
856         FI_HILOGE("Update shadow picture failed, ret:%{public}d", ret);
857     }
858     return ret;
859 }
860 
GetDragData(DragData & dragData)861 int32_t DeviceStatusService::GetDragData(DragData &dragData)
862 {
863     CALL_DEBUG_ENTER;
864     int32_t ret = delegateTasks_.PostSyncTask([this, &dragData] {
865         return this->dragMgr_.GetDragData(dragData);
866     });
867     if (ret != RET_OK) {
868         FI_HILOGE("Get drag data failed, ret:%{public}d", ret);
869     }
870     return ret;
871 }
872 
GetDragState(DragState & dragState)873 int32_t DeviceStatusService::GetDragState(DragState &dragState)
874 {
875     CALL_DEBUG_ENTER;
876     int32_t ret = delegateTasks_.PostSyncTask([this, &dragState] {
877         return this->dragMgr_.GetDragState(dragState);
878     });
879     if (ret != RET_OK) {
880         FI_HILOGE("Get drag state failed, ret:%{public}d", ret);
881     }
882     return ret;
883 }
884 
UpdateDragStyle(DragCursorStyle style)885 int32_t DeviceStatusService::UpdateDragStyle(DragCursorStyle style)
886 {
887     CALL_DEBUG_ENTER;
888     int32_t tid = static_cast<int32_t>(GetCallingTokenID());
889     int32_t pid = GetCallingPid();
890     int32_t ret = delegateTasks_.PostSyncTask([this, style, pid, tid] {
891         return this->dragMgr_.UpdateDragStyle(style, pid, tid);
892     });
893     if (ret != RET_OK) {
894         FI_HILOGE("Update drag style failed, ret:%{public}d", ret);
895     }
896     return ret;
897 }
898 
GetUdKey(std::string & udKey)899 int32_t DeviceStatusService::GetUdKey(std::string &udKey)
900 {
901     CALL_DEBUG_ENTER;
902     int32_t ret = delegateTasks_.PostSyncTask([this, &udKey] {
903         return this->dragMgr_.GetUdKey(udKey);
904     });
905     if (ret != RET_OK) {
906         FI_HILOGE("Get udkey failed, ret:%{public}d", ret);
907     }
908     return ret;
909 }
910 
GetDragTargetPid()911 int32_t DeviceStatusService::GetDragTargetPid()
912 {
913     CALL_DEBUG_ENTER;
914     int32_t ret = delegateTasks_.PostSyncTask([this] {
915         return this->dragMgr_.GetDragTargetPid();
916     });
917     if (ret != RET_OK) {
918         FI_HILOGE("Get drag target pid failed, ret:%{public}d", ret);
919     }
920     return ret;
921 }
922 
GetDragAction(DragAction & dragAction)923 int32_t DeviceStatusService::GetDragAction(DragAction &dragAction)
924 {
925     int32_t ret = delegateTasks_.PostSyncTask([this, &dragAction] {
926         return this->dragMgr_.GetDragAction(dragAction);
927     });
928     if (ret != RET_OK) {
929         FI_HILOGE("Get drag action failed, ret:%{public}d", ret);
930     }
931     return ret;
932 }
933 
GetExtraInfo(std::string & extraInfo)934 int32_t DeviceStatusService::GetExtraInfo(std::string &extraInfo)
935 {
936     int32_t ret = delegateTasks_.PostSyncTask([this, &extraInfo] {
937         return this->dragMgr_.GetExtraInfo(extraInfo);
938     });
939     if (ret != RET_OK) {
940         FI_HILOGE("Get extraInfo failed, ret:%{public}d", ret);
941     }
942     return ret;
943 }
944 
945 #ifdef OHOS_BUILD_ENABLE_COORDINATION
946 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
OnRegisterCoordinationListener(int32_t pid)947 int32_t DeviceStatusService::OnRegisterCoordinationListener(int32_t pid)
948 {
949     CALL_DEBUG_ENTER;
950     SessionPtr sess = GetSession(GetClientFd(pid));
951     CHKPR(sess, RET_ERR);
952     sptr<CoordinationEventManager::EventInfo> event = new (std::nothrow) CoordinationEventManager::EventInfo();
953     CHKPR(event, RET_ERR);
954     event->type = CoordinationEventManager::EventType::LISTENER;
955     event->sess = sess;
956     event->msgId = MessageId::COORDINATION_ADD_LISTENER;
957     return RET_OK;
958 }
959 
OnUnregisterCoordinationListener(int32_t pid)960 int32_t DeviceStatusService::OnUnregisterCoordinationListener(int32_t pid)
961 {
962     CALL_DEBUG_ENTER;
963     SessionPtr sess = GetSession(GetClientFd(pid));
964     sptr<CoordinationEventManager::EventInfo> event = new (std::nothrow) CoordinationEventManager::EventInfo();
965     CHKPR(event, RET_ERR);
966     event->type = CoordinationEventManager::EventType::LISTENER;
967     event->sess = sess;
968     return RET_OK;
969 }
970 
OnPrepareCoordination(int32_t pid,int32_t userData)971 int32_t DeviceStatusService::OnPrepareCoordination(int32_t pid, int32_t userData)
972 {
973     CALL_DEBUG_ENTER;
974     std::string networkId;
975     CoordinationMessage msg = CoordinationMessage::PREPARE;
976     NetPacket pkt(MessageId::COORDINATION_MESSAGE);
977     pkt << userData << networkId << static_cast<int32_t>(msg);
978     if (pkt.ChkRWError()) {
979         FI_HILOGE("Packet write data failed");
980         return RET_ERR;
981     }
982     SessionPtr sess = GetSession(GetClientFd(pid));
983     CHKPR(sess, RET_ERR);
984     if (!sess->SendMsg(pkt)) {
985         FI_HILOGE("Sending failed");
986         return MSG_SEND_FAIL;
987     }
988     return RET_OK;
989 }
990 
OnUnprepareCoordination(int32_t pid,int32_t userData)991 int32_t DeviceStatusService::OnUnprepareCoordination(int32_t pid, int32_t userData)
992 {
993     CALL_DEBUG_ENTER;
994     std::string networkId;
995     CoordinationMessage msg = CoordinationMessage::UNPREPARE;
996     NetPacket pkt(MessageId::COORDINATION_MESSAGE);
997     pkt << userData << networkId << static_cast<int32_t>(msg);
998     if (pkt.ChkRWError()) {
999         FI_HILOGE("Packet write data failed");
1000         return RET_ERR;
1001     }
1002     SessionPtr sess = GetSession(GetClientFd(pid));
1003     CHKPR(sess, RET_ERR);
1004     if (!sess->SendMsg(pkt)) {
1005         FI_HILOGE("Sending failed");
1006         return MSG_SEND_FAIL;
1007     }
1008     return RET_OK;
1009 }
1010 
OnActivateCoordination(int32_t pid,int32_t userData,const std::string & remoteNetworkId,int32_t startDeviceId)1011 int32_t DeviceStatusService::OnActivateCoordination(int32_t pid,
1012     int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId)
1013 {
1014     CALL_DEBUG_ENTER;
1015     SessionPtr sess = GetSession(GetClientFd(pid));
1016     CHKPR(sess, RET_ERR);
1017     sptr<CoordinationEventManager::EventInfo> event = new (std::nothrow) CoordinationEventManager::EventInfo();
1018     CHKPR(event, RET_ERR);
1019     event->type = CoordinationEventManager::EventType::START;
1020     event->sess = sess;
1021     event->msgId = MessageId::COORDINATION_MESSAGE;
1022     event->userData = userData;
1023     return RET_OK;
1024 }
1025 
OnDeactivateCoordination(int32_t pid,int32_t userData,bool isUnchained)1026 int32_t DeviceStatusService::OnDeactivateCoordination(int32_t pid, int32_t userData, bool isUnchained)
1027 {
1028     CALL_DEBUG_ENTER;
1029     SessionPtr sess = GetSession(GetClientFd(pid));
1030     CHKPR(sess, RET_ERR);
1031     sptr<CoordinationEventManager::EventInfo> event = new (std::nothrow) CoordinationEventManager::EventInfo();
1032     CHKPR(event, RET_ERR);
1033     event->type = CoordinationEventManager::EventType::STOP;
1034     event->sess = sess;
1035     event->msgId = MessageId::COORDINATION_MESSAGE;
1036     event->userData = userData;
1037     return RET_OK;
1038 }
1039 
OnGetCoordinationState(int32_t pid,int32_t userData,const std::string & networkId)1040 int32_t DeviceStatusService::OnGetCoordinationState(
1041     int32_t pid, int32_t userData, const std::string &networkId)
1042 {
1043     CALL_DEBUG_ENTER;
1044     SessionPtr sess = GetSession(GetClientFd(pid));
1045     CHKPR(sess, RET_ERR);
1046     sptr<CoordinationEventManager::EventInfo> event = new (std::nothrow) CoordinationEventManager::EventInfo();
1047     CHKPR(event, RET_ERR);
1048     event->type = CoordinationEventManager::EventType::STATE;
1049     event->sess = sess;
1050     event->msgId = MessageId::COORDINATION_GET_STATE;
1051     event->userData = userData;
1052     return RET_OK;
1053 }
1054 
OnGetCoordinationStateSync(const std::string & udId,bool & state)1055 int32_t DeviceStatusService::OnGetCoordinationStateSync(const std::string &udId, bool &state)
1056 {
1057     CALL_DEBUG_ENTER;
1058     return RET_OK;
1059 }
1060 
OnAddHotAreaListener(int32_t pid)1061 int32_t DeviceStatusService::OnAddHotAreaListener(int32_t pid)
1062 {
1063     CALL_DEBUG_ENTER;
1064     auto sess = GetSession(GetClientFd(pid));
1065     CHKPR(sess, RET_ERR);
1066     sptr<CoordinationHotArea::HotAreaInfo> event = new (std::nothrow) CoordinationHotArea::HotAreaInfo();
1067     CHKPR(event, RET_ERR);
1068     event->sess = sess;
1069     event->msgId = MessageId::HOT_AREA_ADD_LISTENER;
1070     HOT_AREA->AddHotAreaListener(event);
1071     return RET_OK;
1072 }
1073 
OnRemoveHotAreaListener(int32_t pid)1074 int32_t DeviceStatusService::OnRemoveHotAreaListener(int32_t pid)
1075 {
1076     CALL_DEBUG_ENTER;
1077     auto sess = GetSession(GetClientFd(pid));
1078     CHKPR(sess, RET_ERR);
1079     sptr<CoordinationHotArea::HotAreaInfo> event = new (std::nothrow) CoordinationHotArea::HotAreaInfo();
1080     CHKPR(event, RET_ERR);
1081     event->sess = sess;
1082     HOT_AREA->RemoveHotAreaListener(event);
1083     return RET_OK;
1084 }
1085 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
1086 #endif // OHOS_BUILD_ENABLE_COORDINATION
1087 
AddHotAreaListener()1088 int32_t DeviceStatusService::AddHotAreaListener()
1089 {
1090     CALL_DEBUG_ENTER;
1091 #ifdef OHOS_BUILD_ENABLE_COORDINATION
1092 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
1093     int32_t pid = GetCallingPid();
1094     int32_t ret = delegateTasks_.PostSyncTask([this, pid] {
1095         return this->OnAddHotAreaListener(pid);
1096     });
1097     if (ret != RET_OK) {
1098         FI_HILOGE("Failed to add hot area listener, ret:%{public}d", ret);
1099         return RET_ERR;
1100     }
1101 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
1102 #endif // OHOS_BUILD_ENABLE_COORDINATION
1103     return RET_OK;
1104 }
1105 
RemoveHotAreaListener()1106 int32_t DeviceStatusService::RemoveHotAreaListener()
1107 {
1108     CALL_DEBUG_ENTER;
1109 #ifdef OHOS_BUILD_ENABLE_COORDINATION
1110 #ifndef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
1111     int32_t pid = GetCallingPid();
1112     int32_t ret = delegateTasks_.PostSyncTask([this, pid] {
1113         return this->OnRemoveHotAreaListener(pid);
1114     });
1115     if (ret != RET_OK) {
1116         FI_HILOGE("Failed to remove hot area listener, ret:%{public}d", ret);
1117         return RET_ERR;
1118     }
1119 #endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
1120 #endif // OHOS_BUILD_ENABLE_COORDINATION
1121     return RET_OK;
1122 }
1123 
UpdatePreviewStyle(const PreviewStyle & previewStyle)1124 int32_t DeviceStatusService::UpdatePreviewStyle(const PreviewStyle &previewStyle)
1125 {
1126     CALL_DEBUG_ENTER;
1127     int32_t ret = delegateTasks_.PostSyncTask([this, previewStyle] {
1128         return this->dragMgr_.UpdatePreviewStyle(previewStyle);
1129     });
1130     if (ret != RET_OK) {
1131         FI_HILOGE("UpdatePreviewStyle failed, ret:%{public}d", ret);
1132     }
1133     return ret;
1134 }
1135 
UpdatePreviewStyleWithAnimation(const PreviewStyle & previewStyle,const PreviewAnimation & animation)1136 int32_t DeviceStatusService::UpdatePreviewStyleWithAnimation(const PreviewStyle &previewStyle,
1137     const PreviewAnimation &animation)
1138 {
1139     CALL_DEBUG_ENTER;
1140     int32_t ret = delegateTasks_.PostSyncTask([this, previewStyle, animation] {
1141         return this->dragMgr_.UpdatePreviewStyleWithAnimation(previewStyle, animation);
1142     });
1143     if (ret != RET_OK) {
1144         FI_HILOGE("UpdatePreviewStyleWithAnimation failed, ret:%{public}d", ret);
1145     }
1146     return ret;
1147 }
1148 
GetDragSummary(std::map<std::string,int64_t> & summarys)1149 int32_t DeviceStatusService::GetDragSummary(std::map<std::string, int64_t> &summarys)
1150 {
1151     int32_t ret = delegateTasks_.PostSyncTask([this, &summarys] {
1152         return this->dragMgr_.GetDragSummary(summarys);
1153     });
1154     if (ret != RET_OK) {
1155         FI_HILOGE("Failed to get drag summarys, ret:%{public}d", ret);
1156         return RET_ERR;
1157     }
1158     return RET_OK;
1159 }
1160 
AddPrivilege()1161 int32_t DeviceStatusService::AddPrivilege()
1162 {
1163     CALL_DEBUG_ENTER;
1164     int32_t tokenId = static_cast<int32_t>(GetCallingTokenID());
1165     int32_t ret = delegateTasks_.PostSyncTask([this, tokenId] {
1166         return this->dragMgr_.AddPrivilege(tokenId);
1167     });
1168     if (ret != RET_OK) {
1169         FI_HILOGE("Failed to add privilege, ret:%{public}d", ret);
1170         return RET_ERR;
1171     }
1172     return RET_OK;
1173 }
1174 
EraseMouseIcon()1175 int32_t DeviceStatusService::EraseMouseIcon()
1176 {
1177     CALL_DEBUG_ENTER;
1178     int32_t ret = delegateTasks_.PostSyncTask([this] {
1179         return this->dragMgr_.EraseMouseIcon();
1180     });
1181     if (ret != RET_OK) {
1182         FI_HILOGE("Failed to erase mouse, ret:%{public}d", ret);
1183     }
1184     return ret;
1185 }
1186 } // namespace DeviceStatus
1187 } // namespace Msdp
1188 } // namespace OHOS
1189