From 601c4ec8c7de23f5e78e2baa21d32bb97c633aac Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 3 Aug 2022 14:52:21 +0800 Subject: [PATCH 1/5] add share form code Signed-off-by: xuchenghua09 --- bundle.json | 2 + dmsfwk.gni | 1 + services/dtbschedmgr/BUILD.gn | 7 + .../include/distributed_sched_interface.h | 13 + .../include/distributed_sched_proxy.h | 7 +- .../include/distributed_sched_service.h | 12 + .../include/distributed_sched_stub.h | 4 + .../src/distributed_sched_proxy.cpp | 58 +++ .../src/distributed_sched_service.cpp | 83 ++++ .../src/distributed_sched_stub.cpp | 46 ++ services/dtbschedmgr/test/BUILD.gn | 8 + .../test/unittest/mock_distributed_sched.cpp | 426 +++++++++--------- .../test/unittest/mock_distributed_sched.h | 184 ++++---- 13 files changed, 555 insertions(+), 296 deletions(-) diff --git a/bundle.json b/bundle.json index 0ad835c0..3382a36f 100644 --- a/bundle.json +++ b/bundle.json @@ -16,6 +16,7 @@ "subsystem": "ability", "adapted_system_type": [ "standard" ], "features" : [ + "dmsfwk_standard_form_share", "dmsfwk_mission_manager" ], "hisysevent_config": [ @@ -33,6 +34,7 @@ "distributeddatamgr", "dsoftbus", "eventhandler", + "form_fwk", "hisysevent_native", "hitrace_native", "hiviewdfx_hilog_native", diff --git a/dmsfwk.gni b/dmsfwk.gni index ff5946a0..082001ae 100644 --- a/dmsfwk.gni +++ b/dmsfwk.gni @@ -12,6 +12,7 @@ # limitations under the License. declare_args() { + dmsfwk_standard_form_share = true dmsfwk_mission_manager = true if (defined(global_parts_info) && !defined(global_parts_info.multimedia_multimedia_image_standard)) { diff --git a/services/dtbschedmgr/BUILD.gn b/services/dtbschedmgr/BUILD.gn index 72ca64e3..2195e60f 100644 --- a/services/dtbschedmgr/BUILD.gn +++ b/services/dtbschedmgr/BUILD.gn @@ -29,6 +29,9 @@ config("distributed_sched_config") { if (dmsfwk_mission_manager) { defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ] } + if (dmsfwk_standard_form_share) { + defines += [ "SUPPORT_DISTRIBUTED_FORM_SHARE" ] + } } ohos_shared_library("distributedschedsvr") { @@ -81,6 +84,10 @@ ohos_shared_library("distributedschedsvr") { deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ] + if (dmsfwk_standard_form_share) { + external_deps += [ "form_fwk:form_manager" ] + } + if (dmsfwk_mission_manager) { defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ] sources += [ diff --git a/services/dtbschedmgr/include/distributed_sched_interface.h b/services/dtbschedmgr/include/distributed_sched_interface.h index 39cba0f3..064a1edc 100755 --- a/services/dtbschedmgr/include/distributed_sched_interface.h +++ b/services/dtbschedmgr/include/distributed_sched_interface.h @@ -20,6 +20,9 @@ #include "ability_info.h" #include "ability_manager_interface.h" #include "caller_info.h" +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +#include "form_share_info.h" +#endif #include "iremote_broker.h" #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER #include "mission_info.h" @@ -115,6 +118,12 @@ public: { return 0; } +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + virtual int32_t StartRemoteShareForm(const std::string &remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0; + virtual int32_t StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0; +#endif virtual int32_t RegisterDistributedComponentListener(const sptr& callback) = 0; virtual int32_t GetDistributedComponentList(std::vector& distributedComponents) = 0; enum { @@ -170,6 +179,10 @@ public: // request code for upload distributed component info REGISTER_DISTRIBUTED_COMPONENT_LISTENER = 160, GET_DISTRIBUTED_COMPONENT_LIST = 161, + + // form share + START_REMOTE_SHARE_FORM = 220, + START_SHARE_FORM_FROM_REMOTE = 221, }; }; } // namespace DistributedSchedule diff --git a/services/dtbschedmgr/include/distributed_sched_proxy.h b/services/dtbschedmgr/include/distributed_sched_proxy.h index a825a16a..34653e92 100755 --- a/services/dtbschedmgr/include/distributed_sched_proxy.h +++ b/services/dtbschedmgr/include/distributed_sched_proxy.h @@ -79,7 +79,12 @@ public: int32_t callerUid, int32_t requestCode, uint32_t accessToken, const sptr& callback) override; int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; - +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareForm(const std::string &remoteDeviceId, + const AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartShareFormFromRemote( + const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override; +#endif int32_t RegisterDistributedComponentListener(const sptr& callback) override; int32_t GetDistributedComponentList(std::vector& distributedComponents) override; private: diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h index 434eae85..d7f775f8 100755 --- a/services/dtbschedmgr/include/distributed_sched_service.h +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -121,6 +121,12 @@ public: const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) override; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareForm(const std::string &remoteDeviceId, + const AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartShareFormFromRemote( + const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override; +#endif void ProcessCallerDied(const sptr& connect, int32_t deviceType); void ProcessCalleeDied(const sptr& connect); int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, @@ -160,6 +166,9 @@ private: static int32_t GetUidLocked(const std::list& sessionList); int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, const CallerInfo& callerInfo); +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + sptr GetFormMgrProxy(); +#endif int32_t CleanMission(int32_t missionId); int32_t SetCallerInfo(int32_t callerUid, std::string localDeviceId, uint32_t accessToken, CallerInfo& callerInfo); int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId); @@ -193,6 +202,9 @@ private: std::mutex distributedLock_; std::mutex connectLock_; sptr connectDeathRecipient_; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + sptr formMgrProxy_; +#endif std::mutex calleeLock_; std::map, ConnectInfo> calleeMap_; sptr callerDeathRecipient_; diff --git a/services/dtbschedmgr/include/distributed_sched_stub.h b/services/dtbschedmgr/include/distributed_sched_stub.h index d10dafd4..4fcb7790 100644 --- a/services/dtbschedmgr/include/distributed_sched_stub.h +++ b/services/dtbschedmgr/include/distributed_sched_stub.h @@ -62,6 +62,10 @@ private: int32_t StartRemoteFreeInstallInner(MessageParcel& data, MessageParcel& reply); int32_t StartFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); int32_t NotifyCompleteFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply); + int32_t StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply); +#endif int32_t RegisterDistributedComponentListenerInner(MessageParcel& data, MessageParcel& reply); int32_t GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply); bool CheckDmsRequestPermission(); diff --git a/services/dtbschedmgr/src/distributed_sched_proxy.cpp b/services/dtbschedmgr/src/distributed_sched_proxy.cpp index 6958f5de..676b9124 100755 --- a/services/dtbschedmgr/src/distributed_sched_proxy.cpp +++ b/services/dtbschedmgr/src/distributed_sched_proxy.cpp @@ -769,6 +769,64 @@ int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskI PARCEL_TRANSACT_SYNC_RET_INT(remote, NOTIFY_COMPLETE_FREE_INSTALL_FROM_REMOTE, data, reply); } +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +int32_t DistributedSchedProxy::StartRemoteShareForm( + const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) +{ + HILOGD("SHAREFORM:: func call"); + if (remoteDeviceId.empty()) { + HILOGE("input params deviceId is nullptr."); + return INVALID_PARAMETERS_ERR; + } + + auto remote = Remote(); + if (remote == nullptr) { + HILOGE("fail to get dms remote."); + return DMSPROXY_SERVICE_ERR; + } + + MessageParcel data; + MessageParcel reply; + if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + HILOGE("WriteInterfaceToken failed"); + return ERR_FLATTEN_OBJECT; + } + + PARCEL_WRITE_HELPER(data, String, remoteDeviceId); + PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo); + + PARCEL_TRANSACT_SYNC_RET_INT(remote, START_REMOTE_SHARE_FORM, data, reply); +} + +int32_t DistributedSchedProxy::StartShareFormFromRemote( + const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) +{ + HILOGD("SHAREFORM:: func call"); + if (remoteDeviceId.empty()) { + HILOGE("input params deviceId is nullptr."); + return INVALID_PARAMETERS_ERR; + } + + auto remote = Remote(); + if (remote == nullptr) { + HILOGE("fail to get dms remote."); + return DMSPROXY_SERVICE_ERR; + } + + MessageParcel data; + MessageParcel reply; + if (!data.WriteInterfaceToken(DMS_PROXY_INTERFACE_TOKEN)) { + HILOGE("WriteInterfaceToken failed"); + return ERR_FLATTEN_OBJECT; + } + + PARCEL_WRITE_HELPER(data, String, remoteDeviceId); + PARCEL_WRITE_HELPER(data, Parcelable, &formShareInfo); + + PARCEL_TRANSACT_SYNC_RET_INT(remote, START_SHARE_FORM_FROM_REMOTE, data, reply); +} +#endif + int32_t DistributedSchedProxy::RegisterDistributedComponentListener(const sptr& callback) { if (callback == nullptr) { diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index 79862c67..1b04e173 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -36,6 +36,9 @@ #include "dtbschedmgr_log.h" #include "element_name.h" #include "file_ex.h" +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +#include "form_mgr_interface.h" +#endif #include "ipc_skeleton.h" #include "iservice_registry.h" #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER @@ -488,6 +491,29 @@ int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sess return ERR_OK; } +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +sptr DistributedSchedService::GetFormMgrProxy() +{ + HILOGD("%{public}s begin.", __func__); + if (formMgrProxy_ != nullptr) { + HILOGD("%{public}s fms proxy get success.", __func__); + return formMgrProxy_; + } + auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (sm == nullptr) { + HILOGE("GetAbilityManagerProxy sm is nullptr"); + return nullptr; + } + + formMgrProxy_ = sm->GetSystemAbility(FORM_MGR_SERVICE_ID); + if (formMgrProxy_ == nullptr) { + HILOGE("failed to get ability manager service"); + return nullptr; + } + return formMgrProxy_; +} +#endif + void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess) { HILOGD("Continuation result is: %{public}d", isSuccess); @@ -967,6 +993,63 @@ int32_t DistributedSchedService::ReleaseAbilityFromRemote(const sptr remoteDms = GetRemoteDms(remoteDeviceId); + if (remoteDms == nullptr) { + HILOGE("StartRemoteShareForm get remote DMS failed, remoteDeviceId : %{public}s", + DnetworkAdapter::AnonymizeDeviceId(remoteDeviceId).c_str()); + return GET_REMOTE_DMS_FAIL; + } + + int32_t result = remoteDms->StartShareFormFromRemote(remoteDeviceId, formShareInfo); + HILOGD("[PerformanceTest] StartRemoteShareForm RPC end"); + if (result != ERR_OK) { + HILOGE("StartRemoteShareForm failed, result : %{public}d", result); + } + return result; +} + +int32_t DistributedSchedService::StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) +{ + HILOGD("SHAREFORM:: func call begin"); + std::string localDeviceId = ""; + GetLocalDeviceId(localDeviceId); + if (CheckDeviceId(localDeviceId, remoteDeviceId)) { + HILOGE("localId is %{public}s != %{public}s", + DnetworkAdapter::AnonymizeDeviceId(localDeviceId).c_str(), + DnetworkAdapter::AnonymizeDeviceId(remoteDeviceId).c_str()); + return INVALID_REMOTE_PARAMETERS_ERR; + } + + auto remote = GetFormMgrProxy(); + if (remote == nullptr) { + HILOGE("Get remote proxy failed"); + return NOT_FIND_SERVICE_PROXY; + } + + auto formMgr = iface_cast(remote); + if (formMgr == nullptr) { + HILOGE("FormMgr type conversion failed"); + return NOT_FIND_SERVICE_PROXY; + } + + auto result = formMgr->RecvFormShareInfoFromRemote(formShareInfo); + HILOGD("SHAREFORM:: func call end"); + return result; +} +#endif + int32_t DistributedSchedService::RegisterDistributedComponentListener(const sptr& callback) { if (callback == nullptr) { diff --git a/services/dtbschedmgr/src/distributed_sched_stub.cpp b/services/dtbschedmgr/src/distributed_sched_stub.cpp index 3f3c2316..33b4e5a9 100755 --- a/services/dtbschedmgr/src/distributed_sched_stub.cpp +++ b/services/dtbschedmgr/src/distributed_sched_stub.cpp @@ -92,6 +92,10 @@ DistributedSchedStub::DistributedSchedStub() localFuncsMap_[RELEASE_REMOTE_ABILITY] = &DistributedSchedStub::ReleaseRemoteAbilityInner; remoteFuncsMap_[START_ABILITY_BY_CALL_FROM_REMOTE] = &DistributedSchedStub::StartAbilityByCallFromRemoteInner; remoteFuncsMap_[RELEASE_ABILITY_FROM_REMOTE] = &DistributedSchedStub::ReleaseAbilityFromRemoteInner; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + localFuncsMap_[START_REMOTE_SHARE_FORM] = &DistributedSchedStub::StartRemoteShareFormInner; + remoteFuncsMap_[START_SHARE_FORM_FROM_REMOTE] = &DistributedSchedStub::StartShareFormFromRemoteInner; +#endif localFuncsMap_[REGISTER_DISTRIBUTED_COMPONENT_LISTENER] = &DistributedSchedStub::RegisterDistributedComponentListenerInner; localFuncsMap_[GET_DISTRIBUTED_COMPONENT_LIST] = &DistributedSchedStub::GetDistributedComponentListInner; @@ -859,6 +863,48 @@ int32_t DistributedSchedStub::ReleaseAbilityFromRemoteInner(MessageParcel& data, PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); } +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply) +{ + HILOGD("SHAREFORM:: func call"); + std::string deviceId = ""; + PARCEL_READ_HELPER(data, String, deviceId); + shared_ptr formShareInfo(data.ReadParcelable()); + if (formShareInfo == nullptr) { + HILOGW("SHARE_FORM readParcelable failed!"); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast(ERR_FLATTEN_OBJECT)); + return ERR_FLATTEN_OBJECT; + } + + int32_t result = StartRemoteShareForm(deviceId, *formShareInfo); + HILOGI("result = %{public}d", result); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); +} + +int32_t DistributedSchedStub::StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply) +{ + HILOGD("SHAREFORM:: func call"); + if (!CheckCallingUid()) { + HILOGW("request DENIED!"); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast(DMS_PERMISSION_DENIED)); + return DMS_PERMISSION_DENIED; + } + + std::string deviceId = ""; + PARCEL_READ_HELPER(data, String, deviceId); + shared_ptr formShareInfo(data.ReadParcelable()); + if (formShareInfo == nullptr) { + HILOGW("SHARE_FORM readParcelable failed!"); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, static_cast(ERR_FLATTEN_OBJECT)); + return ERR_FLATTEN_OBJECT; + } + + int32_t result = StartShareFormFromRemote(deviceId, *formShareInfo); + HILOGI("result = %{public}d", result); + PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); +} +#endif + int32_t DistributedSchedStub::RegisterDistributedComponentListenerInner(MessageParcel& data, MessageParcel& reply) { if (!CheckCallingUid()) { diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index f11eab2d..9bffbe63 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -54,6 +54,10 @@ dsched_external_deps = [ "utils_base:utils", ] +if (dmsfwk_standard_form_share) { + dsched_external_deps += [ "form_fwk:form_manager" ] +} + if (dmsfwk_mission_manager) { dsched_external_deps += [ "multimedia_image_standard:image_native" ] } @@ -153,6 +157,10 @@ ohos_unittest("dschedcontinuetest") { defines = [ "SUPPORT_DISTRIBUTED_MISSION_MANAGER" ] } + if (dmsfwk_standard_form_share) { + defines += [ "SUPPORT_DISTRIBUTED_FORM_SHARE" ] + } + part_name = "dmsfwk" subsystem_name = "ability" } diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp index d3636cc1..a7e21479 100755 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp @@ -1,207 +1,221 @@ -/* - * 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 "mock_distributed_sched.h" -#include "dtbschedmgr_log.h" -#include "string_ex.h" - -using namespace std; -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace DistributedSchedule { -int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, - int32_t callerUid, int32_t requestCode, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, - const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) -{ - return 0; -} - -int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) -{ - return 0; -} - -int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, - int32_t callerUid, int32_t status, uint32_t accessToken) -{ - return 0; -} - -void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; -} - -int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; - return 0; -} - -int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, - const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) -{ - return 0; -} - -int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) -{ - return 0; -} - -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER -int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, - const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) -{ - expectedTrue_ = false; - return ERR_NONE; -} - -int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) -{ - return ERR_NONE; -} -#endif - -int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, - const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, - const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, - int32_t requestCode, uint32_t accessToken, const sptr &callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstall( - const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} -} // namespace DistributedSchedule +/* + * 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 "mock_distributed_sched.h" +#include "dtbschedmgr_log.h" +#include "string_ex.h" + +using namespace std; +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace DistributedSchedule { +int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, + int32_t callerUid, int32_t requestCode, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, + const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) +{ + return 0; +} + +int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) +{ + return 0; +} + +int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, + int32_t callerUid, int32_t status, uint32_t accessToken) +{ + return 0; +} + +void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; +} + +int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; + return 0; +} + +int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, + const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) +{ + return 0; +} + +int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) +{ + return 0; +} + +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER +int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, + const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) +{ + expectedTrue_ = false; + return ERR_NONE; +} + +int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) +{ + return ERR_NONE; +} +#endif + +int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, + const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, + const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, + int32_t requestCode, uint32_t accessToken, const sptr &callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstall( + const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +int32_t MockDistributedSched::StartRemoteShareForm(const std::string &remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo &formShareInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) +{ + return ERR_NONE; +} +#endif +} // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h index c3876e0a..89dd56ba 100644 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h @@ -1,89 +1,95 @@ -/* - * 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. - */ - -#ifndef MOCK_DISTRIBUTED_SCHED_H -#define MOCK_DISTRIBUTED_SCHED_H - -#include "distributed_sched_stub.h" - -namespace OHOS { -namespace DistributedSchedule { -class MockDistributedSched : public DistributedSchedStub { -public: - explicit MockDistributedSched(bool expectedTrue = false) - { - expectedTrue_ = expectedTrue; - } - ~MockDistributedSched() = default; - - int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken) override; - int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) override; - int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo, int32_t resultCode) override; - int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; - int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, - int32_t status, uint32_t accessToken) override; - void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; - int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; - int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) override; - int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) override; - int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER - int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; - 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; - int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) override; - int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) override; - int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) override; - int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; - int32_t StopSyncRemoteMissions(const std::string& devId) override; -#endif - int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) override; - int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, - const CallerInfo& callerInfo) override; - int32_t RegisterDistributedComponentListener(const sptr& callback) override; - int32_t GetDistributedComponentList(std::vector& distributedComponents) override; - int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken, const sptr& callback) override; - int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; - int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; - int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); -private: - bool expectedTrue_ = false; -}; -} // namespace DistributedSchedule -} // namespace OHOS - -#endif // MOCK_DISTRIBUTED_SCHED_H +/* + * 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. + */ + +#ifndef MOCK_DISTRIBUTED_SCHED_H +#define MOCK_DISTRIBUTED_SCHED_H + +#include "distributed_sched_stub.h" + +namespace OHOS { +namespace DistributedSchedule { +class MockDistributedSched : public DistributedSchedStub { +public: + explicit MockDistributedSched(bool expectedTrue = false) + { + expectedTrue_ = expectedTrue; + } + ~MockDistributedSched() = default; + + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken) override; + int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) override; + int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo, int32_t resultCode) override; + int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; + int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, + int32_t status, uint32_t accessToken) override; + void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; + int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; + int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) override; + int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) override; + int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER + int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; + 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; + int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) override; + int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) override; + int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) override; + int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; + int32_t StopSyncRemoteMissions(const std::string& devId) override; +#endif + int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) override; + int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, + const CallerInfo& callerInfo) override; + int32_t RegisterDistributedComponentListener(const sptr& callback) override; + int32_t GetDistributedComponentList(std::vector& distributedComponents) override; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareForm(const std::string &remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; +#endif + int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken, const sptr& callback) override; + int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; + int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; + int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); +private: + bool expectedTrue_ = false; +}; +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // MOCK_DISTRIBUTED_SCHED_H From ee299f05bcc944eaa3be13f7b96528197321b9da Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Wed, 3 Aug 2022 16:55:19 +0800 Subject: [PATCH 2/5] format crlf Signed-off-by: xuchenghua09 --- .../test/unittest/mock_distributed_sched.cpp | 440 +++++++++--------- .../test/unittest/mock_distributed_sched.h | 190 ++++---- 2 files changed, 315 insertions(+), 315 deletions(-) diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp index a7e21479..e1690a29 100755 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp @@ -1,221 +1,221 @@ -/* - * 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 "mock_distributed_sched.h" -#include "dtbschedmgr_log.h" -#include "string_ex.h" - -using namespace std; -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace DistributedSchedule { -int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, - int32_t callerUid, int32_t requestCode, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, - const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) -{ - return 0; -} - -int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) -{ - return 0; -} - -int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, - int32_t callerUid, int32_t status, uint32_t accessToken) -{ - return 0; -} - -void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; -} - -int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; - return 0; -} - -int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, - const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) -{ - return 0; -} - -int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) -{ - return 0; -} - -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER -int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, - const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) -{ - expectedTrue_ = false; - return ERR_NONE; -} - -int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) -{ - return ERR_NONE; -} -#endif - -int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, - const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, - const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, - int32_t requestCode, uint32_t accessToken, const sptr &callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstall( - const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} - -#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE -int32_t MockDistributedSched::StartRemoteShareForm(const std::string &remoteDeviceId, - const OHOS::AppExecFwk::FormShareInfo &formShareInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartShareFormFromRemote( - const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) -{ - return ERR_NONE; -} -#endif -} // namespace DistributedSchedule +/* + * 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 "mock_distributed_sched.h" +#include "dtbschedmgr_log.h" +#include "string_ex.h" + +using namespace std; +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace DistributedSchedule { +int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, + int32_t callerUid, int32_t requestCode, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, + const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) +{ + return 0; +} + +int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) +{ + return 0; +} + +int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, + int32_t callerUid, int32_t status, uint32_t accessToken) +{ + return 0; +} + +void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; +} + +int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; + return 0; +} + +int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, + const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) +{ + return 0; +} + +int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) +{ + return 0; +} + +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER +int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, + const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) +{ + expectedTrue_ = false; + return ERR_NONE; +} + +int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) +{ + return ERR_NONE; +} +#endif + +int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, + const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, + const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, + int32_t requestCode, uint32_t accessToken, const sptr &callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstall( + const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +int32_t MockDistributedSched::StartRemoteShareForm(const std::string &remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo &formShareInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) +{ + return ERR_NONE; +} +#endif +} // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h index 89dd56ba..3e133a46 100644 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h @@ -1,95 +1,95 @@ -/* - * 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. - */ - -#ifndef MOCK_DISTRIBUTED_SCHED_H -#define MOCK_DISTRIBUTED_SCHED_H - -#include "distributed_sched_stub.h" - -namespace OHOS { -namespace DistributedSchedule { -class MockDistributedSched : public DistributedSchedStub { -public: - explicit MockDistributedSched(bool expectedTrue = false) - { - expectedTrue_ = expectedTrue; - } - ~MockDistributedSched() = default; - - int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken) override; - int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) override; - int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo, int32_t resultCode) override; - int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; - int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, - int32_t status, uint32_t accessToken) override; - void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; - int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; - int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) override; - int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) override; - int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER - int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; - 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; - int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) override; - int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) override; - int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) override; - int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; - int32_t StopSyncRemoteMissions(const std::string& devId) override; -#endif - int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) override; - int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, - const CallerInfo& callerInfo) override; - int32_t RegisterDistributedComponentListener(const sptr& callback) override; - int32_t GetDistributedComponentList(std::vector& distributedComponents) override; -#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - int32_t StartRemoteShareForm(const std::string &remoteDeviceId, - const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; - int32_t StartShareFormFromRemote( - const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; -#endif - int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken, const sptr& callback) override; - int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; - int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; - int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); -private: - bool expectedTrue_ = false; -}; -} // namespace DistributedSchedule -} // namespace OHOS - -#endif // MOCK_DISTRIBUTED_SCHED_H +/* + * 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. + */ + +#ifndef MOCK_DISTRIBUTED_SCHED_H +#define MOCK_DISTRIBUTED_SCHED_H + +#include "distributed_sched_stub.h" + +namespace OHOS { +namespace DistributedSchedule { +class MockDistributedSched : public DistributedSchedStub { +public: + explicit MockDistributedSched(bool expectedTrue = false) + { + expectedTrue_ = expectedTrue; + } + ~MockDistributedSched() = default; + + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken) override; + int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) override; + int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo, int32_t resultCode) override; + int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; + int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, + int32_t status, uint32_t accessToken) override; + void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; + int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; + int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) override; + int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) override; + int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER + int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; + 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; + int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) override; + int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) override; + int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) override; + int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; + int32_t StopSyncRemoteMissions(const std::string& devId) override; +#endif + int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) override; + int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, + const CallerInfo& callerInfo) override; + int32_t RegisterDistributedComponentListener(const sptr& callback) override; + int32_t GetDistributedComponentList(std::vector& distributedComponents) override; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareForm(const std::string &remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartShareFormFromRemote( + const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; +#endif + int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken, const sptr& callback) override; + int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; + int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; + int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); +private: + bool expectedTrue_ = false; +}; +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // MOCK_DISTRIBUTED_SCHED_H From 7a6cbd3e22760955e090758ab1e8a02b34a9ecbd Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Fri, 5 Aug 2022 15:32:57 +0800 Subject: [PATCH 3/5] fix review Signed-off-by: xuchenghua09 --- services/dtbschedmgr/BUILD.gn | 3 +- .../include/distributed_sched_interface.h | 6 +- .../include/distributed_sched_proxy.h | 6 +- .../include/distributed_sched_service.h | 16 +- .../include/distributed_sched_stub.h | 4 +- .../include/form_mgr_death_recipient.h | 32 ++ .../src/distributed_sched_proxy.cpp | 4 +- .../src/distributed_sched_service.cpp | 63 ++- .../src/distributed_sched_stub.cpp | 4 +- .../src/form_mgr_death_recipient.cpp | 33 ++ .../test/unittest/mock_distributed_sched.cpp | 440 +++++++++--------- .../test/unittest/mock_distributed_sched.h | 190 ++++---- 12 files changed, 448 insertions(+), 353 deletions(-) create mode 100644 services/dtbschedmgr/include/form_mgr_death_recipient.h create mode 100644 services/dtbschedmgr/src/form_mgr_death_recipient.cpp diff --git a/services/dtbschedmgr/BUILD.gn b/services/dtbschedmgr/BUILD.gn index 2195e60f..a7625183 100644 --- a/services/dtbschedmgr/BUILD.gn +++ b/services/dtbschedmgr/BUILD.gn @@ -85,7 +85,8 @@ ohos_shared_library("distributedschedsvr") { deps = [ "//foundation/ability/dmsfwk/services/base:dmsbaseinner" ] if (dmsfwk_standard_form_share) { - external_deps += [ "form_fwk:form_manager" ] + external_deps += [ "form_fwk:form_manager" ] + sources += [ "src/form_mgr_death_recipient.cpp" ] } if (dmsfwk_mission_manager) { diff --git a/services/dtbschedmgr/include/distributed_sched_interface.h b/services/dtbschedmgr/include/distributed_sched_interface.h index 064a1edc..69183ff0 100755 --- a/services/dtbschedmgr/include/distributed_sched_interface.h +++ b/services/dtbschedmgr/include/distributed_sched_interface.h @@ -119,10 +119,10 @@ public: return 0; } #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - virtual int32_t StartRemoteShareForm(const std::string &remoteDeviceId, - const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0; + virtual int32_t StartRemoteShareForm(const std::string& remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo& formShareInfo) = 0; virtual int32_t StartShareFormFromRemote( - const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) = 0; + const std::string& remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo& formShareInfo) = 0; #endif virtual int32_t RegisterDistributedComponentListener(const sptr& callback) = 0; virtual int32_t GetDistributedComponentList(std::vector& distributedComponents) = 0; diff --git a/services/dtbschedmgr/include/distributed_sched_proxy.h b/services/dtbschedmgr/include/distributed_sched_proxy.h index 34653e92..d557c030 100755 --- a/services/dtbschedmgr/include/distributed_sched_proxy.h +++ b/services/dtbschedmgr/include/distributed_sched_proxy.h @@ -80,10 +80,10 @@ public: int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - int32_t StartRemoteShareForm(const std::string &remoteDeviceId, - const AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartRemoteShareForm(const std::string& remoteDeviceId, + const AppExecFwk::FormShareInfo& formShareInfo) override; int32_t StartShareFormFromRemote( - const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override; + const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) override; #endif int32_t RegisterDistributedComponentListener(const sptr& callback) override; int32_t GetDistributedComponentList(std::vector& distributedComponents) override; diff --git a/services/dtbschedmgr/include/distributed_sched_service.h b/services/dtbschedmgr/include/distributed_sched_service.h index d7f775f8..7c1bde18 100755 --- a/services/dtbschedmgr/include/distributed_sched_service.h +++ b/services/dtbschedmgr/include/distributed_sched_service.h @@ -26,6 +26,9 @@ #include "distributed_sched_continuation.h" #include "dms_callback_task.h" #include "dms_notifier.h" +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +#include "form_mgr_interface.h" +#endif #include "iremote_object.h" #include "iremote_proxy.h" #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER @@ -122,10 +125,11 @@ public: int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) override; #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - int32_t StartRemoteShareForm(const std::string &remoteDeviceId, - const AppExecFwk::FormShareInfo &formShareInfo) override; + int32_t StartRemoteShareForm(const std::string& remoteDeviceId, + const AppExecFwk::FormShareInfo& formShareInfo) override; int32_t StartShareFormFromRemote( - const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) override; + const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) override; + void ProcessFormMgrDied(const wptr& remote); #endif void ProcessCallerDied(const sptr& connect, int32_t deviceType); void ProcessCalleeDied(const sptr& connect); @@ -167,7 +171,7 @@ private: int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, const CallerInfo& callerInfo); #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - sptr GetFormMgrProxy(); + sptr GetFormMgrProxy(); #endif int32_t CleanMission(int32_t missionId); int32_t SetCallerInfo(int32_t callerUid, std::string localDeviceId, uint32_t accessToken, CallerInfo& callerInfo); @@ -203,7 +207,9 @@ private: std::mutex connectLock_; sptr connectDeathRecipient_; #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - sptr formMgrProxy_; + sptr formMgrDeathRecipient_; + sptr formMgrProxy_; + std::mutex formMgrLock_; #endif std::mutex calleeLock_; std::map, ConnectInfo> calleeMap_; diff --git a/services/dtbschedmgr/include/distributed_sched_stub.h b/services/dtbschedmgr/include/distributed_sched_stub.h index 4fcb7790..ac685e3f 100644 --- a/services/dtbschedmgr/include/distributed_sched_stub.h +++ b/services/dtbschedmgr/include/distributed_sched_stub.h @@ -63,8 +63,8 @@ private: int32_t StartFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); int32_t NotifyCompleteFreeInstallFromRemoteInner(MessageParcel& data, MessageParcel& reply); #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - int32_t StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply); - int32_t StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply); + int32_t StartRemoteShareFormInner(MessageParcel& data, MessageParcel& reply); + int32_t StartShareFormFromRemoteInner(MessageParcel& data, MessageParcel& reply); #endif int32_t RegisterDistributedComponentListenerInner(MessageParcel& data, MessageParcel& reply); int32_t GetDistributedComponentListInner(MessageParcel& data, MessageParcel& reply); diff --git a/services/dtbschedmgr/include/form_mgr_death_recipient.h b/services/dtbschedmgr/include/form_mgr_death_recipient.h new file mode 100644 index 00000000..3c111ab3 --- /dev/null +++ b/services/dtbschedmgr/include/form_mgr_death_recipient.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 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. + */ + +#ifndef OHOS_DISTRIBUTED_FORM_MGR_DEATH_RECIPIENT_H +#define OHOS_DISTRIBUTED_FORM_MGR_DEATH_RECIPIENT_H + +#include "iremote_object.h" + +namespace OHOS { +namespace DistributedSchedule { +class FormMgrDeathRecipient : public IRemoteObject::DeathRecipient { +public: + FormMgrDeathRecipient() = default; + ~FormMgrDeathRecipient() override = default; + + void OnRemoteDied(const wptr& remote) override; +}; +} // namespace DistributedSchedule +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_FORM_MGR_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/services/dtbschedmgr/src/distributed_sched_proxy.cpp b/services/dtbschedmgr/src/distributed_sched_proxy.cpp index 676b9124..82625b3b 100755 --- a/services/dtbschedmgr/src/distributed_sched_proxy.cpp +++ b/services/dtbschedmgr/src/distributed_sched_proxy.cpp @@ -771,7 +771,7 @@ int32_t DistributedSchedProxy::NotifyCompleteFreeInstallFromRemote(int64_t taskI #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE int32_t DistributedSchedProxy::StartRemoteShareForm( - const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) + const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) { HILOGD("SHAREFORM:: func call"); if (remoteDeviceId.empty()) { @@ -799,7 +799,7 @@ int32_t DistributedSchedProxy::StartRemoteShareForm( } int32_t DistributedSchedProxy::StartShareFormFromRemote( - const std::string &remoteDeviceId, const AppExecFwk::FormShareInfo &formShareInfo) + const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) { HILOGD("SHAREFORM:: func call"); if (remoteDeviceId.empty()) { diff --git a/services/dtbschedmgr/src/distributed_sched_service.cpp b/services/dtbschedmgr/src/distributed_sched_service.cpp index 1b04e173..3927b9dd 100644 --- a/services/dtbschedmgr/src/distributed_sched_service.cpp +++ b/services/dtbschedmgr/src/distributed_sched_service.cpp @@ -37,7 +37,7 @@ #include "element_name.h" #include "file_ex.h" #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE -#include "form_mgr_interface.h" +#include "form_mgr_death_recipient.h" #endif #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -492,26 +492,55 @@ int32_t DistributedSchedService::NotifyContinuationResultFromRemote(int32_t sess } #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE -sptr DistributedSchedService::GetFormMgrProxy() +sptr DistributedSchedService::GetFormMgrProxy() { HILOGD("%{public}s begin.", __func__); + std::lock_guard lock(formMgrLock_); if (formMgrProxy_ != nullptr) { - HILOGD("%{public}s fms proxy get success.", __func__); + HILOGD("get fms proxy success."); return formMgrProxy_; } - auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (sm == nullptr) { - HILOGE("GetAbilityManagerProxy sm is nullptr"); + + auto systemAbilityMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityMgr == nullptr) { + HILOGE("system ability manager is nullptr."); return nullptr; } - formMgrProxy_ = sm->GetSystemAbility(FORM_MGR_SERVICE_ID); - if (formMgrProxy_ == nullptr) { - HILOGE("failed to get ability manager service"); + auto remoteObj = systemAbilityMgr->GetSystemAbility(FORM_MGR_SERVICE_ID); + if (remoteObj == nullptr) { + HILOGE("failed to get form manager service"); return nullptr; } + + formMgrDeathRecipient_ = sptr(new FormMgrDeathRecipient()); + if (formMgrDeathRecipient_ == nullptr) { + HILOGE("failed to create FormMgrDeathRecipient!"); + return nullptr; + } + + if ((remoteObj->IsProxyObject()) && (!remoteObj->AddDeathRecipient(formMgrDeathRecipient_))) { + HILOGE("add death recipient to FormMgrService failed."); + return nullptr; + } + + formMgrProxy_ = iface_cast(remoteObj); return formMgrProxy_; } + +void DistributedSchedService::ProcessFormMgrDied(const wptr& remote) +{ + std::lock_guard lock(formMgrLock_); + if (formMgrProxy_ == nullptr) { + return; + } + + auto serviceRemote = formMgrProxy_->AsObject(); + if ((serviceRemote != nullptr) && (serviceRemote == remote.promote())) { + serviceRemote->RemoveDeathRecipient(formMgrDeathRecipient_); + formMgrProxy_ = nullptr; + } +} #endif void DistributedSchedService::NotifyContinuationCallbackResult(int32_t missionId, int32_t isSuccess) @@ -994,8 +1023,8 @@ int32_t DistributedSchedService::ReleaseAbilityFromRemote(const sptr(remote); + auto formMgr = GetFormMgrProxy(); if (formMgr == nullptr) { - HILOGE("FormMgr type conversion failed"); + HILOGE("get form mgr proxy failed."); return NOT_FIND_SERVICE_PROXY; } diff --git a/services/dtbschedmgr/src/distributed_sched_stub.cpp b/services/dtbschedmgr/src/distributed_sched_stub.cpp index 33b4e5a9..0df1b9a4 100755 --- a/services/dtbschedmgr/src/distributed_sched_stub.cpp +++ b/services/dtbschedmgr/src/distributed_sched_stub.cpp @@ -864,7 +864,7 @@ int32_t DistributedSchedStub::ReleaseAbilityFromRemoteInner(MessageParcel& data, } #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE -int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel &data, MessageParcel &reply) +int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel& data, MessageParcel& reply) { HILOGD("SHAREFORM:: func call"); std::string deviceId = ""; @@ -881,7 +881,7 @@ int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel &data, Mes PARCEL_WRITE_REPLY_NOERROR(reply, Int32, result); } -int32_t DistributedSchedStub::StartShareFormFromRemoteInner(MessageParcel &data, MessageParcel &reply) +int32_t DistributedSchedStub::StartShareFormFromRemoteInner(MessageParcel& data, MessageParcel& reply) { HILOGD("SHAREFORM:: func call"); if (!CheckCallingUid()) { diff --git a/services/dtbschedmgr/src/form_mgr_death_recipient.cpp b/services/dtbschedmgr/src/form_mgr_death_recipient.cpp new file mode 100644 index 00000000..6e2cf33a --- /dev/null +++ b/services/dtbschedmgr/src/form_mgr_death_recipient.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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 "form_mgr_death_recipient.h" + +#include "distributed_sched_service.h" +#include "dtbschedmgr_log.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace DistributedSchedule { +namespace { +const std::string TAG = "FormMgrDeathRecipient"; +} +void FormMgrDeathRecipient::OnRemoteDied(const wptr& remote) +{ + HILOGI("OnRemoteDied called"); + DistributedSchedService::GetInstance().ProcessFormMgrDied(remote); +} +} // namespace DistributedSchedule +} // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp index e1690a29..08e700b1 100755 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.cpp @@ -1,221 +1,221 @@ -/* - * 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 "mock_distributed_sched.h" -#include "dtbschedmgr_log.h" -#include "string_ex.h" - -using namespace std; -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; - -namespace OHOS { -namespace DistributedSchedule { -int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, - int32_t callerUid, int32_t requestCode, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, - const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) -{ - return 0; -} - -int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) -{ - return 0; -} - -int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, - int32_t callerUid, int32_t status, uint32_t accessToken) -{ - return 0; -} - -void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; -} - -int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) -{ - (void)isSuccess; - return 0; -} - -int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) -{ - return 0; -} - -int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, - const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return 0; -} - -int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) -{ - return 0; -} - -int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) -{ - return 0; -} - -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER -int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, - const sptr& obj) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) -{ - expectedTrue_ = false; - return ERR_NONE; -} - -int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) -{ - return ERR_NONE; -} -#endif - -int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, - const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, - const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, - int32_t requestCode, uint32_t accessToken, const sptr &callback) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::NotifyCompleteFreeInstall( - const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) -{ - return ERR_NONE; -} - -#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE -int32_t MockDistributedSched::StartRemoteShareForm(const std::string &remoteDeviceId, - const OHOS::AppExecFwk::FormShareInfo &formShareInfo) -{ - return ERR_NONE; -} - -int32_t MockDistributedSched::StartShareFormFromRemote( - const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) -{ - return ERR_NONE; -} -#endif -} // namespace DistributedSchedule +/* + * 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 "mock_distributed_sched.h" +#include "dtbschedmgr_log.h" +#include "string_ex.h" + +using namespace std; +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace DistributedSchedule { +int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want, + int32_t callerUid, int32_t requestCode, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, + const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) +{ + return 0; +} + +int32_t MockDistributedSched::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) +{ + return 0; +} + +int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, + int32_t callerUid, int32_t status, uint32_t accessToken) +{ + return 0; +} + +void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; +} + +int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) +{ + (void)isSuccess; + return 0; +} + +int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) +{ + return 0; +} + +int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, + const AppExecFwk::AbilityInfo& abilityInfo, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return 0; +} + +int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) +{ + return 0; +} + +int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) +{ + return 0; +} + +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER +int32_t MockDistributedSched::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterMissionListener(const std::u16string& devId, const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::UnRegisterMissionListener(const std::u16string& devId, + const sptr& obj) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) +{ + expectedTrue_ = false; + return ERR_NONE; +} + +int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncMissionsFromRemote(const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StopSyncRemoteMissions(const std::string& devId) +{ + return ERR_NONE; +} +#endif + +int32_t MockDistributedSched::StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, + const sptr& connect, int32_t callerUid, int32_t callerPid, uint32_t accessToken) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::ReleaseAbilityFromRemote(const sptr& connect, + const AppExecFwk::ElementName &element, const CallerInfo& callerInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::RegisterDistributedComponentListener(const sptr& callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::GetDistributedComponentList(std::vector& distributedComponents) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartRemoteFreeInstall(const OHOS::AAFwk::Want &want, int32_t callerUid, + int32_t requestCode, uint32_t accessToken, const sptr &callback) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartFreeInstallFromRemote(const IDistributedSched::FreeInstallInfo &info, int64_t taskId) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::NotifyCompleteFreeInstall( + const IDistributedSched::FreeInstallInfo &info, int64_t taskId, int32_t resultCode) +{ + return ERR_NONE; +} + +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE +int32_t MockDistributedSched::StartRemoteShareForm(const std::string& remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo& formShareInfo) +{ + return ERR_NONE; +} + +int32_t MockDistributedSched::StartShareFormFromRemote( + const std::string& remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo& formShareInfo) +{ + return ERR_NONE; +} +#endif +} // namespace DistributedSchedule } // namespace OHOS \ No newline at end of file diff --git a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h index 3e133a46..822dbcfc 100644 --- a/services/dtbschedmgr/test/unittest/mock_distributed_sched.h +++ b/services/dtbschedmgr/test/unittest/mock_distributed_sched.h @@ -1,95 +1,95 @@ -/* - * 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. - */ - -#ifndef MOCK_DISTRIBUTED_SCHED_H -#define MOCK_DISTRIBUTED_SCHED_H - -#include "distributed_sched_stub.h" - -namespace OHOS { -namespace DistributedSchedule { -class MockDistributedSched : public DistributedSchedStub { -public: - explicit MockDistributedSched(bool expectedTrue = false) - { - expectedTrue_ = expectedTrue; - } - ~MockDistributedSched() = default; - - int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken) override; - int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, - const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo) override; - int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, - const AccountInfo& accountInfo, int32_t resultCode) override; - int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, - int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; - int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, - int32_t status, uint32_t accessToken) override; - void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; - int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; - int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, - uint32_t accessToken) override; - int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, - const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t DisconnectAbilityFromRemote(const sptr& connect, - int32_t uid, const std::string& sourceDeviceId) override; - int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; -#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER - int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; - 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; - int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, - std::unique_ptr& missionSnapshot) override; - int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, - const CallerInfo& callerInfo) override; - int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, - std::vector& missionInfos) override; - int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; - int32_t StopSyncRemoteMissions(const std::string& devId) override; -#endif - int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, - int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; - int32_t ReleaseRemoteAbility(const sptr& connect, - const AppExecFwk::ElementName &element) override; - int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, - const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; - int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, - const CallerInfo& callerInfo) override; - int32_t RegisterDistributedComponentListener(const sptr& callback) override; - int32_t GetDistributedComponentList(std::vector& distributedComponents) override; -#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE - int32_t StartRemoteShareForm(const std::string &remoteDeviceId, - const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; - int32_t StartShareFormFromRemote( - const std::string &remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo &formShareInfo) override; -#endif - int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, - uint32_t accessToken, const sptr& callback) override; - int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; - int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; - int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); -private: - bool expectedTrue_ = false; -}; -} // namespace DistributedSchedule -} // namespace OHOS - -#endif // MOCK_DISTRIBUTED_SCHED_H +/* + * 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. + */ + +#ifndef MOCK_DISTRIBUTED_SCHED_H +#define MOCK_DISTRIBUTED_SCHED_H + +#include "distributed_sched_stub.h" + +namespace OHOS { +namespace DistributedSchedule { +class MockDistributedSched : public DistributedSchedStub { +public: + explicit MockDistributedSched(bool expectedTrue = false) + { + expectedTrue_ = expectedTrue; + } + ~MockDistributedSched() = default; + + int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken) override; + int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want, + const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo) override; + int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode, const CallerInfo& callerInfo, + const AccountInfo& accountInfo, int32_t resultCode) override; + int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callback, const OHOS::AAFwk::WantParams& wantParams) override; + int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid, + int32_t status, uint32_t accessToken) override; + void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override; + int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override; + int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t DisconnectRemoteAbility(const sptr& connect, int32_t callerUid, + uint32_t accessToken) override; + int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo, + const sptr& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t DisconnectAbilityFromRemote(const sptr& connect, + int32_t uid, const std::string& sourceDeviceId) override; + int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override; +#ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER + int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override; + 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; + int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId, + std::unique_ptr& missionSnapshot) override; + int32_t NotifyMissionsChangedFromRemote(const std::vector& missionInfos, + const CallerInfo& callerInfo) override; + int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo, + std::vector& missionInfos) override; + int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override; + int32_t StopSyncRemoteMissions(const std::string& devId) override; +#endif + int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr& connect, + int32_t callerUid, int32_t callerPid, uint32_t accessToken) override; + int32_t ReleaseRemoteAbility(const sptr& connect, + const AppExecFwk::ElementName &element) override; + int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr& connect, + const CallerInfo& callerInfo, const AccountInfo& accountInfo) override; + int32_t ReleaseAbilityFromRemote(const sptr& connect, const AppExecFwk::ElementName &element, + const CallerInfo& callerInfo) override; + int32_t RegisterDistributedComponentListener(const sptr& callback) override; + int32_t GetDistributedComponentList(std::vector& distributedComponents) override; +#ifdef SUPPORT_DISTRIBUTED_FORM_SHARE + int32_t StartRemoteShareForm(const std::string& remoteDeviceId, + const OHOS::AppExecFwk::FormShareInfo& formShareInfo) override; + int32_t StartShareFormFromRemote( + const std::string& remoteDeviceId, const OHOS::AppExecFwk::FormShareInfo& formShareInfo) override; +#endif + int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode, + uint32_t accessToken, const sptr& callback) override; + int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override; + int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override; + int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode); +private: + bool expectedTrue_ = false; +}; +} // namespace DistributedSchedule +} // namespace OHOS + +#endif // MOCK_DISTRIBUTED_SCHED_H From 8692c13f8010df961dde729376dff714be20d884 Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Fri, 5 Aug 2022 17:40:00 +0800 Subject: [PATCH 4/5] modify code Signed-off-by: xuchenghua09 --- services/dtbschedmgr/test/BUILD.gn | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/dtbschedmgr/test/BUILD.gn b/services/dtbschedmgr/test/BUILD.gn index 9bffbe63..79c56ed0 100644 --- a/services/dtbschedmgr/test/BUILD.gn +++ b/services/dtbschedmgr/test/BUILD.gn @@ -108,6 +108,11 @@ if (dmsfwk_mission_manager) { ] } +if (dmsfwk_standard_form_share) { + dtbschedmgr_sources += + [ "${distributed_service}/dtbschedmgr/src/form_mgr_death_recipient.cpp" ] +} + ohos_unittest("distributedschedsvrtest") { module_out_path = module_output_path From 1a41c95c42c76619a8c14a84d70bb70c875751bc Mon Sep 17 00:00:00 2001 From: xuchenghua09 Date: Fri, 5 Aug 2022 19:08:33 +0800 Subject: [PATCH 5/5] verify permissions Signed-off-by: xuchenghua09 --- services/dtbschedmgr/src/distributed_sched_stub.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/dtbschedmgr/src/distributed_sched_stub.cpp b/services/dtbschedmgr/src/distributed_sched_stub.cpp index 0df1b9a4..ccf6a265 100755 --- a/services/dtbschedmgr/src/distributed_sched_stub.cpp +++ b/services/dtbschedmgr/src/distributed_sched_stub.cpp @@ -867,6 +867,10 @@ int32_t DistributedSchedStub::ReleaseAbilityFromRemoteInner(MessageParcel& data, int32_t DistributedSchedStub::StartRemoteShareFormInner(MessageParcel& data, MessageParcel& reply) { HILOGD("SHAREFORM:: func call"); + if (!DistributedSchedPermission::GetInstance().IsFoundationCall()) { + return DMS_PERMISSION_DENIED; + } + std::string deviceId = ""; PARCEL_READ_HELPER(data, String, deviceId); shared_ptr formShareInfo(data.ReadParcelable());