1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#include "state_machine.h" 17f857971dSopenharmony_ci 18f857971dSopenharmony_ci#include "application_state_observer_stub.h" 19f857971dSopenharmony_ci#include "iservice_registry.h" 20f857971dSopenharmony_ci#include "system_ability_definition.h" 21f857971dSopenharmony_ci 22f857971dSopenharmony_ci#include "common_event_observer.h" 23f857971dSopenharmony_ci#include "cooperate_events.h" 24f857971dSopenharmony_ci#include "cooperate_free.h" 25f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 26f857971dSopenharmony_ci#include "cooperate_hisysevent.h" 27f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 28f857971dSopenharmony_ci#include "cooperate_in.h" 29f857971dSopenharmony_ci#include "cooperate_out.h" 30f857971dSopenharmony_ci#include "devicestatus_define.h" 31f857971dSopenharmony_ci#include "devicestatus_errors.h" 32f857971dSopenharmony_ci#include "event_manager.h" 33f857971dSopenharmony_ci#include "utility.h" 34f857971dSopenharmony_ci 35f857971dSopenharmony_ci#undef LOG_TAG 36f857971dSopenharmony_ci#define LOG_TAG "StateMachine" 37f857971dSopenharmony_ci 38f857971dSopenharmony_cinamespace OHOS { 39f857971dSopenharmony_cinamespace Msdp { 40f857971dSopenharmony_cinamespace DeviceStatus { 41f857971dSopenharmony_cinamespace Cooperate { 42f857971dSopenharmony_ci 43f857971dSopenharmony_ciStateMachine::AppStateObserver::AppStateObserver(Channel<CooperateEvent>::Sender sender, int32_t clientPid) 44f857971dSopenharmony_ci : sender_(sender), clientPid_(clientPid) {} 45f857971dSopenharmony_ci 46f857971dSopenharmony_civoid StateMachine::AppStateObserver::OnProcessDied(const AppExecFwk::ProcessData &processData) 47f857971dSopenharmony_ci{ 48f857971dSopenharmony_ci FI_HILOGI("\'%{public}s\' died, pid:%{public}d", processData.bundleName.c_str(), processData.pid); 49f857971dSopenharmony_ci if (processData.pid == clientPid_) { 50f857971dSopenharmony_ci auto ret = sender_.Send(CooperateEvent( 51f857971dSopenharmony_ci CooperateEventType::APP_CLOSED, 52f857971dSopenharmony_ci ClientDiedEvent { 53f857971dSopenharmony_ci .pid = clientPid_, 54f857971dSopenharmony_ci })); 55f857971dSopenharmony_ci if (ret != Channel<CooperateEvent>::NO_ERROR) { 56f857971dSopenharmony_ci FI_HILOGE("Failed to send event via channel, error:%{public}d", ret); 57f857971dSopenharmony_ci } 58f857971dSopenharmony_ci FI_HILOGI("\'%{public}s\' died, report to handler", processData.bundleName.c_str()); 59f857971dSopenharmony_ci } 60f857971dSopenharmony_ci} 61f857971dSopenharmony_ci 62f857971dSopenharmony_civoid StateMachine::AppStateObserver::UpdateClientPid(int32_t clientPid) 63f857971dSopenharmony_ci{ 64f857971dSopenharmony_ci clientPid_ = clientPid; 65f857971dSopenharmony_ci} 66f857971dSopenharmony_ci 67f857971dSopenharmony_ciStateMachine::StateMachine(IContext *env) 68f857971dSopenharmony_ci : env_(env) 69f857971dSopenharmony_ci{ 70f857971dSopenharmony_ci states_[COOPERATE_STATE_FREE] = std::make_shared<CooperateFree>(*this, env); 71f857971dSopenharmony_ci states_[COOPERATE_STATE_OUT] = std::make_shared<CooperateOut>(*this, env); 72f857971dSopenharmony_ci states_[COOPERATE_STATE_IN] = std::make_shared<CooperateIn>(*this, env); 73f857971dSopenharmony_ci 74f857971dSopenharmony_ci AddHandler(CooperateEventType::ADD_OBSERVER, [this](Context &context, const CooperateEvent &event) { 75f857971dSopenharmony_ci this->AddObserver(context, event); 76f857971dSopenharmony_ci }); 77f857971dSopenharmony_ci AddHandler(CooperateEventType::REMOVE_OBSERVER, [this](Context &context, const CooperateEvent &event) { 78f857971dSopenharmony_ci this->RemoveObserver(context, event); 79f857971dSopenharmony_ci }); 80f857971dSopenharmony_ci AddHandler(CooperateEventType::REGISTER_LISTENER, [this](Context &context, const CooperateEvent &event) { 81f857971dSopenharmony_ci this->RegisterListener(context, event); 82f857971dSopenharmony_ci }); 83f857971dSopenharmony_ci AddHandler(CooperateEventType::UNREGISTER_LISTENER, [this](Context &context, const CooperateEvent &event) { 84f857971dSopenharmony_ci this->UnregisterListener(context, event); 85f857971dSopenharmony_ci }); 86f857971dSopenharmony_ci AddHandler(CooperateEventType::REGISTER_HOTAREA_LISTENER, [this](Context &context, const CooperateEvent &event) { 87f857971dSopenharmony_ci this->RegisterHotAreaListener(context, event); 88f857971dSopenharmony_ci }); 89f857971dSopenharmony_ci AddHandler(CooperateEventType::UNREGISTER_HOTAREA_LISTENER, 90f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 91f857971dSopenharmony_ci this->UnregisterHotAreaListener(context, event); 92f857971dSopenharmony_ci }); 93f857971dSopenharmony_ci AddHandler(CooperateEventType::ENABLE, [this](Context &context, const CooperateEvent &event) { 94f857971dSopenharmony_ci this->EnableCooperate(context, event); 95f857971dSopenharmony_ci }); 96f857971dSopenharmony_ci AddHandler(CooperateEventType::DISABLE, [this](Context &context, const CooperateEvent &event) { 97f857971dSopenharmony_ci this->DisableCooperate(context, event); 98f857971dSopenharmony_ci }); 99f857971dSopenharmony_ci AddHandler(CooperateEventType::START, [this](Context &context, const CooperateEvent &event) { 100f857971dSopenharmony_ci this->StartCooperate(context, event); 101f857971dSopenharmony_ci }); 102f857971dSopenharmony_ci AddHandler(CooperateEventType::GET_COOPERATE_STATE, [this](Context &context, const CooperateEvent &event) { 103f857971dSopenharmony_ci this->GetCooperateState(context, event); 104f857971dSopenharmony_ci }); 105f857971dSopenharmony_ci AddHandler(CooperateEventType::REGISTER_EVENT_LISTENER, 106f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 107f857971dSopenharmony_ci this->RegisterEventListener(context, event); 108f857971dSopenharmony_ci }); 109f857971dSopenharmony_ci AddHandler(CooperateEventType::UNREGISTER_EVENT_LISTENER, 110f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 111f857971dSopenharmony_ci this->UnregisterEventListener(context, event); 112f857971dSopenharmony_ci }); 113f857971dSopenharmony_ci AddHandler(CooperateEventType::DDM_BOARD_ONLINE, 114f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 115f857971dSopenharmony_ci this->OnBoardOnline(context, event); 116f857971dSopenharmony_ci }); 117f857971dSopenharmony_ci AddHandler(CooperateEventType::DDM_BOARD_OFFLINE, 118f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 119f857971dSopenharmony_ci this->OnBoardOffline(context, event); 120f857971dSopenharmony_ci }); 121f857971dSopenharmony_ci AddHandler(CooperateEventType::DDP_COOPERATE_SWITCH_CHANGED, 122f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 123f857971dSopenharmony_ci this->OnProfileChanged(context, event); 124f857971dSopenharmony_ci }); 125f857971dSopenharmony_ci AddHandler(CooperateEventType::INPUT_POINTER_EVENT, 126f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 127f857971dSopenharmony_ci this->OnPointerEvent(context, event); 128f857971dSopenharmony_ci }); 129f857971dSopenharmony_ci AddHandler(CooperateEventType::APP_CLOSED, [this](Context &context, const CooperateEvent &event) { 130f857971dSopenharmony_ci this->OnProcessClientDied(context, event); 131f857971dSopenharmony_ci }); 132f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_SESSION_OPENED, 133f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 134f857971dSopenharmony_ci this->OnSoftbusSessionOpened(context, event); 135f857971dSopenharmony_ci }); 136f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_SESSION_CLOSED, 137f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 138f857971dSopenharmony_ci this->OnSoftbusSessionClosed(context, event); 139f857971dSopenharmony_ci }); 140f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_SUBSCRIBE_MOUSE_LOCATION, 141f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 142f857971dSopenharmony_ci this->OnSoftbusSubscribeMouseLocation(context, event); 143f857971dSopenharmony_ci }); 144f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_UNSUBSCRIBE_MOUSE_LOCATION, 145f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 146f857971dSopenharmony_ci this->OnSoftbusUnSubscribeMouseLocation(context, event); 147f857971dSopenharmony_ci }); 148f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_REPLY_SUBSCRIBE_MOUSE_LOCATION, 149f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 150f857971dSopenharmony_ci this->OnSoftbusReplySubscribeMouseLocation(context, event); 151f857971dSopenharmony_ci }); 152f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_REPLY_UNSUBSCRIBE_MOUSE_LOCATION, 153f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 154f857971dSopenharmony_ci this->OnSoftbusReplyUnSubscribeMouseLocation(context, event); 155f857971dSopenharmony_ci }); 156f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_MOUSE_LOCATION, 157f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 158f857971dSopenharmony_ci this->OnSoftbusMouseLocation(context, event); 159f857971dSopenharmony_ci }); 160f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_START_COOPERATE, 161f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 162f857971dSopenharmony_ci this->OnRemoteStart(context, event); 163f857971dSopenharmony_ci }); 164f857971dSopenharmony_ci AddHandler(CooperateEventType::INPUT_HOTPLUG_EVENT, 165f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 166f857971dSopenharmony_ci this->OnHotPlugEvent(context, event); 167f857971dSopenharmony_ci }); 168f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_INPUT_DEV_HOT_PLUG, 169f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 170f857971dSopenharmony_ci this->OnRemoteHotPlug(context, event); 171f857971dSopenharmony_ci }); 172f857971dSopenharmony_ci AddHandler(CooperateEventType::DSOFTBUS_INPUT_DEV_SYNC, 173f857971dSopenharmony_ci [this](Context &context, const CooperateEvent &event) { 174f857971dSopenharmony_ci this->OnRemoteInputDevice(context, event); 175f857971dSopenharmony_ci }); 176f857971dSopenharmony_ci AddHandler(CooperateEventType::STOP, [this](Context &context, const CooperateEvent &event) { 177f857971dSopenharmony_ci this->StopCooperate(context, event); 178f857971dSopenharmony_ci }); 179f857971dSopenharmony_ci} 180f857971dSopenharmony_ci 181f857971dSopenharmony_civoid StateMachine::OnEvent(Context &context, const CooperateEvent &event) 182f857971dSopenharmony_ci{ 183f857971dSopenharmony_ci if (auto iter = handlers_.find(event.type); iter != handlers_.end()) { 184f857971dSopenharmony_ci iter->second(context, event); 185f857971dSopenharmony_ci } else { 186f857971dSopenharmony_ci Transfer(context, event); 187f857971dSopenharmony_ci } 188f857971dSopenharmony_ci} 189f857971dSopenharmony_ci 190f857971dSopenharmony_civoid StateMachine::TransiteTo(Context &context, CooperateState state) 191f857971dSopenharmony_ci{ 192f857971dSopenharmony_ci if ((state >= COOPERATE_STATE_FREE) && 193f857971dSopenharmony_ci (state < N_COOPERATE_STATES) && 194f857971dSopenharmony_ci (state != current_)) { 195f857971dSopenharmony_ci states_[current_]->OnLeaveState(context); 196f857971dSopenharmony_ci current_ = state; 197f857971dSopenharmony_ci states_[current_]->OnEnterState(context); 198f857971dSopenharmony_ci#ifdef MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 199f857971dSopenharmony_ci auto curState = static_cast<OHOS::Msdp::DeviceStatus::CooperateState>(state); 200f857971dSopenharmony_ci CooperateDFX::WriteCooperateState(curState); 201f857971dSopenharmony_ci#endif // MSDP_HIVIEWDFX_HISYSEVENT_ENABLE 202f857971dSopenharmony_ci } 203f857971dSopenharmony_ci} 204f857971dSopenharmony_ci 205f857971dSopenharmony_civoid StateMachine::AddHandler(CooperateEventType event, std::function<void(Context&, const CooperateEvent&)> handler) 206f857971dSopenharmony_ci{ 207f857971dSopenharmony_ci handlers_.emplace(event, handler); 208f857971dSopenharmony_ci} 209f857971dSopenharmony_ci 210f857971dSopenharmony_civoid StateMachine::OnQuit(Context &context) 211f857971dSopenharmony_ci{ 212f857971dSopenharmony_ci CALL_DEBUG_ENTER; 213f857971dSopenharmony_ci RemoveWatches(context); 214f857971dSopenharmony_ci RemoveMonitor(context); 215f857971dSopenharmony_ci} 216f857971dSopenharmony_ci 217f857971dSopenharmony_civoid StateMachine::AddObserver(Context &context, const CooperateEvent &event) 218f857971dSopenharmony_ci{ 219f857971dSopenharmony_ci AddObserverEvent notice = std::get<AddObserverEvent>(event.event); 220f857971dSopenharmony_ci context.AddObserver(notice.observer); 221f857971dSopenharmony_ci} 222f857971dSopenharmony_ci 223f857971dSopenharmony_civoid StateMachine::RemoveObserver(Context &context, const CooperateEvent &event) 224f857971dSopenharmony_ci{ 225f857971dSopenharmony_ci RemoveObserverEvent notice = std::get<RemoveObserverEvent>(event.event); 226f857971dSopenharmony_ci context.RemoveObserver(notice.observer); 227f857971dSopenharmony_ci} 228f857971dSopenharmony_ci 229f857971dSopenharmony_civoid StateMachine::RegisterListener(Context &context, const CooperateEvent &event) 230f857971dSopenharmony_ci{ 231f857971dSopenharmony_ci RegisterListenerEvent notice = std::get<RegisterListenerEvent>(event.event); 232f857971dSopenharmony_ci context.eventMgr_.RegisterListener(notice); 233f857971dSopenharmony_ci} 234f857971dSopenharmony_ci 235f857971dSopenharmony_civoid StateMachine::UnregisterListener(Context &context, const CooperateEvent &event) 236f857971dSopenharmony_ci{ 237f857971dSopenharmony_ci UnregisterListenerEvent notice = std::get<UnregisterListenerEvent>(event.event); 238f857971dSopenharmony_ci context.eventMgr_.UnregisterListener(notice); 239f857971dSopenharmony_ci} 240f857971dSopenharmony_ci 241f857971dSopenharmony_civoid StateMachine::RegisterHotAreaListener(Context &context, const CooperateEvent &event) 242f857971dSopenharmony_ci{ 243f857971dSopenharmony_ci RegisterHotareaListenerEvent notice = std::get<RegisterHotareaListenerEvent>(event.event); 244f857971dSopenharmony_ci context.hotArea_.AddListener(notice); 245f857971dSopenharmony_ci} 246f857971dSopenharmony_ci 247f857971dSopenharmony_civoid StateMachine::UnregisterHotAreaListener(Context &context, const CooperateEvent &event) 248f857971dSopenharmony_ci{ 249f857971dSopenharmony_ci UnregisterHotareaListenerEvent notice = std::get<UnregisterHotareaListenerEvent>(event.event); 250f857971dSopenharmony_ci context.hotArea_.RemoveListener(notice); 251f857971dSopenharmony_ci} 252f857971dSopenharmony_ci 253f857971dSopenharmony_civoid StateMachine::EnableCooperate(Context &context, const CooperateEvent &event) 254f857971dSopenharmony_ci{ 255f857971dSopenharmony_ci CALL_INFO_TRACE; 256f857971dSopenharmony_ci EnableCooperateEvent enableEvent = std::get<EnableCooperateEvent>(event.event); 257f857971dSopenharmony_ci context.EnableCooperate(enableEvent); 258f857971dSopenharmony_ci context.eventMgr_.EnableCooperate(enableEvent); 259f857971dSopenharmony_ci context.hotArea_.EnableCooperate(enableEvent); 260f857971dSopenharmony_ci observer_ = CommonEventObserver::CreateCommonEventObserver( 261f857971dSopenharmony_ci [&context, this] (const std::string &commonEvent) { 262f857971dSopenharmony_ci OnCommonEvent(context, commonEvent); 263f857971dSopenharmony_ci } 264f857971dSopenharmony_ci ); 265f857971dSopenharmony_ci context.commonEvent_.AddObserver(observer_); 266f857971dSopenharmony_ci AddSessionObserver(context, enableEvent); 267f857971dSopenharmony_ci AddMonitor(context); 268f857971dSopenharmony_ci isCooperateEnable_ = true; 269f857971dSopenharmony_ci Transfer(context, event); 270f857971dSopenharmony_ci} 271f857971dSopenharmony_ci 272f857971dSopenharmony_civoid StateMachine::DisableCooperate(Context &context, const CooperateEvent &event) 273f857971dSopenharmony_ci{ 274f857971dSopenharmony_ci CALL_INFO_TRACE; 275f857971dSopenharmony_ci DisableCooperateEvent disableEvent = std::get<DisableCooperateEvent>(event.event); 276f857971dSopenharmony_ci context.DisableCooperate(disableEvent); 277f857971dSopenharmony_ci context.eventMgr_.DisableCooperate(disableEvent); 278f857971dSopenharmony_ci context.commonEvent_.RemoveObserver(observer_); 279f857971dSopenharmony_ci RemoveSessionObserver(context, disableEvent); 280f857971dSopenharmony_ci RemoveMonitor(context); 281f857971dSopenharmony_ci isCooperateEnable_ = false; 282f857971dSopenharmony_ci Transfer(context, event); 283f857971dSopenharmony_ci} 284f857971dSopenharmony_ci 285f857971dSopenharmony_civoid StateMachine::StartCooperate(Context &context, const CooperateEvent &event) 286f857971dSopenharmony_ci{ 287f857971dSopenharmony_ci CALL_INFO_TRACE; 288f857971dSopenharmony_ci StartCooperateEvent startEvent = std::get<StartCooperateEvent>(event.event); 289f857971dSopenharmony_ci if (!env_->GetDDM().CheckSameAccountToLocal(startEvent.remoteNetworkId)) { 290f857971dSopenharmony_ci FI_HILOGE("CheckSameAccountToLocal failed"); 291f857971dSopenharmony_ci startEvent.errCode->set_value(COMMON_PERMISSION_CHECK_ERROR); 292f857971dSopenharmony_ci return; 293f857971dSopenharmony_ci } 294f857971dSopenharmony_ci UpdateApplicationStateObserver(startEvent.pid); 295f857971dSopenharmony_ci if (!context.IsAllowCooperate()) { 296f857971dSopenharmony_ci FI_HILOGI("Not allow cooperate"); 297f857971dSopenharmony_ci startEvent.errCode->set_value(COMMON_NOT_ALLOWED_DISTRIBUTED); 298f857971dSopenharmony_ci return; 299f857971dSopenharmony_ci } 300f857971dSopenharmony_ci startEvent.errCode->set_value(RET_OK); 301f857971dSopenharmony_ci Transfer(context, event); 302f857971dSopenharmony_ci} 303f857971dSopenharmony_ci 304f857971dSopenharmony_civoid StateMachine::StopCooperate(Context &context, const CooperateEvent &event) 305f857971dSopenharmony_ci{ 306f857971dSopenharmony_ci CALL_DEBUG_ENTER; 307f857971dSopenharmony_ci context.CloseDistributedFileConnection(context.Peer()); 308f857971dSopenharmony_ci Transfer(context, event); 309f857971dSopenharmony_ci} 310f857971dSopenharmony_ci 311f857971dSopenharmony_civoid StateMachine::GetCooperateState(Context &context, const CooperateEvent &event) 312f857971dSopenharmony_ci{ 313f857971dSopenharmony_ci CALL_INFO_TRACE; 314f857971dSopenharmony_ci GetCooperateStateEvent stateEvent = std::get<GetCooperateStateEvent>(event.event); 315f857971dSopenharmony_ci UpdateApplicationStateObserver(stateEvent.pid); 316f857971dSopenharmony_ci EventManager::CooperateStateNotice notice { 317f857971dSopenharmony_ci .pid = stateEvent.pid, 318f857971dSopenharmony_ci .msgId = MessageId::COORDINATION_GET_STATE, 319f857971dSopenharmony_ci .userData = stateEvent.userData, 320f857971dSopenharmony_ci .state = isCooperateEnable_, 321f857971dSopenharmony_ci }; 322f857971dSopenharmony_ci context.eventMgr_.GetCooperateState(notice); 323f857971dSopenharmony_ci} 324f857971dSopenharmony_ci 325f857971dSopenharmony_civoid StateMachine::OnProcessClientDied(Context &context, const CooperateEvent &event) 326f857971dSopenharmony_ci{ 327f857971dSopenharmony_ci CALL_INFO_TRACE; 328f857971dSopenharmony_ci ClientDiedEvent notice = std::get<ClientDiedEvent>(event.event); 329f857971dSopenharmony_ci context.eventMgr_.OnClientDied(notice); 330f857971dSopenharmony_ci context.hotArea_.OnClientDied(notice); 331f857971dSopenharmony_ci context.mouseLocation_.OnClientDied(notice); 332f857971dSopenharmony_ci Transfer(context, event); 333f857971dSopenharmony_ci} 334f857971dSopenharmony_ci 335f857971dSopenharmony_civoid StateMachine::RegisterEventListener(Context &context, const CooperateEvent &event) 336f857971dSopenharmony_ci{ 337f857971dSopenharmony_ci RegisterEventListenerEvent notice = std::get<RegisterEventListenerEvent>(event.event); 338f857971dSopenharmony_ci context.mouseLocation_.AddListener(notice); 339f857971dSopenharmony_ci} 340f857971dSopenharmony_ci 341f857971dSopenharmony_civoid StateMachine::UnregisterEventListener(Context &context, const CooperateEvent &event) 342f857971dSopenharmony_ci{ 343f857971dSopenharmony_ci UnregisterEventListenerEvent notice = std::get<UnregisterEventListenerEvent>(event.event); 344f857971dSopenharmony_ci context.mouseLocation_.RemoveListener(notice); 345f857971dSopenharmony_ci} 346f857971dSopenharmony_ci 347f857971dSopenharmony_civoid StateMachine::OnBoardOnline(Context &context, const CooperateEvent &event) 348f857971dSopenharmony_ci{ 349f857971dSopenharmony_ci CALL_INFO_TRACE; 350f857971dSopenharmony_ci DDMBoardOnlineEvent onlineEvent = std::get<DDMBoardOnlineEvent>(event.event); 351f857971dSopenharmony_ci 352f857971dSopenharmony_ci auto ret = onlineBoards_.insert(onlineEvent.networkId); 353f857971dSopenharmony_ci if (ret.second) { 354f857971dSopenharmony_ci FI_HILOGD("Watch \'%{public}s\'", Utility::Anonymize(onlineEvent.networkId).c_str()); 355f857971dSopenharmony_ci Transfer(context, event); 356f857971dSopenharmony_ci } 357f857971dSopenharmony_ci} 358f857971dSopenharmony_ci 359f857971dSopenharmony_civoid StateMachine::OnBoardOffline(Context &context, const CooperateEvent &event) 360f857971dSopenharmony_ci{ 361f857971dSopenharmony_ci CALL_INFO_TRACE; 362f857971dSopenharmony_ci DDMBoardOfflineEvent offlineEvent = std::get<DDMBoardOfflineEvent>(event.event); 363f857971dSopenharmony_ci 364f857971dSopenharmony_ci if (auto iter = onlineBoards_.find(offlineEvent.networkId); iter != onlineBoards_.end()) { 365f857971dSopenharmony_ci onlineBoards_.erase(iter); 366f857971dSopenharmony_ci FI_HILOGD("Remove watch \'%{public}s\'", Utility::Anonymize(offlineEvent.networkId).c_str()); 367f857971dSopenharmony_ci context.CloseDistributedFileConnection(offlineEvent.networkId); 368f857971dSopenharmony_ci Transfer(context, event); 369f857971dSopenharmony_ci } 370f857971dSopenharmony_ci} 371f857971dSopenharmony_ci 372f857971dSopenharmony_civoid StateMachine::OnProfileChanged(Context &context, const CooperateEvent &event) 373f857971dSopenharmony_ci{ 374f857971dSopenharmony_ci CALL_INFO_TRACE; 375f857971dSopenharmony_ci DDPCooperateSwitchChanged notice = std::get<DDPCooperateSwitchChanged>(event.event); 376f857971dSopenharmony_ci context.eventMgr_.OnProfileChanged(notice); 377f857971dSopenharmony_ci Transfer(context, event); 378f857971dSopenharmony_ci} 379f857971dSopenharmony_ci 380f857971dSopenharmony_civoid StateMachine::OnPointerEvent(Context &context, const CooperateEvent &event) 381f857971dSopenharmony_ci{ 382f857971dSopenharmony_ci CALL_DEBUG_ENTER; 383f857971dSopenharmony_ci InputPointerEvent pointerEvent = std::get<InputPointerEvent>(event.event); 384f857971dSopenharmony_ci Coordinate cursorPos = context.CursorPosition(); 385f857971dSopenharmony_ci context.OnPointerEvent(pointerEvent); 386f857971dSopenharmony_ci pointerEvent.position = cursorPos; 387f857971dSopenharmony_ci Transfer(context, CooperateEvent { CooperateEventType::INPUT_POINTER_EVENT, pointerEvent }); 388f857971dSopenharmony_ci} 389f857971dSopenharmony_ci 390f857971dSopenharmony_civoid StateMachine::OnSoftbusSessionClosed(Context &context, const CooperateEvent &event) 391f857971dSopenharmony_ci{ 392f857971dSopenharmony_ci CALL_INFO_TRACE; 393f857971dSopenharmony_ci DSoftbusSessionClosed notice = std::get<DSoftbusSessionClosed>(event.event); 394f857971dSopenharmony_ci context.eventMgr_.OnSoftbusSessionClosed(notice); 395f857971dSopenharmony_ci context.inputDevMgr_.OnSoftbusSessionClosed(notice); 396f857971dSopenharmony_ci context.mouseLocation_.OnSoftbusSessionClosed(notice); 397f857971dSopenharmony_ci context.CloseDistributedFileConnection(notice.networkId); 398f857971dSopenharmony_ci Transfer(context, event); 399f857971dSopenharmony_ci} 400f857971dSopenharmony_ci 401f857971dSopenharmony_civoid StateMachine::OnSoftbusSessionOpened(Context &context, const CooperateEvent &event) 402f857971dSopenharmony_ci{ 403f857971dSopenharmony_ci CALL_INFO_TRACE; 404f857971dSopenharmony_ci DSoftbusSessionOpened notice = std::get<DSoftbusSessionOpened>(event.event); 405f857971dSopenharmony_ci context.inputDevMgr_.OnSoftbusSessionOpened(notice); 406f857971dSopenharmony_ci Transfer(context, event); 407f857971dSopenharmony_ci} 408f857971dSopenharmony_ci 409f857971dSopenharmony_civoid StateMachine::OnHotPlugEvent(Context &context, const CooperateEvent &event) 410f857971dSopenharmony_ci{ 411f857971dSopenharmony_ci CALL_INFO_TRACE; 412f857971dSopenharmony_ci InputHotplugEvent notice = std::get<InputHotplugEvent>(event.event); 413f857971dSopenharmony_ci context.inputDevMgr_.OnLocalHotPlug(notice); 414f857971dSopenharmony_ci Transfer(context, event); 415f857971dSopenharmony_ci} 416f857971dSopenharmony_ci 417f857971dSopenharmony_civoid StateMachine::OnRemoteInputDevice(Context &context, const CooperateEvent &event) 418f857971dSopenharmony_ci{ 419f857971dSopenharmony_ci CALL_INFO_TRACE; 420f857971dSopenharmony_ci DSoftbusSyncInputDevice notice = std::get<DSoftbusSyncInputDevice>(event.event); 421f857971dSopenharmony_ci context.inputDevMgr_.OnRemoteInputDevice(notice); 422f857971dSopenharmony_ci Transfer(context, event); 423f857971dSopenharmony_ci} 424f857971dSopenharmony_ci 425f857971dSopenharmony_civoid StateMachine::OnRemoteHotPlug(Context &context, const CooperateEvent &event) 426f857971dSopenharmony_ci{ 427f857971dSopenharmony_ci CALL_INFO_TRACE; 428f857971dSopenharmony_ci DSoftbusHotPlugEvent notice = std::get<DSoftbusHotPlugEvent>(event.event); 429f857971dSopenharmony_ci context.inputDevMgr_.OnRemoteHotPlug(notice); 430f857971dSopenharmony_ci Transfer(context, event); 431f857971dSopenharmony_ci} 432f857971dSopenharmony_ci 433f857971dSopenharmony_civoid StateMachine::OnSoftbusSubscribeMouseLocation(Context &context, const CooperateEvent &event) 434f857971dSopenharmony_ci{ 435f857971dSopenharmony_ci CALL_INFO_TRACE; 436f857971dSopenharmony_ci DSoftbusSubscribeMouseLocation notice = std::get<DSoftbusSubscribeMouseLocation>(event.event); 437f857971dSopenharmony_ci context.mouseLocation_.OnSubscribeMouseLocation(notice); 438f857971dSopenharmony_ci} 439f857971dSopenharmony_ci 440f857971dSopenharmony_civoid StateMachine::OnSoftbusUnSubscribeMouseLocation(Context &context, const CooperateEvent &event) 441f857971dSopenharmony_ci{ 442f857971dSopenharmony_ci CALL_INFO_TRACE; 443f857971dSopenharmony_ci DSoftbusUnSubscribeMouseLocation notice = std::get<DSoftbusUnSubscribeMouseLocation>(event.event); 444f857971dSopenharmony_ci context.mouseLocation_.OnUnSubscribeMouseLocation(notice); 445f857971dSopenharmony_ci} 446f857971dSopenharmony_ci 447f857971dSopenharmony_civoid StateMachine::OnSoftbusReplySubscribeMouseLocation(Context &context, const CooperateEvent &event) 448f857971dSopenharmony_ci{ 449f857971dSopenharmony_ci CALL_INFO_TRACE; 450f857971dSopenharmony_ci DSoftbusReplySubscribeMouseLocation notice = std::get<DSoftbusReplySubscribeMouseLocation>(event.event); 451f857971dSopenharmony_ci context.mouseLocation_.OnReplySubscribeMouseLocation(notice); 452f857971dSopenharmony_ci} 453f857971dSopenharmony_ci 454f857971dSopenharmony_civoid StateMachine::OnSoftbusReplyUnSubscribeMouseLocation(Context &context, const CooperateEvent &event) 455f857971dSopenharmony_ci{ 456f857971dSopenharmony_ci CALL_INFO_TRACE; 457f857971dSopenharmony_ci DSoftbusReplyUnSubscribeMouseLocation notice = std::get<DSoftbusReplyUnSubscribeMouseLocation>(event.event); 458f857971dSopenharmony_ci context.mouseLocation_.OnReplyUnSubscribeMouseLocation(notice); 459f857971dSopenharmony_ci} 460f857971dSopenharmony_ci 461f857971dSopenharmony_civoid StateMachine::OnSoftbusMouseLocation(Context &context, const CooperateEvent &event) 462f857971dSopenharmony_ci{ 463f857971dSopenharmony_ci CALL_DEBUG_ENTER; 464f857971dSopenharmony_ci DSoftbusSyncMouseLocation notice = std::get<DSoftbusSyncMouseLocation>(event.event); 465f857971dSopenharmony_ci context.mouseLocation_.OnRemoteMouseLocation(notice); 466f857971dSopenharmony_ci} 467f857971dSopenharmony_ci 468f857971dSopenharmony_civoid StateMachine::OnRemoteStart(Context &context, const CooperateEvent &event) 469f857971dSopenharmony_ci{ 470f857971dSopenharmony_ci CALL_DEBUG_ENTER; 471f857971dSopenharmony_ci DSoftbusStartCooperate startEvent = std::get<DSoftbusStartCooperate>(event.event); 472f857971dSopenharmony_ci if (!env_->GetDDM().CheckSameAccountToLocal(startEvent.originNetworkId) || !isCooperateEnable_) { 473f857971dSopenharmony_ci FI_HILOGE("CheckSameAccountToLocal failed, switch is : %{public}d, unchain", isCooperateEnable_); 474f857971dSopenharmony_ci CooperateEvent stopEvent( 475f857971dSopenharmony_ci CooperateEventType::STOP, 476f857971dSopenharmony_ci StopCooperateEvent{ 477f857971dSopenharmony_ci .isUnchained = true 478f857971dSopenharmony_ci } 479f857971dSopenharmony_ci ); 480f857971dSopenharmony_ci Transfer(context, stopEvent); 481f857971dSopenharmony_ci return; 482f857971dSopenharmony_ci } 483f857971dSopenharmony_ci Transfer(context, event); 484f857971dSopenharmony_ci} 485f857971dSopenharmony_ci 486f857971dSopenharmony_civoid StateMachine::Transfer(Context &context, const CooperateEvent &event) 487f857971dSopenharmony_ci{ 488f857971dSopenharmony_ci states_[current_]->OnEvent(context, event); 489f857971dSopenharmony_ci} 490f857971dSopenharmony_ci 491f857971dSopenharmony_cisptr<AppExecFwk::IAppMgr> StateMachine::GetAppMgr() 492f857971dSopenharmony_ci{ 493f857971dSopenharmony_ci CALL_INFO_TRACE; 494f857971dSopenharmony_ci auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 495f857971dSopenharmony_ci CHKPP(saMgr); 496f857971dSopenharmony_ci auto appMgrObj = saMgr->GetSystemAbility(APP_MGR_SERVICE_ID); 497f857971dSopenharmony_ci CHKPP(appMgrObj); 498f857971dSopenharmony_ci return iface_cast<AppExecFwk::IAppMgr>(appMgrObj); 499f857971dSopenharmony_ci} 500f857971dSopenharmony_ci 501f857971dSopenharmony_ciint32_t StateMachine::RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender, 502f857971dSopenharmony_ci const EnableCooperateEvent &event) 503f857971dSopenharmony_ci{ 504f857971dSopenharmony_ci CALL_INFO_TRACE; 505f857971dSopenharmony_ci auto bundleName = GetPackageName(event.tokenId); 506f857971dSopenharmony_ci clientBundleNames_.push_back(bundleName); 507f857971dSopenharmony_ci FI_HILOGI("Register application %{public}s state observer", bundleName.c_str()); 508f857971dSopenharmony_ci auto appMgr = GetAppMgr(); 509f857971dSopenharmony_ci CHKPR(appMgr, RET_ERR); 510f857971dSopenharmony_ci appStateObserver_ = sptr<AppStateObserver>::MakeSptr(sender, event.pid); 511f857971dSopenharmony_ci auto err = appMgr->RegisterApplicationStateObserver(appStateObserver_, clientBundleNames_); 512f857971dSopenharmony_ci if (err != RET_OK) { 513f857971dSopenharmony_ci appStateObserver_.clear(); 514f857971dSopenharmony_ci FI_HILOGE("IAppMgr::RegisterApplicationStateObserver fail, error:%{public}d", err); 515f857971dSopenharmony_ci return RET_ERR; 516f857971dSopenharmony_ci } 517f857971dSopenharmony_ci return RET_OK; 518f857971dSopenharmony_ci} 519f857971dSopenharmony_ci 520f857971dSopenharmony_civoid StateMachine::UnregisterApplicationStateObserver() 521f857971dSopenharmony_ci{ 522f857971dSopenharmony_ci CALL_INFO_TRACE; 523f857971dSopenharmony_ci CHKPV(appStateObserver_); 524f857971dSopenharmony_ci auto appMgr = GetAppMgr(); 525f857971dSopenharmony_ci CHKPV(appMgr); 526f857971dSopenharmony_ci FI_HILOGI("Unregister application associateassistant state observer"); 527f857971dSopenharmony_ci auto err = appMgr->UnregisterApplicationStateObserver(appStateObserver_); 528f857971dSopenharmony_ci if (err != RET_OK) { 529f857971dSopenharmony_ci FI_HILOGE("IAppMgr::UnregisterApplicationStateObserver fail, error:%{public}d", err); 530f857971dSopenharmony_ci } 531f857971dSopenharmony_ci appStateObserver_.clear(); 532f857971dSopenharmony_ci} 533f857971dSopenharmony_ci 534f857971dSopenharmony_civoid StateMachine::UpdateApplicationStateObserver(int32_t clientPid) 535f857971dSopenharmony_ci{ 536f857971dSopenharmony_ci CALL_INFO_TRACE; 537f857971dSopenharmony_ci CHKPV(appStateObserver_); 538f857971dSopenharmony_ci appStateObserver_->UpdateClientPid(clientPid); 539f857971dSopenharmony_ci} 540f857971dSopenharmony_ci 541f857971dSopenharmony_civoid StateMachine::AddSessionObserver(Context &context, const EnableCooperateEvent &event) 542f857971dSopenharmony_ci{ 543f857971dSopenharmony_ci CALL_INFO_TRACE; 544f857971dSopenharmony_ci RegisterApplicationStateObserver(context.Sender(), event); 545f857971dSopenharmony_ci} 546f857971dSopenharmony_ci 547f857971dSopenharmony_cistd::string StateMachine::GetPackageName(Security::AccessToken::AccessTokenID tokenId) 548f857971dSopenharmony_ci{ 549f857971dSopenharmony_ci CALL_INFO_TRACE; 550f857971dSopenharmony_ci std::string bundleName {"Default"}; 551f857971dSopenharmony_ci int32_t tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); 552f857971dSopenharmony_ci switch (tokenType) { 553f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_HAP: { 554f857971dSopenharmony_ci Security::AccessToken::HapTokenInfo hapInfo; 555f857971dSopenharmony_ci if (Security::AccessToken::AccessTokenKit::GetHapTokenInfo(tokenId, hapInfo) != RET_OK) { 556f857971dSopenharmony_ci FI_HILOGE("Get hap token info failed"); 557f857971dSopenharmony_ci } else { 558f857971dSopenharmony_ci bundleName = hapInfo.bundleName; 559f857971dSopenharmony_ci } 560f857971dSopenharmony_ci break; 561f857971dSopenharmony_ci } 562f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE: 563f857971dSopenharmony_ci case Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL: { 564f857971dSopenharmony_ci Security::AccessToken::NativeTokenInfo tokenInfo; 565f857971dSopenharmony_ci if (Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, tokenInfo) != RET_OK) { 566f857971dSopenharmony_ci FI_HILOGE("Get native token info failed"); 567f857971dSopenharmony_ci } else { 568f857971dSopenharmony_ci bundleName = tokenInfo.processName; 569f857971dSopenharmony_ci } 570f857971dSopenharmony_ci break; 571f857971dSopenharmony_ci } 572f857971dSopenharmony_ci default: { 573f857971dSopenharmony_ci FI_HILOGW("token type not match"); 574f857971dSopenharmony_ci break; 575f857971dSopenharmony_ci } 576f857971dSopenharmony_ci } 577f857971dSopenharmony_ci return bundleName; 578f857971dSopenharmony_ci} 579f857971dSopenharmony_ci 580f857971dSopenharmony_civoid StateMachine::RemoveSessionObserver(Context &context, const DisableCooperateEvent &event) 581f857971dSopenharmony_ci{ 582f857971dSopenharmony_ci UnregisterApplicationStateObserver(); 583f857971dSopenharmony_ci} 584f857971dSopenharmony_ci 585f857971dSopenharmony_civoid StateMachine::OnCommonEvent(Context &context, const std::string &commonEvent) 586f857971dSopenharmony_ci{ 587f857971dSopenharmony_ci FI_HILOGD("Current common event:%{public}s", commonEvent.c_str()); 588f857971dSopenharmony_ci CHKPV(env_); 589f857971dSopenharmony_ci if (commonEvent == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON || 590f857971dSopenharmony_ci commonEvent == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { 591f857971dSopenharmony_ci if ((screenEventTimer_ >= 0) && (env_->GetTimerManager().IsExist(screenEventTimer_))) { 592f857971dSopenharmony_ci env_->GetTimerManager().RemoveTimer(screenEventTimer_); 593f857971dSopenharmony_ci screenEventTimer_ = -1; 594f857971dSopenharmony_ci } 595f857971dSopenharmony_ci } 596f857971dSopenharmony_ci if (commonEvent == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF || 597f857971dSopenharmony_ci commonEvent == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { 598f857971dSopenharmony_ci FI_HILOGD("Receive common event:%{public}s, stop cooperate", commonEvent.c_str()); 599f857971dSopenharmony_ci auto ret = context.Sender().Send(CooperateEvent( 600f857971dSopenharmony_ci CooperateEventType::STOP, 601f857971dSopenharmony_ci StopCooperateEvent{ 602f857971dSopenharmony_ci .isUnchained = false 603f857971dSopenharmony_ci })); 604f857971dSopenharmony_ci if (ret != Channel<CooperateEvent>::NO_ERROR) { 605f857971dSopenharmony_ci FI_HILOGE("Failed to send event via channel, error:%{public}d", ret); 606f857971dSopenharmony_ci } 607f857971dSopenharmony_ci screenEventTimer_ = env_->GetTimerManager().AddTimer(SCREEN_LOCKED_TIMEOUT, REPEAT_ONCE, 608f857971dSopenharmony_ci [sender = context.Sender(), this]() mutable { 609f857971dSopenharmony_ci auto res = sender.Send(CooperateEvent( 610f857971dSopenharmony_ci CooperateEventType::STOP, 611f857971dSopenharmony_ci StopCooperateEvent{ 612f857971dSopenharmony_ci .isUnchained = true 613f857971dSopenharmony_ci })); 614f857971dSopenharmony_ci if (res != Channel<CooperateEvent>::NO_ERROR) { 615f857971dSopenharmony_ci FI_HILOGE("Failed to send event via channel, error:%{public}d", res); 616f857971dSopenharmony_ci } 617f857971dSopenharmony_ci screenEventTimer_ = -1; 618f857971dSopenharmony_ci }); 619f857971dSopenharmony_ci } 620f857971dSopenharmony_ci} 621f857971dSopenharmony_ci 622f857971dSopenharmony_civoid StateMachine::AddMonitor(Context &context) 623f857971dSopenharmony_ci{ 624f857971dSopenharmony_ci CALL_INFO_TRACE; 625f857971dSopenharmony_ci if (monitorId_ >= 0) { 626f857971dSopenharmony_ci return; 627f857971dSopenharmony_ci } 628f857971dSopenharmony_ci CHKPV(env_); 629f857971dSopenharmony_ci monitorId_ = env_->GetInput().AddMonitor([&context, this] ( 630f857971dSopenharmony_ci std::shared_ptr<MMI::PointerEvent> pointerEvent) mutable { 631f857971dSopenharmony_ci context.hotArea_.ProcessData(pointerEvent); 632f857971dSopenharmony_ci context.mouseLocation_.ProcessData(pointerEvent); 633f857971dSopenharmony_ci 634f857971dSopenharmony_ci MMI::PointerEvent::PointerItem pointerItem; 635f857971dSopenharmony_ci if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) { 636f857971dSopenharmony_ci FI_HILOGE("Corrupted pointer event"); 637f857971dSopenharmony_ci return; 638f857971dSopenharmony_ci } 639f857971dSopenharmony_ci auto pointerAction = pointerEvent->GetPointerAction(); 640f857971dSopenharmony_ci auto sourceType = pointerEvent->GetSourceType(); 641f857971dSopenharmony_ci if (pointerEvent->HasFlag(MMI::InputEvent::EVENT_FLAG_SIMULATE) && 642f857971dSopenharmony_ci (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW || 643f857971dSopenharmony_ci pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW)) { 644f857971dSopenharmony_ci FI_HILOGW("PointerAction:%{public}d is simulated, skip", pointerAction); 645f857971dSopenharmony_ci return; 646f857971dSopenharmony_ci } 647f857971dSopenharmony_ci auto ret = context.Sender().Send(CooperateEvent( 648f857971dSopenharmony_ci CooperateEventType::INPUT_POINTER_EVENT, 649f857971dSopenharmony_ci InputPointerEvent { 650f857971dSopenharmony_ci .deviceId = pointerEvent->GetDeviceId(), 651f857971dSopenharmony_ci .pointerAction = pointerAction, 652f857971dSopenharmony_ci .sourceType = sourceType, 653f857971dSopenharmony_ci .position = Coordinate { 654f857971dSopenharmony_ci .x = pointerItem.GetDisplayX(), 655f857971dSopenharmony_ci .y = pointerItem.GetDisplayY(), 656f857971dSopenharmony_ci } 657f857971dSopenharmony_ci })); 658f857971dSopenharmony_ci if (ret != Channel<CooperateEvent>::NO_ERROR) { 659f857971dSopenharmony_ci FI_HILOGE("Failed to send event via channel, error:%{public}d", ret); 660f857971dSopenharmony_ci } 661f857971dSopenharmony_ci }); 662f857971dSopenharmony_ci if (monitorId_ < 0) { 663f857971dSopenharmony_ci FI_HILOGE("MMI::Add Monitor fail"); 664f857971dSopenharmony_ci } 665f857971dSopenharmony_ci} 666f857971dSopenharmony_ci 667f857971dSopenharmony_civoid StateMachine::RemoveMonitor(Context &context) 668f857971dSopenharmony_ci{ 669f857971dSopenharmony_ci CALL_INFO_TRACE; 670f857971dSopenharmony_ci if (monitorId_ < 0) { 671f857971dSopenharmony_ci return; 672f857971dSopenharmony_ci } 673f857971dSopenharmony_ci env_->GetInput().RemoveMonitor(monitorId_); 674f857971dSopenharmony_ci monitorId_ = -1; 675f857971dSopenharmony_ci} 676f857971dSopenharmony_ci 677f857971dSopenharmony_civoid StateMachine::RemoveWatches(Context &context) 678f857971dSopenharmony_ci{ 679f857971dSopenharmony_ci CALL_INFO_TRACE; 680f857971dSopenharmony_ci for (auto iter = onlineBoards_.begin(); 681f857971dSopenharmony_ci iter != onlineBoards_.end(); iter = onlineBoards_.begin()) { 682f857971dSopenharmony_ci FI_HILOGD("Remove watch \'%{public}s\'", Utility::Anonymize(*iter).c_str()); 683f857971dSopenharmony_ci onlineBoards_.erase(iter); 684f857971dSopenharmony_ci } 685f857971dSopenharmony_ci} 686f857971dSopenharmony_cibool StateMachine::IsCooperateEnable() 687f857971dSopenharmony_ci{ 688f857971dSopenharmony_ci return isCooperateEnable_; 689f857971dSopenharmony_ci} 690f857971dSopenharmony_ci} // namespace Cooperate 691f857971dSopenharmony_ci} // namespace DeviceStatus 692f857971dSopenharmony_ci} // namespace Msdp 693f857971dSopenharmony_ci} // namespace OHOS 694