diff --git a/bundle.json b/bundle.json index 48740ca203f85043155fbe69be496540002fddb8..3ee4f2b4ff258589f420a71f34afa3f5fcc38f79 100644 --- a/bundle.json +++ b/bundle.json @@ -119,7 +119,6 @@ } ], "test": [ - "//foundation/deviceprofile/device_info_manager/old/radar/test/unittest:dp_radar_helper_test_old", "//foundation/deviceprofile/device_info_manager/old/services/core:unittest", "//foundation/deviceprofile/device_info_manager/radar/test/unittest:dp_radar_helper_test_new", "//foundation/deviceprofile/device_info_manager/services/core:unittest", diff --git a/old/common/include/device_profile_errors.h b/old/common/include/device_profile_errors.h index fabffb6e5fc123bc5c7ace9f78beb472ebc615c7..759ae519b676f022830f238563bc0df4ffaf4c8d 100644 --- a/old/common/include/device_profile_errors.h +++ b/old/common/include/device_profile_errors.h @@ -45,10 +45,6 @@ enum { ERR_DP_GET_NETWORKID_FAILED = 98566158, ERR_DP_FILE_FAILED_ERR = 98566159, ERR_DP_LOAD_SERVICE_ERR = 98566160, - ERR_DP_GET_DATA_FAILED = 98566161, - ERR_DP_DELETE_DATA_FAILED = 98566162, - ERR_DP_ADD_DATA_FAILED = 98566163, - ERR_DP_SYNC_DATA_FAILED = 98566164, }; } // namespace DeviceProfile } // namespace OHOS diff --git a/old/interfaces/innerkits/core/BUILD.gn b/old/interfaces/innerkits/core/BUILD.gn index f64ed40adaaf5a2cfa2a484f0187d3f5286c758b..c98e5f086ec0729ba35e1ccca27ba373833d0d16 100644 --- a/old/interfaces/innerkits/core/BUILD.gn +++ b/old/interfaces/innerkits/core/BUILD.gn @@ -64,8 +64,6 @@ ohos_shared_library("distributed_device_profile_client") { "${old_device_profile_test}/resource:coverage_flags", ] - deps = [ "${old_device_profile_path}/radar:deviceprofileradar" ] - external_deps = [ "c_utils:utils", "eventhandler:libeventhandler", diff --git a/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index 7dbe3e01a2bd2faf2b3acd127e1202021673e3f4..b303a5639627494590dc62412909688959906f0b 100644 --- a/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -30,7 +30,6 @@ #include "callback/device_profile_load_callback.h" #include "device_profile_errors.h" #include "device_profile_log.h" -#include "dp_radar_helper.h" #include "event_handler.h" #include "event_runner.h" #include "idistributed_device_profile.h" @@ -70,18 +69,6 @@ bool DistributedDeviceProfileClient::LoadDeviceProfileService() } int32_t ret = samgrProxy->LoadSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, loadCallback); - struct RadarInfo info = { - .funcName = "LoadDeviceProfileService", - .stageRes = (ret == ERR_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (ret == ERR_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .toCallPkg = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSa(info)) { - HILOGE("ReportLoadDpSa failed"); - } if (ret != ERR_OK) { HILOGE("Failed to Load systemAbility"); return false; @@ -99,14 +86,6 @@ bool DistributedDeviceProfileClient::LoadDeviceProfileService() void DistributedDeviceProfileClient::LoadSystemAbilitySuccess(const sptr &remoteObject) { HILOGI("DistributedDeviceProfileClient FinishStartSA"); - struct RadarInfo info = { - .funcName = "LoadSystemAbilitySuccess", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .hostName = SAMAGRNAME, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSaCb(info)) { - HILOGE("ReportLoadDpSaCb failed"); - } std::lock_guard lock(serviceLock_); if (dpDeathRecipient_ == nullptr) { dpDeathRecipient_ = sptr( @@ -121,16 +100,6 @@ void DistributedDeviceProfileClient::LoadSystemAbilitySuccess(const sptr(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .hostName = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSaCb(info)) { - HILOGE("ReportLoadDpSaCb failed"); - } std::lock_guard lock(serviceLock_); dpProxy_ = nullptr; } @@ -309,17 +278,6 @@ sptr DistributedDeviceProfileClient::GetDeviceProfile return nullptr; } auto object = samgrProxy->CheckSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID); - struct RadarInfo info = { - .funcName = "GetDeviceProfileService", - .stageRes = (object != nullptr) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_START), - .toCallPkg = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportCheckDpSa(info)) { - HILOGE("ReportCheckDpSa failed"); - } if (object != nullptr) { HILOGI("get service succeeded"); if (dpDeathRecipient_ == nullptr) { diff --git a/old/radar/BUILD.gn b/old/radar/BUILD.gn deleted file mode 100644 index 71f387807428900441aa67545a08ae3da6963f85..0000000000000000000000000000000000000000 --- a/old/radar/BUILD.gn +++ /dev/null @@ -1,52 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -ohos_shared_library("deviceprofileradar") { - branch_protector_ret = "pac_ret" - - cflags = [ - "-fstack-protector-strong", - "-D_FORTIFY_SOURCE=2", - "-O2", - ] - - cflags_cc = cflags - - sanitize = { - boundary_sanitize = true - integer_overflow = true - ubsan = true - cfi = true - cfi_cross_dso = true - debug = false - } - - include_dirs = [ - "include", - "${old_device_profile_path}/common/include", - ] - - sources = [ "src/dp_radar_helper.cpp" ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "hisysevent:libhisysevent", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/radar/include/dp_radar_helper.h b/old/radar/include/dp_radar_helper.h deleted file mode 100644 index 1e84ba8b9aeeaac3aa5f4e9c009510de485c241f..0000000000000000000000000000000000000000 --- a/old/radar/include/dp_radar_helper.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * 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_DP_RADAR_HELPER_H -#define OHOS_DP_RADAR_HELPER_H - -#include -#include -#include -#include -#include - -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -const std::string ORGPKGNAME = "deviceprofile"; -const std::string SAMAGRNAME = "SA"; -const std::string kvNAME = "distrubitedKv"; -const std::string DP_DATA_OPERATE_BEHAVIOR = "DP_DATA_OPERATE_BEHAVIOR"; -const int32_t SUBSYS_DISTRIBUTEDHARDWARE_DP = 205; -constexpr int32_t INVALID_UDID_LENGTH = 10; -constexpr int32_t SUBSTR_UDID_LENGTH = 5; -enum class BizScene : int32_t { - DP_GET_SA = 0x1, - DP_ADD_DATA = 0x2, - DP_DELET_DATA = 0x3, - DP_GET_DATA = 0x4, - DP_SUBSCRIBE_DATA = 0x5, - DP_UNSUBSCRIBE_DATA = 0x6, - DP_SYNC_DATA = 0x7, -}; - -enum class StageRes : int32_t { - STAGE_IDLE = 0x0, - STAGE_SUCC = 0x1, - STAGE_FAIL = 0x2, - STAGE_CANCEL = 0x3, - STAGE_UNKNOW = 0x4, -}; - -enum class BizState : int32_t { - BIZ_STATE_START = 0x1, - BIZ_STATE_END = 0x2, - BIZ_STATE_CANCEL = 0x3, -}; - -enum class GetSaStage : int32_t { - DP_CHECK_SA = 0x1, - DP_LOAD_SA = 0x2, - DP_SA_CHACK_AUTH = 0x3, -}; - -enum class GetDataStage : int32_t { - DP_GET_DATA = 0x1, -}; - -enum class AddDataStage : int32_t { - DP_ADD_DATA = 0x1, -}; - -enum class DelDataStage : int32_t { - DP_DELET_DATA = 0x1, -}; - -enum class SubscribeDataStage : int32_t { - DP_SUBSCRIBE_DATA = 0x1, - DP_RECIVE_DATA_CHANGE = 0x2, -}; - -enum class UnSubscribeDataStage : int32_t { - DP_UNSUBSCRIBE_DATA = 0x1, -}; - -enum class SyncDataStage : int32_t { - DP_SYNC_DATA = 0x1, - DP_RECIVE_SYNC_CALLBACK = 0x2, -}; - -enum class Module : int32_t { - DEVICE_PROFILE = 0x0, - SA_MGR = 0x1, - DISTRIBUTED_KV = 0x2, -}; - -struct RadarInfo { - std::string funcName; - int32_t stageRes; - int32_t bizState; - std::string toCallPkg; - std::string hostName; - std::string localUdid; - std::string peerUdid; - int32_t errCode; -}; - -class DpRadarHelper { - DECLARE_SINGLE_INSTANCE(DpRadarHelper); -public: - bool ReportCheckDpSa(struct RadarInfo info); - bool ReportLoadDpSa(struct RadarInfo info); - bool ReportLoadDpSaCb(struct RadarInfo info); - bool ReportSaCheckAuth(struct RadarInfo info); - bool ReportGetData(struct RadarInfo info); - bool ReportAddData(struct RadarInfo info); - bool ReportDeleteData(struct RadarInfo info); - bool ReportSubscribeData(struct RadarInfo info); - bool ReportNotifyDataChange(struct RadarInfo info); - bool ReportUnsbscribeData(struct RadarInfo info); - bool ReportSyncData(struct RadarInfo info); - bool ReportSyncDataCb(struct RadarInfo info); - std::string GetHostNameByServiceId(std::string serviceId); - std::string GetStringUdidList(std::list &udidList); -private: - int32_t GetErrorCode(int32_t errCode, int32_t module); - std::string GetAnonyUdid(std::string udid); - std::map hostNameMap_ = { - {"infoCollection", "CollaborationFwk"}, - {"pasteboardService", "pasteboardService"}, - {"appInfo", "dmsfwk"}, - {"deviceStatus", "msdp"}, - }; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_RADAR_HELPER_H \ No newline at end of file diff --git a/old/radar/src/dp_radar_helper.cpp b/old/radar/src/dp_radar_helper.cpp deleted file mode 100644 index 21283385db5a2e8c2c3eebae4b8f68ce0f7ead27..0000000000000000000000000000000000000000 --- a/old/radar/src/dp_radar_helper.cpp +++ /dev/null @@ -1,457 +0,0 @@ -/* - * 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 "dp_radar_helper.h" -#include -#include "hisysevent.h" -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -IMPLEMENT_SINGLE_INSTANCE(DpRadarHelper); -bool DpRadarHelper::ReportCheckDpSa(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_CHECK_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_CHECK_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportLoadDpSa(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportLoadDpSaCb(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "HOST_NAME", info.hostName); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "HOST_NAME", info.hostName, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSaCheckAuth(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_SA_CHACK_AUTH), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_SA_CHACK_AUTH), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportGetData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_DATA), - "BIZ_STAGE", static_cast(GetDataStage::DP_GET_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_DATA), - "BIZ_STAGE", static_cast(GetDataStage::DP_GET_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportAddData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_ADD_DATA), - "BIZ_STAGE", static_cast(AddDataStage::DP_ADD_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_ADD_DATA), - "BIZ_STAGE", static_cast(AddDataStage::DP_ADD_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportDeleteData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_DELET_DATA), - "BIZ_STAGE", static_cast(static_cast(DelDataStage::DP_DELET_DATA)), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_DELET_DATA), - "BIZ_STAGE", static_cast(static_cast(DelDataStage::DP_DELET_DATA)), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSubscribeData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SubscribeProfileEvents", - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_SUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_START), - "TO_CALL_PKG", kvNAME); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SubscribeProfileEvents", - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_SUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "TO_CALL_PKG", kvNAME, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportNotifyDataChange(struct RadarInfo info) -{ - int32_t res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_RECIVE_DATA_CHANGE), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END)); - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportUnsbscribeData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_UNSUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(UnSubscribeDataStage::DP_UNSUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_UNSUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(UnSubscribeDataStage::DP_UNSUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSyncData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SyncDeviceProfile", - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_SYNC_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_START), - "HOST_PKG", info.hostName, - "PEER_UDID", GetAnonyUdid(info.peerUdid), - "TO_CALL_PKG", kvNAME); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SyncDeviceProfile", - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_SYNC_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "PEER_UDID", GetAnonyUdid(info.peerUdid), - "TO_CALL_PKG", kvNAME, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSyncDataCb(struct RadarInfo info) -{ - int32_t res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_RECIVE_SYNC_CALLBACK), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - if (res != ERR_OK) { - return false; - } - return true; -} - -std::string DpRadarHelper::GetHostNameByServiceId(std::string serviceId) -{ - return hostNameMap_[serviceId]; -} - -std::string DpRadarHelper::GetStringUdidList(std::list &udidList) -{ - std::string ret = ""; - for (auto it = udidList.begin(); it != udidList.end(); it++) { - if ((*it).compare(udidList.back()) == 0) { - ret += GetAnonyUdid(*it); - } else { - ret += GetAnonyUdid(*it); - ret += ","; - } - } - return ret; -} - -int32_t DpRadarHelper::GetErrorCode(int32_t errCode, int32_t module) -{ - return ErrCodeOffset(SUBSYS_DISTRIBUTEDHARDWARE_DP, module) + errCode; -} - -std::string DpRadarHelper::GetAnonyUdid(std::string udid) -{ - if (udid.empty() || udid.length() < INVALID_UDID_LENGTH) { - return ""; - } - return udid.substr(0, SUBSTR_UDID_LENGTH) + "**" + udid.substr(udid.length() - SUBSTR_UDID_LENGTH); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/radar/test/unittest/BUILD.gn b/old/radar/test/unittest/BUILD.gn deleted file mode 100644 index 05f601f840928337e18d64c1d7d8783776de88fb..0000000000000000000000000000000000000000 --- a/old/radar/test/unittest/BUILD.gn +++ /dev/null @@ -1,41 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -module_output_path = "device_info_manager/deviceprofiletest" - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_path}/radar:deviceprofileradar", - "${old_device_profile_service}/core:distributed_device_profile", -] - -device_profile_external_deps = [ "hisysevent:libhisysevent" ] - -ohos_unittest("dp_radar_helper_test_old") { - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] - module_out_path = module_output_path - include_dirs = [ "${old_device_profile_path}/radar/include" ] - sources = [ "dp_radar_helper_test.cpp" ] - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/radar/test/unittest/dp_radar_helper_test.cpp b/old/radar/test/unittest/dp_radar_helper_test.cpp deleted file mode 100644 index 6ec00106d1db80631458825523f2e83e44eac8da..0000000000000000000000000000000000000000 --- a/old/radar/test/unittest/dp_radar_helper_test.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - * 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 "dp_radar_helper_test.h" -#include "dp_radar_helper.h" - -namespace OHOS { -namespace DeviceProfile { -void DpRadarHelperTest::SetUp() -{ -} - -void DpRadarHelperTest::TearDown() -{ -} - -void DpRadarHelperTest::SetUpTestCase() -{ -} - -void DpRadarHelperTest::TearDownTestCase() -{ -} - -HWTEST_F(DpRadarHelperTest, ReportCheckDpSa_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportCheckDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportCheckDpSa_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_CANCEL); - bool res = DpRadarHelper::GetInstance().ReportCheckDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSa_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSa_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSaCb_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_CANCEL); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSaCb(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportLoadDpSaCb_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSaCb(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSaCheckAuth_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSaCheckAuth(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSaCheckAuth_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSaCheckAuth(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportGetData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportGetData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportGetData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportGetData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportAddData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportAddData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportAddData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportAddData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportDeleteData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportDeleteData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportDeleteData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportDeleteData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSubscribeData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSubscribeData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportSubscribeData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSubscribeData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportNotifyDataChange_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportNotifyDataChange(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportUnsbscribeData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportUnsbscribeData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportUnsbscribeData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportUnsbscribeData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSyncData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSyncData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncDataCb_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSyncDataCb(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, GetAnonyUdid_001, testing::ext::TestSize.Level0) -{ - std::string udid = ""; - std::string res = DpRadarHelper::GetInstance().GetAnonyUdid(udid); - EXPECT_EQ(res, ""); - - udid = "1234567890abcdef"; - res = DpRadarHelper::GetInstance().GetAnonyUdid(udid); - EXPECT_EQ(res, "12345**bcdef"); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/radar/test/unittest/dp_radar_helper_test.h b/old/radar/test/unittest/dp_radar_helper_test.h deleted file mode 100644 index e8670d7eaa37869e1777372b84e914a649c51944..0000000000000000000000000000000000000000 --- a/old/radar/test/unittest/dp_radar_helper_test.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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_DP_RADAR_HELPER_TEST_H -#define OHOS_DP_RADAR_HELPER_TEST_H - -#include -#include - -namespace OHOS { -namespace DeviceProfile { -class DpRadarHelperTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_RADAR_HELPER_TEST_H diff --git a/old/services/core/BUILD.gn b/old/services/core/BUILD.gn index 3818c349c09680aa8a1ce83a220b28b76bcf9680..37e788816f988483c0a6d1c0bf303195c61d163b 100644 --- a/old/services/core/BUILD.gn +++ b/old/services/core/BUILD.gn @@ -115,7 +115,6 @@ ohos_shared_library("distributed_device_profile") { deps = [ "${device_profile_common}:distributed_device_profile_common", "${device_profile_service}:distributed_device_profile_svr", - "${old_device_profile_path}/radar:deviceprofileradar", ] external_deps = [ diff --git a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp index 6138571c13a0cb922bd521678e10160aa4d59770..f3788a244399becd055b17895f3b48a99d844858 100644 --- a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp +++ b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp @@ -22,7 +22,6 @@ #include "device_profile_log.h" #include "device_profile_utils.h" #include "dp_device_manager.h" -#include "dp_radar_helper.h" #include "hisysevent.h" #include "hitrace_meter.h" #include "sync_coordinator.h" @@ -176,18 +175,6 @@ int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristi profileItems_[keys[i]] = values[i]; } } - struct RadarInfo info = { - .funcName = "PutDeviceProfile", - .stageRes = (errCode == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - .errCode = ERR_DP_ADD_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportAddData(info)) { - HILOGE("ReportAddData failed"); - } return errCode; } @@ -228,18 +215,6 @@ int32_t DeviceProfileStorageManager::GetDeviceProfile(const std::string& udid, autoLock.unlock(); result = onlineSyncTbl_->GetDeviceProfile(udid, key, value); } - struct RadarInfo info = { - .funcName = "GetDeviceProfile", - .stageRes = (result == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - .errCode = ERR_DP_GET_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportGetData(info)) { - HILOGE("ReportGetData failed"); - } profile.SetServiceId(serviceId); profile.SetCharacteristicProfileJson(value); return result; @@ -300,12 +275,6 @@ int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serv std::string servicesValue = servicesJson_.dump(); int32_t errCode = ERR_OK; std::string serviceKey = GenerateKey(localUdid_, serviceId, KeyType::SERVICE); - struct RadarInfo info = { - .funcName = "DeleteDeviceProfile", - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - }; if (onlineSyncTbl_ != nullptr && onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_SUCCEED) { errCode = onlineSyncTbl_->DeleteDeviceProfile(serviceKey); if (errCode != ERR_OK) { @@ -313,20 +282,13 @@ int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serv return errCode; } errCode = onlineSyncTbl_->PutDeviceProfile(servicesKey, servicesValue); - info.stageRes = (errCode == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL); - info.errCode = ERR_DP_DELETE_DATA_FAILED; if (errCode != ERR_OK) { HILOGW("update services failed, errorCode = %{public}d", errCode); } } else { - info.stageRes = static_cast(StageRes::STAGE_SUCC); profileItems_.erase(serviceKey); profileItems_[servicesKey] = std::move(servicesValue); } - if (!DpRadarHelper::GetInstance().ReportDeleteData(info)) { - HILOGE("ReportDeleteData failed"); - } return errCode; } @@ -396,17 +358,6 @@ int32_t DeviceProfileStorageManager::SyncDeviceProfile(const SyncOptions& syncOp SyncCoordinator::GetInstance().SetSyncTrigger(false); std::vector devicesVector(std::vector { devicesList.begin(), devicesList.end() }); int32_t result = onlineSyncTbl_->SyncDeviceProfile(devicesVector, syncOptions.GetSyncMode()); - struct RadarInfo info = { - .stageRes = (result == ERR_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (result == ERR_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .peerUdid = DpRadarHelper::GetInstance().GetStringUdidList(devicesList), - .errCode = ERR_DP_SYNC_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportSyncData(info)) { - HILOGE("ReportSyncData failed"); - } if (result != ERR_OK) { ReportFaultEvent(DP_SYNC_FAILED, FAULT_CODE_KEY, result); HILOGE("sync failed result : %{public}d", result); diff --git a/old/services/core/src/distributed_device_profile_service.cpp b/old/services/core/src/distributed_device_profile_service.cpp index 07c8fa2b7487d131f3ef2434a9ec1446f62203a5..a733c8a6de02530f4f45ce4c971da68cb10a4770 100644 --- a/old/services/core/src/distributed_device_profile_service.cpp +++ b/old/services/core/src/distributed_device_profile_service.cpp @@ -26,7 +26,6 @@ #include "device_profile_storage_manager.h" #include "distributed_device_profile_service_new.h" #include "dp_device_manager.h" -#include "dp_radar_helper.h" #include "event_handler_factory.h" #include "hitrace_meter.h" #include "if_system_ability_manager.h" @@ -83,19 +82,8 @@ bool DistributedDeviceProfileService::Init() int32_t DistributedDeviceProfileService::PutDeviceProfile(const ServiceCharacteristicProfile& profile) { - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - profile.GetServiceId()); - struct RadarInfo info = { - .funcName = "PutDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { + if (!AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, + profile.GetServiceId())) { return ERR_DP_PERMISSION_DENIED; } return DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); @@ -117,19 +105,8 @@ void DistributedDeviceProfileService::DeviceOnline() int32_t DistributedDeviceProfileService::GetDeviceProfile(const std::string& udid, const std::string& serviceId, ServiceCharacteristicProfile& profile) { - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, - serviceId); - struct RadarInfo info = { - .funcName = "GetDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { + if (!AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, + serviceId)) { return ERR_DP_PERMISSION_DENIED; } return DeviceProfileStorageManager::GetInstance().GetDeviceProfile(udid, serviceId, profile); @@ -137,19 +114,8 @@ int32_t DistributedDeviceProfileService::GetDeviceProfile(const std::string& udi int32_t DistributedDeviceProfileService::DeleteDeviceProfile(const std::string& serviceId) { - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - serviceId); - struct RadarInfo info = { - .funcName = "DeleteDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { + if (!AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, + serviceId)) { return ERR_DP_PERMISSION_DENIED; } return DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile(serviceId); @@ -160,14 +126,6 @@ int32_t DistributedDeviceProfileService::SubscribeProfileEvents(const std::list< std::list& failedEvents) { HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SUB_TRACE); - struct RadarInfo info = { - .funcName = "SubscribeProfileEvents", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } return SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos, profileEventNotifier, failedEvents); } @@ -176,14 +134,6 @@ int32_t DistributedDeviceProfileService::UnsubscribeProfileEvents(const std::lis const sptr& profileEventNotifier, std::list& failedEvents) { - struct RadarInfo info = { - .funcName = "UnsubscribeProfileEvents", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } return SubscribeManager::GetInstance().UnsubscribeProfileEvents(profileEvents, profileEventNotifier, failedEvents); } @@ -191,18 +141,7 @@ int32_t DistributedDeviceProfileService::UnsubscribeProfileEvents(const std::lis int32_t DistributedDeviceProfileService::SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) { - bool ret = AuthorityManager::GetInstance().CheckInterfaceAuthority("sync"); - struct RadarInfo info = { - .funcName = "SyncDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { + if (!AuthorityManager::GetInstance().CheckInterfaceAuthority("sync")) { return ERR_DP_PERMISSION_DENIED; } return DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, profileEventNotifier); diff --git a/old/services/core/src/subscribemanager/profile_change_handler.cpp b/old/services/core/src/subscribemanager/profile_change_handler.cpp index aa5a769672230ac9d6b3de01a91ed1cae7b6bb8c..9f5e48444d8da3f3ed21570cafef87f9b420f3c4 100644 --- a/old/services/core/src/subscribemanager/profile_change_handler.cpp +++ b/old/services/core/src/subscribemanager/profile_change_handler.cpp @@ -25,7 +25,6 @@ #include "device_profile_log.h" #include "device_profile_storage_manager.h" #include "device_profile_utils.h" -#include "dp_radar_helper.h" #include "profile_change_notification.h" namespace OHOS { @@ -156,14 +155,6 @@ void ProfileChangeHandler::NotifyProfileChanged(const ProfileChangeNotification& HILOGD("called"); std::lock_guard autoLock(notifierLock_); HILOGI("subscribers size = %{public}zu", profileEventSubscribeInfos_.size()); - struct RadarInfo info = { - .funcName = "NotifyProfileChanged", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .hostName = kvNAME, - }; - if (!DpRadarHelper::GetInstance().ReportNotifyDataChange(info)) { - HILOGE("ReportNotifyDataChange failed"); - } for (const auto& [notifier, subscribeInfo] : profileEventSubscribeInfos_) { sptr profileEventNotifier = iface_cast(notifier); if (profileEventNotifier == nullptr) { diff --git a/old/services/core/src/subscribemanager/profile_sync_handler.cpp b/old/services/core/src/subscribemanager/profile_sync_handler.cpp index bf6d4304c009ce63bd0da23103c9a6b0bbe8e7a9..88c58ce64383791d08b72f0ba534867aaedaff18 100644 --- a/old/services/core/src/subscribemanager/profile_sync_handler.cpp +++ b/old/services/core/src/subscribemanager/profile_sync_handler.cpp @@ -18,7 +18,6 @@ #include "device_profile_log.h" #include "device_profile_storage_manager.h" #include "device_profile_utils.h" -#include "dp_radar_helper.h" #include "subscribe_manager.h" namespace OHOS { @@ -51,15 +50,6 @@ void ProfileSyncHandler::SyncCompleted(const std::map& resu void ProfileSyncHandler::NotifySyncCompleted(const SyncResult& syncResults) { - struct RadarInfo info = { - .funcName = "NotifySyncCompleted", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - .hostName = kvNAME, - }; - if (!DpRadarHelper::GetInstance().ReportSyncDataCb(info)) { - HILOGE("ReportSyncDataCb failed"); - } { std::lock_guard autoLock(notifierLock_); HILOGI("profileEventSubscribeInfos size %{public}zu", profileEventSubscribeInfos_.size()); diff --git a/old/services/core/src/subscribemanager/subscribe_manager.cpp b/old/services/core/src/subscribemanager/subscribe_manager.cpp index a3bca60ba975a256f947c7ba84af92c2019bcb15..9811d0536e082874bb3fec9c79c7d70529bec9b1 100644 --- a/old/services/core/src/subscribemanager/subscribe_manager.cpp +++ b/old/services/core/src/subscribemanager/subscribe_manager.cpp @@ -21,7 +21,6 @@ #include "device_profile_errors.h" #include "device_profile_log.h" #include "device_profile_storage_manager.h" -#include "dp_radar_helper.h" #include "profile_change_handler.h" #include "profile_event_handler_factory.h" #include "subscribe_info_checker.h" @@ -93,14 +92,6 @@ int32_t SubscribeManager::SubscribeProfileEvents(const std::list& if (!subProfileEvents.none()) { TryAddNotifierLocked(profileEventNotifier, subProfileEvents); } - struct RadarInfo info = { - .stageRes = failedEvents.empty() ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .errCode = ERR_DP_SUBSCRIBE_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportSubscribeData(info)) { - HILOGE("ReportSubscribeData failed"); - } return failedEvents.empty() ? ERR_OK : ERR_DP_SUBSCRIBE_FAILED; } @@ -128,16 +119,6 @@ int32_t SubscribeManager::UnsubscribeProfileEvents(const std::list if (!unsubProfileEvents.none()) { TryRemoveNotiferLocked(profileEventNotifier, unsubProfileEvents); } - struct RadarInfo info = { - .funcName = "UnsubscribeProfileEvents", - .stageRes = failedEvents.empty() ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .errCode = ERR_DP_UNSUBSCRIBE_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportUnsbscribeData(info)) { - HILOGE("ReportUnsbscribeData failed"); - } return failedEvents.empty() ? ERR_OK : ERR_DP_UNSUBSCRIBE_FAILED; } diff --git a/old/tools/dp/BUILD.gn b/old/tools/dp/BUILD.gn deleted file mode 100644 index cae14f4db8ac06d1ef514159c951a8a210cc513b..0000000000000000000000000000000000000000 --- a/old/tools/dp/BUILD.gn +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2021-2023 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -config("dp_tools_config") { - visibility = [ ":*" ] - include_dirs = [ "include" ] -} - -ohos_executable("dp") { - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - install_enable = true - - configs = [ - ":dp_tools_config", - "${old_device_profile_test}/resource:coverage_flags", - ] - - sources = [ - "src/dp_command.cpp", - "src/main.cpp", - "src/shell_command.cpp", - ] - - deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - ] - external_deps = [ - "c_utils:utils", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/tools/dp/include/dp_command.h b/old/tools/dp/include/dp_command.h deleted file mode 100644 index 0756dce8c6fa33312779f180c6a521713cd87fb9..0000000000000000000000000000000000000000 --- a/old/tools/dp/include/dp_command.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021 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 DEVICE_PROFILE_DP_COMMAND_H -#define DEVICE_PROFILE_DP_COMMAND_H - -#include -#include -#include - -#include "device_profile_log.h" -#include "errors.h" -#include "iprofile_event_callback.h" -#include "shell_command.h" - -namespace OHOS { -namespace DeviceProfile { -class DpShellCommand : public OHOS::DeviceProfile::ShellCommand { -public: - DpShellCommand(int argc, char *argv[]); - ~DpShellCommand() override {} - -private: - ErrCode CreateCommandMap() override; - ErrCode CreateMessageMap() override; - ErrCode init() override; - - ErrCode HelpCommand(); - ErrCode GetDeviceCommand(); - ErrCode QueryCommand(); - ErrCode PutCommand(); - ErrCode DeleteCommand(); - ErrCode SyncCommand(); - ErrCode SubscribeCommand(); - - int32_t HandleUnknownOption(char optopt); - int32_t HandleNormalOption(int option, std::string& deviceId, - std::string& serviceId, std::string& serviceType); - int32_t HandleSyncOption(int option, std::string& mode, - std::list& deviceIds); - int32_t HandleSubscribeOption(int option, std::string& deviceId, - std::list& serviceIds); -}; - -class ProfileEventCallback : public IProfileEventCallback { -public: - void OnSyncCompleted(const SyncResult& syncResults) override; - void OnProfileChanged(const ProfileChangeNotification& changeNotification) override; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // DEVICE_PROFILE_DP_COMMAND_H \ No newline at end of file diff --git a/old/tools/dp/include/shell_command.h b/old/tools/dp/include/shell_command.h deleted file mode 100644 index 3eb7b39ebc4bae6c95fd9e193be4a382ae636918..0000000000000000000000000000000000000000 --- a/old/tools/dp/include/shell_command.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 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 DEVICE_PROFILE_SHELL_COMMAND_H -#define DEVICE_PROFILE_SHELL_COMMAND_H - -#include -#include -#include -#include -#include -#include -#include - -#include "errors.h" - -namespace OHOS { -namespace DeviceProfile { -class ShellCommand { -public: - ShellCommand(int argc, char *argv[], std::string name); - virtual ~ShellCommand() = default; - - ErrCode OnCommand(); - std::string ExecCommand(); - std::string GetCommandErrorMsg() const; - std::string GetUnknownOptionMsg(std::string &unknownOption) const; - std::string GetMessageFromCode(int32_t code) const; - - virtual ErrCode CreateCommandMap() = 0; - virtual ErrCode CreateMessageMap() = 0; - virtual ErrCode init() = 0; - -protected: - static constexpr int MIN_ARGUMENT_NUMBER = 2; - - int argc_; - char **argv_; - - std::string cmd_; - std::vector argList_; - - std::string name_; - std::map> commandMap_; - std::map messageMap_; - - std::string resultReceiver_ = ""; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // DEVICE_PROFILE_SHELL_COMMAND_H \ No newline at end of file diff --git a/old/tools/dp/src/dp_command.cpp b/old/tools/dp/src/dp_command.cpp deleted file mode 100644 index 82024660505a6d2f7ff235a0146d9f51b71dbc16..0000000000000000000000000000000000000000 --- a/old/tools/dp/src/dp_command.cpp +++ /dev/null @@ -1,489 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "dp_command.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "device_profile_log.h" -#include "distributed_device_profile_client.h" -#include "iprofile_event_notifier.h" -#include "nlohmann/json.hpp" -#include "nlohmann/json_fwd.hpp" -#include "profile_event.h" -#include "service_characteristic_profile.h" -#include "softbus_bus_center.h" -#include "subscribe_info.h" -#include "sync_options.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DpShellCommand"; -const std::string DP_TOOL_NAME = "dp"; -const std::string DP_HELP_MSG = "usage: dp \n" - "These are common dp commands list:\n" - " help list available commands\n" - " getDevice list all devices\n" - " query query device info with options\n" - " put put device info with options\n" - " sync sync device info with options\n" - " delete delete device info with options\n" - " subscribe subscribe device info with options\n"; -const std::string HELP_MSG_QUERY = - "usage: dp query \n" - "options list:\n" - " -h, --help list available commands\n" - " -d query device info by a device id\n" - " -s query device info by a service id\n"; -const std::string HELP_MSG_SYNC = - "usage: dp sync \n" - "options list:\n" - " -h, --help list available commands\n" - " -d sync device info by a device ids\n" - " -m sync device info by mode\n"; -const std::string HELP_MSG_PUT = - "usage: dp put \n" - "options list:\n" - " -h, --help list available commands\n" - " -s put device info by service id\n" - " -t put device info by service type\n"; -const std::string HELP_MSG_SUBSCRIBE = - "usage: dp subscribe \n" - "options list:\n" - " -h, --help list available commands\n" - " -s subscribe device info by service ids\n" - " -d subscribe device info by device id\n"; -const std::string HELP_MSG_DELETE = - "usage: dp delete \n" - "options list:\n" - " -h, --help list available commands\n" - " -s service id to delete\n"; -constexpr int32_t API_LEVEL = 7; -constexpr int32_t SYNC_SLEEP_TIME = 10; -constexpr int32_t BASE = 10; -constexpr int32_t SUBSCRIBE_SLEEP_TIME = 120; -const std::string SHORT_OPTIONS = "hd:s:m:t:"; -const struct option LONG_OPTIONS[] = { - {"help", no_argument, nullptr, 'h'}, - {"device-id", required_argument, nullptr, 'd'}, - {"service-id", required_argument, nullptr, 's'}, - {"mode", required_argument, nullptr, 'm'}, - {"service-type", required_argument, nullptr, 't'}, - {nullptr, nullptr, nullptr, nullptr}, -}; -} - -DpShellCommand::DpShellCommand(int argc, char *argv[]) : ShellCommand(argc, argv, DP_TOOL_NAME) -{ -} - -ErrCode DpShellCommand::init() -{ - return ERR_OK; -} - -ErrCode DpShellCommand::CreateCommandMap() -{ - commandMap_ = { - {"help", std::bind(&DpShellCommand::HelpCommand, this)}, - {"getDevice", std::bind(&DpShellCommand::GetDeviceCommand, this)}, - {"query", std::bind(&DpShellCommand::QueryCommand, this)}, - {"put", std::bind(&DpShellCommand::PutCommand, this)}, - {"delete", std::bind(&DpShellCommand::DeleteCommand, this)}, - {"sync", std::bind(&DpShellCommand::SyncCommand, this)}, - {"subscribe", std::bind(&DpShellCommand::SubscribeCommand, this)}, - }; - return ERR_OK; -} - -ErrCode DpShellCommand::CreateMessageMap() -{ - messageMap_ = {}; - return ERR_OK; -} - -ErrCode DpShellCommand::HelpCommand() -{ - resultReceiver_.append(DP_HELP_MSG); - return ERR_OK; -} - -ErrCode DpShellCommand::GetDeviceCommand() -{ - resultReceiver_.append("[remote device list]\n"); - NodeBasicInfo *info = nullptr; - int32_t infoNum = 0; - int32_t ret = GetAllNodeDeviceInfo("dp", &info, &infoNum); - if (ret != ERR_OK) { - resultReceiver_.append("get remote device list error\n"); - return ret; - } - for (int32_t i = 0; i < infoNum; i++) { - if (info == nullptr) { - continue; - } - resultReceiver_.append("networkId: " + std::string(info->networkId) - + " deviceName:" + std::string(info->deviceName) + "\n"); - info++; - } - - resultReceiver_.append("[local device list]\n"); - NodeBasicInfo localInfo; - ret = GetLocalNodeDeviceInfo("dp", &localInfo); - if (ret != ERR_OK) { - resultReceiver_.append("get local device error\n"); - FreeNodeInfo(info); - return ret; - } - resultReceiver_.append("networkId: " + std::string(localInfo.networkId) - + " deviceName:" + std::string(localInfo.deviceName) + "\n"); - FreeNodeInfo(info); - return ERR_OK; -} - -ErrCode DpShellCommand::QueryCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string deviceId; - std::string serviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - ServiceCharacteristicProfile profile; - DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, serviceId, profile); - std::string jsonData = profile.GetCharacteristicProfileJson(); - resultReceiver_.append("ServiceId:" + profile.GetServiceId() + "\n"); - resultReceiver_.append("ServiceType:" + profile.GetServiceType() + "\n"); - resultReceiver_.append("jsonData:" + jsonData + "\n"); - } else { - resultReceiver_.append(HELP_MSG_QUERY); - } - return result; -} - -ErrCode DpShellCommand::PutCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string serviceId; - std::string deviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - ServiceCharacteristicProfile profile; - profile.SetServiceId(serviceId); - profile.SetServiceType(serviceType); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = API_LEVEL; - profile.SetCharacteristicProfileJson(j.dump()); - DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - } else { - resultReceiver_.append(HELP_MSG_PUT); - } - return result; -} - -ErrCode DpShellCommand::DeleteCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string deviceId; - std::string serviceId; - - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId); - } else { - resultReceiver_.append(HELP_MSG_DELETE); - } - return result; -} - -ErrCode DpShellCommand::SyncCommand() -{ - int32_t result = ERR_OK; - std::list deviceIds; - std::string modeStr; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleSyncOption(option, modeStr, deviceIds); - } - - if (result == ERR_OK) { - SyncOptions syncOption; - int64_t mode = strtol(modeStr.c_str(), nullptr, BASE); - syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)mode); - for (const auto& deviceId : deviceIds) { - syncOption.AddDevice(deviceId); - } - DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOption, - std::make_shared()); - sleep(SYNC_SLEEP_TIME); - HILOGI("sync end"); - } else { - resultReceiver_.append(HELP_MSG_SYNC); - } - return result; -} - -ErrCode DpShellCommand::SubscribeCommand() -{ - int32_t result = ERR_OK; - std::list serviceIds; - std::string deviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleSubscribeOption(option, deviceId, serviceIds); - } - - if (result == ERR_OK) { - auto callback = std::make_shared(); - std::list subscribeInfos; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - sleep(SUBSCRIBE_SLEEP_TIME); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - failedEvents.clear(); - DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, callback, failedEvents); - sleep(SYNC_SLEEP_TIME); - } else { - resultReceiver_.append(HELP_MSG_SUBSCRIBE); - } - return result; -} - -int32_t DpShellCommand::HandleNormalOption(int option, std::string& deviceId, - std::string& serviceId, std::string& serviceType) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp query' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - deviceId = optarg; - break; - } - case 's': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - serviceId = optarg; - break; - } - case 't': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - serviceType = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp query' invalid option."); - break; - } - } - return result; -} - -int32_t DpShellCommand::HandleSyncOption(int option, std::string& mode, std::list& deviceIds) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp sync' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - std::stringstream input(optarg); - std::string temp; - while (std::getline(input, temp, ' ')) { - deviceIds.push_back(temp); - } - break; - } - case 'm': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - mode = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp sync' invalid option."); - break; - } - } - return result; -} - -int32_t DpShellCommand::HandleSubscribeOption(int option, std::string& deviceId, - std::list& serviceIds) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp subscribe' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 's': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - std::stringstream input(optarg); - std::string temp; - while (std::getline(input, temp, ' ')) { - serviceIds.push_back(temp); - } - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - deviceId = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp subscribe' invalid option."); - break; - } - } - return result; -} - -void ProfileEventCallback::OnSyncCompleted(const SyncResult& syncResults) -{ - HILOGI("OnSyncCompleted"); -} - -void ProfileEventCallback::OnProfileChanged(const ProfileChangeNotification& changeNotification) -{ - HILOGI("OnProfileChanged"); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/tools/dp/src/main.cpp b/old/tools/dp/src/main.cpp deleted file mode 100644 index dc5351f18f4bc81fcb34af0891325430953b3889..0000000000000000000000000000000000000000 --- a/old/tools/dp/src/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 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 "dp_command.h" - -#include -#include -#include - -#include "shell_command.h" - -using namespace std; -using namespace OHOS::DeviceProfile; - -int main(int argc, char *argv[]) -{ - DpShellCommand cmd(argc, argv); - std::cout << cmd.ExecCommand(); - return 0; -} \ No newline at end of file diff --git a/old/tools/dp/src/shell_command.cpp b/old/tools/dp/src/shell_command.cpp deleted file mode 100644 index b99589a4b325ff9f22e8e8745955cc207c5c3cb2..0000000000000000000000000000000000000000 --- a/old/tools/dp/src/shell_command.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 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 "shell_command.h" - -#include -#include -#include -#include -#include -#include - -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ShellCommand"; - -const std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least."; -} - -ShellCommand::ShellCommand(int argc, char *argv[], std::string name) -{ - opterr = 0; - argc_ = argc; - argv_ = argv; - name_ = name; - - if (argc < MIN_ARGUMENT_NUMBER) { - cmd_ = "help"; - return; - } - cmd_ = argv[1]; - for (int i = 2; i < argc; i++) { - argList_.push_back(argv[i]); - } -} - -ErrCode ShellCommand::OnCommand() -{ - int result = ERR_OK; - - auto respond = commandMap_[cmd_]; - if (respond == nullptr) { - resultReceiver_.append(GetCommandErrorMsg()); - respond = commandMap_["help"]; - } - - if (init() == ERR_OK) { - respond(); - } else { - result = OHOS::ERR_INVALID_VALUE; - } - - return result; -} - -std::string ShellCommand::ExecCommand() -{ - int result = CreateCommandMap(); - if (result != ERR_OK) { - HILOGE("failed to create command map.\n"); - } - - result = CreateMessageMap(); - if (result != ERR_OK) { - HILOGE("failed to create message map.\n"); - } - - result = OnCommand(); - if (result != ERR_OK) { - HILOGE("failed to execute your command.\n"); - resultReceiver_ = "error: failed to execute your command.\n"; - } - - return resultReceiver_; -} - -std::string ShellCommand::GetCommandErrorMsg() const -{ - std::string commandErrorMsg = - name_ + ": '" + cmd_ + "' is not a valid " + name_ + " command. See '" + name_ + " help'.\n"; - return commandErrorMsg; -} - -std::string ShellCommand::GetUnknownOptionMsg(std::string &unknownOption) const -{ - std::string result = ""; - - if (optind < 0 || optind > argc_) { - return result; - } - - result.append("error: unknown option"); - result.append(".\n"); - return result; -} - -std::string ShellCommand::GetMessageFromCode(int32_t code) const -{ - HILOGI("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - HILOGI("code = %{public}d", code); - - std::string result = ""; - if (messageMap_.find(code) != messageMap_.end()) { - std::string message = messageMap_.at(code); - if (message.size() != 0) { - result.append(message + "\n"); - } - } - HILOGI("result = %{public}s", result.c_str()); - return result; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file