1686862fbSopenharmony_ci/* 2686862fbSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4686862fbSopenharmony_ci * you may not use this file except in compliance with the License. 5686862fbSopenharmony_ci * You may obtain a copy of the License at 6686862fbSopenharmony_ci * 7686862fbSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8686862fbSopenharmony_ci * 9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12686862fbSopenharmony_ci * See the License for the specific language governing permissions and 13686862fbSopenharmony_ci * limitations under the License. 14686862fbSopenharmony_ci */ 15686862fbSopenharmony_ci 16686862fbSopenharmony_ci#include "dsched_continue.h" 17686862fbSopenharmony_ci 18686862fbSopenharmony_ci#include <chrono> 19686862fbSopenharmony_ci#include <sys/prctl.h> 20686862fbSopenharmony_ci#include <thread> 21686862fbSopenharmony_ci 22686862fbSopenharmony_ci#include "ability_manager_client.h" 23686862fbSopenharmony_ci#include "bool_wrapper.h" 24686862fbSopenharmony_ci#include "bundle/bundle_manager_internal.h" 25686862fbSopenharmony_ci#include "continue_scene_session_handler.h" 26686862fbSopenharmony_ci#include "datetime_ex.h" 27686862fbSopenharmony_ci#include "dfx/distributed_radar.h" 28686862fbSopenharmony_ci#include "dfx/distributed_ue.h" 29686862fbSopenharmony_ci#include "dfx/dms_continue_time_dumper.h" 30686862fbSopenharmony_ci#include "distributed_sched_permission.h" 31686862fbSopenharmony_ci#include "distributed_sched_service.h" 32686862fbSopenharmony_ci#include "distributed_sched_utils.h" 33686862fbSopenharmony_ci#include "dsched_continue_event.h" 34686862fbSopenharmony_ci#include "dsched_continue_manager.h" 35686862fbSopenharmony_ci#include "dsched_data_buffer.h" 36686862fbSopenharmony_ci#include "dtbschedmgr_device_info_storage.h" 37686862fbSopenharmony_ci#include "dtbschedmgr_log.h" 38686862fbSopenharmony_ci#include "mission/distributed_bm_storage.h" 39686862fbSopenharmony_ci#include "mission/dsched_sync_e2e.h" 40686862fbSopenharmony_ci#include "ipc_skeleton.h" 41686862fbSopenharmony_ci#include "parcel_helper.h" 42686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER 43686862fbSopenharmony_ci#include "mission/dms_continue_send_manager.h" 44686862fbSopenharmony_ci#endif 45686862fbSopenharmony_ci#include "scene_board_judgement.h" 46686862fbSopenharmony_ci#include "softbus_adapter/transport/dsched_transport_softbus_adapter.h" 47686862fbSopenharmony_ci#include "softbus_error_code.h" 48686862fbSopenharmony_ci 49686862fbSopenharmony_cinamespace OHOS { 50686862fbSopenharmony_cinamespace DistributedSchedule { 51686862fbSopenharmony_ciusing namespace AAFwk; 52686862fbSopenharmony_cinamespace { 53686862fbSopenharmony_ciconst std::string TAG = "DSchedContinue"; 54686862fbSopenharmony_ciconst std::string VERSION_CODE_KEY = "version"; 55686862fbSopenharmony_ciconst std::string DMS_SRC_NETWORK_ID = "dmsSrcNetworkId"; 56686862fbSopenharmony_ciconst std::string DMS_VERSION_ID = "dmsVersion"; 57686862fbSopenharmony_ciconst std::string SUPPORT_CONTINUE_PAGE_STACK_KEY = "ohos.extra.param.key.supportContinuePageStack"; 58686862fbSopenharmony_ciconst std::string SUPPORT_CONTINUE_SOURCE_EXIT_KEY = "ohos.extra.param.key.supportContinueSourceExit"; 59686862fbSopenharmony_ciconst std::string SUPPORT_CONTINUE_MODULE_NAME_UPDATE_KEY = "ohos.extra.param.key.supportContinueModuleNameUpdate"; 60686862fbSopenharmony_ciconst std::string DMSDURATION_SAVETIME = "ohos.dschedule.SaveDataTime"; 61686862fbSopenharmony_ciconst std::string DMS_PERSISTENT_ID = "ohos.dms.persistentId"; 62686862fbSopenharmony_ciconst std::string DMS_CONTINUE_SESSION_ID = "ohos.dms.continueSessionId"; 63686862fbSopenharmony_ciconst std::string QUICK_START_CONFIGURATION = "_ContinueQuickStart"; 64686862fbSopenharmony_ciconst std::u16string NAPI_MISSION_CALLBACK_INTERFACE_TOKEN = u"ohos.DistributedSchedule.IMissionCallback"; 65686862fbSopenharmony_ci 66686862fbSopenharmony_ciconstexpr int32_t DSCHED_CONTINUE_PROTOCOL_VERSION = 1; 67686862fbSopenharmony_ciconstexpr uint32_t MAX_MODULENAME_LEN = 2048; 68686862fbSopenharmony_ciconstexpr int32_t DEFAULT_REQUEST_CODE = -1; 69686862fbSopenharmony_ciconstexpr int32_t NOTIFY_MISSION_CALLBACK_RESULT = 4; 70686862fbSopenharmony_ciconstexpr int32_t DMS_VERSION = 5; 71686862fbSopenharmony_ciconstexpr int32_t START_PERMISSION = 0; 72686862fbSopenharmony_ci 73686862fbSopenharmony_ciconstexpr int32_t CONTINUE_BEGIN_TIME = 0; 74686862fbSopenharmony_ciconstexpr int32_t CONTINUE_END_TIME = 1; 75686862fbSopenharmony_ciconstexpr int32_t CONTINUE_TOTAL_TIME = 2; 76686862fbSopenharmony_ciconstexpr int32_t CONTINUE_FIRST_TRANS_TIME = 3; 77686862fbSopenharmony_ciconstexpr int32_t CONTINUE_DATA_TRANS_TIME = 5; 78686862fbSopenharmony_ciconstexpr int32_t CONTINUE_START_ABILITY_TIME = 6; 79686862fbSopenharmony_ciconstexpr int32_t GET_ABILITY_STATE_RETRY_TIMES = 40; 80686862fbSopenharmony_ciconstexpr int32_t GET_ABILITY_STATE_SLEEP_TIME = 50; 81686862fbSopenharmony_ci} 82686862fbSopenharmony_ci 83686862fbSopenharmony_ciconst std::map<int32_t, int32_t> DSchedContinue::DMS_CONVERT_TO_SDK_ERR_MAP = { 84686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_STA_CHIP_CONFLICT, 85686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 86686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_P2P_CHIP_CONFLICT, 87686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 88686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_HML_CHIP_CONFLICT, 89686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 90686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_STA_HML_CHIP_CONFLICT, 91686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 92686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_STA_P2P_CHIP_CONFLICT, 93686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 94686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_AP_P2P_HML_CHIP_CONFLICT, 95686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 96686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(ERROR_PEER_THREE_VAP_CONFLICT, 97686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_HOTSPOT_ENABLE_STATE), 98686862fbSopenharmony_ci 99686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_HML_NUM_LIMITED_CONFLICT, 100686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 101686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PV1_PEER_GC_CONNECTED_TO_ANOTHER_DEVICE, 102686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 103686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PV2_PEER_GC_CONNECTED_TO_ANOTHER_DEVICE, 104686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 105686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_STA_P2P_HML_55_CONFLICT, 106686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 107686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_STA_P2P_HML_225_CONFLICT, 108686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 109686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_STA_P2P_HML_255_CONFLICT, 110686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 111686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_STA_P2P_HML_525_CONFLICT, 112686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 113686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_STA_P2P_HML_555_CONFLICT, 114686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 115686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(SoftBusErrNo::SOFTBUS_CONN_PASSIVE_TYPE_P2P_GO_GC_CONFLICT, 116686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_BIND_REMOTE_IN_BUSY_LINK), 117686862fbSopenharmony_ci 118686862fbSopenharmony_ci std::map<int32_t, int32_t>::value_type(CONTINUE_ALREADY_IN_PROGRESS, 119686862fbSopenharmony_ci DmsInterfaceSdkErr::ERR_CONTINUE_ALREADY_IN_PROGRESS), 120686862fbSopenharmony_ci}; 121686862fbSopenharmony_ci 122686862fbSopenharmony_ciDSchedContinue::DSchedContinue(int32_t subServiceType, int32_t direction, const sptr<IRemoteObject>& callback, 123686862fbSopenharmony_ci const DSchedContinueInfo& continueInfo) : subServiceType_(subServiceType), direction_(direction), 124686862fbSopenharmony_ci continueInfo_(continueInfo), callback_(callback) 125686862fbSopenharmony_ci{ 126686862fbSopenharmony_ci HILOGI("DSchedContinue create"); 127686862fbSopenharmony_ci version_ = DSCHED_CONTINUE_PROTOCOL_VERSION; 128686862fbSopenharmony_ci continueByType_ = !continueInfo.continueType_.empty(); 129686862fbSopenharmony_ci 130686862fbSopenharmony_ci SetEventData(); 131686862fbSopenharmony_ci NotifyDSchedEventResult(ERR_OK); 132686862fbSopenharmony_ci} 133686862fbSopenharmony_ci 134686862fbSopenharmony_ciDSchedContinue::DSchedContinue(std::shared_ptr<DSchedContinueStartCmd> startCmd, int32_t sessionId) 135686862fbSopenharmony_ci{ 136686862fbSopenharmony_ci HILOGI("DSchedContinue create by start command"); 137686862fbSopenharmony_ci if (startCmd == nullptr) { 138686862fbSopenharmony_ci HILOGE("startCmd is null"); 139686862fbSopenharmony_ci return; 140686862fbSopenharmony_ci } 141686862fbSopenharmony_ci version_ = startCmd->version_; 142686862fbSopenharmony_ci subServiceType_ = startCmd->subServiceType_; 143686862fbSopenharmony_ci continueByType_ = startCmd->continueByType_; 144686862fbSopenharmony_ci direction_ = (startCmd->direction_ == CONTINUE_SOURCE) ? CONTINUE_SINK : CONTINUE_SOURCE; 145686862fbSopenharmony_ci continueInfo_.sourceDeviceId_ = startCmd->srcDeviceId_; 146686862fbSopenharmony_ci continueInfo_.sourceBundleName_ = startCmd->srcBundleName_; 147686862fbSopenharmony_ci continueInfo_.sinkDeviceId_ = startCmd->dstDeviceId_; 148686862fbSopenharmony_ci continueInfo_.sinkBundleName_ = startCmd->dstBundleName_; 149686862fbSopenharmony_ci continueInfo_.continueType_ = startCmd->continueType_; 150686862fbSopenharmony_ci continueInfo_.missionId_ = startCmd->sourceMissionId_; 151686862fbSopenharmony_ci softbusSessionId_ = sessionId; 152686862fbSopenharmony_ci SetEventData(); 153686862fbSopenharmony_ci NotifyDSchedEventResult(ERR_OK); 154686862fbSopenharmony_ci if (continueInfo_.sourceBundleName_.empty() && continueInfo_.sinkBundleName_.empty() 155686862fbSopenharmony_ci && continueInfo_.missionId_ != 0) { 156686862fbSopenharmony_ci MissionInfo missionInfo; 157686862fbSopenharmony_ci if (AbilityManagerClient::GetInstance()->GetMissionInfo("", continueInfo_.missionId_, missionInfo) != ERR_OK) { 158686862fbSopenharmony_ci HILOGE("get missionInfo failed"); 159686862fbSopenharmony_ci return; 160686862fbSopenharmony_ci } 161686862fbSopenharmony_ci continueInfo_.sourceBundleName_ = missionInfo.want.GetBundle(); 162686862fbSopenharmony_ci continueInfo_.sinkBundleName_ = missionInfo.want.GetBundle(); 163686862fbSopenharmony_ci } 164686862fbSopenharmony_ci} 165686862fbSopenharmony_ci 166686862fbSopenharmony_ciDSchedContinue::~DSchedContinue() 167686862fbSopenharmony_ci{ 168686862fbSopenharmony_ci HILOGI("DSchedContinue delete enter"); 169686862fbSopenharmony_ci if ((eventHandler_ != nullptr) && (eventHandler_->GetEventRunner() != nullptr)) { 170686862fbSopenharmony_ci eventHandler_->GetEventRunner()->Stop(); 171686862fbSopenharmony_ci } 172686862fbSopenharmony_ci eventThread_.join(); 173686862fbSopenharmony_ci eventHandler_ = nullptr; 174686862fbSopenharmony_ci HILOGI("DSchedContinue delete end"); 175686862fbSopenharmony_ci} 176686862fbSopenharmony_ci 177686862fbSopenharmony_civoid DSchedContinue::SetEventData() 178686862fbSopenharmony_ci{ 179686862fbSopenharmony_ci HILOGI("called"); 180686862fbSopenharmony_ci ContinueEventInfo srcContinueInfo; 181686862fbSopenharmony_ci DmsBmStorage::GetInstance()->GetContinueEventInfo(continueInfo_.sourceDeviceId_, continueInfo_.sourceBundleName_, 182686862fbSopenharmony_ci continueInfo_.continueType_, srcContinueInfo); 183686862fbSopenharmony_ci ContinueEventInfo dstContinueInfo; 184686862fbSopenharmony_ci DmsBmStorage::GetInstance()->GetContinueEventInfo(continueInfo_.sinkDeviceId_, continueInfo_.sinkBundleName_, 185686862fbSopenharmony_ci continueInfo_.continueType_, dstContinueInfo); 186686862fbSopenharmony_ci eventData_.eventResult_ = 0; 187686862fbSopenharmony_ci eventData_.srcNetworkId_ = srcContinueInfo.networkId; 188686862fbSopenharmony_ci eventData_.srcBundleName_ = srcContinueInfo.bundleName; 189686862fbSopenharmony_ci eventData_.srcModuleName_ = srcContinueInfo.moduleName; 190686862fbSopenharmony_ci eventData_.srcAbilityName_ = srcContinueInfo.abilityName; 191686862fbSopenharmony_ci eventData_.dstNetworkId_ = dstContinueInfo.networkId; 192686862fbSopenharmony_ci eventData_.destBundleName_ = dstContinueInfo.bundleName; 193686862fbSopenharmony_ci eventData_.destModuleName_ = dstContinueInfo.moduleName; 194686862fbSopenharmony_ci eventData_.destAbilityName_ = dstContinueInfo.abilityName; 195686862fbSopenharmony_ci eventData_.developerId_ = srcContinueInfo.developerId; 196686862fbSopenharmony_ci eventData_.dSchedEventType_ = DMS_CONTINUE; 197686862fbSopenharmony_ci eventData_.state_ = DMS_DSCHED_EVENT_START; 198686862fbSopenharmony_ci} 199686862fbSopenharmony_ci 200686862fbSopenharmony_ciint32_t DSchedContinue::Init() 201686862fbSopenharmony_ci{ 202686862fbSopenharmony_ci HILOGI("DSchedContinue init start"); 203686862fbSopenharmony_ci if (eventHandler_ != nullptr) { 204686862fbSopenharmony_ci HILOGI("Already inited, end."); 205686862fbSopenharmony_ci return ERR_OK; 206686862fbSopenharmony_ci } 207686862fbSopenharmony_ci auto dContinue = std::shared_ptr<DSchedContinue>(shared_from_this()); 208686862fbSopenharmony_ci stateMachine_ = std::make_shared<DSchedContinueStateMachine>(dContinue); 209686862fbSopenharmony_ci if (direction_ == CONTINUE_SOURCE) { 210686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SOURCE_START_STATE); 211686862fbSopenharmony_ci } else { 212686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SINK_START_STATE); 213686862fbSopenharmony_ci } 214686862fbSopenharmony_ci 215686862fbSopenharmony_ci eventThread_ = std::thread(&DSchedContinue::StartEventHandler, this); 216686862fbSopenharmony_ci std::unique_lock<std::mutex> lock(eventMutex_); 217686862fbSopenharmony_ci eventCon_.wait(lock, [this] { 218686862fbSopenharmony_ci return eventHandler_ != nullptr; 219686862fbSopenharmony_ci }); 220686862fbSopenharmony_ci HILOGI("DSchedContinue init end"); 221686862fbSopenharmony_ci return ERR_OK; 222686862fbSopenharmony_ci} 223686862fbSopenharmony_ci 224686862fbSopenharmony_civoid DSchedContinue::StartEventHandler() 225686862fbSopenharmony_ci{ 226686862fbSopenharmony_ci HILOGI("called"); 227686862fbSopenharmony_ci std::string eventThreadName = "DSchedContinue_EventHandler"; 228686862fbSopenharmony_ci prctl(PR_SET_NAME, eventThreadName.c_str()); 229686862fbSopenharmony_ci auto runner = AppExecFwk::EventRunner::Create(false); 230686862fbSopenharmony_ci if (runner == nullptr) { 231686862fbSopenharmony_ci HILOGE("continue start eventHandler failed."); 232686862fbSopenharmony_ci return; 233686862fbSopenharmony_ci } 234686862fbSopenharmony_ci { 235686862fbSopenharmony_ci std::lock_guard<std::mutex> lock(eventMutex_); 236686862fbSopenharmony_ci eventHandler_ = std::make_shared<DSchedContinueEventHandler>(runner, shared_from_this()); 237686862fbSopenharmony_ci } 238686862fbSopenharmony_ci eventCon_.notify_one(); 239686862fbSopenharmony_ci runner->Run(); 240686862fbSopenharmony_ci} 241686862fbSopenharmony_ci 242686862fbSopenharmony_ciint32_t DSchedContinue::OnContinueMission(const OHOS::AAFwk::WantParams& wantParams) 243686862fbSopenharmony_ci{ 244686862fbSopenharmony_ci HILOGI("called"); 245686862fbSopenharmony_ci return PostStartTask(wantParams); 246686862fbSopenharmony_ci} 247686862fbSopenharmony_ci 248686862fbSopenharmony_ciint32_t DSchedContinue::PostStartTask(const OHOS::AAFwk::WantParams& wantParams) 249686862fbSopenharmony_ci{ 250686862fbSopenharmony_ci DSchedContinueEventType eventType = (subServiceType_ == CONTINUE_PULL) ? 251686862fbSopenharmony_ci DSCHED_CONTINUE_REQ_PULL_EVENT : DSHCED_CONTINUE_REQ_PUSH_EVENT; 252686862fbSopenharmony_ci HILOGI("PostStartTask %{public}d, continueInfo: %{public}s", eventType, continueInfo_.toString().c_str()); 253686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 254686862fbSopenharmony_ci HILOGE("PostStartTask eventHandler is nullptr"); 255686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 256686862fbSopenharmony_ci } 257686862fbSopenharmony_ci 258686862fbSopenharmony_ci auto wantParamsPtr = std::make_shared<OHOS::AAFwk::WantParams>(wantParams); 259686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, wantParamsPtr, 0); 260686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 261686862fbSopenharmony_ci HILOGE("PostStartTask eventHandler send event type %{public}d fail", eventType); 262686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 263686862fbSopenharmony_ci } 264686862fbSopenharmony_ci return ERR_OK; 265686862fbSopenharmony_ci} 266686862fbSopenharmony_ci 267686862fbSopenharmony_ciint32_t DSchedContinue::OnStartCmd(int32_t appVersion) 268686862fbSopenharmony_ci{ 269686862fbSopenharmony_ci HILOGI("called"); 270686862fbSopenharmony_ci return PostCotinueAbilityTask(appVersion); 271686862fbSopenharmony_ci} 272686862fbSopenharmony_ci 273686862fbSopenharmony_ciint32_t DSchedContinue::PostCotinueAbilityTask(int32_t appVersion) 274686862fbSopenharmony_ci{ 275686862fbSopenharmony_ci DSchedContinueEventType eventType = DSHCED_CONTINUE_ABILITY_EVENT; 276686862fbSopenharmony_ci HILOGI("PostCotinueAbilityTask %{public}d, continueInfo %{public}s", eventType, 277686862fbSopenharmony_ci continueInfo_.toString().c_str()); 278686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 279686862fbSopenharmony_ci HILOGE("PostCotinueAbilityTask eventHandler is nullptr"); 280686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 281686862fbSopenharmony_ci } 282686862fbSopenharmony_ci auto data = std::make_shared<int32_t>(appVersion); 283686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, data, 0); 284686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 285686862fbSopenharmony_ci HILOGE("PostCotinueAbilityTask eventHandler send event type %{public}d fail", eventType); 286686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 287686862fbSopenharmony_ci } 288686862fbSopenharmony_ci return ERR_OK; 289686862fbSopenharmony_ci} 290686862fbSopenharmony_ci 291686862fbSopenharmony_ciint32_t DSchedContinue::OnReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd) 292686862fbSopenharmony_ci{ 293686862fbSopenharmony_ci HILOGI("called"); 294686862fbSopenharmony_ci return PostReplyTask(cmd); 295686862fbSopenharmony_ci} 296686862fbSopenharmony_ci 297686862fbSopenharmony_ciint32_t DSchedContinue::PostReplyTask(std::shared_ptr<DSchedContinueReplyCmd> cmd) 298686862fbSopenharmony_ci{ 299686862fbSopenharmony_ci if (cmd == nullptr) { 300686862fbSopenharmony_ci HILOGE("cmd is null"); 301686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 302686862fbSopenharmony_ci } 303686862fbSopenharmony_ci HILOGI("PostReplyTask called, replyCmd: %{public}d, result: %{public}d, reason: %{public}s", cmd->replyCmd_, 304686862fbSopenharmony_ci cmd->result_, cmd->reason_.c_str()); 305686862fbSopenharmony_ci 306686862fbSopenharmony_ci DSchedContinueEventType eventType = DSCHED_CONTINUE_INVALID_EVENT; 307686862fbSopenharmony_ci switch (cmd->replyCmd_) { 308686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_START: { 309686862fbSopenharmony_ci eventType = DSHCED_CONTINUE_ABILITY_EVENT; 310686862fbSopenharmony_ci break; 311686862fbSopenharmony_ci } 312686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_END: { 313686862fbSopenharmony_ci eventType = DSCHED_CONTINUE_END_EVENT; 314686862fbSopenharmony_ci break; 315686862fbSopenharmony_ci } 316686862fbSopenharmony_ci default: 317686862fbSopenharmony_ci HILOGW("PostReplyTask %{public}d, receive irrelevant reply to cmd %{public}d", eventType, 318686862fbSopenharmony_ci cmd->replyCmd_); 319686862fbSopenharmony_ci return ERR_OK; 320686862fbSopenharmony_ci } 321686862fbSopenharmony_ci 322686862fbSopenharmony_ci HILOGI("PostReplyTask %{public}d, continueInfo %{public}s", eventType, continueInfo_.toString().c_str()); 323686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 324686862fbSopenharmony_ci HILOGE("PostReplyTask eventHandler is nullptr"); 325686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 326686862fbSopenharmony_ci } 327686862fbSopenharmony_ci 328686862fbSopenharmony_ci auto result = std::make_shared<int32_t>(cmd->result_); 329686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, result, 0); 330686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 331686862fbSopenharmony_ci HILOGE("PostReplyTask eventHandler send event type %{public}d fail", eventType); 332686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 333686862fbSopenharmony_ci } 334686862fbSopenharmony_ci return ERR_OK; 335686862fbSopenharmony_ci} 336686862fbSopenharmony_ci 337686862fbSopenharmony_ciint32_t DSchedContinue::OnStartContinuation(const OHOS::AAFwk::Want& want, int32_t callerUid, 338686862fbSopenharmony_ci int32_t status, uint32_t accessToken) 339686862fbSopenharmony_ci{ 340686862fbSopenharmony_ci HILOGI("called"); 341686862fbSopenharmony_ci return PostContinueSendTask(want, callerUid, status, accessToken); 342686862fbSopenharmony_ci} 343686862fbSopenharmony_ci 344686862fbSopenharmony_ciint32_t DSchedContinue::PostContinueSendTask(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t status, 345686862fbSopenharmony_ci uint32_t accessToken) 346686862fbSopenharmony_ci{ 347686862fbSopenharmony_ci HILOGI("PostContinueSendTask called"); 348686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 349686862fbSopenharmony_ci HILOGE("eventHandler_ is nullptr"); 350686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 351686862fbSopenharmony_ci } 352686862fbSopenharmony_ci DSchedContinueEventType eventType = DSHCED_CONTINUE_SEND_DATA_EVENT; 353686862fbSopenharmony_ci if (status != ERR_OK) { 354686862fbSopenharmony_ci HILOGE("continuation has been rejected, status: %{public}d", status); 355686862fbSopenharmony_ci eventType = DSCHED_CONTINUE_END_EVENT; 356686862fbSopenharmony_ci auto result = std::make_shared<int32_t>(status); 357686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, result, 0); 358686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 359686862fbSopenharmony_ci HILOGE("PostContinueSendTask eventHandler send event type %{public}d fail", eventType); 360686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 361686862fbSopenharmony_ci } 362686862fbSopenharmony_ci return ERR_OK; 363686862fbSopenharmony_ci } 364686862fbSopenharmony_ci 365686862fbSopenharmony_ci HILOGI("PostContinueSendTask %{public}d, continueInfo %{public}s", eventType, continueInfo_.toString().c_str()); 366686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 367686862fbSopenharmony_ci HILOGE("PostContinueSendTask eventHandler is nullptr"); 368686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 369686862fbSopenharmony_ci } 370686862fbSopenharmony_ci auto data = std::make_shared<ContinueAbilityData>(); 371686862fbSopenharmony_ci data->want = want; 372686862fbSopenharmony_ci data->callerUid = callerUid; 373686862fbSopenharmony_ci data->accessToken = accessToken; 374686862fbSopenharmony_ci 375686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, data, 0); 376686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 377686862fbSopenharmony_ci HILOGE("PostContinueSendTask eventHandler send event type %{public}d fail", eventType); 378686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 379686862fbSopenharmony_ci } 380686862fbSopenharmony_ci return ERR_OK; 381686862fbSopenharmony_ci} 382686862fbSopenharmony_ci 383686862fbSopenharmony_ciint32_t DSchedContinue::OnContinueDataCmd(std::shared_ptr<DSchedContinueDataCmd> cmd) 384686862fbSopenharmony_ci{ 385686862fbSopenharmony_ci HILOGI("called"); 386686862fbSopenharmony_ci return PostContinueDataTask(cmd); 387686862fbSopenharmony_ci} 388686862fbSopenharmony_ci 389686862fbSopenharmony_ciint32_t DSchedContinue::PostContinueDataTask(std::shared_ptr<DSchedContinueDataCmd> cmd) 390686862fbSopenharmony_ci{ 391686862fbSopenharmony_ci DSchedContinueEventType eventType = DSCHED_CONTINUE_DATA_EVENT; 392686862fbSopenharmony_ci HILOGI("PostContinueDataTask %{public}d, continueInfo %{public}s", eventType, continueInfo_.toString().c_str()); 393686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 394686862fbSopenharmony_ci HILOGE("PostContinueDataTask eventHandler is nullptr"); 395686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 396686862fbSopenharmony_ci } 397686862fbSopenharmony_ci 398686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, cmd, 0); 399686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 400686862fbSopenharmony_ci HILOGE("PostContinueDataTask eventHandler send event type %{public}d fail", eventType); 401686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 402686862fbSopenharmony_ci } 403686862fbSopenharmony_ci return ERR_OK; 404686862fbSopenharmony_ci} 405686862fbSopenharmony_ci 406686862fbSopenharmony_ciint32_t DSchedContinue::OnNotifyComplete(int32_t missionId, bool isSuccess) 407686862fbSopenharmony_ci{ 408686862fbSopenharmony_ci HILOGI("called"); 409686862fbSopenharmony_ci if (!isSuccess) { 410686862fbSopenharmony_ci HILOGE("start ability not success"); 411686862fbSopenharmony_ci PostNotifyCompleteTask(CONTINUE_CALL_START_ABILITY_FAILED); 412686862fbSopenharmony_ci return ERR_OK; 413686862fbSopenharmony_ci } 414686862fbSopenharmony_ci if (missionId <= 0) { 415686862fbSopenharmony_ci HILOGE("start ability returns invalid missionId"); 416686862fbSopenharmony_ci PostNotifyCompleteTask(INVALID_PARAMETERS_ERR); 417686862fbSopenharmony_ci return ERR_OK; 418686862fbSopenharmony_ci } 419686862fbSopenharmony_ci PostNotifyCompleteTask(ERR_OK); 420686862fbSopenharmony_ci return ERR_OK; 421686862fbSopenharmony_ci} 422686862fbSopenharmony_ci 423686862fbSopenharmony_ciint32_t DSchedContinue::OnContinueEndCmd(std::shared_ptr<DSchedContinueEndCmd> cmd) 424686862fbSopenharmony_ci{ 425686862fbSopenharmony_ci HILOGI("called"); 426686862fbSopenharmony_ci if (cmd == nullptr) { 427686862fbSopenharmony_ci HILOGE("cmd is null"); 428686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 429686862fbSopenharmony_ci } 430686862fbSopenharmony_ci return PostNotifyCompleteTask(cmd->result_); 431686862fbSopenharmony_ci} 432686862fbSopenharmony_ci 433686862fbSopenharmony_ciint32_t DSchedContinue::PostNotifyCompleteTask(int32_t result) 434686862fbSopenharmony_ci{ 435686862fbSopenharmony_ci DSchedContinueEventType eventType = DSCHED_CONTINUE_COMPLETE_EVENT; 436686862fbSopenharmony_ci HILOGI("PostNotifyCompleteTask %{public}d, continueInfo %{public}s", eventType, 437686862fbSopenharmony_ci continueInfo_.toString().c_str()); 438686862fbSopenharmony_ci 439686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 440686862fbSopenharmony_ci HILOGE("PostNotifyCompleteTask eventHandler is nullptr"); 441686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 442686862fbSopenharmony_ci } 443686862fbSopenharmony_ci 444686862fbSopenharmony_ci auto data = std::make_shared<int32_t>(result); 445686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, data, 0); 446686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 447686862fbSopenharmony_ci HILOGE("PostNotifyCompleteTask eventHandler send event type %{public}d fail", eventType); 448686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 449686862fbSopenharmony_ci } 450686862fbSopenharmony_ci return ERR_OK; 451686862fbSopenharmony_ci} 452686862fbSopenharmony_ci 453686862fbSopenharmony_ciint32_t DSchedContinue::OnContinueEnd(int32_t result) 454686862fbSopenharmony_ci{ 455686862fbSopenharmony_ci HILOGI("called"); 456686862fbSopenharmony_ci return PostContinueEndTask(result); 457686862fbSopenharmony_ci} 458686862fbSopenharmony_ci 459686862fbSopenharmony_ciint32_t DSchedContinue::PostContinueEndTask(int32_t result) 460686862fbSopenharmony_ci{ 461686862fbSopenharmony_ci DSchedContinueEventType eventType = DSCHED_CONTINUE_END_EVENT; 462686862fbSopenharmony_ci HILOGI("PostContinueEndTask %{public}d, continueInfo %{public}s", eventType, continueInfo_.toString().c_str()); 463686862fbSopenharmony_ci if (eventHandler_ == nullptr) { 464686862fbSopenharmony_ci HILOGE("PostContinueEndTask eventHandler is nullptr"); 465686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 466686862fbSopenharmony_ci } 467686862fbSopenharmony_ci 468686862fbSopenharmony_ci auto data = std::make_shared<int32_t>(result); 469686862fbSopenharmony_ci auto msgEvent = AppExecFwk::InnerEvent::Get(eventType, data, 0); 470686862fbSopenharmony_ci if (!eventHandler_->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE)) { 471686862fbSopenharmony_ci HILOGE("PostContinueEndTask eventHandler send event type %{public}d fail", eventType); 472686862fbSopenharmony_ci return CONTINUE_SEND_EVENT_FAILED; 473686862fbSopenharmony_ci } 474686862fbSopenharmony_ci return ERR_OK; 475686862fbSopenharmony_ci} 476686862fbSopenharmony_ci 477686862fbSopenharmony_civoid DSchedContinue::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) 478686862fbSopenharmony_ci{ 479686862fbSopenharmony_ci if (event == nullptr || stateMachine_ == nullptr) { 480686862fbSopenharmony_ci HILOGE("event or state machine is null"); 481686862fbSopenharmony_ci return; 482686862fbSopenharmony_ci } 483686862fbSopenharmony_ci auto eventId = event->GetInnerEventId(); 484686862fbSopenharmony_ci HILOGI("process event %{public}d with state %{public}d", eventId, stateMachine_->GetStateType()); 485686862fbSopenharmony_ci int32_t ret = stateMachine_->Execute(event); 486686862fbSopenharmony_ci if (ret != ERR_OK) { 487686862fbSopenharmony_ci HILOGE("event %{public}d execute failed, ret %{public}d", eventId, ret); 488686862fbSopenharmony_ci OnContinueEnd(ret); 489686862fbSopenharmony_ci } 490686862fbSopenharmony_ci return; 491686862fbSopenharmony_ci} 492686862fbSopenharmony_ci 493686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueReq(std::shared_ptr<DistributedWantParams> wantParams) 494686862fbSopenharmony_ci{ 495686862fbSopenharmony_ci HILOGI("ExecuteContinueReq start, continueInfo: %{public}s", continueInfo_.toString().c_str()); 496686862fbSopenharmony_ci DurationDumperStart(); 497686862fbSopenharmony_ci 498686862fbSopenharmony_ci std::string peerDeviceId = (direction_ == CONTINUE_SOURCE) ? 499686862fbSopenharmony_ci continueInfo_.sinkDeviceId_ : continueInfo_.sourceDeviceId_; 500686862fbSopenharmony_ci 501686862fbSopenharmony_ci DmsRadar::GetInstance().ClickIconDmsContinue("ContinueMission", ERR_OK, peerDeviceId, 502686862fbSopenharmony_ci continueInfo_.sourceBundleName_, continueInfo_.sinkBundleName_); 503686862fbSopenharmony_ci 504686862fbSopenharmony_ci DmsUE::GetInstance().TriggerDmsContinue(continueInfo_.sinkBundleName_, continueInfo_.sinkAbilityName_, 505686862fbSopenharmony_ci continueInfo_.sourceDeviceId_, ERR_OK); 506686862fbSopenharmony_ci 507686862fbSopenharmony_ci if (subServiceType_ == CONTINUE_PULL && CheckQuickStartConfiguration()) { 508686862fbSopenharmony_ci QuickStartAbility(); 509686862fbSopenharmony_ci } 510686862fbSopenharmony_ci 511686862fbSopenharmony_ci int32_t ret = DSchedTransportSoftbusAdapter::GetInstance().ConnectDevice(peerDeviceId, softbusSessionId_); 512686862fbSopenharmony_ci if (ret != ERR_OK) { 513686862fbSopenharmony_ci HILOGE("ExecuteContinueReq connect peer device %{public}s failed, ret %{public}d", 514686862fbSopenharmony_ci GetAnonymStr(peerDeviceId).c_str(), ret); 515686862fbSopenharmony_ci return ret; 516686862fbSopenharmony_ci } 517686862fbSopenharmony_ci HILOGI("ExecuteContinueReq peer %{public}s connected, sessionId %{public}d", 518686862fbSopenharmony_ci GetAnonymStr(peerDeviceId).c_str(), softbusSessionId_); 519686862fbSopenharmony_ci 520686862fbSopenharmony_ci auto startCmd = std::make_shared<DSchedContinueStartCmd>(); 521686862fbSopenharmony_ci ret = PackStartCmd(startCmd, wantParams); 522686862fbSopenharmony_ci if (ret != ERR_OK) { 523686862fbSopenharmony_ci HILOGE("ExecuteContinueReq pack start cmd failed, ret %{public}d", ret); 524686862fbSopenharmony_ci return ret; 525686862fbSopenharmony_ci } 526686862fbSopenharmony_ci ret = SendCommand(startCmd); 527686862fbSopenharmony_ci if (ret != ERR_OK) { 528686862fbSopenharmony_ci HILOGE("ExecuteContinueReq send start cmd failed, ret %{public}d", ret); 529686862fbSopenharmony_ci return ret; 530686862fbSopenharmony_ci } 531686862fbSopenharmony_ci if (direction_ == CONTINUE_SINK) { 532686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_DATA_STATE); 533686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationEnd(CONTINUE_FIRST_TRANS_TIME, GetTickCount()); 534686862fbSopenharmony_ci } 535686862fbSopenharmony_ci HILOGI("ExecuteContinueReq end"); 536686862fbSopenharmony_ci return ERR_OK; 537686862fbSopenharmony_ci} 538686862fbSopenharmony_ci 539686862fbSopenharmony_cibool DSchedContinue::CheckQuickStartConfiguration() 540686862fbSopenharmony_ci{ 541686862fbSopenharmony_ci std::string continueType = continueInfo_.continueType_; 542686862fbSopenharmony_ci std::string suffix = QUICK_START_CONFIGURATION; 543686862fbSopenharmony_ci 544686862fbSopenharmony_ci if (suffix.length() > continueType.length()) { 545686862fbSopenharmony_ci return false; 546686862fbSopenharmony_ci } 547686862fbSopenharmony_ci return (continueType.rfind(suffix) == (continueType.length() - suffix.length())); 548686862fbSopenharmony_ci} 549686862fbSopenharmony_ci 550686862fbSopenharmony_ciint32_t DSchedContinue::QuickStartAbility() 551686862fbSopenharmony_ci{ 552686862fbSopenharmony_ci HILOGI("called"); 553686862fbSopenharmony_ci if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { 554686862fbSopenharmony_ci HILOGE("sceneBoard not available."); 555686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 556686862fbSopenharmony_ci } 557686862fbSopenharmony_ci 558686862fbSopenharmony_ci std::string abilityName = QuerySinkAbilityName(); 559686862fbSopenharmony_ci if (abilityName.empty()) { 560686862fbSopenharmony_ci HILOGE("QuickStartAbility failed."); 561686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 562686862fbSopenharmony_ci } 563686862fbSopenharmony_ci ContinueSceneSessionHandler::GetInstance().UpdateContinueSessionId(continueInfo_.sinkBundleName_, abilityName); 564686862fbSopenharmony_ci std::string continueSessionId = ContinueSceneSessionHandler::GetInstance().GetContinueSessionId(); 565686862fbSopenharmony_ci HILOGI("continueSessionId is %{public}s", continueSessionId.c_str()); 566686862fbSopenharmony_ci 567686862fbSopenharmony_ci AAFwk::Want want; 568686862fbSopenharmony_ci want.SetElementName(continueInfo_.sinkBundleName_, abilityName); 569686862fbSopenharmony_ci want.SetParam(DMS_CONTINUE_SESSION_ID, continueSessionId); 570686862fbSopenharmony_ci want.SetFlags(AAFwk::Want::FLAG_ABILITY_PREPARE_CONTINUATION); 571686862fbSopenharmony_ci 572686862fbSopenharmony_ci return StartAbility(want, DEFAULT_REQUEST_CODE); 573686862fbSopenharmony_ci} 574686862fbSopenharmony_ci 575686862fbSopenharmony_cistd::string DSchedContinue::QuerySinkAbilityName() 576686862fbSopenharmony_ci{ 577686862fbSopenharmony_ci std::string abilityName = GetAbilityNameByContinueType(); 578686862fbSopenharmony_ci if (!abilityName.empty()) { 579686862fbSopenharmony_ci return abilityName; 580686862fbSopenharmony_ci } 581686862fbSopenharmony_ci 582686862fbSopenharmony_ci AppExecFwk::BundleInfo localBundleInfo; 583686862fbSopenharmony_ci if (BundleManagerInternal::GetLocalBundleInfo(continueInfo_.sinkBundleName_, localBundleInfo) != ERR_OK) { 584686862fbSopenharmony_ci HILOGE("get local bundle info failed."); 585686862fbSopenharmony_ci return abilityName; 586686862fbSopenharmony_ci } 587686862fbSopenharmony_ci if (localBundleInfo.abilityInfos.empty() || localBundleInfo.abilityInfos.size() > 1) { 588686862fbSopenharmony_ci HILOGE("quick start is not supported, abilityInfos size: %{public}d", 589686862fbSopenharmony_ci static_cast<int32_t>(localBundleInfo.abilityInfos.size())); 590686862fbSopenharmony_ci return abilityName; 591686862fbSopenharmony_ci } 592686862fbSopenharmony_ci 593686862fbSopenharmony_ci return localBundleInfo.abilityInfos.front().name; 594686862fbSopenharmony_ci} 595686862fbSopenharmony_ci 596686862fbSopenharmony_cistd::string DSchedContinue::GetAbilityNameByContinueType() 597686862fbSopenharmony_ci{ 598686862fbSopenharmony_ci std::string continueType = continueInfo_.continueType_; 599686862fbSopenharmony_ci if (CheckQuickStartConfiguration()) { 600686862fbSopenharmony_ci continueType = continueType.substr(0, continueType.rfind(QUICK_START_CONFIGURATION)); 601686862fbSopenharmony_ci } 602686862fbSopenharmony_ci std::string abilityName = BundleManagerInternal::GetAbilityName(continueInfo_.sinkDeviceId_, 603686862fbSopenharmony_ci continueInfo_.sinkBundleName_, continueType); 604686862fbSopenharmony_ci if (!abilityName.empty()) { 605686862fbSopenharmony_ci return abilityName; 606686862fbSopenharmony_ci } 607686862fbSopenharmony_ci 608686862fbSopenharmony_ci continueType += QUICK_START_CONFIGURATION; 609686862fbSopenharmony_ci abilityName = BundleManagerInternal::GetAbilityName(continueInfo_.sinkDeviceId_, 610686862fbSopenharmony_ci continueInfo_.sinkBundleName_, continueType); 611686862fbSopenharmony_ci return abilityName; 612686862fbSopenharmony_ci} 613686862fbSopenharmony_ci 614686862fbSopenharmony_civoid DSchedContinue::DurationDumperStart() 615686862fbSopenharmony_ci{ 616686862fbSopenharmony_ci DmsContinueTime::GetInstance().Init(); 617686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetNetWorkId(continueInfo_.sourceDeviceId_, continueInfo_.sinkDeviceId_); 618686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetPull(subServiceType_ == CONTINUE_PULL); 619686862fbSopenharmony_ci 620686862fbSopenharmony_ci std::string strBeginTime = DmsContinueTime::GetInstance().GetCurrentTime(); 621686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationStrTime(CONTINUE_BEGIN_TIME, strBeginTime); 622686862fbSopenharmony_ci int64_t tick = GetTickCount(); 623686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_TOTAL_TIME, tick); 624686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_FIRST_TRANS_TIME, tick); 625686862fbSopenharmony_ci} 626686862fbSopenharmony_ci 627686862fbSopenharmony_ciint32_t DSchedContinue::PackStartCmd(std::shared_ptr<DSchedContinueStartCmd>& cmd, 628686862fbSopenharmony_ci std::shared_ptr<DistributedWantParams> wantParams) 629686862fbSopenharmony_ci{ 630686862fbSopenharmony_ci if (cmd == nullptr || wantParams == nullptr) { 631686862fbSopenharmony_ci HILOGE("cmd or wantParams is null"); 632686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 633686862fbSopenharmony_ci } 634686862fbSopenharmony_ci cmd->version_ = version_; 635686862fbSopenharmony_ci cmd->serviceType_ = SERVICE_TYPE_CONTINUE; 636686862fbSopenharmony_ci cmd->subServiceType_ = subServiceType_; 637686862fbSopenharmony_ci cmd->command_ = DSCHED_CONTINUE_CMD_START; 638686862fbSopenharmony_ci cmd->srcDeviceId_ = continueInfo_.sourceDeviceId_; 639686862fbSopenharmony_ci cmd->srcBundleName_ = continueInfo_.sourceBundleName_; 640686862fbSopenharmony_ci cmd->dstDeviceId_ = continueInfo_.sinkDeviceId_; 641686862fbSopenharmony_ci cmd->dstBundleName_ = continueInfo_.sinkBundleName_; 642686862fbSopenharmony_ci cmd->continueType_ = continueInfo_.continueType_; 643686862fbSopenharmony_ci cmd->sourceMissionId_ = continueInfo_.missionId_; 644686862fbSopenharmony_ci cmd->continueByType_ = continueByType_; 645686862fbSopenharmony_ci cmd->dmsVersion_ = DMS_VERSION; 646686862fbSopenharmony_ci 647686862fbSopenharmony_ci cmd->direction_ = direction_; 648686862fbSopenharmony_ci if (subServiceType_ == CONTINUE_PULL && continueInfo_.missionId_ == 0) { 649686862fbSopenharmony_ci AppExecFwk::BundleInfo localBundleInfo; 650686862fbSopenharmony_ci int32_t ret = BundleManagerInternal::GetLocalBundleInfoV9(continueInfo_.sinkBundleName_, localBundleInfo); 651686862fbSopenharmony_ci if (ret != ERR_OK) { 652686862fbSopenharmony_ci HILOGE("pack start cmd failed, the bundle is not installed on local device."); 653686862fbSopenharmony_ci return ret; 654686862fbSopenharmony_ci } 655686862fbSopenharmony_ci cmd->appVersion_ = static_cast<int32_t>(localBundleInfo.versionCode); 656686862fbSopenharmony_ci } 657686862fbSopenharmony_ci cmd->wantParams_ = *wantParams; 658686862fbSopenharmony_ci return ERR_OK; 659686862fbSopenharmony_ci} 660686862fbSopenharmony_ci 661686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueAbility(int32_t appVersion) 662686862fbSopenharmony_ci{ 663686862fbSopenharmony_ci HILOGI("ExecuteContinueAbility start, appVersion: %{public}d", appVersion); 664686862fbSopenharmony_ci DmsRadar::GetInstance().SaveDataDmsContinue("ContinueAbility", ERR_OK); 665686862fbSopenharmony_ci 666686862fbSopenharmony_ci int32_t result = GetMissionIdByBundleName(); 667686862fbSopenharmony_ci if (result != ERR_OK) { 668686862fbSopenharmony_ci HILOGE("ExecuteContinueAbility GetMissionIdByBundleName failed"); 669686862fbSopenharmony_ci return result; 670686862fbSopenharmony_ci } 671686862fbSopenharmony_ci 672686862fbSopenharmony_ci result = CheckContinueAbilityPermission(); 673686862fbSopenharmony_ci if (result != ERR_OK) { 674686862fbSopenharmony_ci HILOGE("ExecuteContinueAbility CheckContinueAbilityPermission failed"); 675686862fbSopenharmony_ci return result; 676686862fbSopenharmony_ci } 677686862fbSopenharmony_ci 678686862fbSopenharmony_ci auto tick = GetTickCount(); 679686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationEnd(CONTINUE_FIRST_TRANS_TIME, tick); 680686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSaveDataDurationBegin(tick); 681686862fbSopenharmony_ci 682686862fbSopenharmony_ci HILOGI("ExecuteContinueAbility call continueAbility begin, continueInfo: %{public}s", 683686862fbSopenharmony_ci continueInfo_.toString().c_str()); 684686862fbSopenharmony_ci result = AbilityManagerClient::GetInstance()->ContinueAbility(continueInfo_.sinkDeviceId_, 685686862fbSopenharmony_ci continueInfo_.missionId_, appVersion); 686686862fbSopenharmony_ci HILOGI("ExecuteContinueAbility call continueAbility end, result: %{public}d.", result); 687686862fbSopenharmony_ci 688686862fbSopenharmony_ci if (result != ERR_OK) { 689686862fbSopenharmony_ci return CONTINUE_CALL_CONTINUE_ABILITY_FAILED; 690686862fbSopenharmony_ci } 691686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_ABILITY_STATE); 692686862fbSopenharmony_ci HILOGI("ExecuteContinueAbility end"); 693686862fbSopenharmony_ci return result; 694686862fbSopenharmony_ci} 695686862fbSopenharmony_ci 696686862fbSopenharmony_ciint32_t DSchedContinue::GetMissionIdByBundleName() 697686862fbSopenharmony_ci{ 698686862fbSopenharmony_ci#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER 699686862fbSopenharmony_ci if (continueInfo_.missionId_ == 0) { 700686862fbSopenharmony_ci return DMSContinueSendMgr::GetInstance().GetMissionIdByBundleName(continueInfo_.sourceBundleName_, 701686862fbSopenharmony_ci continueInfo_.missionId_); 702686862fbSopenharmony_ci } 703686862fbSopenharmony_ci#endif 704686862fbSopenharmony_ci return ERR_OK; 705686862fbSopenharmony_ci} 706686862fbSopenharmony_ci 707686862fbSopenharmony_ciint32_t DSchedContinue::CheckContinueAbilityPermission() 708686862fbSopenharmony_ci{ 709686862fbSopenharmony_ci if (!DmsKvSyncE2E::GetInstance()->CheckBundleContinueConfig(continueInfo_.sourceBundleName_)) { 710686862fbSopenharmony_ci HILOGI("App does not allow continue in config file, bundle name %{public}s", 711686862fbSopenharmony_ci continueInfo_.sourceBundleName_.c_str()); 712686862fbSopenharmony_ci return REMOTE_DEVICE_BIND_ABILITY_ERR; 713686862fbSopenharmony_ci } 714686862fbSopenharmony_ci 715686862fbSopenharmony_ci MissionInfo missionInfo; 716686862fbSopenharmony_ci int32_t result = AbilityManagerClient::GetInstance()->GetMissionInfo("", continueInfo_.missionId_, missionInfo); 717686862fbSopenharmony_ci if (result != ERR_OK) { 718686862fbSopenharmony_ci HILOGE("get missionInfo failed"); 719686862fbSopenharmony_ci return NO_MISSION_INFO_FOR_MISSION_ID; 720686862fbSopenharmony_ci } 721686862fbSopenharmony_ci 722686862fbSopenharmony_ci if (missionInfo.continueState != AAFwk::ContinueState::CONTINUESTATE_ACTIVE) { 723686862fbSopenharmony_ci HILOGE("Mission continue state set to INACTIVE. Can't continue. Mission id: %{public}d", 724686862fbSopenharmony_ci continueInfo_.missionId_); 725686862fbSopenharmony_ci return MISSION_NOT_CONTINUE_ACTIVE; 726686862fbSopenharmony_ci } 727686862fbSopenharmony_ci return ERR_OK; 728686862fbSopenharmony_ci} 729686862fbSopenharmony_ci 730686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueReply() 731686862fbSopenharmony_ci{ 732686862fbSopenharmony_ci HILOGI("ExecuteContinueReply start, continueInfo: %{public}s", continueInfo_.toString().c_str()); 733686862fbSopenharmony_ci 734686862fbSopenharmony_ci AppExecFwk::BundleInfo bundleInfo; 735686862fbSopenharmony_ci if (BundleManagerInternal::GetLocalBundleInfoV9(continueInfo_.sourceBundleName_, bundleInfo) != ERR_OK) { 736686862fbSopenharmony_ci HILOGE("ExecuteContinueReply get local bundleInfo failed, the bundle is not installed on local device."); 737686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 738686862fbSopenharmony_ci } 739686862fbSopenharmony_ci auto cmd = std::make_shared<DSchedContinueReplyCmd>(); 740686862fbSopenharmony_ci int32_t ret = PackReplyCmd(cmd, DSCHED_CONTINUE_CMD_START, bundleInfo.versionCode, ERR_OK, "ExecuteContinueReply"); 741686862fbSopenharmony_ci if (ret != ERR_OK) { 742686862fbSopenharmony_ci HILOGE("ExecuteContinueReply pack reply cmd failed, ret %{public}d", ret); 743686862fbSopenharmony_ci return ret; 744686862fbSopenharmony_ci } 745686862fbSopenharmony_ci ret = SendCommand(cmd); 746686862fbSopenharmony_ci if (ret != ERR_OK) { 747686862fbSopenharmony_ci HILOGE("ExecuteContinueReply send reply cmd failed, ret %{public}d", ret); 748686862fbSopenharmony_ci return ret; 749686862fbSopenharmony_ci } 750686862fbSopenharmony_ci 751686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_DATA_STATE); 752686862fbSopenharmony_ci HILOGI("ExecuteContinueReply end"); 753686862fbSopenharmony_ci return ERR_OK; 754686862fbSopenharmony_ci} 755686862fbSopenharmony_ci 756686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueSend(std::shared_ptr<ContinueAbilityData> data) 757686862fbSopenharmony_ci{ 758686862fbSopenharmony_ci HILOGI("ExecuteContinueSend start, continueInfo: %{public}s", continueInfo_.toString().c_str()); 759686862fbSopenharmony_ci if (data == nullptr) { 760686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 761686862fbSopenharmony_ci } 762686862fbSopenharmony_ci DurationDumperBeforeStartRemoteAbility(); 763686862fbSopenharmony_ci 764686862fbSopenharmony_ci SetCleanMissionFlag(data->want); 765686862fbSopenharmony_ci 766686862fbSopenharmony_ci AAFwk::Want newWant = data->want; 767686862fbSopenharmony_ci if ((newWant.GetFlags() & AAFwk::Want::FLAG_ABILITY_CONTINUATION) == 0) { 768686862fbSopenharmony_ci HILOGE("StartContinuation want continuation flags invalid!"); 769686862fbSopenharmony_ci return INVALID_REMOTE_PARAMETERS_ERR; 770686862fbSopenharmony_ci } 771686862fbSopenharmony_ci 772686862fbSopenharmony_ci if (SetWantForContinuation(newWant) != ERR_OK) { 773686862fbSopenharmony_ci HILOGE("set new want failed"); 774686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 775686862fbSopenharmony_ci } 776686862fbSopenharmony_ci 777686862fbSopenharmony_ci AppExecFwk::AbilityInfo abilityInfo; 778686862fbSopenharmony_ci CallerInfo callerInfo; 779686862fbSopenharmony_ci callerInfo.sourceDeviceId = continueInfo_.sourceDeviceId_; 780686862fbSopenharmony_ci callerInfo.uid = data->callerUid; 781686862fbSopenharmony_ci callerInfo.accessToken = data->accessToken; 782686862fbSopenharmony_ci if (!BundleManagerInternal::GetCallerAppIdFromBms(callerInfo.uid, callerInfo.callerAppId)) { 783686862fbSopenharmony_ci HILOGE("GetCallerAppIdFromBms failed"); 784686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 785686862fbSopenharmony_ci } 786686862fbSopenharmony_ci if (!BundleManagerInternal::GetBundleNameListFromBms(callerInfo.uid, callerInfo.bundleNames)) { 787686862fbSopenharmony_ci HILOGE("GetBundleNameListFromBms failed"); 788686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 789686862fbSopenharmony_ci } 790686862fbSopenharmony_ci callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION; 791686862fbSopenharmony_ci AccountInfo accountInfo; 792686862fbSopenharmony_ci int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(continueInfo_.sinkDeviceId_, callerInfo, 793686862fbSopenharmony_ci accountInfo); 794686862fbSopenharmony_ci if (ret != ERR_OK) { 795686862fbSopenharmony_ci HILOGE("GetAccountInfo failed"); 796686862fbSopenharmony_ci return ret; 797686862fbSopenharmony_ci } 798686862fbSopenharmony_ci 799686862fbSopenharmony_ci auto cmd = std::make_shared<DSchedContinueDataCmd>(); 800686862fbSopenharmony_ci PackDataCmd(cmd, newWant, abilityInfo, callerInfo, accountInfo); 801686862fbSopenharmony_ci ret = SendCommand(cmd); 802686862fbSopenharmony_ci DmsRadar::GetInstance().SaveDataDmsRemoteWant("SendContinueData", ret); 803686862fbSopenharmony_ci if (ret != ERR_OK) { 804686862fbSopenharmony_ci HILOGE("ExecuteContinueSend send data cmd failed, ret %{public}d", ret); 805686862fbSopenharmony_ci return ret; 806686862fbSopenharmony_ci } 807686862fbSopenharmony_ci 808686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationEnd(CONTINUE_DATA_TRANS_TIME, GetTickCount()); 809686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SOURCE_WAIT_END_STATE); 810686862fbSopenharmony_ci HILOGI("ExecuteContinueSend end"); 811686862fbSopenharmony_ci return ERR_OK; 812686862fbSopenharmony_ci} 813686862fbSopenharmony_ci 814686862fbSopenharmony_civoid DSchedContinue::DurationDumperBeforeStartRemoteAbility() 815686862fbSopenharmony_ci{ 816686862fbSopenharmony_ci auto tick = GetTickCount(); 817686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSaveDataDurationEnd(tick); 818686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_DATA_TRANS_TIME, tick); 819686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_START_ABILITY_TIME, tick); 820686862fbSopenharmony_ci} 821686862fbSopenharmony_ci 822686862fbSopenharmony_civoid DSchedContinue::SetCleanMissionFlag(const OHOS::AAFwk::Want& want) 823686862fbSopenharmony_ci{ 824686862fbSopenharmony_ci auto value = want.GetParams().GetParam(SUPPORT_CONTINUE_SOURCE_EXIT_KEY); 825686862fbSopenharmony_ci IBoolean *ao = IBoolean::Query(value); 826686862fbSopenharmony_ci if (ao != nullptr) { 827686862fbSopenharmony_ci isSourceExit_ = AAFwk::Boolean::Unbox(ao); 828686862fbSopenharmony_ci } 829686862fbSopenharmony_ci} 830686862fbSopenharmony_ci 831686862fbSopenharmony_ciint32_t DSchedContinue::SetWantForContinuation(AAFwk::Want& newWant) 832686862fbSopenharmony_ci{ 833686862fbSopenharmony_ci newWant.SetParam("sessionId", continueInfo_.missionId_); 834686862fbSopenharmony_ci newWant.SetParam("deviceId", continueInfo_.sourceDeviceId_); 835686862fbSopenharmony_ci 836686862fbSopenharmony_ci AppExecFwk::BundleInfo localBundleInfo; 837686862fbSopenharmony_ci if (BundleManagerInternal::GetLocalBundleInfo(newWant.GetBundle(), localBundleInfo) != ERR_OK) { 838686862fbSopenharmony_ci HILOGE("get local bundle info failed"); 839686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 840686862fbSopenharmony_ci } 841686862fbSopenharmony_ci newWant.SetParam(VERSION_CODE_KEY, static_cast<int32_t>(localBundleInfo.versionCode)); 842686862fbSopenharmony_ci HILOGD("local version = %{public}u!", localBundleInfo.versionCode); 843686862fbSopenharmony_ci 844686862fbSopenharmony_ci bool isPageStackContinue = newWant.GetBoolParam(SUPPORT_CONTINUE_PAGE_STACK_KEY, true); 845686862fbSopenharmony_ci std::string moduleName = newWant.GetStringParam(SUPPORT_CONTINUE_MODULE_NAME_UPDATE_KEY); 846686862fbSopenharmony_ci if (!isPageStackContinue && !moduleName.empty() && moduleName.length() <= MAX_MODULENAME_LEN) { 847686862fbSopenharmony_ci HILOGD("set application moduleName = %{public}s!", moduleName.c_str()); 848686862fbSopenharmony_ci auto element = newWant.GetElement(); 849686862fbSopenharmony_ci newWant.SetElementName(element.GetDeviceID(), element.GetBundleName(), element.GetAbilityName(), moduleName); 850686862fbSopenharmony_ci } 851686862fbSopenharmony_ci 852686862fbSopenharmony_ci std::string saveDataTime = 853686862fbSopenharmony_ci DmsContinueTime::GetInstance().WriteDurationInfo(DmsContinueTime::GetInstance().GetSaveDataDuration()); 854686862fbSopenharmony_ci newWant.SetParam(DMSDURATION_SAVETIME, saveDataTime); 855686862fbSopenharmony_ci if (subServiceType_ == CONTINUE_PUSH) { 856686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSrcBundleName(continueInfo_.sourceBundleName_); 857686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSrcAbilityName(newWant.GetElement().GetAbilityName()); 858686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDstBundleName(continueInfo_.sinkBundleName_); 859686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDstAbilityName(newWant.GetElement().GetAbilityName()); 860686862fbSopenharmony_ci } 861686862fbSopenharmony_ci return ERR_OK; 862686862fbSopenharmony_ci} 863686862fbSopenharmony_ci 864686862fbSopenharmony_ciint32_t DSchedContinue::PackDataCmd(std::shared_ptr<DSchedContinueDataCmd>& cmd, 865686862fbSopenharmony_ci const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, const CallerInfo& callerInfo, 866686862fbSopenharmony_ci const AccountInfo& accountInfo) 867686862fbSopenharmony_ci{ 868686862fbSopenharmony_ci if (cmd == nullptr) { 869686862fbSopenharmony_ci HILOGE("cmd is null"); 870686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 871686862fbSopenharmony_ci } 872686862fbSopenharmony_ci cmd->version_ = version_; 873686862fbSopenharmony_ci cmd->serviceType_ = SERVICE_TYPE_CONTINUE; 874686862fbSopenharmony_ci cmd->subServiceType_ = subServiceType_; 875686862fbSopenharmony_ci cmd->command_ = DSCHED_CONTINUE_CMD_DATA; 876686862fbSopenharmony_ci cmd->srcDeviceId_ = continueInfo_.sourceDeviceId_; 877686862fbSopenharmony_ci cmd->srcBundleName_ = continueInfo_.sourceBundleName_; 878686862fbSopenharmony_ci cmd->dstDeviceId_ = continueInfo_.sinkDeviceId_; 879686862fbSopenharmony_ci cmd->dstBundleName_ = continueInfo_.sinkBundleName_; 880686862fbSopenharmony_ci cmd->continueType_ = continueInfo_.continueType_; 881686862fbSopenharmony_ci cmd->sourceMissionId_ = continueInfo_.missionId_; 882686862fbSopenharmony_ci cmd->continueByType_ = continueByType_; 883686862fbSopenharmony_ci cmd->dmsVersion_ = DMS_VERSION; 884686862fbSopenharmony_ci 885686862fbSopenharmony_ci cmd->want_ = want; 886686862fbSopenharmony_ci AppExecFwk::CompatibleAbilityInfo compatibleAbilityInfo; 887686862fbSopenharmony_ci abilityInfo.ConvertToCompatiableAbilityInfo(compatibleAbilityInfo); 888686862fbSopenharmony_ci cmd->abilityInfo_ = compatibleAbilityInfo; 889686862fbSopenharmony_ci cmd->callerInfo_ = callerInfo; 890686862fbSopenharmony_ci cmd->accountInfo_ = accountInfo; 891686862fbSopenharmony_ci cmd->requestCode_ = DEFAULT_REQUEST_CODE; 892686862fbSopenharmony_ci 893686862fbSopenharmony_ci AppExecFwk::AppProvisionInfo appProvisionInfo; 894686862fbSopenharmony_ci BundleManagerInternal::GetAppProvisionInfo4CurrentUser(cmd->srcBundleName_, appProvisionInfo); 895686862fbSopenharmony_ci cmd->srcDeveloperId_ = appProvisionInfo.developerId; 896686862fbSopenharmony_ci return ERR_OK; 897686862fbSopenharmony_ci} 898686862fbSopenharmony_ci 899686862fbSopenharmony_ciint32_t DSchedContinue::CheckStartPermission(std::shared_ptr<DSchedContinueDataCmd> cmd) 900686862fbSopenharmony_ci{ 901686862fbSopenharmony_ci if (cmd->srcBundleName_ == cmd->dstBundleName_) { 902686862fbSopenharmony_ci return DistributedSchedService::GetInstance().CheckTargetPermission4DiffBundle(cmd->want_, cmd->callerInfo_, 903686862fbSopenharmony_ci cmd->accountInfo_, START_PERMISSION, true); 904686862fbSopenharmony_ci } else { 905686862fbSopenharmony_ci if (!BundleManagerInternal::IsSameDeveloperId(cmd->dstBundleName_, cmd->srcDeveloperId_)) { 906686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 907686862fbSopenharmony_ci } 908686862fbSopenharmony_ci return DistributedSchedService::GetInstance().CheckTargetPermission4DiffBundle(cmd->want_, cmd->callerInfo_, 909686862fbSopenharmony_ci cmd->accountInfo_, START_PERMISSION, true); 910686862fbSopenharmony_ci } 911686862fbSopenharmony_ci} 912686862fbSopenharmony_ci 913686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueData(std::shared_ptr<DSchedContinueDataCmd> cmd) 914686862fbSopenharmony_ci{ 915686862fbSopenharmony_ci HILOGI("ExecuteContinueData start, continueInfo: %{public}s", continueInfo_.toString().c_str()); 916686862fbSopenharmony_ci if (cmd == nullptr) { 917686862fbSopenharmony_ci HILOGE("cmd is null"); 918686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 919686862fbSopenharmony_ci } 920686862fbSopenharmony_ci 921686862fbSopenharmony_ci DurationDumperBeforeStartAbility(cmd); 922686862fbSopenharmony_ci 923686862fbSopenharmony_ci std::string localDeviceId; 924686862fbSopenharmony_ci std::string deviceId = cmd->want_.GetElement().GetDeviceID(); 925686862fbSopenharmony_ci if (!GetLocalDeviceId(localDeviceId) || 926686862fbSopenharmony_ci !CheckDeviceIdFromRemote(localDeviceId, deviceId, cmd->callerInfo_.sourceDeviceId)) { 927686862fbSopenharmony_ci HILOGE("check deviceId failed"); 928686862fbSopenharmony_ci return INVALID_REMOTE_PARAMETERS_ERR; 929686862fbSopenharmony_ci } 930686862fbSopenharmony_ci int32_t ret = CheckStartPermission(cmd); 931686862fbSopenharmony_ci if (ret != ERR_OK) { 932686862fbSopenharmony_ci HILOGE("ExecuteContinueData CheckTargetPermission failed!"); 933686862fbSopenharmony_ci return ret; 934686862fbSopenharmony_ci } 935686862fbSopenharmony_ci 936686862fbSopenharmony_ci OHOS::AAFwk::Want want = cmd->want_; 937686862fbSopenharmony_ci UpdateWantForContinueType(want); 938686862fbSopenharmony_ci if (subServiceType_ == CONTINUE_PULL && 939686862fbSopenharmony_ci !ContinueSceneSessionHandler::GetInstance().GetContinueSessionId().empty()) { 940686862fbSopenharmony_ci int32_t persistentId; 941686862fbSopenharmony_ci if (ContinueSceneSessionHandler::GetInstance().GetPersistentId(persistentId) != ERR_OK) { 942686862fbSopenharmony_ci HILOGE("get persistentId failed, stop start ability"); 943686862fbSopenharmony_ci return OnContinueEnd(ERR_OK); 944686862fbSopenharmony_ci } 945686862fbSopenharmony_ci HILOGI("get persistentId success, persistentId: %{public}d", persistentId); 946686862fbSopenharmony_ci WaitAbilityStateInitial(persistentId); 947686862fbSopenharmony_ci want.SetParam(DMS_PERSISTENT_ID, persistentId); 948686862fbSopenharmony_ci 949686862fbSopenharmony_ci if (ContinueSceneSessionHandler::GetInstance().GetPersistentId(persistentId) != ERR_OK) { 950686862fbSopenharmony_ci HILOGE("get persistentId failed, stop start ability"); 951686862fbSopenharmony_ci return OnContinueEnd(ERR_OK); 952686862fbSopenharmony_ci } 953686862fbSopenharmony_ci } 954686862fbSopenharmony_ci 955686862fbSopenharmony_ci ret = StartAbility(want, cmd->requestCode_); 956686862fbSopenharmony_ci if (ret == ERR_OK) { 957686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SINK_WAIT_END_STATE); 958686862fbSopenharmony_ci HILOGI("ExecuteContinueData end"); 959686862fbSopenharmony_ci } 960686862fbSopenharmony_ci return ret; 961686862fbSopenharmony_ci} 962686862fbSopenharmony_ci 963686862fbSopenharmony_ciint32_t DSchedContinue::UpdateWantForContinueType(OHOS::AAFwk::Want& want) 964686862fbSopenharmony_ci{ 965686862fbSopenharmony_ci std::string srcAbilityName = want.GetElement().GetAbilityName(); 966686862fbSopenharmony_ci std::string sinkAbilityName = GetAbilityNameByContinueType(); 967686862fbSopenharmony_ci if (!sinkAbilityName.empty() && sinkAbilityName != srcAbilityName) { 968686862fbSopenharmony_ci OHOS::AppExecFwk::ElementName element = want.GetElement(); 969686862fbSopenharmony_ci want.SetElementName(element.GetDeviceID(), element.GetBundleName(), sinkAbilityName); 970686862fbSopenharmony_ci want.RemoveParam(SUPPORT_CONTINUE_PAGE_STACK_KEY); 971686862fbSopenharmony_ci want.SetParam(SUPPORT_CONTINUE_PAGE_STACK_KEY, false); 972686862fbSopenharmony_ci 973686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDstAbilityName(sinkAbilityName); 974686862fbSopenharmony_ci } 975686862fbSopenharmony_ci return ERR_OK; 976686862fbSopenharmony_ci} 977686862fbSopenharmony_ci 978686862fbSopenharmony_civoid DSchedContinue::DurationDumperBeforeStartAbility(std::shared_ptr<DSchedContinueDataCmd> cmd) 979686862fbSopenharmony_ci{ 980686862fbSopenharmony_ci if (subServiceType_ == CONTINUE_PULL && cmd != nullptr) { 981686862fbSopenharmony_ci std::string timeInfo = cmd->want_.GetStringParam(DMSDURATION_SAVETIME); 982686862fbSopenharmony_ci DmsContinueTime::GetInstance().ReadDurationInfo(timeInfo.c_str()); 983686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSrcBundleName(continueInfo_.sourceBundleName_); 984686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetSrcAbilityName(cmd->want_.GetElement().GetAbilityName()); 985686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDstBundleName(continueInfo_.sinkBundleName_); 986686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDstAbilityName(cmd->want_.GetElement().GetAbilityName()); 987686862fbSopenharmony_ci } 988686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationBegin(CONTINUE_START_ABILITY_TIME, GetTickCount()); 989686862fbSopenharmony_ci} 990686862fbSopenharmony_ci 991686862fbSopenharmony_cibool DSchedContinue::WaitAbilityStateInitial(int32_t persistentId) 992686862fbSopenharmony_ci{ 993686862fbSopenharmony_ci int32_t retryTimeout = GET_ABILITY_STATE_RETRY_TIMES; 994686862fbSopenharmony_ci int32_t err; 995686862fbSopenharmony_ci do { 996686862fbSopenharmony_ci bool state = false; 997686862fbSopenharmony_ci err = AAFwk::AbilityManagerClient::GetInstance()->GetAbilityStateByPersistentId(persistentId, state); 998686862fbSopenharmony_ci if (err == ERR_OK && state) { 999686862fbSopenharmony_ci HILOGI("ability state initial."); 1000686862fbSopenharmony_ci return state; 1001686862fbSopenharmony_ci } 1002686862fbSopenharmony_ci HILOGI("waiting ability state initial..."); 1003686862fbSopenharmony_ci std::this_thread::sleep_for(std::chrono::milliseconds(GET_ABILITY_STATE_SLEEP_TIME)); 1004686862fbSopenharmony_ci } while (--retryTimeout > 0); 1005686862fbSopenharmony_ci 1006686862fbSopenharmony_ci HILOGE("wait timeout, persistentId: %{public}d, errorCode: %{public}d", 1007686862fbSopenharmony_ci persistentId, err); 1008686862fbSopenharmony_ci return false; 1009686862fbSopenharmony_ci} 1010686862fbSopenharmony_ci 1011686862fbSopenharmony_ciint32_t DSchedContinue::StartAbility(const OHOS::AAFwk::Want& want, int32_t requestCode) 1012686862fbSopenharmony_ci{ 1013686862fbSopenharmony_ci int32_t ret = AAFwk::AbilityManagerClient::GetInstance()->Connect(); 1014686862fbSopenharmony_ci if (ret != ERR_OK) { 1015686862fbSopenharmony_ci HILOGE("connect ability server failed %{public}d", ret); 1016686862fbSopenharmony_ci return ret; 1017686862fbSopenharmony_ci } 1018686862fbSopenharmony_ci 1019686862fbSopenharmony_ci int32_t activeAccountId = 0; 1020686862fbSopenharmony_ci ret = DistributedSchedService::GetInstance().QueryOsAccount(activeAccountId); 1021686862fbSopenharmony_ci if (ret != ERR_OK) { 1022686862fbSopenharmony_ci HILOGE("QueryOsAccount failed %{public}d", ret); 1023686862fbSopenharmony_ci return ret; 1024686862fbSopenharmony_ci } 1025686862fbSopenharmony_ci 1026686862fbSopenharmony_ci continueInfo_.sinkAbilityName_ = want.GetElement().GetAbilityName(); 1027686862fbSopenharmony_ci DmsRadar::GetInstance().ClickIconDmsStartAbility("StartAbility", ret); 1028686862fbSopenharmony_ci 1029686862fbSopenharmony_ci HILOGI("call StartAbility start, flag is %{public}d", want.GetFlags()); 1030686862fbSopenharmony_ci ret = AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want, DEFAULT_REQUEST_CODE, activeAccountId); 1031686862fbSopenharmony_ci if (ret != ERR_OK) { 1032686862fbSopenharmony_ci HILOGE("failed %{public}d", ret); 1033686862fbSopenharmony_ci return ret; 1034686862fbSopenharmony_ci } 1035686862fbSopenharmony_ci return ret; 1036686862fbSopenharmony_ci} 1037686862fbSopenharmony_ci 1038686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteNotifyComplete(int32_t result) 1039686862fbSopenharmony_ci{ 1040686862fbSopenharmony_ci HILOGI("ExecuteNotifyComplete start, result %{public}d", result); 1041686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationEnd(CONTINUE_START_ABILITY_TIME, GetTickCount()); 1042686862fbSopenharmony_ci 1043686862fbSopenharmony_ci int32_t ret = 0; 1044686862fbSopenharmony_ci if (direction_ == CONTINUE_SINK) { 1045686862fbSopenharmony_ci auto cmd = std::make_shared<DSchedContinueEndCmd>(); 1046686862fbSopenharmony_ci PackEndCmd(cmd, result); 1047686862fbSopenharmony_ci 1048686862fbSopenharmony_ci ret = SendCommand(cmd); 1049686862fbSopenharmony_ci if (ret != ERR_OK) { 1050686862fbSopenharmony_ci HILOGE("ExecuteNotifyComplete send end cmd failed, ret %{public}d", ret); 1051686862fbSopenharmony_ci return ret; 1052686862fbSopenharmony_ci } 1053686862fbSopenharmony_ci 1054686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SINK_END_STATE); 1055686862fbSopenharmony_ci HILOGI("ExecuteNotifyComplete end"); 1056686862fbSopenharmony_ci return ERR_OK; 1057686862fbSopenharmony_ci } 1058686862fbSopenharmony_ci 1059686862fbSopenharmony_ci auto cmd = std::make_shared<DSchedContinueReplyCmd>(); 1060686862fbSopenharmony_ci PackReplyCmd(cmd, DSCHED_CONTINUE_CMD_END, 0, result, "ExecuteNotifyComplete"); 1061686862fbSopenharmony_ci ret = SendCommand(cmd); 1062686862fbSopenharmony_ci if (ret != ERR_OK) { 1063686862fbSopenharmony_ci HILOGE("ExecuteNotifyComplete send reply cmd failed, ret %{public}d", ret); 1064686862fbSopenharmony_ci return ret; 1065686862fbSopenharmony_ci } 1066686862fbSopenharmony_ci 1067686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SOURCE_END_STATE); 1068686862fbSopenharmony_ci PostContinueEndTask(result); 1069686862fbSopenharmony_ci 1070686862fbSopenharmony_ci HILOGI("ExecuteNotifyComplete end"); 1071686862fbSopenharmony_ci return ERR_OK; 1072686862fbSopenharmony_ci} 1073686862fbSopenharmony_ci 1074686862fbSopenharmony_ciint32_t DSchedContinue::PackReplyCmd(std::shared_ptr<DSchedContinueReplyCmd> cmd, int32_t replyCmd, int32_t appVersion, 1075686862fbSopenharmony_ci int32_t result, const std::string reason) 1076686862fbSopenharmony_ci{ 1077686862fbSopenharmony_ci if (cmd == nullptr) { 1078686862fbSopenharmony_ci HILOGE("cmd is null"); 1079686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 1080686862fbSopenharmony_ci } 1081686862fbSopenharmony_ci cmd->version_ = version_; 1082686862fbSopenharmony_ci cmd->serviceType_ = SERVICE_TYPE_CONTINUE; 1083686862fbSopenharmony_ci cmd->subServiceType_ = subServiceType_; 1084686862fbSopenharmony_ci cmd->command_ = DSCHED_CONTINUE_CMD_REPLY; 1085686862fbSopenharmony_ci cmd->srcDeviceId_ = continueInfo_.sourceDeviceId_; 1086686862fbSopenharmony_ci cmd->srcBundleName_ = continueInfo_.sourceBundleName_; 1087686862fbSopenharmony_ci cmd->dstDeviceId_ = continueInfo_.sinkDeviceId_; 1088686862fbSopenharmony_ci cmd->dstBundleName_ = continueInfo_.sinkBundleName_; 1089686862fbSopenharmony_ci cmd->continueType_ = continueInfo_.continueType_; 1090686862fbSopenharmony_ci cmd->sourceMissionId_ = continueInfo_.missionId_; 1091686862fbSopenharmony_ci cmd->continueByType_ = continueByType_; 1092686862fbSopenharmony_ci cmd->dmsVersion_ = DMS_VERSION; 1093686862fbSopenharmony_ci 1094686862fbSopenharmony_ci cmd->replyCmd_ = replyCmd; 1095686862fbSopenharmony_ci cmd->appVersion_ = appVersion; 1096686862fbSopenharmony_ci cmd->result_ = result; 1097686862fbSopenharmony_ci cmd->reason_ = reason; 1098686862fbSopenharmony_ci return ERR_OK; 1099686862fbSopenharmony_ci} 1100686862fbSopenharmony_ci 1101686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueEnd(int32_t result) 1102686862fbSopenharmony_ci{ 1103686862fbSopenharmony_ci HILOGI("ExecuteContinueEnd start, result %{public}d", result); 1104686862fbSopenharmony_ci 1105686862fbSopenharmony_ci std::string peerDeviceId = (direction_ == CONTINUE_SOURCE) ? 1106686862fbSopenharmony_ci continueInfo_.sinkDeviceId_ : continueInfo_.sourceDeviceId_; 1107686862fbSopenharmony_ci if ((subServiceType_ == CONTINUE_PULL && direction_ == CONTINUE_SINK) || 1108686862fbSopenharmony_ci (subServiceType_ == CONTINUE_PUSH && direction_ == CONTINUE_SOURCE)) { 1109686862fbSopenharmony_ci HILOGI("ExecuteContinueEnd disconnect peer device %{public}s", GetAnonymStr(peerDeviceId).c_str()); 1110686862fbSopenharmony_ci DSchedTransportSoftbusAdapter::GetInstance().DisconnectDevice(peerDeviceId); 1111686862fbSopenharmony_ci } 1112686862fbSopenharmony_ci 1113686862fbSopenharmony_ci eventData_.state_ = result != ERR_OK ? DMS_DSCHED_EVENT_STOP : DMS_DSCHED_EVENT_FINISH; 1114686862fbSopenharmony_ci if (result == ERR_OK && direction_ == CONTINUE_SOURCE && isSourceExit_) { 1115686862fbSopenharmony_ci int32_t ret = AbilityManagerClient::GetInstance()->CleanMission(continueInfo_.missionId_); 1116686862fbSopenharmony_ci HILOGD("ExecuteContinueEnd clean mission result: %{public}d", ret); 1117686862fbSopenharmony_ci } 1118686862fbSopenharmony_ci 1119686862fbSopenharmony_ci if (direction_ == CONTINUE_SINK) { 1120686862fbSopenharmony_ci DmsRadar::GetInstance().ClickIconDmsRecvOver("NotifyContinuationResultFromRemote", result); 1121686862fbSopenharmony_ci } 1122686862fbSopenharmony_ci 1123686862fbSopenharmony_ci NotifyContinuationCallbackResult(result); 1124686862fbSopenharmony_ci NotifyDSchedEventResult(result); 1125686862fbSopenharmony_ci DurationDumperComplete(result); 1126686862fbSopenharmony_ci 1127686862fbSopenharmony_ci DSchedContinueManager::GetInstance().OnContinueEnd(continueInfo_); 1128686862fbSopenharmony_ci HILOGI("ExecuteContinueEnd end"); 1129686862fbSopenharmony_ci return ERR_OK; 1130686862fbSopenharmony_ci} 1131686862fbSopenharmony_ci 1132686862fbSopenharmony_ciint32_t DSchedContinue::ConvertToDmsSdkErr(int32_t result) 1133686862fbSopenharmony_ci{ 1134686862fbSopenharmony_ci if (result == ERR_OK) { 1135686862fbSopenharmony_ci return result; 1136686862fbSopenharmony_ci } 1137686862fbSopenharmony_ci 1138686862fbSopenharmony_ci auto it = DMS_CONVERT_TO_SDK_ERR_MAP.find(result); 1139686862fbSopenharmony_ci if (it != DMS_CONVERT_TO_SDK_ERR_MAP.end()) { 1140686862fbSopenharmony_ci return it->second; 1141686862fbSopenharmony_ci } 1142686862fbSopenharmony_ci return DmsInterfaceSdkErr::ERR_DMS_WORK_ABNORMALLY; 1143686862fbSopenharmony_ci} 1144686862fbSopenharmony_ci 1145686862fbSopenharmony_civoid DSchedContinue::NotifyContinuationCallbackResult(int32_t result) 1146686862fbSopenharmony_ci{ 1147686862fbSopenharmony_ci HILOGD("continuation result is: %{public}d", result); 1148686862fbSopenharmony_ci if (callback_ == nullptr) { 1149686862fbSopenharmony_ci HILOGW("callback object null."); 1150686862fbSopenharmony_ci return; 1151686862fbSopenharmony_ci } 1152686862fbSopenharmony_ci 1153686862fbSopenharmony_ci MessageParcel data; 1154686862fbSopenharmony_ci if (!data.WriteInterfaceToken(NAPI_MISSION_CALLBACK_INTERFACE_TOKEN)) { 1155686862fbSopenharmony_ci HILOGE("write token failed"); 1156686862fbSopenharmony_ci return; 1157686862fbSopenharmony_ci } 1158686862fbSopenharmony_ci PARCEL_WRITE_HELPER_NORET(data, Int32, ConvertToDmsSdkErr(result)); 1159686862fbSopenharmony_ci MessageParcel reply; 1160686862fbSopenharmony_ci MessageOption option; 1161686862fbSopenharmony_ci int32_t ret = callback_->SendRequest(NOTIFY_MISSION_CALLBACK_RESULT, data, reply, option); 1162686862fbSopenharmony_ci callback_ = nullptr; 1163686862fbSopenharmony_ci if (ret != ERR_OK) { 1164686862fbSopenharmony_ci HILOGE("send request failed, ret: %{public}d", ret); 1165686862fbSopenharmony_ci } 1166686862fbSopenharmony_ci return; 1167686862fbSopenharmony_ci} 1168686862fbSopenharmony_ci 1169686862fbSopenharmony_civoid DSchedContinue::NotifyDSchedEventResult(int32_t result) 1170686862fbSopenharmony_ci{ 1171686862fbSopenharmony_ci result = (result == ERR_OK) ? ERR_OK : NOTIFYCOMPLETECONTINUATION_FAILED; 1172686862fbSopenharmony_ci DistributedSchedService::GetInstance().NotifyDSchedEventCallbackResult(result, eventData_); 1173686862fbSopenharmony_ci} 1174686862fbSopenharmony_ci 1175686862fbSopenharmony_civoid DSchedContinue::DurationDumperComplete(int32_t result) 1176686862fbSopenharmony_ci{ 1177686862fbSopenharmony_ci if (result != ERR_OK) { 1178686862fbSopenharmony_ci return; 1179686862fbSopenharmony_ci } 1180686862fbSopenharmony_ci if ((subServiceType_ == CONTINUE_PULL && direction_ == CONTINUE_SINK) || 1181686862fbSopenharmony_ci (subServiceType_ == CONTINUE_PUSH && direction_ == CONTINUE_SOURCE)) { 1182686862fbSopenharmony_ci std::string strEndTime = DmsContinueTime::GetInstance().GetCurrentTime(); 1183686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationEnd(CONTINUE_TOTAL_TIME, GetTickCount()); 1184686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetDurationStrTime(CONTINUE_END_TIME, strEndTime); 1185686862fbSopenharmony_ci 1186686862fbSopenharmony_ci DmsUE::GetInstance().DmsContinueComplete(continueInfo_.sourceBundleName_, continueInfo_.sinkAbilityName_, 1187686862fbSopenharmony_ci continueInfo_.sourceDeviceId_, result); 1188686862fbSopenharmony_ci 1189686862fbSopenharmony_ci DmsContinueTime::GetInstance().AppendInfo(); 1190686862fbSopenharmony_ci DmsContinueTime::GetInstance().SetPull(false); 1191686862fbSopenharmony_ci } 1192686862fbSopenharmony_ci return; 1193686862fbSopenharmony_ci} 1194686862fbSopenharmony_ci 1195686862fbSopenharmony_ciint32_t DSchedContinue::ExecuteContinueError(int32_t result) 1196686862fbSopenharmony_ci{ 1197686862fbSopenharmony_ci HILOGI("start, result %{public}d", result); 1198686862fbSopenharmony_ci auto cmd = std::make_shared<DSchedContinueEndCmd>(); 1199686862fbSopenharmony_ci PackEndCmd(cmd, result); 1200686862fbSopenharmony_ci SendCommand(cmd); 1201686862fbSopenharmony_ci if (direction_ == CONTINUE_SOURCE) { 1202686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SOURCE_END_STATE); 1203686862fbSopenharmony_ci } else { 1204686862fbSopenharmony_ci UpdateState(DSCHED_CONTINUE_SINK_END_STATE); 1205686862fbSopenharmony_ci } 1206686862fbSopenharmony_ci OnContinueEnd(result); 1207686862fbSopenharmony_ci HILOGI("ExecuteNotifyComplete end"); 1208686862fbSopenharmony_ci return ERR_OK; 1209686862fbSopenharmony_ci} 1210686862fbSopenharmony_ci 1211686862fbSopenharmony_ciint32_t DSchedContinue::PackEndCmd(std::shared_ptr<DSchedContinueEndCmd> cmd, int32_t result) 1212686862fbSopenharmony_ci{ 1213686862fbSopenharmony_ci if (cmd == nullptr) { 1214686862fbSopenharmony_ci HILOGE("cmd is null"); 1215686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 1216686862fbSopenharmony_ci } 1217686862fbSopenharmony_ci cmd->version_ = version_; 1218686862fbSopenharmony_ci cmd->serviceType_ = SERVICE_TYPE_CONTINUE; 1219686862fbSopenharmony_ci cmd->subServiceType_ = subServiceType_; 1220686862fbSopenharmony_ci cmd->command_ = DSCHED_CONTINUE_CMD_END; 1221686862fbSopenharmony_ci cmd->srcDeviceId_ = continueInfo_.sourceDeviceId_; 1222686862fbSopenharmony_ci cmd->srcBundleName_ = continueInfo_.sourceBundleName_; 1223686862fbSopenharmony_ci cmd->dstDeviceId_ = continueInfo_.sinkDeviceId_; 1224686862fbSopenharmony_ci cmd->dstBundleName_ = continueInfo_.sinkBundleName_; 1225686862fbSopenharmony_ci cmd->continueType_ = continueInfo_.continueType_; 1226686862fbSopenharmony_ci cmd->sourceMissionId_ = continueInfo_.missionId_; 1227686862fbSopenharmony_ci cmd->continueByType_ = continueByType_; 1228686862fbSopenharmony_ci cmd->dmsVersion_ = DMS_VERSION; 1229686862fbSopenharmony_ci 1230686862fbSopenharmony_ci cmd->result_ = result; 1231686862fbSopenharmony_ci return ERR_OK; 1232686862fbSopenharmony_ci} 1233686862fbSopenharmony_ci 1234686862fbSopenharmony_ciint32_t DSchedContinue::SendCommand(std::shared_ptr<DSchedContinueCmdBase> cmd) 1235686862fbSopenharmony_ci{ 1236686862fbSopenharmony_ci if (cmd == nullptr) { 1237686862fbSopenharmony_ci HILOGE("cmd is null"); 1238686862fbSopenharmony_ci return INVALID_PARAMETERS_ERR; 1239686862fbSopenharmony_ci } 1240686862fbSopenharmony_ci HILOGI("SendCommand start, cmd %{public}d", cmd->command_); 1241686862fbSopenharmony_ci std::string jsonStr; 1242686862fbSopenharmony_ci int32_t ret = cmd->Marshal(jsonStr); 1243686862fbSopenharmony_ci if (ret != ERR_OK) { 1244686862fbSopenharmony_ci HILOGE("SendCommand marshal cmd %{public}d failed, ret %{public}d", cmd->command_, ret); 1245686862fbSopenharmony_ci return ret; 1246686862fbSopenharmony_ci } 1247686862fbSopenharmony_ci auto buffer = std::make_shared<DSchedDataBuffer>(jsonStr.length() + 1); 1248686862fbSopenharmony_ci ret = memcpy_s(buffer->Data(), buffer->Capacity(), jsonStr.c_str(), jsonStr.length()); 1249686862fbSopenharmony_ci if (ret != ERR_OK) { 1250686862fbSopenharmony_ci HILOGE("SendCommand memcpy_s failed, cmd %{public}d, ret %{public}d", cmd->command_, ret); 1251686862fbSopenharmony_ci return ret; 1252686862fbSopenharmony_ci } 1253686862fbSopenharmony_ci ret = DSchedTransportSoftbusAdapter::GetInstance().SendData(softbusSessionId_, SERVICE_TYPE_CONTINUE, buffer); 1254686862fbSopenharmony_ci if (ret != ERR_OK) { 1255686862fbSopenharmony_ci HILOGE("SendCommand send data failed, cmd %{public}d, ret %{public}d", cmd->command_, ret); 1256686862fbSopenharmony_ci return ret; 1257686862fbSopenharmony_ci } 1258686862fbSopenharmony_ci HILOGI("SendCommand end, cmd %{public}d", cmd->command_); 1259686862fbSopenharmony_ci return ERR_OK; 1260686862fbSopenharmony_ci} 1261686862fbSopenharmony_ci 1262686862fbSopenharmony_ciint32_t DSchedContinue::GetSessionId() 1263686862fbSopenharmony_ci{ 1264686862fbSopenharmony_ci return softbusSessionId_; 1265686862fbSopenharmony_ci} 1266686862fbSopenharmony_ci 1267686862fbSopenharmony_ciDSchedContinueInfo DSchedContinue::GetContinueInfo() 1268686862fbSopenharmony_ci{ 1269686862fbSopenharmony_ci return continueInfo_; 1270686862fbSopenharmony_ci} 1271686862fbSopenharmony_ci 1272686862fbSopenharmony_cibool DSchedContinue::GetLocalDeviceId(std::string& localDeviceId) 1273686862fbSopenharmony_ci{ 1274686862fbSopenharmony_ci if (!DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(localDeviceId)) { 1275686862fbSopenharmony_ci HILOGE("GetLocalDeviceId failed"); 1276686862fbSopenharmony_ci return false; 1277686862fbSopenharmony_ci } 1278686862fbSopenharmony_ci return true; 1279686862fbSopenharmony_ci} 1280686862fbSopenharmony_ci 1281686862fbSopenharmony_cibool DSchedContinue::CheckDeviceIdFromRemote(const std::string& localDevId, const std::string& destDevId, 1282686862fbSopenharmony_ci const std::string& srcDevId) 1283686862fbSopenharmony_ci{ 1284686862fbSopenharmony_ci if (localDevId.empty() || destDevId.empty() || srcDevId.empty()) { 1285686862fbSopenharmony_ci HILOGE("CheckDeviceIdFromRemote failed"); 1286686862fbSopenharmony_ci return false; 1287686862fbSopenharmony_ci } 1288686862fbSopenharmony_ci // destDevId set by remote must be same with localDevId 1289686862fbSopenharmony_ci if (localDevId != destDevId) { 1290686862fbSopenharmony_ci HILOGE("destDevId is not same with localDevId"); 1291686862fbSopenharmony_ci return false; 1292686862fbSopenharmony_ci } 1293686862fbSopenharmony_ci HILOGD("CheckDeviceIdFromRemote srcDevId %{public}s", GetAnonymStr(srcDevId).c_str()); 1294686862fbSopenharmony_ci HILOGD("CheckDeviceIdFromRemote localDevId %{public}s", GetAnonymStr(localDevId).c_str()); 1295686862fbSopenharmony_ci HILOGD("CheckDeviceIdFromRemote destDevId %{public}s", GetAnonymStr(destDevId).c_str()); 1296686862fbSopenharmony_ci 1297686862fbSopenharmony_ci if (srcDevId == destDevId || srcDevId == localDevId) { 1298686862fbSopenharmony_ci HILOGE("destDevId is different with localDevId and destDevId"); 1299686862fbSopenharmony_ci return false; 1300686862fbSopenharmony_ci } 1301686862fbSopenharmony_ci 1302686862fbSopenharmony_ci if (srcDevId != continueInfo_.sourceDeviceId_) { 1303686862fbSopenharmony_ci HILOGE("srcDevId is not correct"); 1304686862fbSopenharmony_ci return false; 1305686862fbSopenharmony_ci } 1306686862fbSopenharmony_ci return true; 1307686862fbSopenharmony_ci} 1308686862fbSopenharmony_ci 1309686862fbSopenharmony_civoid DSchedContinue::OnDataRecv(int32_t command, std::shared_ptr<DSchedDataBuffer> dataBuffer) 1310686862fbSopenharmony_ci{ 1311686862fbSopenharmony_ci HILOGI("called, command %{public}d", command); 1312686862fbSopenharmony_ci if (dataBuffer == nullptr) { 1313686862fbSopenharmony_ci HILOGE("dataBuffer is null"); 1314686862fbSopenharmony_ci return; 1315686862fbSopenharmony_ci } 1316686862fbSopenharmony_ci int32_t ret = 0; 1317686862fbSopenharmony_ci uint8_t *data = dataBuffer->Data(); 1318686862fbSopenharmony_ci std::string jsonStr(reinterpret_cast<const char *>(data), dataBuffer->Capacity()); 1319686862fbSopenharmony_ci 1320686862fbSopenharmony_ci switch (command) { 1321686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_START: { 1322686862fbSopenharmony_ci HILOGW("continue already started, cmd abort."); 1323686862fbSopenharmony_ci break; 1324686862fbSopenharmony_ci } 1325686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_DATA: { 1326686862fbSopenharmony_ci auto dataCmd = std::make_shared<DSchedContinueDataCmd>(); 1327686862fbSopenharmony_ci ret = dataCmd->Unmarshal(jsonStr); 1328686862fbSopenharmony_ci if (ret != ERR_OK) { 1329686862fbSopenharmony_ci HILOGE("Unmarshal data cmd failed, ret: %{public}d", ret); 1330686862fbSopenharmony_ci return; 1331686862fbSopenharmony_ci } 1332686862fbSopenharmony_ci dataCmd->want_.SetBundle(dataCmd->dstBundleName_); 1333686862fbSopenharmony_ci OnContinueDataCmd(dataCmd); 1334686862fbSopenharmony_ci break; 1335686862fbSopenharmony_ci } 1336686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_REPLY: { 1337686862fbSopenharmony_ci auto replyCmd = std::make_shared<DSchedContinueReplyCmd>(); 1338686862fbSopenharmony_ci ret = replyCmd->Unmarshal(jsonStr); 1339686862fbSopenharmony_ci if (ret != ERR_OK) { 1340686862fbSopenharmony_ci HILOGE("Unmarshal reply cmd failed, ret: %{public}d", ret); 1341686862fbSopenharmony_ci return; 1342686862fbSopenharmony_ci } 1343686862fbSopenharmony_ci OnReplyCmd(replyCmd); 1344686862fbSopenharmony_ci break; 1345686862fbSopenharmony_ci } 1346686862fbSopenharmony_ci case DSCHED_CONTINUE_CMD_END: { 1347686862fbSopenharmony_ci auto endCmd = std::make_shared<DSchedContinueEndCmd>(); 1348686862fbSopenharmony_ci ret = endCmd->Unmarshal(jsonStr); 1349686862fbSopenharmony_ci if (ret != ERR_OK) { 1350686862fbSopenharmony_ci HILOGE("Unmarshal end cmd failed, ret: %{public}d", ret); 1351686862fbSopenharmony_ci return; 1352686862fbSopenharmony_ci } 1353686862fbSopenharmony_ci OnContinueEndCmd(endCmd); 1354686862fbSopenharmony_ci break; 1355686862fbSopenharmony_ci } 1356686862fbSopenharmony_ci default: 1357686862fbSopenharmony_ci HILOGW("Invalid command."); 1358686862fbSopenharmony_ci break; 1359686862fbSopenharmony_ci } 1360686862fbSopenharmony_ci} 1361686862fbSopenharmony_ci 1362686862fbSopenharmony_civoid DSchedContinue::UpdateState(DSchedContinueStateType stateType) 1363686862fbSopenharmony_ci{ 1364686862fbSopenharmony_ci if (stateMachine_ == nullptr) { 1365686862fbSopenharmony_ci HILOGE("stateMachine is null"); 1366686862fbSopenharmony_ci return; 1367686862fbSopenharmony_ci } 1368686862fbSopenharmony_ci stateMachine_->UpdateState(stateType); 1369686862fbSopenharmony_ci} 1370686862fbSopenharmony_ci 1371686862fbSopenharmony_civoid DSchedContinue::OnShutDown() 1372686862fbSopenharmony_ci{ 1373686862fbSopenharmony_ci} 1374686862fbSopenharmony_ci 1375686862fbSopenharmony_civoid DSchedContinue::OnBind() 1376686862fbSopenharmony_ci{ 1377686862fbSopenharmony_ci} 1378686862fbSopenharmony_ci} // namespace DistributedSchedule 1379686862fbSopenharmony_ci} // namespace OHOS 1380