1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "cooperate_in.h"
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include "devicestatus_define.h"
19c29fa5a6Sopenharmony_ci#include "utility.h"
20c29fa5a6Sopenharmony_ci
21c29fa5a6Sopenharmony_ci#undef LOG_TAG
22c29fa5a6Sopenharmony_ci#define LOG_TAG "CooperateIn"
23c29fa5a6Sopenharmony_ci
24c29fa5a6Sopenharmony_cinamespace OHOS {
25c29fa5a6Sopenharmony_cinamespace Msdp {
26c29fa5a6Sopenharmony_cinamespace DeviceStatus {
27c29fa5a6Sopenharmony_cinamespace Cooperate {
28c29fa5a6Sopenharmony_ci
29c29fa5a6Sopenharmony_ciCooperateIn::CooperateIn(IStateMachine &parent, IContext *env)
30c29fa5a6Sopenharmony_ci    : ICooperateState(parent), env_(env)
31c29fa5a6Sopenharmony_ci{
32c29fa5a6Sopenharmony_ci    initial_ = std::make_shared<Initial>(*this);
33c29fa5a6Sopenharmony_ci    Initial::BuildChains(initial_, *this);
34c29fa5a6Sopenharmony_ci    current_ = initial_;
35c29fa5a6Sopenharmony_ci}
36c29fa5a6Sopenharmony_ci
37c29fa5a6Sopenharmony_ciCooperateIn::~CooperateIn()
38c29fa5a6Sopenharmony_ci{
39c29fa5a6Sopenharmony_ci    Initial::RemoveChains(initial_);
40c29fa5a6Sopenharmony_ci}
41c29fa5a6Sopenharmony_ci
42c29fa5a6Sopenharmony_civoid CooperateIn::OnEvent(Context &context, const CooperateEvent &event)
43c29fa5a6Sopenharmony_ci{
44c29fa5a6Sopenharmony_ci    current_->OnEvent(context, event);
45c29fa5a6Sopenharmony_ci}
46c29fa5a6Sopenharmony_ci
47c29fa5a6Sopenharmony_civoid CooperateIn::OnEnterState(Context &context)
48c29fa5a6Sopenharmony_ci{
49c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
50c29fa5a6Sopenharmony_ci    env_->GetInput().SetPointerVisibility(!context.NeedHideCursor());
51c29fa5a6Sopenharmony_ci}
52c29fa5a6Sopenharmony_ci
53c29fa5a6Sopenharmony_civoid CooperateIn::OnLeaveState(Context & context)
54c29fa5a6Sopenharmony_ci{
55c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
56c29fa5a6Sopenharmony_ci    UpdateCooperateFlagEvent event {
57c29fa5a6Sopenharmony_ci        .mask = COOPERATE_FLAG_HIDE_CURSOR,
58c29fa5a6Sopenharmony_ci        .flag = COOPERATE_FLAG_HIDE_CURSOR,
59c29fa5a6Sopenharmony_ci    };
60c29fa5a6Sopenharmony_ci    context.UpdateCooperateFlag(event);
61c29fa5a6Sopenharmony_ci    CHKPV(env_);
62c29fa5a6Sopenharmony_ci    env_->GetInput().SetPointerVisibility(false);
63c29fa5a6Sopenharmony_ci}
64c29fa5a6Sopenharmony_ci
65c29fa5a6Sopenharmony_cistd::set<int32_t> CooperateIn::Initial::filterPointerActions_ {
66c29fa5a6Sopenharmony_ci    MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW,
67c29fa5a6Sopenharmony_ci    MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW,
68c29fa5a6Sopenharmony_ci    MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW,
69c29fa5a6Sopenharmony_ci    MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW,
70c29fa5a6Sopenharmony_ci};
71c29fa5a6Sopenharmony_ci
72c29fa5a6Sopenharmony_civoid CooperateIn::Initial::BuildChains(std::shared_ptr<Initial> self, CooperateIn &parent)
73c29fa5a6Sopenharmony_ci{
74c29fa5a6Sopenharmony_ci    auto s11 = std::make_shared<RelayConfirmation>(parent, self);
75c29fa5a6Sopenharmony_ci    self->relay_ = s11;
76c29fa5a6Sopenharmony_ci    s11->SetNext(self);
77c29fa5a6Sopenharmony_ci}
78c29fa5a6Sopenharmony_ci
79c29fa5a6Sopenharmony_civoid CooperateIn::Initial::RemoveChains(std::shared_ptr<Initial> self)
80c29fa5a6Sopenharmony_ci{
81c29fa5a6Sopenharmony_ci    if (self->relay_ != nullptr) {
82c29fa5a6Sopenharmony_ci        self->relay_->SetNext(nullptr);
83c29fa5a6Sopenharmony_ci        self->relay_ = nullptr;
84c29fa5a6Sopenharmony_ci    }
85c29fa5a6Sopenharmony_ci}
86c29fa5a6Sopenharmony_ci
87c29fa5a6Sopenharmony_ciCooperateIn::Initial::Initial(CooperateIn &parent)
88c29fa5a6Sopenharmony_ci    : ICooperateStep(parent, nullptr), parent_(parent)
89c29fa5a6Sopenharmony_ci{
90c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DISABLE, [this](Context &context, const CooperateEvent &event) {
91c29fa5a6Sopenharmony_ci        this->OnDisable(context, event);
92c29fa5a6Sopenharmony_ci    });
93c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::START, [this](Context &context, const CooperateEvent &event) {
94c29fa5a6Sopenharmony_ci        this->OnStart(context, event);
95c29fa5a6Sopenharmony_ci    });
96c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::STOP, [this](Context &context, const CooperateEvent &event) {
97c29fa5a6Sopenharmony_ci        this->OnStop(context, event);
98c29fa5a6Sopenharmony_ci    });
99c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::APP_CLOSED, [this](Context &context, const CooperateEvent &event) {
100c29fa5a6Sopenharmony_ci        this->OnAppClosed(context, event);
101c29fa5a6Sopenharmony_ci    });
102c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::INPUT_POINTER_EVENT, [this](Context &context, const CooperateEvent &event) {
103c29fa5a6Sopenharmony_ci        this->OnPointerEvent(context, event);
104c29fa5a6Sopenharmony_ci    });
105c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DDM_BOARD_OFFLINE, [this](Context &context, const CooperateEvent &event) {
106c29fa5a6Sopenharmony_ci        this->OnBoardOffline(context, event);
107c29fa5a6Sopenharmony_ci    });
108c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DDP_COOPERATE_SWITCH_CHANGED,
109c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
110c29fa5a6Sopenharmony_ci            this->OnSwitchChanged(context, event);
111c29fa5a6Sopenharmony_ci    });
112c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_SESSION_CLOSED,
113c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
114c29fa5a6Sopenharmony_ci            this->OnSoftbusSessionClosed(context, event);
115c29fa5a6Sopenharmony_ci    });
116c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_START_COOPERATE,
117c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
118c29fa5a6Sopenharmony_ci            this->OnRemoteStart(context, event);
119c29fa5a6Sopenharmony_ci    });
120c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_STOP_COOPERATE,
121c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
122c29fa5a6Sopenharmony_ci            this->OnRemoteStop(context, event);
123c29fa5a6Sopenharmony_ci    });
124c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::UPDATE_COOPERATE_FLAG,
125c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
126c29fa5a6Sopenharmony_ci            this->OnUpdateCooperateFlag(context, event);
127c29fa5a6Sopenharmony_ci    });
128c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_INPUT_DEV_SYNC,
129c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
130c29fa5a6Sopenharmony_ci            this->OnRemoteInputDevice(context, event);
131c29fa5a6Sopenharmony_ci    });
132c29fa5a6Sopenharmony_ci}
133c29fa5a6Sopenharmony_ci
134c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnDisable(Context &context, const CooperateEvent &event)
135c29fa5a6Sopenharmony_ci{
136c29fa5a6Sopenharmony_ci    FI_HILOGI("[disable cooperation] Stop cooperation");
137c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
138c29fa5a6Sopenharmony_ci}
139c29fa5a6Sopenharmony_ci
140c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnStart(Context &context, const CooperateEvent &event)
141c29fa5a6Sopenharmony_ci{
142c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
143c29fa5a6Sopenharmony_ci    StartCooperateEvent startEvent = std::get<StartCooperateEvent>(event.event);
144c29fa5a6Sopenharmony_ci
145c29fa5a6Sopenharmony_ci    if (context.IsLocal(startEvent.remoteNetworkId)) {
146c29fa5a6Sopenharmony_ci        DSoftbusStartCooperateFinished result {
147c29fa5a6Sopenharmony_ci            .success = false,
148c29fa5a6Sopenharmony_ci            .errCode = static_cast<int32_t>(CoordinationErrCode::UNEXPECTED_START_CALL)
149c29fa5a6Sopenharmony_ci        };
150c29fa5a6Sopenharmony_ci        context.eventMgr_.StartCooperateFinish(result);
151c29fa5a6Sopenharmony_ci        return;
152c29fa5a6Sopenharmony_ci    }
153c29fa5a6Sopenharmony_ci    FI_HILOGI("[start] start cooperation(%{public}s, %{public}d)",
154c29fa5a6Sopenharmony_ci        Utility::Anonymize(startEvent.remoteNetworkId).c_str(), startEvent.startDeviceId);
155c29fa5a6Sopenharmony_ci    context.eventMgr_.StartCooperate(startEvent);
156c29fa5a6Sopenharmony_ci
157c29fa5a6Sopenharmony_ci    if (context.IsPeer(startEvent.remoteNetworkId)) {
158c29fa5a6Sopenharmony_ci        OnComeBack(context, event);
159c29fa5a6Sopenharmony_ci    } else {
160c29fa5a6Sopenharmony_ci        OnRelay(context, event);
161c29fa5a6Sopenharmony_ci    }
162c29fa5a6Sopenharmony_ci}
163c29fa5a6Sopenharmony_ci
164c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnComeBack(Context &context, const CooperateEvent &event)
165c29fa5a6Sopenharmony_ci{
166c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
167c29fa5a6Sopenharmony_ci    context.inputEventBuilder_.Disable();
168c29fa5a6Sopenharmony_ci    FI_HILOGI("[come back] To \'%{public}s\'", Utility::Anonymize(context.Peer()).c_str());
169c29fa5a6Sopenharmony_ci    DSoftbusComeBack notice {
170c29fa5a6Sopenharmony_ci        .originNetworkId = context.Local(),
171c29fa5a6Sopenharmony_ci        .success = true,
172c29fa5a6Sopenharmony_ci        .cursorPos = context.NormalizedCursorPosition(),
173c29fa5a6Sopenharmony_ci    };
174c29fa5a6Sopenharmony_ci    context.OnStartCooperate(notice.extra);
175c29fa5a6Sopenharmony_ci    if (context.dsoftbus_.ComeBack(context.Peer(), notice) != RET_OK) {
176c29fa5a6Sopenharmony_ci        notice.success = false;
177c29fa5a6Sopenharmony_ci        notice.errCode = static_cast<int32_t>(CoordinationErrCode::SEND_PACKET_FAILED);
178c29fa5a6Sopenharmony_ci    }
179c29fa5a6Sopenharmony_ci    context.eventMgr_.StartCooperateFinish(notice);
180c29fa5a6Sopenharmony_ci    context.inputDevMgr_.RemoveVirtualInputDevice(context.Peer());
181c29fa5a6Sopenharmony_ci    TransiteTo(context, CooperateState::COOPERATE_STATE_FREE);
182c29fa5a6Sopenharmony_ci    context.OnBack();
183c29fa5a6Sopenharmony_ci}
184c29fa5a6Sopenharmony_ci
185c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnRelay(Context &context, const CooperateEvent &event)
186c29fa5a6Sopenharmony_ci{
187c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
188c29fa5a6Sopenharmony_ci    StartCooperateEvent startEvent = std::get<StartCooperateEvent>(event.event);
189c29fa5a6Sopenharmony_ci    parent_.process_.StartCooperate(context, startEvent);
190c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] To \'%{public}s\'", Utility::Anonymize(parent_.process_.Peer()).c_str());
191c29fa5a6Sopenharmony_ci
192c29fa5a6Sopenharmony_ci    if (relay_ != nullptr) {
193c29fa5a6Sopenharmony_ci        Switch(relay_);
194c29fa5a6Sopenharmony_ci        relay_->OnProgress(context, event);
195c29fa5a6Sopenharmony_ci    }
196c29fa5a6Sopenharmony_ci}
197c29fa5a6Sopenharmony_ci
198c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnStop(Context &context, const CooperateEvent &event)
199c29fa5a6Sopenharmony_ci{
200c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
201c29fa5a6Sopenharmony_ci    StopCooperateEvent param = std::get<StopCooperateEvent>(event.event);
202c29fa5a6Sopenharmony_ci
203c29fa5a6Sopenharmony_ci    context.eventMgr_.StopCooperate(param);
204c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
205c29fa5a6Sopenharmony_ci
206c29fa5a6Sopenharmony_ci    DSoftbusStopCooperateFinished notice {
207c29fa5a6Sopenharmony_ci        .normal = true,
208c29fa5a6Sopenharmony_ci    };
209c29fa5a6Sopenharmony_ci    context.eventMgr_.StopCooperateFinish(notice);
210c29fa5a6Sopenharmony_ci
211c29fa5a6Sopenharmony_ci    parent_.UnchainConnections(context, param);
212c29fa5a6Sopenharmony_ci}
213c29fa5a6Sopenharmony_ci
214c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnRemoteStart(Context &context, const CooperateEvent &event)
215c29fa5a6Sopenharmony_ci{
216c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
217c29fa5a6Sopenharmony_ci    DSoftbusStartCooperate notice = std::get<DSoftbusStartCooperate>(event.event);
218c29fa5a6Sopenharmony_ci
219c29fa5a6Sopenharmony_ci    if (context.IsPeer(notice.networkId) || context.IsLocal(notice.networkId)) {
220c29fa5a6Sopenharmony_ci        return;
221c29fa5a6Sopenharmony_ci    }
222c29fa5a6Sopenharmony_ci    context.OnRemoteStartCooperate(notice.extra);
223c29fa5a6Sopenharmony_ci    context.eventMgr_.RemoteStart(notice);
224c29fa5a6Sopenharmony_ci
225c29fa5a6Sopenharmony_ci    DSoftbusStopCooperate stopNotice {};
226c29fa5a6Sopenharmony_ci    context.dsoftbus_.StopCooperate(context.Peer(), stopNotice);
227c29fa5a6Sopenharmony_ci
228c29fa5a6Sopenharmony_ci    context.RemoteStartSuccess(notice);
229c29fa5a6Sopenharmony_ci    context.inputEventBuilder_.Update(context);
230c29fa5a6Sopenharmony_ci    context.eventMgr_.RemoteStartFinish(notice);
231c29fa5a6Sopenharmony_ci    FI_HILOGI("[remote start] Cooperation with \'%{public}s\' established", Utility::Anonymize(context.Peer()).c_str());
232c29fa5a6Sopenharmony_ci    context.OnTransitionIn();
233c29fa5a6Sopenharmony_ci}
234c29fa5a6Sopenharmony_ci
235c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnRemoteStop(Context &context, const CooperateEvent &event)
236c29fa5a6Sopenharmony_ci{
237c29fa5a6Sopenharmony_ci    DSoftbusStopCooperate notice = std::get<DSoftbusStopCooperate>(event.event);
238c29fa5a6Sopenharmony_ci
239c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
240c29fa5a6Sopenharmony_ci        return;
241c29fa5a6Sopenharmony_ci    }
242c29fa5a6Sopenharmony_ci    FI_HILOGI("[remote stop] Notification from \'%{public}s\'", Utility::Anonymize(notice.networkId).c_str());
243c29fa5a6Sopenharmony_ci    context.eventMgr_.RemoteStop(notice);
244c29fa5a6Sopenharmony_ci    context.inputEventBuilder_.Disable();
245c29fa5a6Sopenharmony_ci    context.eventMgr_.RemoteStopFinish(notice);
246c29fa5a6Sopenharmony_ci    context.inputDevMgr_.RemoveVirtualInputDevice(context.Peer());
247c29fa5a6Sopenharmony_ci    TransiteTo(context, CooperateState::COOPERATE_STATE_FREE);
248c29fa5a6Sopenharmony_ci    context.OnResetCooperation();
249c29fa5a6Sopenharmony_ci}
250c29fa5a6Sopenharmony_ci
251c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnAppClosed(Context &context, const CooperateEvent &event)
252c29fa5a6Sopenharmony_ci{
253c29fa5a6Sopenharmony_ci    FI_HILOGI("[app closed] Close all connections");
254c29fa5a6Sopenharmony_ci    context.dsoftbus_.CloseAllSessions();
255c29fa5a6Sopenharmony_ci    FI_HILOGI("[app closed] Stop cooperation");
256c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
257c29fa5a6Sopenharmony_ci}
258c29fa5a6Sopenharmony_ci
259c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnPointerEvent(Context &context, const CooperateEvent &event)
260c29fa5a6Sopenharmony_ci{
261c29fa5a6Sopenharmony_ci    InputPointerEvent notice = std::get<InputPointerEvent>(event.event);
262c29fa5a6Sopenharmony_ci
263c29fa5a6Sopenharmony_ci    if ((notice.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) ||
264c29fa5a6Sopenharmony_ci        (filterPointerActions_.find(notice.pointerAction) != filterPointerActions_.end()) ||
265c29fa5a6Sopenharmony_ci        !InputEventBuilder::IsLocalEvent(notice)) {
266c29fa5a6Sopenharmony_ci        return;
267c29fa5a6Sopenharmony_ci    }
268c29fa5a6Sopenharmony_ci    FI_HILOGI("Stop cooperation on operation of local pointer");
269c29fa5a6Sopenharmony_ci    context.OnPointerEvent(notice);
270c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
271c29fa5a6Sopenharmony_ci}
272c29fa5a6Sopenharmony_ci
273c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnBoardOffline(Context &context, const CooperateEvent &event)
274c29fa5a6Sopenharmony_ci{
275c29fa5a6Sopenharmony_ci    DDMBoardOfflineEvent notice = std::get<DDMBoardOfflineEvent>(event.event);
276c29fa5a6Sopenharmony_ci
277c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
278c29fa5a6Sopenharmony_ci        return;
279c29fa5a6Sopenharmony_ci    }
280c29fa5a6Sopenharmony_ci    FI_HILOGI("[board offline] Peer(\'%{public}s\') is offline", Utility::Anonymize(notice.networkId).c_str());
281c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
282c29fa5a6Sopenharmony_ci}
283c29fa5a6Sopenharmony_ci
284c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnSwitchChanged(Context &context, const CooperateEvent &event)
285c29fa5a6Sopenharmony_ci{
286c29fa5a6Sopenharmony_ci    DDPCooperateSwitchChanged notice = std::get<DDPCooperateSwitchChanged>(event.event);
287c29fa5a6Sopenharmony_ci
288c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId) || notice.normal) {
289c29fa5a6Sopenharmony_ci        return;
290c29fa5a6Sopenharmony_ci    }
291c29fa5a6Sopenharmony_ci    FI_HILOGI("[switch off] Peer(\'%{public}s\') switch off", Utility::Anonymize(notice.networkId).c_str());
292c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
293c29fa5a6Sopenharmony_ci}
294c29fa5a6Sopenharmony_ci
295c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnSoftbusSessionClosed(Context &context, const CooperateEvent &event)
296c29fa5a6Sopenharmony_ci{
297c29fa5a6Sopenharmony_ci    DSoftbusSessionClosed notice = std::get<DSoftbusSessionClosed>(event.event);
298c29fa5a6Sopenharmony_ci
299c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
300c29fa5a6Sopenharmony_ci        return;
301c29fa5a6Sopenharmony_ci    }
302c29fa5a6Sopenharmony_ci    FI_HILOGI("[softbus session closed] Disconnected with \'%{public}s\'",
303c29fa5a6Sopenharmony_ci        Utility::Anonymize(notice.networkId).c_str());
304c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
305c29fa5a6Sopenharmony_ci    context.eventMgr_.OnSoftbusSessionClosed(notice);
306c29fa5a6Sopenharmony_ci}
307c29fa5a6Sopenharmony_ci
308c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnRemoteInputDevice(Context &context, const CooperateEvent &event)
309c29fa5a6Sopenharmony_ci{
310c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
311c29fa5a6Sopenharmony_ci    DSoftbusSyncInputDevice notice = std::get<DSoftbusSyncInputDevice>(event.event);
312c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
313c29fa5a6Sopenharmony_ci        return;
314c29fa5a6Sopenharmony_ci    }
315c29fa5a6Sopenharmony_ci    FI_HILOGI("Remote input device from \'%{public}s\'", Utility::Anonymize(notice.networkId).c_str());
316c29fa5a6Sopenharmony_ci    context.inputDevMgr_.AddVirtualInputDevice(notice.networkId);
317c29fa5a6Sopenharmony_ci}
318c29fa5a6Sopenharmony_ci
319c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnRemoteHotPlug(Context &context, const CooperateEvent &event)
320c29fa5a6Sopenharmony_ci{
321c29fa5a6Sopenharmony_ci    DSoftbusHotPlugEvent notice = std::get<DSoftbusHotPlugEvent>(event.event);
322c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
323c29fa5a6Sopenharmony_ci        return;
324c29fa5a6Sopenharmony_ci    }
325c29fa5a6Sopenharmony_ci    FI_HILOGI("Remote hot plug event from \'%{public}s\'", Utility::Anonymize(notice.networkId).c_str());
326c29fa5a6Sopenharmony_ci}
327c29fa5a6Sopenharmony_ci
328c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnUpdateCooperateFlag(Context &context, const CooperateEvent &event)
329c29fa5a6Sopenharmony_ci{
330c29fa5a6Sopenharmony_ci    UpdateCooperateFlagEvent notice = std::get<UpdateCooperateFlagEvent>(event.event);
331c29fa5a6Sopenharmony_ci    uint32_t changed = (notice.mask & (context.CooperateFlag() ^ notice.flag));
332c29fa5a6Sopenharmony_ci    context.UpdateCooperateFlag(notice);
333c29fa5a6Sopenharmony_ci
334c29fa5a6Sopenharmony_ci    if (changed & COOPERATE_FLAG_FREEZE_CURSOR) {
335c29fa5a6Sopenharmony_ci        FI_HILOGI("Toggle freezing state of cursor");
336c29fa5a6Sopenharmony_ci        if (notice.flag & COOPERATE_FLAG_FREEZE_CURSOR) {
337c29fa5a6Sopenharmony_ci            context.inputEventBuilder_.Freeze();
338c29fa5a6Sopenharmony_ci        } else {
339c29fa5a6Sopenharmony_ci            context.inputEventBuilder_.Thaw();
340c29fa5a6Sopenharmony_ci        }
341c29fa5a6Sopenharmony_ci    }
342c29fa5a6Sopenharmony_ci}
343c29fa5a6Sopenharmony_ci
344c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnProgress(Context &context, const CooperateEvent &event)
345c29fa5a6Sopenharmony_ci{}
346c29fa5a6Sopenharmony_ci
347c29fa5a6Sopenharmony_civoid CooperateIn::Initial::OnReset(Context &context, const CooperateEvent &event)
348c29fa5a6Sopenharmony_ci{}
349c29fa5a6Sopenharmony_ci
350c29fa5a6Sopenharmony_ciCooperateIn::RelayConfirmation::RelayConfirmation(CooperateIn &parent, std::shared_ptr<ICooperateStep> prev)
351c29fa5a6Sopenharmony_ci    : ICooperateStep(parent, prev), parent_(parent)
352c29fa5a6Sopenharmony_ci{
353c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DISABLE, [this](Context &context, const CooperateEvent &event) {
354c29fa5a6Sopenharmony_ci        this->OnDisable(context, event);
355c29fa5a6Sopenharmony_ci    });
356c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::STOP, [this](Context &context, const CooperateEvent &event) {
357c29fa5a6Sopenharmony_ci        this->OnStop(context, event);
358c29fa5a6Sopenharmony_ci    });
359c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::APP_CLOSED, [this](Context &context, const CooperateEvent &event) {
360c29fa5a6Sopenharmony_ci        this->OnAppClosed(context, event);
361c29fa5a6Sopenharmony_ci    });
362c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::INPUT_POINTER_EVENT,
363c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
364c29fa5a6Sopenharmony_ci            this->OnPointerEvent(context, event);
365c29fa5a6Sopenharmony_ci    });
366c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DDM_BOARD_OFFLINE,
367c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
368c29fa5a6Sopenharmony_ci            this->OnBoardOffline(context, event);
369c29fa5a6Sopenharmony_ci    });
370c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DDP_COOPERATE_SWITCH_CHANGED,
371c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
372c29fa5a6Sopenharmony_ci            this->OnSwitchChanged(context, event);
373c29fa5a6Sopenharmony_ci    });
374c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_SESSION_CLOSED,
375c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
376c29fa5a6Sopenharmony_ci            this->OnSoftbusSessionClosed(context, event);
377c29fa5a6Sopenharmony_ci    });
378c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_RELAY_COOPERATE_FINISHED,
379c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
380c29fa5a6Sopenharmony_ci            this->OnResponse(context, event);
381c29fa5a6Sopenharmony_ci    });
382c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_START_COOPERATE,
383c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
384c29fa5a6Sopenharmony_ci            this->OnRemoteStart(context, event);
385c29fa5a6Sopenharmony_ci    });
386c29fa5a6Sopenharmony_ci    AddHandler(CooperateEventType::DSOFTBUS_STOP_COOPERATE,
387c29fa5a6Sopenharmony_ci        [this](Context &context, const CooperateEvent &event) {
388c29fa5a6Sopenharmony_ci            this->OnRemoteStop(context, event);
389c29fa5a6Sopenharmony_ci    });
390c29fa5a6Sopenharmony_ci}
391c29fa5a6Sopenharmony_ci
392c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnDisable(Context &context, const CooperateEvent &event)
393c29fa5a6Sopenharmony_ci{
394c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Disable cooperation");
395c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
396c29fa5a6Sopenharmony_ci    OnReset(context, event);
397c29fa5a6Sopenharmony_ci}
398c29fa5a6Sopenharmony_ci
399c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnStop(Context &context, const CooperateEvent &event)
400c29fa5a6Sopenharmony_ci{
401c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Stop cooperation");
402c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
403c29fa5a6Sopenharmony_ci    OnReset(context, event);
404c29fa5a6Sopenharmony_ci
405c29fa5a6Sopenharmony_ci    StopCooperateEvent param = std::get<StopCooperateEvent>(event.event);
406c29fa5a6Sopenharmony_ci    parent_.UnchainConnections(context, param);
407c29fa5a6Sopenharmony_ci}
408c29fa5a6Sopenharmony_ci
409c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnRemoteStart(Context &context, const CooperateEvent &event)
410c29fa5a6Sopenharmony_ci{
411c29fa5a6Sopenharmony_ci    CALL_INFO_TRACE;
412c29fa5a6Sopenharmony_ci    DSoftbusStartCooperate notice = std::get<DSoftbusStartCooperate>(event.event);
413c29fa5a6Sopenharmony_ci
414c29fa5a6Sopenharmony_ci    if (context.IsPeer(notice.networkId) || context.IsLocal(notice.networkId)) {
415c29fa5a6Sopenharmony_ci        return;
416c29fa5a6Sopenharmony_ci    }
417c29fa5a6Sopenharmony_ci    FI_HILOGI("[remote start] Notification from %{public}s", Utility::Anonymize(notice.networkId).c_str());
418c29fa5a6Sopenharmony_ci    if (parent_.process_.IsPeer(notice.networkId)) {
419c29fa5a6Sopenharmony_ci        auto ret = context.Sender().Send(event);
420c29fa5a6Sopenharmony_ci        if (ret != Channel<CooperateEvent>::NO_ERROR) {
421c29fa5a6Sopenharmony_ci            FI_HILOGE("Failed to send event via channel, error:%{public}d", ret);
422c29fa5a6Sopenharmony_ci        }
423c29fa5a6Sopenharmony_ci        OnReset(context, event);
424c29fa5a6Sopenharmony_ci        return;
425c29fa5a6Sopenharmony_ci    }
426c29fa5a6Sopenharmony_ci    parent_.env_->GetTimerManager().AddTimer(DEFAULT_COOLING_TIME, REPEAT_ONCE,
427c29fa5a6Sopenharmony_ci        [sender = context.Sender(), event]() mutable {
428c29fa5a6Sopenharmony_ci            auto ret = sender.Send(event);
429c29fa5a6Sopenharmony_ci            if (ret != Channel<CooperateEvent>::NO_ERROR) {
430c29fa5a6Sopenharmony_ci                FI_HILOGE("Failed to send event via channel, error:%{public}d", ret);
431c29fa5a6Sopenharmony_ci            }
432c29fa5a6Sopenharmony_ci        });
433c29fa5a6Sopenharmony_ci}
434c29fa5a6Sopenharmony_ci
435c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnRemoteStop(Context &context, const CooperateEvent &event)
436c29fa5a6Sopenharmony_ci{
437c29fa5a6Sopenharmony_ci    DSoftbusStopCooperate notice = std::get<DSoftbusStopCooperate>(event.event);
438c29fa5a6Sopenharmony_ci
439c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
440c29fa5a6Sopenharmony_ci        return;
441c29fa5a6Sopenharmony_ci    }
442c29fa5a6Sopenharmony_ci    FI_HILOGI("[remote stop] Notification from %{public}s", Utility::Anonymize(notice.networkId).c_str());
443c29fa5a6Sopenharmony_ci    auto ret = context.Sender().Send(event);
444c29fa5a6Sopenharmony_ci    if (ret != Channel<CooperateEvent>::NO_ERROR) {
445c29fa5a6Sopenharmony_ci        FI_HILOGE("Failed to send event via channel, error:%{public}d", ret);
446c29fa5a6Sopenharmony_ci    }
447c29fa5a6Sopenharmony_ci    OnReset(context, event);
448c29fa5a6Sopenharmony_ci}
449c29fa5a6Sopenharmony_ci
450c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnAppClosed(Context &context, const CooperateEvent &event)
451c29fa5a6Sopenharmony_ci{
452c29fa5a6Sopenharmony_ci    FI_HILOGI("[app closed] Close all connections");
453c29fa5a6Sopenharmony_ci    context.dsoftbus_.CloseAllSessions();
454c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Stop cooperation on app closed");
455c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
456c29fa5a6Sopenharmony_ci    OnReset(context, event);
457c29fa5a6Sopenharmony_ci}
458c29fa5a6Sopenharmony_ci
459c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnPointerEvent(Context &context, const CooperateEvent &event)
460c29fa5a6Sopenharmony_ci{
461c29fa5a6Sopenharmony_ci    InputPointerEvent notice = std::get<InputPointerEvent>(event.event);
462c29fa5a6Sopenharmony_ci
463c29fa5a6Sopenharmony_ci    if ((notice.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) ||
464c29fa5a6Sopenharmony_ci        !InputEventBuilder::IsLocalEvent(notice)) {
465c29fa5a6Sopenharmony_ci        return;
466c29fa5a6Sopenharmony_ci    }
467c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Stop cooperation on operation of local pointer");
468c29fa5a6Sopenharmony_ci    context.OnPointerEvent(notice);
469c29fa5a6Sopenharmony_ci    parent_.StopCooperate(context, event);
470c29fa5a6Sopenharmony_ci    OnReset(context, event);
471c29fa5a6Sopenharmony_ci}
472c29fa5a6Sopenharmony_ci
473c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnBoardOffline(Context &context, const CooperateEvent &event)
474c29fa5a6Sopenharmony_ci{
475c29fa5a6Sopenharmony_ci    DDMBoardOfflineEvent notice = std::get<DDMBoardOfflineEvent>(event.event);
476c29fa5a6Sopenharmony_ci
477c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId) && !parent_.process_.IsPeer(notice.networkId)) {
478c29fa5a6Sopenharmony_ci        return;
479c29fa5a6Sopenharmony_ci    }
480c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Peer(%{public}s) is offline", Utility::Anonymize(notice.networkId).c_str());
481c29fa5a6Sopenharmony_ci    if (context.IsPeer(notice.networkId)) {
482c29fa5a6Sopenharmony_ci        parent_.StopCooperate(context, event);
483c29fa5a6Sopenharmony_ci    }
484c29fa5a6Sopenharmony_ci    OnReset(context, event);
485c29fa5a6Sopenharmony_ci}
486c29fa5a6Sopenharmony_ci
487c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnSwitchChanged(Context &context, const CooperateEvent &event)
488c29fa5a6Sopenharmony_ci{
489c29fa5a6Sopenharmony_ci    DDPCooperateSwitchChanged notice = std::get<DDPCooperateSwitchChanged>(event.event);
490c29fa5a6Sopenharmony_ci
491c29fa5a6Sopenharmony_ci    if (notice.normal ||
492c29fa5a6Sopenharmony_ci        (!context.IsPeer(notice.networkId) &&
493c29fa5a6Sopenharmony_ci         !parent_.process_.IsPeer(notice.networkId))) {
494c29fa5a6Sopenharmony_ci        return;
495c29fa5a6Sopenharmony_ci    }
496c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Peer(\'%{public}s\') switch off", Utility::Anonymize(notice.networkId).c_str());
497c29fa5a6Sopenharmony_ci    if (context.IsPeer(notice.networkId)) {
498c29fa5a6Sopenharmony_ci        parent_.StopCooperate(context, event);
499c29fa5a6Sopenharmony_ci    }
500c29fa5a6Sopenharmony_ci    OnReset(context, event);
501c29fa5a6Sopenharmony_ci}
502c29fa5a6Sopenharmony_ci
503c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnSoftbusSessionClosed(Context &context, const CooperateEvent &event)
504c29fa5a6Sopenharmony_ci{
505c29fa5a6Sopenharmony_ci    DSoftbusSessionClosed notice = std::get<DSoftbusSessionClosed>(event.event);
506c29fa5a6Sopenharmony_ci
507c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId) && !parent_.process_.IsPeer(notice.networkId)) {
508c29fa5a6Sopenharmony_ci        return;
509c29fa5a6Sopenharmony_ci    }
510c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Disconnected with \'%{public}s\'", Utility::Anonymize(notice.networkId).c_str());
511c29fa5a6Sopenharmony_ci    if (context.IsPeer(notice.networkId)) {
512c29fa5a6Sopenharmony_ci        parent_.StopCooperate(context, event);
513c29fa5a6Sopenharmony_ci    }
514c29fa5a6Sopenharmony_ci    OnReset(context, event);
515c29fa5a6Sopenharmony_ci}
516c29fa5a6Sopenharmony_ci
517c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnResponse(Context &context, const CooperateEvent &event)
518c29fa5a6Sopenharmony_ci{
519c29fa5a6Sopenharmony_ci    DSoftbusRelayCooperateFinished notice = std::get<DSoftbusRelayCooperateFinished>(event.event);
520c29fa5a6Sopenharmony_ci
521c29fa5a6Sopenharmony_ci    if (!context.IsPeer(notice.networkId)) {
522c29fa5a6Sopenharmony_ci        return;
523c29fa5a6Sopenharmony_ci    }
524c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] \'%{public}s\' respond", Utility::Anonymize(notice.networkId).c_str());
525c29fa5a6Sopenharmony_ci    parent_.env_->GetTimerManager().RemoveTimer(timerId_);
526c29fa5a6Sopenharmony_ci    if (notice.normal) {
527c29fa5a6Sopenharmony_ci        OnNormal(context, event);
528c29fa5a6Sopenharmony_ci        Proceed(context, event);
529c29fa5a6Sopenharmony_ci    } else {
530c29fa5a6Sopenharmony_ci        OnReset(context, event);
531c29fa5a6Sopenharmony_ci    }
532c29fa5a6Sopenharmony_ci}
533c29fa5a6Sopenharmony_ci
534c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnNormal(Context &context, const CooperateEvent &event)
535c29fa5a6Sopenharmony_ci{
536c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Cooperation with \'%{public}s\' established",
537c29fa5a6Sopenharmony_ci        Utility::Anonymize(parent_.process_.Peer()).c_str());
538c29fa5a6Sopenharmony_ci    context.inputEventBuilder_.Disable();
539c29fa5a6Sopenharmony_ci
540c29fa5a6Sopenharmony_ci    DSoftbusStartCooperate notice {
541c29fa5a6Sopenharmony_ci        .originNetworkId = context.Peer(),
542c29fa5a6Sopenharmony_ci        .success = true,
543c29fa5a6Sopenharmony_ci        .cursorPos = context.NormalizedCursorPosition(),
544c29fa5a6Sopenharmony_ci    };
545c29fa5a6Sopenharmony_ci    context.OnStartCooperate(notice.extra);
546c29fa5a6Sopenharmony_ci    context.dsoftbus_.StartCooperate(parent_.process_.Peer(), notice);
547c29fa5a6Sopenharmony_ci
548c29fa5a6Sopenharmony_ci    context.eventMgr_.StartCooperateFinish(notice);
549c29fa5a6Sopenharmony_ci    TransiteTo(context, CooperateState::COOPERATE_STATE_FREE);
550c29fa5a6Sopenharmony_ci    context.OnRelayCooperation(parent_.process_.Peer(), context.NormalizedCursorPosition());
551c29fa5a6Sopenharmony_ci}
552c29fa5a6Sopenharmony_ci
553c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnProgress(Context &context, const CooperateEvent &event)
554c29fa5a6Sopenharmony_ci{
555c29fa5a6Sopenharmony_ci    std::string remoteNetworkId = parent_.process_.Peer();
556c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Connect \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str());
557c29fa5a6Sopenharmony_ci    int32_t ret = context.dsoftbus_.OpenSession(remoteNetworkId);
558c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
559c29fa5a6Sopenharmony_ci        FI_HILOGE("[relay cooperate] Failed to connect to \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str());
560c29fa5a6Sopenharmony_ci        OnReset(context, event);
561c29fa5a6Sopenharmony_ci        return;
562c29fa5a6Sopenharmony_ci    }
563c29fa5a6Sopenharmony_ci
564c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] Notify origin(\'%{public}s\')", Utility::Anonymize(context.Peer()).c_str());
565c29fa5a6Sopenharmony_ci    DSoftbusRelayCooperate notice {
566c29fa5a6Sopenharmony_ci        .targetNetworkId = parent_.process_.Peer(),
567c29fa5a6Sopenharmony_ci    };
568c29fa5a6Sopenharmony_ci    context.dsoftbus_.RelayCooperate(context.Peer(), notice);
569c29fa5a6Sopenharmony_ci
570c29fa5a6Sopenharmony_ci    timerId_ = parent_.env_->GetTimerManager().AddTimer(DEFAULT_TIMEOUT, REPEAT_ONCE,
571c29fa5a6Sopenharmony_ci        [sender = context.Sender(), remoteNetworkId = context.Peer()]() mutable {
572c29fa5a6Sopenharmony_ci            auto ret = sender.Send(CooperateEvent(
573c29fa5a6Sopenharmony_ci                CooperateEventType::DSOFTBUS_RELAY_COOPERATE_FINISHED,
574c29fa5a6Sopenharmony_ci                DSoftbusRelayCooperateFinished {
575c29fa5a6Sopenharmony_ci                    .networkId = remoteNetworkId,
576c29fa5a6Sopenharmony_ci                    .normal = false,
577c29fa5a6Sopenharmony_ci                }));
578c29fa5a6Sopenharmony_ci            if (ret != Channel<CooperateEvent>::NO_ERROR) {
579c29fa5a6Sopenharmony_ci                FI_HILOGE("Failed to send event via channel, error:%{public}d", ret);
580c29fa5a6Sopenharmony_ci            }
581c29fa5a6Sopenharmony_ci        });
582c29fa5a6Sopenharmony_ci}
583c29fa5a6Sopenharmony_ci
584c29fa5a6Sopenharmony_civoid CooperateIn::RelayConfirmation::OnReset(Context &context, const CooperateEvent &event)
585c29fa5a6Sopenharmony_ci{
586c29fa5a6Sopenharmony_ci    FI_HILOGI("[relay cooperate] reset cooperation with \'%{public}s\'",
587c29fa5a6Sopenharmony_ci        Utility::Anonymize(parent_.process_.Peer()).c_str());
588c29fa5a6Sopenharmony_ci    DSoftbusStartCooperateFinished result {
589c29fa5a6Sopenharmony_ci        .success = false
590c29fa5a6Sopenharmony_ci    };
591c29fa5a6Sopenharmony_ci    context.eventMgr_.StartCooperateFinish(result);
592c29fa5a6Sopenharmony_ci    Reset(context, event);
593c29fa5a6Sopenharmony_ci}
594c29fa5a6Sopenharmony_ci
595c29fa5a6Sopenharmony_civoid CooperateIn::StopCooperate(Context &context, const CooperateEvent &event)
596c29fa5a6Sopenharmony_ci{
597c29fa5a6Sopenharmony_ci    FI_HILOGI("Stop cooperation with \'%{public}s\'", Utility::Anonymize(context.Peer()).c_str());
598c29fa5a6Sopenharmony_ci    context.inputEventBuilder_.Disable();
599c29fa5a6Sopenharmony_ci    context.UpdateCursorPosition();
600c29fa5a6Sopenharmony_ci
601c29fa5a6Sopenharmony_ci    DSoftbusStopCooperate notice {};
602c29fa5a6Sopenharmony_ci    context.dsoftbus_.StopCooperate(context.Peer(), notice);
603c29fa5a6Sopenharmony_ci    context.inputDevMgr_.RemoveVirtualInputDevice(context.Peer());
604c29fa5a6Sopenharmony_ci    TransiteTo(context, CooperateState::COOPERATE_STATE_FREE);
605c29fa5a6Sopenharmony_ci    context.OnResetCooperation();
606c29fa5a6Sopenharmony_ci}
607c29fa5a6Sopenharmony_ci
608c29fa5a6Sopenharmony_civoid CooperateIn::UnchainConnections(Context &context, const StopCooperateEvent &event) const
609c29fa5a6Sopenharmony_ci{
610c29fa5a6Sopenharmony_ci    if (event.isUnchained) {
611c29fa5a6Sopenharmony_ci        FI_HILOGI("Unchain all connections");
612c29fa5a6Sopenharmony_ci        context.dsoftbus_.CloseAllSessions();
613c29fa5a6Sopenharmony_ci        context.eventMgr_.OnUnchain(event);
614c29fa5a6Sopenharmony_ci    }
615c29fa5a6Sopenharmony_ci}
616c29fa5a6Sopenharmony_ci} // namespace Cooperate
617c29fa5a6Sopenharmony_ci} // namespace DeviceStatus
618c29fa5a6Sopenharmony_ci} // namespace Msdp
619c29fa5a6Sopenharmony_ci} // namespace OHOS
620