From 21f2cd90d90b3493e2389b2bbcf4d9a0f5fb27fa Mon Sep 17 00:00:00 2001 From: majiajun <864428661@qq.com> Date: Fri, 7 Jan 2022 03:28:23 -0800 Subject: [PATCH] mission management interface modification Signed-off-by: majiajun <864428661@qq.com> Change-Id: I0f3fc35fd79b86cbcdfea6a542f7897bd0aa0c63 --- .../include/mock_ability_manager_service.h | 10 +++ .../mock/AMS/mock_ability_manager_service.h | 10 +++ .../AMS/mock_serviceability_manager_service.h | 8 +++ .../include/ability_manager_client.h | 15 ++++ .../include/ability_manager_interface.h | 22 ++++++ .../include/ability_manager_proxy.h | 4 ++ .../include/ability_manager_service.h | 8 +++ .../abilitymgr/include/ability_manager_stub.h | 3 + .../abilitymgr/src/ability_manager_client.cpp | 26 +++++++ .../abilitymgr/src/ability_manager_proxy.cpp | 59 +++++++++++++++- .../src/ability_manager_service.cpp | 69 +++++++++++++++++-- .../abilitymgr/src/ability_manager_stub.cpp | 23 +++++++ .../ability_manager_stub_mock.h | 9 ++- .../ability_manager_stub_impl_mock.h | 8 +++ .../ability_manager_stub_mock.h | 8 +++ .../mock/include/mock_ability_mgr_service.h | 9 ++- tools/test/mock/mock_ability_manager_stub.h | 9 ++- 17 files changed, 290 insertions(+), 10 deletions(-) diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index f3e8291a8d..d94401e2b8 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -196,6 +196,16 @@ public: return 0; } + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } + enum RequestCode { E_STATE_INITIAL = 0, E_STATE_INACTIVE, diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 630f7a0063..b7bd262d5a 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -163,6 +163,16 @@ public: return 0; } + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } + AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; sptr abilityScheduler_; // kit interface used to schedule ability life Want want_; diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index f5f6afc353..fe52d4dec3 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -180,6 +180,14 @@ public: { return 0; } + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } sptr abilityScheduler_ = nullptr; // kit interface used to schedule ability life Want want_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index 5d200e8191..bea4e389a5 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -556,6 +556,21 @@ public: */ ErrCode MoveMissionToFront(int32_t missionId); + /** + * Start synchronizing remote device mission + * @param devId, deviceId. + * @param fixConflict, resolve synchronizing conflicts flag. + * @param tag, call tag. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag); + + /** + * Stop synchronizing remote device mission + * @param devId, deviceId. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode StopSyncRemoteMissions(const std::string& devId); private: static std::mutex mutex_; static std::shared_ptr instance_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 447c1c6d57..dc12965595 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -532,6 +532,22 @@ public: virtual int StopUser(int userId, const sptr &callback) = 0; + /** + * Start synchronizing remote device mission + * @param devId, deviceId. + * @param fixConflict, resolve synchronizing conflicts flag. + * @param tag, call tag. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) = 0; + + /** + * Stop synchronizing remote device mission + * @param devId, deviceId. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int StopSyncRemoteMissions(const std::string& devId) = 0; + enum { // ipc id 1-1000 for kit // ipc id for terminating ability (1) @@ -741,6 +757,12 @@ public: NOTIFY_CONTINUATION_RESULT = 1102, + // ipc id for mission manager(1110) + REGISTER_REMOTE_MISSION_LISTENER = 1110, + UNREGISTER_REMOTE_MISSION_LISTENER = 1111, + START_SYNC_MISSIONS = 1112, + STOP_SYNC_MISSIONS = 1113, + // ipc id 2001-3000 for tools // ipc id for dumping state (2001) DUMP_STATE = 2001, diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 9e09a3088d..2d7dd2080e 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -490,6 +490,10 @@ public: virtual int NotifyContinuationResult(const sptr &abilityToken, const int32_t result) override; + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; + + virtual int StopSyncRemoteMissions(const std::string& devId) override; + virtual int LockMissionForCleanup(int32_t missionId) override; virtual int UnlockMissionForCleanup(int32_t missionId) override; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 28cc16439d..2fd9f2e9a0 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -583,6 +583,10 @@ public: virtual int MoveMissionToFront(int32_t missionId) override; + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; + + virtual int StopSyncRemoteMissions(const std::string& devId) override; + /** * Get system memory information. * @param SystemMemoryAttr, memory information. @@ -783,6 +787,10 @@ private: void RequestPermission(const Want *resultWant); bool CheckIsRemote(const std::string& deviceId); + int GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax, + std::vector &missionInfos); + int GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId, + MissionInfo &missionInfo); void DumpInner(const std::string &args, std::vector &info); void DumpStackListInner(const std::string &args, std::vector &info); diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index fbb6e82b53..17215b29c6 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -121,6 +121,9 @@ private: int StartUserInner(MessageParcel &data, MessageParcel &reply); int StopUserInner(MessageParcel &data, MessageParcel &reply); + int StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply); + int StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply); + using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; }; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index a31d208cab..4e36300320 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -722,5 +722,31 @@ ErrCode AbilityManagerClient::MoveMissionToFront(int32_t missionId) sptr abms = iface_cast(remoteObject_); return abms->MoveMissionToFront(missionId); } + +/** + * Start synchronizing remote device mission + * @param devId, deviceId. + * @param fixConflict, resolve synchronizing conflicts flag. + * @param tag, call tag. + * @return Returns ERR_OK on success, others on failure. + */ +ErrCode AbilityManagerClient::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + auto abms = iface_cast(remoteObject_); + return abms->StartSyncRemoteMissions(devId, fixConflict, tag); +} + +/** + * Stop synchronizing remote device mission + * @param devId, deviceId. + * @return Returns ERR_OK on success, others on failure. + */ +ErrCode AbilityManagerClient::StopSyncRemoteMissions(const std::string& devId) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + auto abms = iface_cast(remoteObject_); + return abms->StopSyncRemoteMissions(devId); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 83c95acc54..705eea51bc 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1824,5 +1824,62 @@ int AbilityManagerProxy::StopUser(int userId, const sptr &cal } return reply.ReadInt32(); } + +int AbilityManagerProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + HILOG_INFO("called"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("WriteInterfaceToken faild"); + return ERR_INVALID_VALUE; + } + if (!data.WriteString(devId)) { + HILOG_ERROR("write deviceId fail."); + return ERR_INVALID_VALUE; + } + + if (!data.WriteBool(fixConflict)) { + HILOG_ERROR("WriteBool fail."); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt64(tag)) { + HILOG_ERROR("WriteInt64 fail."); + return ERR_INVALID_VALUE; + } + + auto error = Remote()->SendRequest(IAbilityManager::START_SYNC_MISSIONS, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + +int32_t AbilityManagerProxy::StopSyncRemoteMissions(const std::string& devId) +{ + HILOG_INFO("called"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("WriteInterfaceToken faild"); + return ERR_INVALID_VALUE; + } + if (!data.WriteString(devId)) { + HILOG_ERROR("write deviceId fail."); + return ERR_INVALID_VALUE; + } + auto error = Remote()->SendRequest(IAbilityManager::STOP_SYNC_MISSIONS, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index d6afd8de73..268b83f117 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -35,6 +35,7 @@ #include "iservice_registry.h" #include "locale_config.h" #include "lock_screen_white_list.h" +#include "mission/mission_info_converter.h" #include "sa_mgr_client.h" #include "softbus_bus_center.h" #include "string_ex.h" @@ -49,6 +50,7 @@ static const int EXPERIENCE_MEM_THRESHOLD = 20; constexpr auto DATA_ABILITY_START_TIMEOUT = 5s; constexpr int32_t NON_ANONYMIZE_LENGTH = 6; const int32_t EXTENSION_SUPPORT_API_VERSION = 8; +const int32_t MAX_NUMBER_OF_DISTRIBUTED_MISSIONS = 20; const std::string EMPTY_DEVICE_ID = ""; const std::string PKG_NAME = "ohos.distributedhardware.devicemanager"; const std::map AbilityManagerService::dumpMap = { @@ -472,10 +474,10 @@ sptr AbilityManagerService::GetDmsProxy( return nullptr; } HILOG_INFO("get dms proxy success."); - sptr iDistributedSchedule = + sptr dmsProxy = iface_cast(remoteObject); HILOG_INFO("%{public}s end.", __func__); - return iDistributedSchedule; + return dmsProxy; } bool AbilityManagerService::GetLocalDeviceId(std::string& localDeviceId) @@ -854,6 +856,26 @@ int AbilityManagerService::NotifyContinuationResult(const sptr &a return ERR_OK; } +int AbilityManagerService::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + sptr dmsProxy = GetDmsProxy(); + if (dmsProxy == nullptr) { + HILOG_ERROR("AbilityManagerService::StartSyncRemoteMissions failed to get dms."); + return ERR_INVALID_VALUE; + } + return dmsProxy->StartSyncRemoteMissions(devId, fixConflict, tag); +} + +int AbilityManagerService::StopSyncRemoteMissions(const std::string& devId) +{ + sptr dmsProxy = GetDmsProxy(); + if (dmsProxy == nullptr) { + HILOG_ERROR("AbilityManagerService::StopSyncRemoteMissions failed to get dms."); + return ERR_INVALID_VALUE; + } + return dmsProxy->StopSyncRemoteMissions(devId); +} + void AbilityManagerService::RemoveAllServiceRecord() { connectManager_->RemoveAll(); @@ -1094,13 +1116,30 @@ int AbilityManagerService::GetMissionInfos(const std::string& deviceId, int32_t } if (CheckIsRemote(deviceId)) { - HILOG_ERROR("get remote missioninfos not support yet."); - return -1; + return GetRemoteMissionInfos(deviceId, numMax, missionInfos); } return currentMissionListManager_->GetMissionInfos(numMax, missionInfos); } +int AbilityManagerService::GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax, + std::vector &missionInfos) +{ + HILOG_INFO("GetRemoteMissionInfos begin"); + sptr dmsProxy = GetDmsProxy(); + if (dmsProxy == nullptr) { + HILOG_ERROR("GetRemoteMissionInfos failed to get dms."); + return ERR_INVALID_VALUE; + } + std::vector dstbMissionInfos; + int result = dmsProxy->GetMissionInfos(deviceId, numMax, dstbMissionInfos); + if (result != ERR_OK) { + HILOG_ERROR("GetRemoteMissionInfos failed, result = %{public}d", result); + return result; + } + return DistributedSchedule::MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos); +} + int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo) { @@ -1114,13 +1153,31 @@ int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t m } if (CheckIsRemote(deviceId)) { - HILOG_ERROR("get remote mission not support yet."); - return -1; + return GetRemoteMissionInfo(deviceId, missionId, missionInfo); } return currentMissionListManager_->GetMissionInfo(missionId, missionInfo); } +int AbilityManagerService::GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId, + MissionInfo &missionInfo) +{ + HILOG_INFO("GetMissionInfoFromDms begin"); + std::vector missionVector; + int result = GetRemoteMissionInfos(deviceId, MAX_NUMBER_OF_DISTRIBUTED_MISSIONS, missionVector); + if (result != ERR_OK) { + return result; + } + for (auto iter = missionVector.begin(); iter != missionVector.end(); iter++) { + if (iter->id == missionId) { + missionInfo = *iter; + return ERR_OK; + } + } + HILOG_WARN("missionId not found"); + return ERR_INVALID_VALUE; +} + int AbilityManagerService::CleanMission(int32_t missionId) { HILOG_INFO("request CleanMission, missionId:%{public}d", missionId); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 7e74892c8b..cd3b901c11 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1074,5 +1074,28 @@ int AbilityManagerStub::StopUserInner(MessageParcel &data, MessageParcel &reply) } return NO_ERROR; } + +int AbilityManagerStub::StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId = data.ReadString(); + bool fixConflict = data.ReadBool(); + int64_t tag = data.ReadInt64(); + int result = StartSyncRemoteMissions(deviceId, fixConflict, tag); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("StartSyncRemoteMissionsInner failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + +int AbilityManagerStub::StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply) +{ + int result = StopSyncRemoteMissions(data.ReadString()); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("StopSyncRemoteMissionsInner failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 550281f4ed..3307bcab02 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -308,7 +308,14 @@ public: { return 0; } - + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(StartAbility, int(const Want &want, const sptr &callerToken, int requestCode)); MOCK_METHOD2( diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 84e003ae49..f9c2624c9f 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -351,6 +351,14 @@ public: { return 0; } + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index ce73212fa7..c0ce32c53b 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -106,6 +106,14 @@ public: { return 0; } + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index 9f75a9e71a..9f03a2918f 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -114,7 +114,14 @@ public: { return 0; } - + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } void Wait() { sem_.Wait(); diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 5ee888ec7e..135e1292f9 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -139,7 +139,14 @@ public: { return 0; } - + virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + virtual int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } public: std::string powerState_; };