diff --git a/bundle.json b/bundle.json index 7b103877..4ca7fa0b 100644 --- a/bundle.json +++ b/bundle.json @@ -1,6 +1,6 @@ { "name": "@ohos/distributedschedule_dms_fwk", - "description": "支持跨设备组件的启动和调用;支持分布式任务迁移;支持全局任务快照信息的实时获取能力。", + "description": "distributed ability manager service", "version": "3.1", "license": "Apache License 2.0", "repository": "https://gitee.com/openharmony/distributedschedule_dms_fwk", @@ -45,10 +45,6 @@ "name": "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "header": { "header_files": [ - "caller_info.h", - "distributed_sched_interface.h", - "distributed_sched_proxy.h", - "mission/distributed_mission_info.h", "uri.h" ], "header_base": "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include" diff --git a/services/dtbschedmgr/include/distributed_sched_interface.h b/services/dtbschedmgr/include/distributed_sched_interface.h index 976cdbd5..d4673bbd 100755 --- a/services/dtbschedmgr/include/distributed_sched_interface.h +++ b/services/dtbschedmgr/include/distributed_sched_interface.h @@ -20,6 +20,7 @@ #include "ability_info.h" #include "caller_info.h" #include "iremote_broker.h" +#include "mission_info.h" #include "mission/distributed_mission_info.h" #include "mission_snapshot.h" #include "ohos/aafwk/content/want.h" @@ -64,7 +65,7 @@ public: virtual int32_t RegisterMissionListener(const std::u16string& devId, const sptr& obj) = 0; virtual int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr& obj) = 0; virtual int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) = 0; + std::vector& missionInfos) = 0; virtual int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId, const uint8_t* byteStream, size_t len) = 0; virtual int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) = 0; diff --git a/services/dtbschedmgr/include/distributed_sched_proxy.h b/services/dtbschedmgr/include/distributed_sched_proxy.h index 5df05e09..ea8d3af0 100755 --- a/services/dtbschedmgr/include/distributed_sched_proxy.h +++ b/services/dtbschedmgr/include/distributed_sched_proxy.h @@ -51,7 +51,7 @@ public: int32_t RegisterMissionListener(const std::u16string& devId, const sptr& obj) override; int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr& obj) override; int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) override; + std::vector& missionInfos) override; int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId, const uint8_t* byteStream, size_t len) override; int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override; diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h index 1dd43b7b..ffe87fe3 100755 --- a/services/dtbschedmgr/include/distributed_sched_service.h +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -76,7 +76,7 @@ public: int32_t uid, const std::string& sourceDeviceId) override; int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) override; + std::vector& missionInfos) override; int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId, const uint8_t* byteStream, size_t len) override; int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override; diff --git a/services/dtbschedmgr/include/mission/distributed_mission_info.h b/services/dtbschedmgr/include/mission/distributed_mission_info.h index f57a8155..c18475ec 100644 --- a/services/dtbschedmgr/include/mission/distributed_mission_info.h +++ b/services/dtbschedmgr/include/mission/distributed_mission_info.h @@ -57,8 +57,8 @@ struct DstbMissionInfo : public Parcelable { static DstbMissionInfo* Unmarshalling(Parcel& parcel); std::string ToString() const; - static bool ReadMissionInfoVectorFromParcel(Parcel& parcel, std::vector &missionInfos); - static bool WriteMissionInfoVectorFromParcel(Parcel& parcel, const std::vector &missionInfos); + static bool ReadDstbMissionInfosFromParcel(Parcel& parcel, std::vector& missionInfos); + static bool WriteDstbMissionInfosToParcel(Parcel& parcel, const std::vector& missionInfos); }; } // namespace DistributedSchedule } // namespace OHOS diff --git a/services/dtbschedmgr/include/mission/distributed_sched_mission_manager.h b/services/dtbschedmgr/include/mission/distributed_sched_mission_manager.h index 5e03e924..ad37730a 100644 --- a/services/dtbschedmgr/include/mission/distributed_sched_mission_manager.h +++ b/services/dtbschedmgr/include/mission/distributed_sched_mission_manager.h @@ -23,6 +23,7 @@ #include "common_event_manager.h" #include "distributed_data_storage.h" #include "distributed_mission_change_listener.h" +#include "distributed_mission_info.h" #include "distributed_sched_interface.h" #include "event_handler.h" #include "single_instance.h" @@ -73,7 +74,7 @@ class DistributedSchedMissionManager { public: void Init(); int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos); + std::vector& missionInfos); int32_t InitDataStorage(); int32_t StopDataStorage(); int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId, diff --git a/services/dtbschedmgr/include/mission/mission_info_converter.h b/services/dtbschedmgr/include/mission/mission_info_converter.h index be6fe497..9ee4c03a 100644 --- a/services/dtbschedmgr/include/mission/mission_info_converter.h +++ b/services/dtbschedmgr/include/mission/mission_info_converter.h @@ -30,6 +30,8 @@ public: std::vector& dstbMissionInfos); static int32_t ConvertToMissionInfos(std::vector& dstbMissionInfos, std::vector& missionInfos); + static bool ReadMissionInfosFromParcel(Parcel& parcel, std::vector& missionInfos); + static bool WriteMissionInfosToParcel(Parcel& parcel, const std::vector& missionInfos); }; } } diff --git a/services/dtbschedmgr/src/distributed_sched_adapter.cpp b/services/dtbschedmgr/src/distributed_sched_adapter.cpp index 8066b760..83d06a9b 100644 --- a/services/dtbschedmgr/src/distributed_sched_adapter.cpp +++ b/services/dtbschedmgr/src/distributed_sched_adapter.cpp @@ -244,7 +244,7 @@ int32_t DistributedSchedAdapter::RegisterMissionListener(const sptr &listener) +int32_t DistributedSchedAdapter::UnRegisterMissionListener(const sptr& listener) { if (listener == nullptr) { HILOGE("listener is null"); diff --git a/services/dtbschedmgr/src/distributed_sched_proxy.cpp b/services/dtbschedmgr/src/distributed_sched_proxy.cpp index 3909ef41..bea69449 100755 --- a/services/dtbschedmgr/src/distributed_sched_proxy.cpp +++ b/services/dtbschedmgr/src/distributed_sched_proxy.cpp @@ -325,7 +325,7 @@ int32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& cal } int32_t version = reply.ReadInt32(); HILOGD("version : %{public}d", version); - return DstbMissionInfo::ReadMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; + return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; } int32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId) @@ -409,7 +409,7 @@ int32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& d } int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) + std::vector& missionInfos) { HILOGI("called"); sptr remote = Remote(); @@ -431,7 +431,7 @@ int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int3 HILOGW("sendRequest fail, error: %{public}d", ret); return ret; } - return DstbMissionInfo::ReadMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; + return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; } int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, @@ -449,7 +449,7 @@ int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector return ERR_FLATTEN_OBJECT; } PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion); - if (!DstbMissionInfo::WriteMissionInfoVectorFromParcel(data, missionInfos)) { + if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) { return ERR_FLATTEN_OBJECT; } PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId); diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index 3dc4366c..b4d0907a 100755 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -1045,7 +1045,7 @@ void DistributedSchedService::DumpElementLocked(const std::list& missionInfos) + std::vector& missionInfos) { return DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceId, numMissions, missionInfos); } diff --git a/services/dtbschedmgr/src/distributed_sched_stub.cpp b/services/dtbschedmgr/src/distributed_sched_stub.cpp index 76d51a79..6bc1d3de 100755 --- a/services/dtbschedmgr/src/distributed_sched_stub.cpp +++ b/services/dtbschedmgr/src/distributed_sched_stub.cpp @@ -25,6 +25,7 @@ #include "ipc_skeleton.h" #include "message_parcel.h" #include "mission/distributed_sched_mission_manager.h" +#include "mission/mission_info_converter.h" #include "mission/snapshot_converter.h" #include "parcel_helper.h" @@ -361,13 +362,13 @@ int32_t DistributedSchedStub::GetMissionInfosInner(MessageParcel& data, MessageP int32_t numMissions = 0; PARCEL_READ_HELPER(data, Int32, numMissions); - std::vector missionInfos; - int result = GetMissionInfos(Str16ToStr8(deviceId), numMissions, missionInfos); + std::vector missionInfos; + int32_t result = GetMissionInfos(Str16ToStr8(deviceId), numMissions, missionInfos); HILOGI("result = %{public}d", result); if (result == ERR_NONE) { - return DstbMissionInfo::WriteMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; + result = MissionInfoConverter::WriteMissionInfosToParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT; } - return ERR_NULL_OBJECT; + return result; } int32_t DistributedSchedStub::GetRemoteSnapshotInfoInner(MessageParcel& data, MessageParcel& reply) @@ -485,7 +486,7 @@ int32_t DistributedSchedStub::StartSyncMissionsFromRemoteInner(MessageParcel& da if (!reply.WriteInt32(VERSION)) { return ERR_FLATTEN_OBJECT; } - if (!DstbMissionInfo::WriteMissionInfoVectorFromParcel(reply, missionInfos)) { + if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(reply, missionInfos)) { HILOGE("write mission info failed!"); return ERR_FLATTEN_OBJECT; } @@ -545,7 +546,7 @@ int32_t DistributedSchedStub::NotifyMissionsChangedFromRemoteInner(MessageParcel int32_t version = data.ReadInt32(); HILOGD("version is %{public}d", version); std::vector missionInfos; - if (!DstbMissionInfo::ReadMissionInfoVectorFromParcel(data, missionInfos)) { + if (!DstbMissionInfo::ReadDstbMissionInfosFromParcel(data, missionInfos)) { return ERR_FLATTEN_OBJECT; } CallerInfo callerInfo; diff --git a/services/dtbschedmgr/src/mission/distributed_mission_info.cpp b/services/dtbschedmgr/src/mission/distributed_mission_info.cpp index 7cfa53c9..0552f871 100644 --- a/services/dtbschedmgr/src/mission/distributed_mission_info.cpp +++ b/services/dtbschedmgr/src/mission/distributed_mission_info.cpp @@ -100,13 +100,13 @@ bool DstbMissionInfo::Marshalling(Parcel& parcel) const return true; } -bool DstbMissionInfo::ReadMissionInfoVectorFromParcel(Parcel& parcel, - std::vector &missionInfos) +bool DstbMissionInfo::ReadDstbMissionInfosFromParcel(Parcel& parcel, + std::vector& missionInfos) { int32_t empty = parcel.ReadInt32(); if (empty == VALUE_OBJECT) { int32_t len = parcel.ReadInt32(); - HILOGD("ReadMissionInfoVectorFromParcel::readLength is:%{public}d", len); + HILOGD("ReadDstbMissionInfosFromParcel::readLength is:%{public}d", len); if (len < 0) { return false; } @@ -127,12 +127,12 @@ bool DstbMissionInfo::ReadMissionInfoVectorFromParcel(Parcel& parcel, } } - HILOGI("read ReadMissionInfoVectorFromParcel end. info size is:%{public}zu", missionInfos.size()); + HILOGI("read ReadDstbMissionInfosFromParcel end. info size is:%{public}zu", missionInfos.size()); return true; } -bool DstbMissionInfo::WriteMissionInfoVectorFromParcel(Parcel& parcel, - const std::vector &missionInfos) +bool DstbMissionInfo::WriteDstbMissionInfosToParcel(Parcel& parcel, + const std::vector& missionInfos) { size_t size = missionInfos.size(); if (size == 0) { diff --git a/services/dtbschedmgr/src/mission/distributed_sched_mission_manager.cpp b/services/dtbschedmgr/src/mission/distributed_sched_mission_manager.cpp index 0b0aa852..4bdf3305 100644 --- a/services/dtbschedmgr/src/mission/distributed_sched_mission_manager.cpp +++ b/services/dtbschedmgr/src/mission/distributed_sched_mission_manager.cpp @@ -27,6 +27,7 @@ #include "iservice_registry.h" #include "mission/mission_changed_notify.h" #include "mission/mission_constant.h" +#include "mission/mission_info_converter.h" #include "mission/snapshot_converter.h" #include "nlohmann/json.hpp" #include "string_ex.h" @@ -71,7 +72,7 @@ void DistributedSchedMissionManager::Init() } int32_t DistributedSchedMissionManager::GetMissionInfos(const std::string& deviceId, - int32_t numMissions, std::vector& missionInfos) + int32_t numMissions, std::vector& missionInfos) { HILOGI("start!"); if (!AllowMissionUid(IPCSkeleton::GetCallingUid())) { @@ -85,8 +86,13 @@ int32_t DistributedSchedMissionManager::GetMissionInfos(const std::string& devic HILOGE("numMissions is illegal! numMissions:%{public}d", numMissions); return INVALID_PARAMETERS_ERR; } - - return FetchCachedRemoteMissions(deviceId, numMissions, missionInfos); + std::vector dstbMissionInfos; + int32_t ret = FetchCachedRemoteMissions(deviceId, numMissions, dstbMissionInfos); + if (ret != ERR_OK) { + HILOGE("FetchCachedRemoteMissions failed, ret = %{public}d", ret); + return ret; + } + return MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos); } sptr DistributedSchedMissionManager::GetRemoteDms(const std::string& deviceId) diff --git a/services/dtbschedmgr/src/mission/mission_info_converter.cpp b/services/dtbschedmgr/src/mission/mission_info_converter.cpp index 9f3f9826..d82b0735 100644 --- a/services/dtbschedmgr/src/mission/mission_info_converter.cpp +++ b/services/dtbschedmgr/src/mission/mission_info_converter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -15,12 +15,17 @@ #include "mission/mission_info_converter.h" +#include "adapter/adapter_constant.h" #include "dtbschedmgr_log.h" +#include "parcel_helper.h" using namespace std; - namespace OHOS { namespace DistributedSchedule { +using namespace Constants::Adapter; +namespace { +const std::string TAG = "MissionInfoConverter"; +} int32_t MissionInfoConverter::ConvertToDstbMissionInfos(std::vector& missionInfos, std::vector& dstbMissionInfos) { @@ -59,5 +64,53 @@ int32_t MissionInfoConverter::ConvertToMissionInfos(std::vector } return ERR_OK; } + +bool MissionInfoConverter::ReadMissionInfosFromParcel(Parcel& parcel, + std::vector& missionInfos) +{ + int32_t empty = parcel.ReadInt32(); + if (empty == VALUE_OBJECT) { + int32_t len = parcel.ReadInt32(); + HILOGD("ReadMissionInfosFromParcel::readLength is:%{public}d", len); + if (len < 0) { + return false; + } + size_t size = static_cast(len); + if ((size > parcel.GetReadableBytes()) || (missionInfos.max_size() < size)) { + HILOGE("Failed to read MissionInfo vector, size = %{public}zu", size); + return false; + } + missionInfos.clear(); + for (size_t i = 0; i < size; i++) { + AAFwk::MissionInfo *ptr = parcel.ReadParcelable(); + if (ptr == nullptr) { + HILOGW("read MissionInfo failed"); + return false; + } + missionInfos.emplace_back(*ptr); + delete ptr; + } + } + + HILOGI("ReadMissionInfosFromParcel end. info size is:%{public}zu", missionInfos.size()); + return true; +} + +bool MissionInfoConverter::WriteMissionInfosToParcel(Parcel& parcel, + const std::vector& missionInfos) +{ + size_t size = missionInfos.size(); + if (size == 0) { + PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_NULL, false); + return true; + } + + PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_OBJECT, false); + PARCEL_WRITE_HELPER_RET(parcel, Int32, size, false); + for (auto& info : missionInfos) { + PARCEL_WRITE_HELPER_RET(parcel, Parcelable, &info, false); + } + return true; +} } } diff --git a/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp b/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp index 566c0267..13f4e44d 100644 --- a/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp +++ b/services/dtbschedmgr/test/unittest/mission/dms_mission_manager_test.cpp @@ -93,7 +93,7 @@ sptr DMSMissionManagerTest::GetDms() */ HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo001, TestSize.Level1) { - std::vector infos; + std::vector infos; auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, 0, infos); EXPECT_TRUE(ret != ERR_NONE); @@ -122,7 +122,7 @@ HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo002, TestSize.Level1) if (proxy == nullptr) { return; } - std::vector infos; + std::vector infos; auto ret = proxy->GetMissionInfos(DEVICE_ID, 0, infos); EXPECT_TRUE(ret != ERR_NONE); @@ -151,7 +151,6 @@ HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions001, TestSize.Level1) if (proxy == nullptr) { return; } - std::vector infos; auto ret = proxy->StartSyncRemoteMissions(DEVICE_ID, false, 0); EXPECT_TRUE(ret != ERR_NONE); @@ -191,7 +190,7 @@ HWTEST_F(DMSMissionManagerTest, testGetMissionInfos001, TestSize.Level1) { std::string deviceid = DEVICE_ID; int32_t numMissions = NUM_MISSIONS; - std::vector missionInfos; + std::vector missionInfos; auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos); EXPECT_TRUE(ret != ERR_NONE); diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp index c892462d..2e675bca 100755 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp @@ -145,7 +145,7 @@ int32_t MockDistributedSched::GetOsdSwitchValueFromRemote() } int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) + std::vector& missionInfos) { return ERR_NONE; } diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h index 039f4100..b566d88e 100644 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h @@ -50,7 +50,7 @@ public: int32_t RegisterMissionListener(const std::u16string& devId, const sptr& obj) override; int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr& obj) override; int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) override; + std::vector& missionInfos) override; int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId, const uint8_t* byteStream, size_t len) override; int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override;