From f5cbc49604173cada23a9210961b5a805a899564 Mon Sep 17 00:00:00 2001 From: dengxiaoyu Date: Wed, 10 Jul 2024 18:16:29 +0800 Subject: [PATCH] add ue dot Signed-off-by: dengxiaoyu --- services/dtbschedmgr/BUILD.gn | 1 + .../include/dfx/dms_continue_time_dumper.h | 2 + services/dtbschedmgr/include/distributed_ue.h | 75 ++++++ .../src/continue/dsched_continue.cpp | 7 + .../src/dfx/dms_continue_time_dumper.cpp | 5 + .../src/distributed_sched_service.cpp | 22 +- services/dtbschedmgr/src/distributed_ue.cpp | 238 ++++++++++++++++++ .../src/mission/dms_continue_recv_manager.cpp | 8 + 8 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 services/dtbschedmgr/include/distributed_ue.h create mode 100644 services/dtbschedmgr/src/distributed_ue.cpp diff --git a/services/dtbschedmgr/BUILD.gn b/services/dtbschedmgr/BUILD.gn index d67070e4..66f96fa7 100644 --- a/services/dtbschedmgr/BUILD.gn +++ b/services/dtbschedmgr/BUILD.gn @@ -125,6 +125,7 @@ ohos_shared_library("distributedschedsvr") { "src/distributed_sched_proxy.cpp", "src/distributed_sched_service.cpp", "src/distributed_sched_stub.cpp", + "src/distributed_ue.cpp", "src/dms_callback_task.cpp", "src/dms_free_install_callback.cpp", "src/dms_free_install_callback_proxy.cpp", diff --git a/services/dtbschedmgr/include/dfx/dms_continue_time_dumper.h b/services/dtbschedmgr/include/dfx/dms_continue_time_dumper.h index dff4de54..0c8ed4ac 100644 --- a/services/dtbschedmgr/include/dfx/dms_continue_time_dumper.h +++ b/services/dtbschedmgr/include/dfx/dms_continue_time_dumper.h @@ -96,6 +96,8 @@ public: void AppendInfo(); void ShowInfo(std::string& result); + int64_t GetTotalTime(); + private: bool isPull_; std::list timeInfoList_; diff --git a/services/dtbschedmgr/include/distributed_ue.h b/services/dtbschedmgr/include/distributed_ue.h new file mode 100644 index 00000000..27543720 --- /dev/null +++ b/services/dtbschedmgr/include/distributed_ue.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DISTRIBUTED_UE_H +#define OHOS_DISTRIBUTED_UE_H + +#include +#include +#include +#include + +#include "dsched_continue.h" +#include "dtbschedmgr_device_info_storage.h" +#include "dtbschedmgr_log.h" +#include "single_instance.h" + +namespace OHOS { +namespace DistributedSchedule { +const std::string CONTINUATION_BEHAVIOR = "CONTINUATION_BEHAVIOR"; +const std::string ERROR_CODE_UE = "ERROR_CODE_UE"; +const std::string PNAMEID = "PNAMEID"; +const std::string PVERSIONID = "PVERSIONID"; +const std::string BUNDLE_NAME = "BUNDLE_NAME"; +const std::string ABILITY_NAME = "ABILITY_NAME"; +const std::string SOURCE_DEVICE_TYPE = "SOURCE_DEVICE_TYPE"; + +const std::string CONTINUATION_STATE = "CONTINUATION_STATE"; +const std::string FAILED_EXTRAINFO = "FAILED_EXTRAINFO"; +const std::string CONTINUATION_DURATION = "CONTINUATION_DURATION"; + +const std::string SWITCH_STATE = "SWITCH_STATE"; + +const std::string SHOW_CONTINUATION_ICON = "SHOW_CONTINUATION_ICON"; +const std::string CLICK_CONTINUATION_ICON = "CLICK_CONTINUATION_ICON"; +const std::string COMPLETE_OF_CONTINUATION = "COMPLETE_OF_CONTINUATION"; +const std::string ORIGINAL_SWITCH_STATE = "ORIGINAL_SWITCH_STATE"; +const std::string CHANGED_SWITCH_STATE = "CHANGED_SWITCH_STATE"; + +constexpr char CONTINUATION_DOMAIN[] = "CONTINUATION_UE"; + +enum class continuationState : int32_t { + CONTINUATION_SUCC = 0; + CONTINUATION_FAIL = -1; +}; + +class DmsUE { + DECLARE_SINGLE_INSTANCE(DmsUE); +public: + bool NotifyDockShowIcon(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode); + bool TriggerDmsContinue(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode); + bool DmsContinueComplete(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode); + bool OriginalSwitchState(const std::string& switchState, int32_t errCode); + bool ChangedSwitchState(const std::string& switchState, int32_t errCode); + + int32_t GetDeviceTypeByNetworkId(std::string networkId); + std::string ConvertErrCodeToStr(int32_t errorCode); +}; +} // namespace DistributedSchedule +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_UE_H \ No newline at end of file diff --git a/services/dtbschedmgr/src/continue/dsched_continue.cpp b/services/dtbschedmgr/src/continue/dsched_continue.cpp index 8d46e7d0..8997c68a 100644 --- a/services/dtbschedmgr/src/continue/dsched_continue.cpp +++ b/services/dtbschedmgr/src/continue/dsched_continue.cpp @@ -29,6 +29,7 @@ #include "distributed_sched_permission.h" #include "distributed_sched_service.h" #include "distributed_sched_utils.h" +#include "distributed_ue.h" #include "dsched_continue_event.h" #include "dsched_continue_manager.h" #include "dsched_data_buffer.h" @@ -454,6 +455,9 @@ int32_t DSchedContinue::ExecuteContinueReq(std::shared_ptrGetMissionInfo("", missionId, missionInfo); + if (ret != ERR_OK) { + HILOGE("GeGetMissionInfo failed %{public}d", ret); + return ret; + } + std::string bundleName = missionInfo.want.GetElement().GetBundleName(); + std::string abilityName = missionInfo.want.GetElement().GetAbilityName(); + HILOGD("bundlename: %{public}s, ability is %{public}s", bundleName.c_str(), abilityName.c_str()); + DmsUE::GetInstance().TriggerDmsContinue(bundleName, abilityName, srcDeviceId, ERR_OK); + int32_t result = remoteDms->ContinueMission(srcDeviceId, dstDeviceId, missionId, callback, wantParams); HILOGI("ContinueRemoteMission result: %{public}d!", result); return result; @@ -1199,6 +1215,10 @@ void DistributedSchedService::NotifyCompleteContinuation(const std::u16string& d } int dSchedEventResult = dschedContinuation_->NotifyDSchedEventResult(ERR_OK); HILOGD("NotifyDSchedEventResult result:%{public}d", dSchedEventResult); + std::string bundleName = DmsContinueTime::GetInstance().GetDstInfo().bundleName; + std::string abilityName = DmsContinueTime::GetInstance().GetDstInfo().abilityName; + std::string srcNetworkId = dschedContinuation_->continueInfo_.srcNetworkId_; + DmsUE::GetInstance().DmsContinueComplete(bundleName, abilityName, srcNetworkId, dSchedEventResult); remoteDms->NotifyContinuationResultFromRemote(sessionId, isSuccess, dstInfo); dschedContinuation_->continueInfo_.srcNetworkId_ = ""; dschedContinuation_->continueInfo_.dstNetworkId_ = ""; diff --git a/services/dtbschedmgr/src/distributed_ue.cpp b/services/dtbschedmgr/src/distributed_ue.cpp new file mode 100644 index 00000000..91f5e23d --- /dev/null +++ b/services/dtbschedmgr/src/distributed_ue.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dfx/dms_continue_time_dumper.h" +#include "distributed_ue.h" +#include "dms_constant.h" + +#include "hisysevent.h" + +namespace OHOS { +namespace DistributedSchedule { +namespace { + const std::string TAG = "DmsUE"; + const std::string NO_FAILED_EXTRAINFO = "NULL"; + constexpr int32_t DEVICE_TYPE_UNKNOWN = 0; +} + +IMPLEMENT_SINGLE_INSTANCE(DmsUE); + +bool DmsUE::NotifyDockShowIcon(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode) +{ + int32_t res = ERR_OK; + if(errCode == ERR_OK) { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + SHOW_CONTINUATION_ICON, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId)); + } else { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + SHOW_CONTINUATION_ICON, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId) + ERROR_CODE_UE, errCode); + } + if (res != ERR_OK) { + HILOGE("NotifyDockShowIcon error, res:%{public}d", res); + return false; + } + return true; +} + +bool DmsUE::TriggerDmsContinue(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode) +{ + int32_t res = ERR_OK; + if (errCode == ERR_OK) { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + CLICK_CONTINUATION_ICON, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId)); + } else { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + CLICK_CONTINUATION_ICON, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId), + ERROR_CODE, errCode); + } + if (res != ERR_OK) { + HILOGE("TriggerDmsContinue error, res:%{public}d", res); + return false; + } + return true; +} + +bool DmsUE::DmsContinueComplete(const std::string& bundleName, const std::string& abilityName, + const std::string& networkId, int32_t errCode) +{ + int32_t res = ERR_OK; + if (errCode == ERR_OK) { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + COMPLETE_OF_CONTINUATION, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId), + CONTINUATION_STATE, static_cast(continuationState::CONTINUATION_SUCC), + FAILED_EXTRAINFO, NO_FAILED_EXTRAINFO, + CONTINUATION_DURATION, DmsContinueTime::GetInstance().GetTotalTime()); + } else { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + COMPLETE_OF_CONTINUATION, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + BUNDLE_NAME, bundleName, + ABILITY_NAME, abilityName, + SOURCE_DEVICE_TYPE, GetDeviceTypeByNetworkId(networkId), + CONTINUATION_STATE, static_cast(continuationState::CONTINUATION_FAIL), + FAILED_EXTRAINFO, ConvertErrCodeToStr(errCode), + CONTINUATION_DURATION, DmsContinueTime::GetInstance().GetTotalTime(), + ERROR_CODE, errCode); + } + if (res != ERR_OK) { + HILOGE("DmsContinueComplete error, res:%{public}d", res); + return false; + } + return true; +} + +bool DmsUE::OriginalSwitchState(const std::string& switchState, int32_t errCode) +{ + int32_t res = ERR_OK; + if (errCode == ERR_OK) { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + ORIGINAL_SWITCH_STATE, + HiviewDFX::HiSysEvent::EventType::STATISTIC, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + SWITCH_STATE, switchState); + } else { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + ORIGINAL_SWITCH_STATE, + HiviewDFX::HiSysEvent::EventType::STATISTIC, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + SWITCH_STATE, switchState, + ERROR_CODE, errCode); + } + if (res != ERR_OK) { + HILOGE("OriginalSwitchState error, res:%{public}d", res); + return false; + } + return true; +} + +bool DmsUE::ChangedSwitchState(const std::string& switchState, int32_t errCode) +{ + int32_t res = ERR_OK; + if (errCode == ERR_OK) { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + CHANGED_SWITCH_STATE, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + SWITCH_STATE, switchState); + } else { + res = HiSysEventWrite( + CONTINUATION_DOMAIN, + CHANGED_SWITCH_STATE, + HiviewDFX::HiSysEvent::EventType::BEHAVIOR, + PNAMEID, CONTINUATION_DOMAIN, + PVERSIONID, Constants::DMS_VERSION, + SWITCH_STATE, switchState, + ERROR_CODE, errCode); + } + if (res != ERR_OK) { + HILOGE("ChangedSwitchState error, res:%{public}d", res); + return false; + } + return true; +} + +int32_t DmsUE::GetDeviceTypeByNetworkId(int32_t networkId) +{ + auto deviceInfo = DtbschedmgrDeviceInfoStorage::GetInstance().GetDeviceInfoById(networkId); + if (deviceInfo == nullptr) { + return DEVICE_TYPE_UNKNOWN; + } + return deviceInfo->GetDeviceType(); +} + +std::string DmsUE::ConvertErrCodeToStr(int32_t errorCode) +{ + switch(errorCode) { + case INVALID_PARAMETERS_ERR: + return "invalid parameters"; + case INVALID_REMOTE_PARAMETERS_ERR: + return "remote invalid parameters"; + case DMS_START_CONTROL_PERMISSION_DENIED: + return "start control permission check failed"; + case NO_MISSION_INFO_FOR_MISSION_ID: + return "failed to get the missionInfo of the specified missionId"; + case OPERATION_DEVICE_NOT_INITIATOR_OR_TARGET: + return "the operation device must be the target device to be continued"; + case CONTINUE_ALREADY_IN_PROGRESS: + return "the local continuation task is already in progress"; + case MISSION_FOR_CONTINUING_IS_NOT_ALIVE: + return "the mission for continuing is not alive, try again after restart mission."; + case CONTINUE_SEND_EVENT_FAILED: + return "sending event failed during continuation"; + case CONTINUE_STATE_MACHINE_INVALID_STATE: + return "state machine receving invalid state code"; + case CONTINUE_SESSION_SHUTDOWN: + return "session shutdown during continuation"; + case CONTINUE_CALL_CONTINUE_ABILITY_FAILED: + return "calling ContinueAbility failed during continuation"; + case CONTINUE_CALL_START_ABILITY_FAILED: + return "calling StartAbility failed during continuation"; + case CONTINUE_SINK_ABILITY_TERMINATED: + return "sink Ability abnormal termination during continuation"; + case DMS_CONNECT_APPLY_REJECT_FAILED: + return "all connect manager reject connect apply"; + default: + return "internal error"; + } +} +} // namespace DistributedSchedule +} // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp index 5c63e2c9..7514ffee 100644 --- a/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp +++ b/services/dtbschedmgr/src/mission/dms_continue_recv_manager.cpp @@ -24,6 +24,7 @@ #include "distributed_sched_adapter.h" #include "dtbschedmgr_device_info_storage.h" #include "dtbschedmgr_log.h" +#include "distributed_ue.h" #include "parcel_helper.h" #include "softbus_adapter/softbus_adapter.h" #include "switch_status_dependency.h" @@ -331,6 +332,13 @@ void DMSContinueRecvMgr::NotifyRecvBroadcast(const sptr& obj, if (!res) { HILOGE("%{public}s failed", (state == INACTIVE) ? "NotifyDockUnfocused" : "NotifyDockFocused"); } + if (state != INACTIVE) { + std::string bName = bundleName; + std::string cType = continueType; + std::string abilityName = BundleDistributedManager::GetInstance().GetAbilityName(netwokId, + bName, cType) + DmsUE::GetInstance().NotifyDockShowIcon(bundleName, abilityName, networkId, error); + } if (error != ERR_NONE) { HILOGE("NotifyRecvBroadcast fail, error: %{public}d", error); return;