diff --git a/frameworks/native/ability/ability_runtime/local_call_container.cpp b/frameworks/native/ability/ability_runtime/local_call_container.cpp index 91bfcc54e4..41509ff1cd 100644 --- a/frameworks/native/ability/ability_runtime/local_call_container.cpp +++ b/frameworks/native/ability/ability_runtime/local_call_container.cpp @@ -46,8 +46,6 @@ int LocalCallContainer::StartAbilityByCallInner( std::shared_ptr localCallRecord; if (!GetCallLocalRecord(element, localCallRecord)) { localCallRecord = std::make_shared(element); - std::string uri = element.GetURI(); - callProxyRecords_.emplace(uri, localCallRecord); } HILOG_DEBUG("start ability by call, localCallRecord->AddCaller(callback) begin"); @@ -66,57 +64,98 @@ int LocalCallContainer::StartAbilityByCallInner( } auto abilityClient = AAFwk::AbilityManagerClient::GetInstance(); if (abilityClient == nullptr) { - HILOG_ERROR("LocalCallContainer::Resolve abilityClient is nullptr"); + HILOG_ERROR("LocalCallContainer::StartAbilityByCallInner abilityClient is nullptr"); return ERR_INVALID_VALUE; } - sptr connect = iface_cast(this->AsObject()); - HILOG_DEBUG("start ability by call, abilityClient->StartAbilityByCall call"); + + sptr connect = new (std::nothrow) CallerConnection(); + connections_.emplace(connect); + connect->SetRecordAndContainer(localCallRecord, this->AsObject()); + HILOG_DEBUG("LocalCallContainer::StartAbilityByCallInner connections_.size is %{public}d", + static_cast(connections_.size())); return abilityClient->StartAbilityByCall(want, connect, callerToken); } int LocalCallContainer::ReleaseCall(const std::shared_ptr& callback) { HILOG_DEBUG("LocalCallContainer::ReleaseCall begin."); - auto isExist = [&callback](auto& record) { - return record.second->RemoveCaller(callback); - }; - - auto iter = std::find_if(callProxyRecords_.begin(), callProxyRecords_.end(), isExist); - if (iter == callProxyRecords_.end()) { - HILOG_ERROR("release localCallRecord failed."); + if (callback == nullptr) { + HILOG_ERROR("LocalCallContainer::ReleaseCall input params is nullptr"); return ERR_INVALID_VALUE; } - - std::shared_ptr record = iter->second; - if (record == nullptr) { - HILOG_ERROR("record is nullptr."); + auto abilityClient = AAFwk::AbilityManagerClient::GetInstance(); + if (abilityClient == nullptr) { + HILOG_ERROR("LocalCallContainer::ReleaseCall abilityClient is nullptr"); return ERR_INVALID_VALUE; } - - if (record->IsExistCallBack()) { + auto localCallRecord = callback->GetRecord(); + if (localCallRecord == nullptr) { + HILOG_ERROR("LocalCallContainer::ReleaseCall abilityClient is nullptr"); + return ERR_INVALID_VALUE; + } + localCallRecord->RemoveCaller(callback); + if (localCallRecord->IsExistCallBack()) { // just release callback. HILOG_DEBUG("LocalCallContainer::ReleaseCall, The callee has onther callers, just release this callback."); return ERR_OK; } - - // notify ams this connect need to release. - AppExecFwk::ElementName elementName = record->GetElementName(); - auto abilityClient = AAFwk::AbilityManagerClient::GetInstance(); - if (abilityClient == nullptr) { - HILOG_ERROR("LocalCallContainer::Resolve abilityClient is nullptr"); + auto connect = iface_cast(localCallRecord->GetConnection()); + if (connect == nullptr) { + HILOG_ERROR("LocalCallContainer::ReleaseCall connection conversion failed."); return ERR_INVALID_VALUE; } - sptr connect = iface_cast(this->AsObject()); - if (abilityClient->ReleaseCall(connect, elementName) != ERR_OK) { + int32_t retval = ERR_OK; + if (localCallRecord->IsSingletonRemote()) { + retval = RemoveSingletonCallLocalRecord(localCallRecord); + } else { + retval = RemoveMultipleCallLocalRecord(localCallRecord); + } + + if (retval != ERR_OK) { + HILOG_ERROR("Remove call local record failed"); + return retval; + } + + connections_.erase(connect); + if (abilityClient->ReleaseCall(connect, localCallRecord->GetElementName()) != ERR_OK) { HILOG_ERROR("ReleaseCall failed."); return ERR_INVALID_VALUE; } - - callProxyRecords_.erase(iter); HILOG_DEBUG("LocalCallContainer::ReleaseCall end."); return ERR_OK; } +int32_t LocalCallContainer::RemoveSingletonCallLocalRecord(std::shared_ptr &record) +{ + if (record == nullptr) { + HILOG_ERROR("input params invalid value"); + return ERR_INVALID_VALUE; + } + callProxyRecords_.erase(record->GetElementName().GetURI()); + return ERR_OK; +} + +int32_t LocalCallContainer::RemoveMultipleCallLocalRecord(std::shared_ptr &record) +{ + if (record == nullptr) { + HILOG_ERROR("input params invalid value"); + return ERR_INVALID_VALUE; + } + + auto iterRecord = multipleCallProxyRecords_.find(record->GetElementName().GetURI()); + if (iterRecord == multipleCallProxyRecords_.end()) { + HILOG_ERROR("release record in multiple not found."); + return ERR_INVALID_VALUE; + } + + iterRecord->second.erase(record); + if (iterRecord->second.empty()) { + multipleCallProxyRecords_.erase(iterRecord); + } + + return ERR_OK; +} + void LocalCallContainer::DumpCalls(std::vector& info) const { HILOG_DEBUG("LocalCallContainer::DumpCalls called."); @@ -148,27 +187,11 @@ void LocalCallContainer::DumpCalls(std::vector& info) const } void LocalCallContainer::OnAbilityConnectDone( - const AppExecFwk::ElementName& element, const sptr& remoteObject, int resultCode) -{ - HILOG_DEBUG("LocalCallContainer::OnAbilityConnectDone start %{public}s .", element.GetURI().c_str()); - if (resultCode != ERR_OK) { - HILOG_ERROR("OnAbilityConnectDone failed."); - } - std::shared_ptr localCallRecord; - if (GetCallLocalRecord(element, localCallRecord)) { - auto callRecipient = new (std::nothrow) CallRecipient( - std::bind(&LocalCallContainer::OnCallStubDied, this, std::placeholders::_1)); - localCallRecord->SetRemoteObject(remoteObject, callRecipient); - localCallRecord->InvokeCallBack(); - } + const AppExecFwk::ElementName& element, const sptr& remoteObject, int code) +{} - HILOG_DEBUG("LocalCallContainer::OnAbilityConnectDone end. resultCode:%{public}d.", resultCode); - return; -} - -void LocalCallContainer::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) -{ -} +void LocalCallContainer::OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int code) +{} void LocalCallContainer::OnRemoteStateChanged(const AppExecFwk::ElementName &element, int32_t abilityState) { @@ -211,14 +234,104 @@ void LocalCallContainer::OnCallStubDied(const wptr& remote) }; auto iter = std::find_if(callProxyRecords_.begin(), callProxyRecords_.end(), isExist); - if (iter == callProxyRecords_.end()) { - HILOG_ERROR("StubDied object not found from localCallRecord."); + if (iter != callProxyRecords_.end()) { + iter->second->OnCallStubDied(remote); + callProxyRecords_.erase(iter); return; } - iter->second->OnCallStubDied(remote); - callProxyRecords_.erase(iter); + auto isMultipleExit = [&diedRemote] (auto& record) { + return record->IsSameObject(diedRemote); + }; + for (auto &item : multipleCallProxyRecords_) { + HILOG_DEBUG("LocalCallContainer::OnCallStubDied multiple key[%{public}s].", item.first.c_str()); + auto iterMultiple = find_if(item.second.begin(), item.second.end(), isMultipleExit); + if (iterMultiple == item.second.end()) { + continue; + } + HILOG_DEBUG("LocalCallContainer::OnCallStubDied multiple key[%{public}s]. notify died event", + item.first.c_str()); + (*iterMultiple)->OnCallStubDied(remote); + item.second.erase(iterMultiple); + if (item.second.empty()) { + HILOG_DEBUG("LocalCallContainer::OnCallStubDied multiple key[%{public}s] empty.", item.first.c_str()); + multipleCallProxyRecords_.erase(item.first); + break; + } + } HILOG_DEBUG("LocalCallContainer::OnCallStubDied end."); } + +void LocalCallContainer::SetCallLocalRecord( + const AppExecFwk::ElementName& element, const std::shared_ptr &localCallRecord) +{ + HILOG_DEBUG("LocalCallContainer::SetCallLocalRecord called uri is %{private}s.", element.GetURI().c_str()); + const std::string strKey = element.GetURI(); + callProxyRecords_.erase(strKey); + callProxyRecords_.emplace(strKey, localCallRecord); +} + +void LocalCallContainer::SetMultipleCallLocalRecord( + const AppExecFwk::ElementName& element, const std::shared_ptr &localCallRecord) +{ + HILOG_DEBUG("LocalCallContainer::SetMultipleCallLocalRecord called uri is %{private}s.", element.GetURI().c_str()); + const std::string strKey = element.GetURI(); + auto iter = multipleCallProxyRecords_.find(strKey); + if (iter == multipleCallProxyRecords_.end()) { + std::set> records = { localCallRecord }; + multipleCallProxyRecords_.emplace(strKey, records); + return; + } + + iter->second.emplace(localCallRecord); +} + +void CallerConnection::SetRecordAndContainer(const std::shared_ptr &localCallRecord, + const sptr &container) +{ + localCallRecord_ = localCallRecord; + container_ = iface_cast(container); + localCallRecord_->SetConnection(this->AsObject()); +} + +void CallerConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int code) +{ + HILOG_DEBUG("CallerConnection::OnAbilityConnectDone start %{public}s .", element.GetURI().c_str()); + auto container = container_.promote(); + if (container == nullptr) { + HILOG_ERROR("CallerConnection::OnAbilityConnectDone container is nullptr."); + return; + } + + const bool isSingleton = (code == static_cast(AppExecFwk::LaunchMode::SINGLETON)); + localCallRecord_->SetIsSingleton(isSingleton); + + auto callRecipient = new (std::nothrow) CallRecipient( + std::bind(&LocalCallContainer::OnCallStubDied, container, std::placeholders::_1)); + localCallRecord_->SetRemoteObject(remoteObject, callRecipient); + + if (isSingleton) { + container->SetCallLocalRecord(element, localCallRecord_); + } else { + container->SetMultipleCallLocalRecord(element, localCallRecord_); + } + + localCallRecord_->InvokeCallBack(); + HILOG_DEBUG("CallerConnection::OnAbilityConnectDone end. code:%{public}d.", code); + return; +} + +void CallerConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int code) +{ + HILOG_DEBUG("CallerConnection::OnAbilityDisconnectDone start %{public}s.", element.GetURI().c_str()); + if (container_ == nullptr) { + HILOG_ERROR("CallerConnection::OnAbilityDisconnectDone container is nullptr."); + return; + } + + container_->OnAbilityDisconnectDone(element, code); + HILOG_DEBUG("CallerConnection::OnAbilityDisconnectDone end. code:%{public}d.", code); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/ability/ability_runtime/local_call_record.cpp b/frameworks/native/ability/ability_runtime/local_call_record.cpp index 94d0b5f81c..d00b28c30f 100644 --- a/frameworks/native/ability/ability_runtime/local_call_record.cpp +++ b/frameworks/native/ability/ability_runtime/local_call_record.cpp @@ -77,6 +77,8 @@ void LocalCallRecord::SetRemoteObject(const sptr& call, void LocalCallRecord::AddCaller(const std::shared_ptr& callback) { + std::shared_ptr caller = callback; + caller->SetRecord(weak_from_this()); callers_.emplace_back(callback); } @@ -184,5 +186,25 @@ bool LocalCallRecord::IsSameObject(const sptr& remote) const __func__, retVal ? "true" : "false"); return retVal; } + +void LocalCallRecord::SetIsSingleton(bool flag) +{ + isSingleton_ = flag; +} + +bool LocalCallRecord::IsSingletonRemote() +{ + return isSingleton_; +} + +void LocalCallRecord::SetConnection(const sptr &connect) +{ + connection_ = connect; +} + +sptr LocalCallRecord::GetConnection() +{ + return connection_.promote(); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/ability_runtime/caller_callback.h b/interfaces/kits/native/ability/ability_runtime/caller_callback.h index 0ff41b923a..c1ce7dadf3 100644 --- a/interfaces/kits/native/ability/ability_runtime/caller_callback.h +++ b/interfaces/kits/native/ability/ability_runtime/caller_callback.h @@ -22,6 +22,7 @@ namespace OHOS { namespace AbilityRuntime { constexpr const char* ON_RELEASE = "release"; constexpr const char* ON_DIED = "died"; +class LocalCallRecord; /** * @class CallerCallBack * CallerCallBack the callback function of caller. @@ -72,11 +73,22 @@ public: return isCallBack_; }; + void SetRecord(const std::weak_ptr &localCallRecord) + { + localCallRecord_ = localCallRecord; + } + + std::shared_ptr GetRecord() + { + return localCallRecord_.lock(); + } + private: CallBackClosure callback_ = {}; OnReleaseClosure onRelease_ = {}; OnRemoteStateChangedClosure onRemoteStateChanged_ = {}; bool isCallBack_ = false; + std::weak_ptr localCallRecord_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/ability_runtime/local_call_container.h b/interfaces/kits/native/ability/ability_runtime/local_call_container.h index f80145676c..31aa2879b6 100644 --- a/interfaces/kits/native/ability/ability_runtime/local_call_container.h +++ b/interfaces/kits/native/ability/ability_runtime/local_call_container.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,6 +25,7 @@ namespace OHOS { namespace AbilityRuntime { using Want = OHOS::AAFwk::Want; using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; +class CallerConnection; class LocalCallContainer : public AbilityConnectionStub { public: LocalCallContainer() = default; @@ -38,18 +39,46 @@ public: void DumpCalls(std::vector &info) const; virtual void OnAbilityConnectDone( - const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + const AppExecFwk::ElementName &element, const sptr &remoteObject, int code) override; - virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int code) override; + void SetCallLocalRecord( + const AppExecFwk::ElementName& element, const std::shared_ptr &localCallRecord); + void SetMultipleCallLocalRecord( + const AppExecFwk::ElementName& element, const std::shared_ptr &localCallRecord); + + void OnCallStubDied(const wptr &remote); void OnRemoteStateChanged(const AppExecFwk::ElementName &element, int32_t abilityState) override; private: bool GetCallLocalRecord( const AppExecFwk::ElementName &elementName, std::shared_ptr &localCallRecord); - void OnCallStubDied(const wptr &remote); + void OnSingletonCallStubDied(const wptr &remote); + int32_t RemoveSingletonCallLocalRecord(std::shared_ptr &record); + int32_t RemoveMultipleCallLocalRecord(std::shared_ptr &record); private: std::map> callProxyRecords_; + std::map>> multipleCallProxyRecords_; + std::set> connections_; +}; + +class CallerConnection : public AbilityConnectionStub { +public: + CallerConnection() = default; + virtual ~CallerConnection() = default; + + void SetRecordAndContainer(const std::shared_ptr &localCallRecord, + const sptr &container); + + virtual void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int code) override; + + virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int code) override; + +private: + std::shared_ptr localCallRecord_; + wptr container_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/ability_runtime/local_call_record.h b/interfaces/kits/native/ability/ability_runtime/local_call_record.h index 0b5ff873df..ef938e25b8 100644 --- a/interfaces/kits/native/ability/ability_runtime/local_call_record.h +++ b/interfaces/kits/native/ability/ability_runtime/local_call_record.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,14 +44,19 @@ public: int GetRecordId() const; std::vector> GetCallers() const; bool IsSameObject(const sptr &remote) const; - + void SetIsSingleton(bool flag); + bool IsSingletonRemote(); + void SetConnection(const sptr &connect); + sptr GetConnection(); private: static int64_t callRecordId; int recordId_ = 0; sptr remoteObject_ = nullptr; + wptr connection_ = nullptr; sptr callRecipient_ = nullptr; std::vector> callers_; AppExecFwk::ElementName elementName_ = {}; + bool isSingleton_ = false; }; /** diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index b16cf6a04a..ab64f2a1c9 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -845,6 +845,7 @@ public: void SetOtherMissionStackAbilityRecord(const std::shared_ptr &abilityRecord); void RevokeUriPermission(); void RemoveAbilityDeathRecipient() const; + bool IsExistConnection(const sptr &connect); protected: void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1); diff --git a/services/abilitymgr/include/call_container.h b/services/abilitymgr/include/call_container.h index 380df0912f..7bec7e53f7 100644 --- a/services/abilitymgr/include/call_container.h +++ b/services/abilitymgr/include/call_container.h @@ -47,6 +47,7 @@ public: bool CallRequestDone(const sptr & callStub); void Dump(std::vector &info) const; bool IsNeedToCallRequest() const; + bool IsExistConnection(const sptr &connect); private: void RemoveConnectDeathRecipient(const sptr &connect); diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index 9ce536db08..9d75a4ca2c 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -171,6 +171,16 @@ public: */ std::shared_ptr GetAbilityRecordByName(const AppExecFwk::ElementName &element); + /** + * @brief Get the Ability Records By elementName + * + * @param element conditions for search + * @param records out of parameter, list of returned records + * @return void + */ + void GetAbilityRecordsByName( + const AppExecFwk::ElementName &element, std::vector> &records); + /** * Get ability token by target mission id. * diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index e1d58264e1..392323407e 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -458,6 +458,7 @@ private: void CompleteForegroundFailed(const std::shared_ptr &abilityRecord, AbilityState state); int ResolveAbility(const std::shared_ptr &targetAbility, const AbilityRequest &abilityRequest); std::shared_ptr GetAbilityRecordByName(const AppExecFwk::ElementName &element); + std::vector> GetAbilityRecordsByName(const AppExecFwk::ElementName &element); int CallAbilityLocked(const AbilityRequest &abilityRequest); void UpdateMissionSnapshot(const std::shared_ptr &abilityRecord) const; void AddUninstallTags(const std::string &bundleName, int32_t uid); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f624bf8bf7..e712d8a697 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5999,11 +5999,10 @@ int AbilityManagerService::CheckStartByCallPermission(const AbilityRequest &abil { HILOG_INFO("%{public}s begin", __func__); // check whether the target ability is singleton mode and page type. - if (abilityRequest.abilityInfo.type == AppExecFwk::AbilityType::PAGE && - abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SINGLETON) { - HILOG_DEBUG("Called ability is common ability and singleton."); + if (abilityRequest.abilityInfo.type == AppExecFwk::AbilityType::PAGE) { + HILOG_DEBUG("Called ability is common ability."); } else { - HILOG_ERROR("Called ability is not common ability or singleton."); + HILOG_ERROR("Called ability is not common ability."); return RESOLVE_CALL_ABILITY_TYPE_ERR; } diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 5230c4d488..b65e8d6aee 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -2190,6 +2190,14 @@ bool AbilityRecord::ReleaseCall(const sptr& connect) return callContainer_->RemoveCallRecord(connect); } +bool AbilityRecord::IsExistConnection(const sptr &connect) +{ + HILOG_DEBUG("ability find call record by callback."); + CHECK_POINTER_RETURN_BOOL(callContainer_); + + return callContainer_->IsExistConnection(connect); +} + bool AbilityRecord::IsNeedToCallRequest() const { HILOG_DEBUG("ability release call record by callback."); diff --git a/services/abilitymgr/src/call_container.cpp b/services/abilitymgr/src/call_container.cpp index 09a44070cb..632e4dd3dc 100644 --- a/services/abilitymgr/src/call_container.cpp +++ b/services/abilitymgr/src/call_container.cpp @@ -199,5 +199,10 @@ void CallContainer::RemoveConnectDeathRecipient(const sptr & return; } } + +bool CallContainer::IsExistConnection(const sptr &connect) +{ + return callRecordMap_.find(connect->AsObject()) != callRecordMap_.end(); +} } // namespace AAFwk } // namesspace OHOS diff --git a/services/abilitymgr/src/call_record.cpp b/services/abilitymgr/src/call_record.cpp index 6bcd5ae659..6475a49367 100644 --- a/services/abilitymgr/src/call_record.cpp +++ b/services/abilitymgr/src/call_record.cpp @@ -130,11 +130,11 @@ bool CallRecord::SchedulerConnectDone() const AppExecFwk::AbilityInfo &abilityInfo = tmpService->GetAbilityInfo(); AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name, abilityInfo.moduleName); - connCallback_->OnAbilityConnectDone(element, callRemoteObject_, ERR_OK); + connCallback_->OnAbilityConnectDone(element, callRemoteObject_, static_cast(abilityInfo.launchMode)); state_ = CallState::REQUESTED; - HILOG_DEBUG("element: %{public}s, result: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(), - ERR_OK, state_); + HILOG_DEBUG("element: %{public}s, mode: %{public}d. connectstate:%{public}d.", element.GetURI().c_str(), + static_cast(abilityInfo.launchMode), state_); return true; } diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index 7670a80fd8..171fc46a84 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -263,6 +263,24 @@ std::shared_ptr MissionList::GetAbilityRecordByName(const AppExec return nullptr; } +void MissionList::GetAbilityRecordsByName( + const AppExecFwk::ElementName &element, std::vector> &records) +{ + for (auto mission : missions_) { + if (mission) { + const AppExecFwk::AbilityInfo &abilityInfo = mission->GetAbilityRecord()->GetAbilityInfo(); + AppExecFwk::ElementName localElement(abilityInfo.deviceId, abilityInfo.bundleName, + abilityInfo.name, abilityInfo.moduleName); + AppExecFwk::ElementName localElementNoModuleName(abilityInfo.deviceId, + abilityInfo.bundleName, abilityInfo.name); + if (localElement == element || localElementNoModuleName == element) { + HILOG_DEBUG("find element %{public}s", localElement.GetURI().c_str()); + records.push_back(mission->GetAbilityRecord()); + } + } + } +} + sptr MissionList::GetAbilityTokenByMissionId(int32_t missionId) { for (auto mission : missions_) { diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 960d36ee51..72f4bc6aaf 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -2762,7 +2762,11 @@ int MissionListManager::CallAbilityLocked(const AbilityRequest &abilityRequest) // mission is first created, add mission to default call mission list. // other keep in current mission list. if (!targetMission->GetMissionList()) { - defaultSingleList_->AddMissionToTop(targetMission); + if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SINGLETON) { + defaultSingleList_->AddMissionToTop(targetMission); + } else { + defaultStandardList_->AddMissionToTop(targetMission); + } } NotifyAbilityToken(targetAbilityRecord->GetToken(), abilityRequest); @@ -2806,7 +2810,16 @@ int MissionListManager::ReleaseCallLocked( std::lock_guard guard(managerLock_); - std::shared_ptr abilityRecord = GetAbilityRecordByName(element); + auto abilityRecords = GetAbilityRecordsByName(element); + auto isExist = [connect] (const std::shared_ptr &abilityRecord) { + return abilityRecord->IsExistConnection(connect); + }; + auto findRecord = std::find_if(abilityRecords.begin(), abilityRecords.end(), isExist); + if (findRecord == abilityRecords.end()) { + HILOG_ERROR("not found ability record by callback"); + return RELEASE_CALL_ABILITY_INNER_ERR; + } + auto abilityRecord = *findRecord; CHECK_POINTER_AND_RETURN(abilityRecord, RELEASE_CALL_ABILITY_INNER_ERR); if (!abilityRecord->ReleaseCall(connect)) { @@ -2863,6 +2876,38 @@ std::shared_ptr MissionListManager::GetAbilityRecordByName(const return defaultSingleList_->GetAbilityRecordByName(element); } +std::vector> MissionListManager::GetAbilityRecordsByName( + const AppExecFwk::ElementName &element) +{ + std::vector> records; + for (auto missionList : currentMissionLists_) { + if (missionList != nullptr) { + missionList->GetAbilityRecordsByName(element, records); + } + } + + // find in launcherMissionList_ + if (launcherList_ != nullptr) { + launcherList_->GetAbilityRecordsByName(element, records); + } + + // find in defaultStandardList_ + if (defaultStandardList_ != nullptr) { + defaultStandardList_->GetAbilityRecordsByName(element, records); + } + + if (!records.empty()) { + return records; + } + + // find in default singlelist_ + if (defaultSingleList_ != nullptr) { + defaultSingleList_->GetAbilityRecordsByName(element, records); + } + HILOG_DEBUG("records is %{public}s.", records.empty() ? "empty" : "not empty"); + return records; +} + void MissionListManager::OnCallConnectDied(const std::shared_ptr &callRecord) { HILOG_INFO("On callConnect died."); @@ -2870,7 +2915,16 @@ void MissionListManager::OnCallConnectDied(const std::shared_ptr &ca std::lock_guard guard(managerLock_); AppExecFwk::ElementName element = callRecord->GetTargetServiceName(); - auto abilityRecord = GetAbilityRecordByName(element); + auto abilityRecords = GetAbilityRecordsByName(element); + auto isExist = [callRecord] (const std::shared_ptr &abilityRecord) { + return abilityRecord->IsExistConnection(callRecord->GetConCallBack()); + }; + auto findRecord = std::find_if(abilityRecords.begin(), abilityRecords.end(), isExist); + if (findRecord == abilityRecords.end()) { + HILOG_ERROR("not found ability record by callback"); + return; + } + auto abilityRecord = *findRecord; CHECK_POINTER(abilityRecord); abilityRecord->ReleaseCall(callRecord->GetConCallBack()); } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 400ffebe2d..80d4b91406 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -330,6 +330,7 @@ group("unittest") { "atomic_service_status_callback_stub_test:unittest", "authorization_result_test:unittest", "background_task_observer_test:unittest", + "call_record_test:unittest", "completed_dispatcher_test:unittest", "configuration_test:unittest", "connect_server_manager_test:unittest", diff --git a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp index 1b27b37cd6..dd734d5119 100755 --- a/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp +++ b/test/unittest/ability_manager_service_test/ability_manager_service_test.cpp @@ -437,19 +437,9 @@ HWTEST_F(AbilityManagerServiceTest, CheckStartByCallPermission_002, TestSize.Lev { HILOG_INFO("AbilityManagerServiceTest CheckStartByCallPermission_002 start"); abilityRequest_.abilityInfo.type = AbilityType::PAGE; - abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON; EXPECT_EQ(abilityMs_->CheckStartByCallPermission(abilityRequest_), ERR_INVALID_VALUE); - abilityRequest_.abilityInfo.type = AbilityType::PAGE; - abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; - EXPECT_EQ(abilityMs_->CheckStartByCallPermission(abilityRequest_), RESOLVE_CALL_ABILITY_TYPE_ERR); - abilityRequest_.abilityInfo.type = AbilityType::DATA; - abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SINGLETON; - EXPECT_EQ(abilityMs_->CheckStartByCallPermission(abilityRequest_), RESOLVE_CALL_ABILITY_TYPE_ERR); - - abilityRequest_.abilityInfo.type = AbilityType::DATA; - abilityRequest_.abilityInfo.launchMode = AppExecFwk::LaunchMode::SPECIFIED; EXPECT_EQ(abilityMs_->CheckStartByCallPermission(abilityRequest_), RESOLVE_CALL_ABILITY_TYPE_ERR); HILOG_INFO("AbilityManagerServiceTest CheckStartByCallPermission_002 end"); } diff --git a/test/unittest/call_container_test/call_container_test.cpp b/test/unittest/call_container_test/call_container_test.cpp index 5cbe284980..1a6c8e69c3 100644 --- a/test/unittest/call_container_test/call_container_test.cpp +++ b/test/unittest/call_container_test/call_container_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -451,5 +451,20 @@ HWTEST_F(CallContainerTest, Call_Container_On_Connect_Died_001, TestSize.Level1) EXPECT_EQ(callContainer->callRecordMap_.size(), 0); } + +/* + * Feature: CallContainer + * Function: IsExistConnection + * SubFunction: NA + * FunctionPoints: NA + * EnvConditions:NA + * CaseDescription: Verify IsExistConnection funtion call called + */ +HWTEST_F(CallContainerTest, Call_Container_Is_Exist_Connection_001, TestSize.Level1) +{ + std::shared_ptr callContainer = get(); + sptr connect = new AbilityConnectCallback(); + EXPECT_FALSE(callContainer->IsExistConnection(connect)); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/call_record_test/BUILD.gn b/test/unittest/call_record_test/BUILD.gn new file mode 100644 index 0000000000..1451ae5890 --- /dev/null +++ b/test/unittest/call_record_test/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("call_record_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/ability_scheduler_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + ] + + sources = [ + "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", + "./call_record_test.cpp", # add mock file + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", + "//third_party/googletest:gmock_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "relational_store:native_appdatafwk", + "relational_store:native_dataability", + "relational_store:native_rdb", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":call_record_test" ] +} diff --git a/test/unittest/call_record_test/call_record_test.cpp b/test/unittest/call_record_test/call_record_test.cpp new file mode 100644 index 0000000000..7dbe4a7cd5 --- /dev/null +++ b/test/unittest/call_record_test/call_record_test.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include "ability_record.h" +#include "call_record.h" +#include "mock_serviceability_manager_service.h" + +namespace OHOS { +namespace AAFwk { +using namespace testing::ext; +using namespace OHOS::AbilityRuntime; + +namespace { +class MyAbilityConnection : public IAbilityConnection { +public: + MyAbilityConnection() = default; + virtual ~MyAbilityConnection() = default; + void OnAbilityConnectDone( + const AppExecFwk::ElementName& element, const sptr& remoteObject, int resultCode) override + {} + void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override + {} + sptr AsObject() override + { + return {}; + } +}; +} + +class CallRecordTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void CallRecordTest::SetUpTestCase(void) +{} + +void CallRecordTest::TearDownTestCase(void) +{} + +void CallRecordTest::SetUp(void) +{} + +void CallRecordTest::TearDown(void) +{} + +/** + * @tc.number: CallRecord_SchedulerConnectDone_001 + * @tc.name: SchedulerConnectDone + * @tc.desc: CallRecord to process SchedulerConnectDone success. + */ +HWTEST_F(CallRecordTest, CallRecord_SchedulerConnectDone_001, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "CallRecord_SchedulerConnectDone_001 begin"; + std::shared_ptr abilityRecord; + AbilityRequest abilityRequest; + abilityRequest.callerUid = 1; + abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE; + abilityRequest.connect = new MyAbilityConnection(); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + Want want; + abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + std::shared_ptr callRecord = CallRecord::CreateCallRecord( + abilityRequest.callerUid, abilityRecord->shared_from_this(), + abilityRequest.connect, abilityRequest.callerToken); + OHOS::sptr call = new (std::nothrow) MockServiceAbilityManagerService(); + callRecord->SetCallStub(call); + callRecord->SetConCallBack(abilityRequest.connect); + EXPECT_TRUE(callRecord->SchedulerConnectDone()); + + GTEST_LOG_(INFO) << "CallRecord_SchedulerConnectDone_001 end"; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn index 5489647ad4..7fb77dd153 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn @@ -69,7 +69,10 @@ ohos_unittest("caller_call_back_ut_test") { "//third_party/googletest:gtest_main", ] - external_deps = [ "c_utils:utils" ] + external_deps = [ + "ability_base:want", + "c_utils:utils" + ] } ohos_unittest("local_call_container_ut_test") { diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/caller_call_back_ut_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/caller_call_back_ut_test.cpp index 2f3c0320e5..4ae464bb20 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/caller_call_back_ut_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/caller_call_back_ut_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -17,6 +17,7 @@ #define private public #define protected public #include "caller_callback.h" +#include "local_call_record.h" #undef private #undef protected @@ -154,5 +155,20 @@ HWTEST_F(CallerCallBackTest, Caller_Call_Back_IsCallBack_0100, Function | Medium EXPECT_EQ(ret, true); } + +/** + * @tc.number: Caller_Call_Back_SetRecord_0100 + * @tc.name: SetRecord + * @tc.desc: Caller call back to process SetRecord and GetRecord success. + */ +HWTEST_F(CallerCallBackTest, Caller_Call_Back_SetRecord_0100, Function | MediumTest | Level1) +{ + CallerCallBack callerCallBack; + EXPECT_EQ(callerCallBack.GetRecord(), nullptr); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + callerCallBack.SetRecord(localCallRecord); + EXPECT_NE(callerCallBack.GetRecord(), nullptr); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp index 96644e72ea..daed3b9b22 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp @@ -159,12 +159,15 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0100, Function | M want.SetElementName("DemoDeviceId", "DemoBundleName", ""); std::shared_ptr callback = std::make_shared(); + std::shared_ptr callbackSec = std::make_shared(); AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); std::shared_ptr localCallRecord = std::make_shared(elementName); localCallRecord->AddCaller(callback); + localCallRecord->AddCaller(callbackSec); callback->SetCallBack([](const sptr&) {}); + callbackSec->SetCallBack([](const sptr&) {}); std::string uri = elementName.GetURI(); localCallContainer->callProxyRecords_.emplace(uri, localCallRecord); @@ -193,6 +196,249 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0200, Function | M EXPECT_TRUE(ret == ERR_INVALID_VALUE); } +/** + * @tc.number: Local_Call_Container_Release_0300 + * @tc.name: Release + * @tc.desc: Parameter 'callback' is nullptr, and Error 'ERR_INVALID_VALUE' returned. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0300, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + ErrCode ret = localCallContainer->ReleaseCall(nullptr); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/** + * @tc.number: Local_Call_Container_Release_0400 + * @tc.name: Release + * @tc.desc: Parameter 'localCallRecord' is nullptr, and Error 'ERR_INVALID_VALUE' returned. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0400, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + ErrCode ret = localCallContainer->ReleaseCall(nullptr); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/** + * @tc.number: Local_Call_Container_Release_0700 + * @tc.name: Release + * @tc.desc: Parameter 'connect' is nullptr, and Error 'ERR_INVALID_VALUE' returned. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0700, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr LocalCallRecordFirst = std::make_shared(elementName); + std::weak_ptr LocalCallRecordSec = LocalCallRecordFirst; + std::shared_ptr callback = std::make_shared(); + callback->SetRecord(LocalCallRecordSec); + ErrCode ret = localCallContainer->ReleaseCall(callback); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/** + * @tc.number: Local_Call_Container_Release_0800 + * @tc.name: Release + * @tc.desc: When 'localCallRecord' is an 'IsSingletonRemote', + * remove 'localCallRecord' by 'RemoveSingletonCallLocalRecord', and return 'ERR_OK'. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0800, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr LocalCallRecordFirst = std::make_shared(elementName); + std::weak_ptr LocalCallRecordSec = LocalCallRecordFirst; + LocalCallRecordFirst->SetIsSingleton(true); + LocalCallRecordFirst->SetConnection(localCallContainer); + std::shared_ptr callback = std::make_shared(); + callback->SetRecord(LocalCallRecordSec); + ErrCode ret = localCallContainer->ReleaseCall(callback); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Local_Call_Container_Release_0900 + * @tc.name: Release + * @tc.desc: Release record in multiple not found. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0900, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr LocalCallRecordFirst = std::make_shared(elementName); + std::weak_ptr LocalCallRecordSec = LocalCallRecordFirst; + LocalCallRecordFirst->SetConnection(localCallContainer); + std::shared_ptr callback = std::make_shared(); + callback->SetRecord(LocalCallRecordSec); + ErrCode ret = localCallContainer->ReleaseCall(callback); + EXPECT_EQ(ret, ERR_INVALID_VALUE); +} + +/** + * @tc.number: Local_Call_Container_Release_1000 + * @tc.name: Release + * @tc.desc: When 'element' doesn't have record, delete itself from 'multipleCallProxyRecords_'. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_1000, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr LocalCallRecordFirst = std::make_shared(elementName); + std::weak_ptr LocalCallRecordSec = LocalCallRecordFirst; + LocalCallRecordFirst->SetConnection(localCallContainer); + std::shared_ptr callback = std::make_shared(); + callback->SetRecord(LocalCallRecordSec); + localCallContainer->SetMultipleCallLocalRecord(elementName, LocalCallRecordFirst); + ErrCode ret = localCallContainer->ReleaseCall(callback); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Local_Call_Container_SetCallLocalRecord_1000 + * @tc.name: SetCallLocalRecord + * @tc.desc: Set 'callProxyRecords_'. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_SetCallLocalRecord_0100, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + localCallContainer->SetCallLocalRecord(elementName, localCallRecord); + EXPECT_NE( + localCallContainer->callProxyRecords_.find(elementName.GetURI()), + localCallContainer->callProxyRecords_.end()); +} + +/** + * @tc.number: Local_Call_Container_SetMultipleCallLocalRecord_0100 + * @tc.name: SetMultipleCallLocalRecord + * @tc.desc: Set 'multipleCallProxyRecords_'. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_SetMultipleCallLocalRecord_0100, Function | MediumTest | Level1) +{ + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecordFirst = std::make_shared(elementName); + constexpr int32_t COUNT_NUM = 1; + localCallContainer->SetMultipleCallLocalRecord(elementName, localCallRecordFirst); + EXPECT_EQ( + COUNT_NUM, localCallContainer->multipleCallProxyRecords_[elementName.GetURI()].count(localCallRecordFirst)); + + std::shared_ptr localCallRecordSecond = std::make_shared(elementName); + localCallContainer->SetMultipleCallLocalRecord(elementName, localCallRecordSecond); + + EXPECT_EQ( + COUNT_NUM, localCallContainer->multipleCallProxyRecords_[elementName.GetURI()].count(localCallRecordSecond)); +} + +/** + * @tc.number: Local_Call_Container_SetRecordAndContainer_0100 + * @tc.name: SetRecordAndContainer + * @tc.desc: Set 'container_' and 'localCallRecord_'. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_SetRecordAndContainer_0100, Function | MediumTest | Level1) +{ + sptr Container = new CallerConnection(); + sptr callRemoteObject = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + Container->SetRecordAndContainer(localCallRecord,callRemoteObject); + EXPECT_EQ(Container->localCallRecord_, localCallRecord); + EXPECT_EQ(Container->container_, iface_cast(callRemoteObject)); +} + +/** + * @tc.number: Local_Call_Container_OnAbilityConnectDone_0400 + * @tc.name: OnAbilityConnectDone + * @tc.desc: OnAbilityConnectDone container is nullptr. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0400, Function | MediumTest | Level1) +{ + sptr Container = new CallerConnection(); + sptr callRemoteObject = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + Container->OnAbilityConnectDone(elementName, callRemoteObject, + static_cast(AppExecFwk::LaunchMode::SINGLETON)); + EXPECT_EQ(nullptr,Container->container_.promote()); +} + +/** + * @tc.number: Local_Call_Container_OnAbilityConnectDone_0500 + * @tc.name: OnAbilityConnectDone + * @tc.desc: 'Code' is a Singleton. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0500, Function | MediumTest | Level1) +{ + sptr Connection = new CallerConnection(); + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + Connection->container_ = localCallContainer; + constexpr int32_t code = 0; + std::shared_ptr localCallRecord = std::make_shared(elementName); + Connection->localCallRecord_ = localCallRecord; + Connection->OnAbilityConnectDone(elementName, localCallContainer, code); + EXPECT_EQ(localCallContainer->callProxyRecords_[elementName.GetURI()], Connection->localCallRecord_); +} + +/** + * @tc.number: Local_Call_Container_OnAbilityConnectDone_0600 + * @tc.name: OnAbilityConnectDone + * @tc.desc: 'Code' is not a Singleton. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0600, Function | MediumTest | Level1) +{ + std::shared_ptr callback = std::make_shared(); + callback->SetCallBack([](const sptr&) {}); + sptr Connection = new CallerConnection(); + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + Connection->container_ = localCallContainer; + constexpr int32_t code = 1; + std::shared_ptr localCallRecord = std::make_shared(elementName); + localCallRecord->AddCaller(callback); + Connection->localCallRecord_ = localCallRecord; + Connection->OnAbilityConnectDone(elementName, localCallContainer, code); + constexpr int32_t COUNT_NUM = 1; + EXPECT_EQ(Connection->container_->multipleCallProxyRecords_[elementName.GetURI()]. + count(Connection->localCallRecord_),COUNT_NUM); + EXPECT_TRUE(callback->isCallBack_); +} + +/** + * @tc.number: Local_Call_Container_OnAbilityDisconnectDone_0100 + * @tc.name: OnAbilityDisconnectDone + * @tc.desc: OnAbilityDisconnectDone container is nullptr. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityDisconnectDone_0100, Function | MediumTest | Level1) +{ + sptr Connection = new CallerConnection(); + constexpr int32_t code = 0; + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + Connection->container_ = nullptr; + Connection->OnAbilityDisconnectDone(elementName, code); + EXPECT_EQ(Connection->container_, nullptr); +} + +/** + * @tc.number: Local_Call_Container_OnAbilityDisconnectDone_0200 + * @tc.name: OnAbilityDisconnectDone + * @tc.desc: OnAbilityDisconnectDone container is not nullptr. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityDisconnectDone_0200, Function | MediumTest | Level1) +{ + sptr Connection = new CallerConnection(); + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + constexpr int32_t code = 0; + Connection->container_ = localCallContainer; + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + Connection->OnAbilityDisconnectDone(elementName, code); + EXPECT_NE(Connection->container_, nullptr); +} + /** * @tc.number: Local_Call_Container_DumpCalls_0100 * @tc.name: DumpCalls @@ -303,77 +549,6 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_DumpCalls_0400, Function | EXPECT_TRUE(resultReceiver == ""); } -/** - * @tc.number: Local_Call_Container_OnAbilityConnectDone_0100 - * @tc.name: OnAbilityConnectDone - * @tc.desc: Local Call Container to process OnAbilityConnectDone, and the result is success resultCode == ERR_OK. - */ -HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0100, Function | MediumTest | Level1) -{ - LocalCallContainer localCallContainer; - - std::shared_ptr callback = std::make_shared(); - callback->SetCallBack([](const sptr&) {}); - AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); - std::shared_ptr localCallRecord = std::make_shared(elementName); - localCallRecord->AddCaller(callback); - localCallRecord->callers_.emplace_back(callback); - - std::string uri = elementName.GetURI(); - localCallContainer.callProxyRecords_.emplace(uri, localCallRecord); - - OHOS::sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); - - localCallContainer.OnAbilityConnectDone(elementName, remoteObject, 0); - EXPECT_EQ(callback->isCallBack_, true); -} - -/** - * @tc.number: Local_Call_Container_OnAbilityConnectDone_0200 - * @tc.name: OnAbilityConnectDone - * @tc.desc: Local Call Container to process OnAbilityConnectDone success when resultCode != ERR_OK. - */ -HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0200, Function | MediumTest | Level1) -{ - LocalCallContainer localCallContainer; - - std::shared_ptr callback = std::make_shared(); - callback->SetCallBack([](const sptr&) {}); - AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); - std::shared_ptr localCallRecord = std::make_shared(elementName); - localCallRecord->AddCaller(callback); - localCallRecord->callers_.emplace_back(callback); - - std::string uri = elementName.GetURI(); - localCallContainer.callProxyRecords_.emplace(uri, localCallRecord); - - OHOS::sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); - - localCallContainer.OnAbilityConnectDone(elementName, remoteObject, -1); - EXPECT_EQ(callback->isCallBack_, true); -} - -/** - * @tc.number: Local_Call_Container_OnAbilityConnectDone_0300 - * @tc.name: OnAbilityConnectDone - * @tc.desc: Local Call Container to process OnAbilityConnectDone fail because localCallRecord is null. - */ -HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0300, Function | MediumTest | Level1) -{ - LocalCallContainer localCallContainer; - - std::shared_ptr callback = std::make_shared(); - EXPECT_EQ(callback->isCallBack_, false); - AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); - std::shared_ptr localCallRecord = std::make_shared(elementName); - localCallRecord->AddCaller(callback); - - OHOS::sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); - - localCallContainer.OnAbilityConnectDone(elementName, remoteObject, 0); - EXPECT_EQ(callback->isCallBack_, false); -} - /** * @tc.number: Local_Call_Container_OnRemoteStateChanged_0100 * @tc.name: OnRemoteStateChanged @@ -381,21 +556,19 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnAbilityConnectDone_0300, */ HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnRemoteStateChanged_0100, Function | MediumTest | Level1) { - LocalCallContainer localCallContainer; - std::shared_ptr callback = std::make_shared(); callback->SetCallBack([](const sptr&) {}); AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); std::shared_ptr localCallRecord = std::make_shared(elementName); localCallRecord->AddCaller(callback); - localCallRecord->callers_.emplace_back(callback); + sptr Connection = new CallerConnection(); + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + Connection->container_ = localCallContainer; + constexpr int32_t code = 1; + Connection->localCallRecord_ = localCallRecord; + Connection->OnAbilityConnectDone(elementName, localCallContainer, code); - std::string uri = elementName.GetURI(); - localCallContainer.callProxyRecords_.emplace(uri, localCallRecord); - OHOS::sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); - localCallContainer.OnAbilityConnectDone(elementName, remoteObject, 0); - - localCallContainer.OnRemoteStateChanged(elementName, 0); + localCallContainer->OnRemoteStateChanged(elementName, 0); EXPECT_EQ(callback->isCallBack_, true); } @@ -406,21 +579,19 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnRemoteStateChanged_0100, */ HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnRemoteStateChanged_0200, Function | MediumTest | Level1) { - LocalCallContainer localCallContainer; - std::shared_ptr callback = std::make_shared(); callback->SetCallBack([](const sptr&) {}); AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); std::shared_ptr localCallRecord = std::make_shared(elementName); localCallRecord->AddCaller(callback); - localCallRecord->callers_.emplace_back(callback); + sptr Connection = new CallerConnection(); + sptr localCallContainer = new (std::nothrow)LocalCallContainer(); + Connection->container_ = localCallContainer; + constexpr int32_t code = 1; + Connection->localCallRecord_ = localCallRecord; + Connection->OnAbilityConnectDone(elementName, localCallContainer, code); - std::string uri = elementName.GetURI(); - localCallContainer.callProxyRecords_.emplace(uri, localCallRecord); - OHOS::sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); - localCallContainer.OnAbilityConnectDone(elementName, remoteObject, 0); - - localCallContainer.OnRemoteStateChanged(elementName, -1); + localCallContainer->OnRemoteStateChanged(elementName, -1); EXPECT_EQ(callback->isCallBack_, true); } @@ -465,7 +636,7 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_GetCallLocalRecord_0100, F } /** - * @tc.number: Local_Call_Container_GetCallLocalRecord_0100 + * @tc.number: Local_Call_Container_GetCallLocalRecord_0200 * @tc.name: GetCallLocalRecord * @tc.desc: Local Call Container to process GetCallLocalRecord, and the result is fail * because call proxy records is empty. @@ -499,5 +670,65 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0100, Funct localCallContainer.OnCallStubDied(remote); EXPECT_TRUE(localCallContainer.callProxyRecords_.empty()); } + +/** + * @tc.number: Local_Call_Container_OnCallStubDied_0200 + * @tc.name: OnCallStubDied + * @tc.desc: Delete records with empty remote in single instance. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0200, Function | MediumTest | Level1) +{ + LocalCallContainer localCallContainer; + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); + wptr remote(remoteObject); + const std::string strKey = elementName.GetURI(); + localCallRecord->SetRemoteObject(remoteObject); + localCallContainer.callProxyRecords_.emplace(strKey, localCallRecord); + localCallContainer.OnCallStubDied(remote); + EXPECT_TRUE(localCallContainer.callProxyRecords_.empty()); +} + +/** + * @tc.number: Local_Call_Container_OnCallStubDied_0300 + * @tc.name: OnCallStubDied + * @tc.desc: Delete the record of the specified remote in multiple instances. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0300, Function | MediumTest | Level1) +{ + LocalCallContainer localCallContainer; + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + AppExecFwk::ElementName elementNameSec("DemoDeviceIdSec", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecordSec = std::make_shared(elementNameSec); + localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecord); + localCallContainer.SetMultipleCallLocalRecord(elementNameSec, localCallRecordSec); + sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); + wptr remote(remoteObject); + localCallRecordSec->SetRemoteObject(remoteObject); + localCallContainer.OnCallStubDied(remote); + EXPECT_FALSE(localCallContainer.multipleCallProxyRecords_.empty()); +} + +/** + * @tc.number: Local_Call_Container_OnCallStubDied_0400 + * @tc.name: OnCallStubDied + * @tc.desc: Delete the specified remote in multiple instances + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0400, Function | MediumTest | Level1) +{ + LocalCallContainer localCallContainer; + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + std::shared_ptr localCallRecordSec = std::make_shared(elementName); + localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecord); + localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecordSec); + sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); + wptr remote(remoteObject); + localCallRecordSec->SetRemoteObject(remoteObject); + localCallContainer.OnCallStubDied(remote); + EXPECT_FALSE(localCallContainer.multipleCallProxyRecords_.empty()); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_record_ut_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_record_ut_test.cpp index bb7767885d..a4d75978f7 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_record_ut_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_record_ut_test.cpp @@ -453,5 +453,45 @@ HWTEST_F(LocalCallRecordTest, Local_Call_Record_IsSameObject_0300, Function | Me auto result = localCallRecord.IsSameObject(remote); EXPECT_FALSE(result); } + +/** +* @tc.number: Local_Call_Record_SetIsSingleton_0100 +* @tc.name: SetIsSingleton +* @tc.desc: SetIsSingleton input parameter false and IsSingletonRemote return false. +*/ +HWTEST_F(LocalCallRecordTest, Local_Call_Record_SetIsSingleton_0100, Function | MediumTest | Level1) +{ + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + LocalCallRecord localCallRecord(elementName); + localCallRecord.SetIsSingleton(false); + EXPECT_FALSE(localCallRecord.IsSingletonRemote()); +} + +/** +* @tc.number: Local_Call_Record_SetIsSingleton_0200 +* @tc.name: SetIsSingleton +* @tc.desc: SetIsSingleton input parameter true and IsSingletonRemote return true. +*/ +HWTEST_F(LocalCallRecordTest, Local_Call_Record_SetIsSingleton_0200, Function | MediumTest | Level1) +{ + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + LocalCallRecord localCallRecord(elementName); + localCallRecord.SetIsSingleton(true); + EXPECT_TRUE(localCallRecord.IsSingletonRemote()); +} + +/** +* @tc.number: Local_Call_Record_SetConnection_0100 +* @tc.name: SetConnection +* @tc.desc: SetConnection input parameter connect and GetConnection return connect. +*/ +HWTEST_F(LocalCallRecordTest, Local_Call_Record_SetConnection_0100, Function | MediumTest | Level1) +{ + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + LocalCallRecord localCallRecord(elementName); + sptr connect = new (std::nothrow) MockServiceAbilityManagerService(); + localCallRecord.SetConnection(connect); + EXPECT_EQ(localCallRecord.GetConnection(), connect); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/mission_list_manager_ut_test/mission_list_manager_ut_test.cpp b/test/unittest/mission_list_manager_ut_test/mission_list_manager_ut_test.cpp index 555d79dea0..3055838ccf 100644 --- a/test/unittest/mission_list_manager_ut_test/mission_list_manager_ut_test.cpp +++ b/test/unittest/mission_list_manager_ut_test/mission_list_manager_ut_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -370,6 +370,7 @@ HWTEST_F(MissionListManagerTest, MissionListManager_008, Function | MediumTest | missionListMgr->currentMissionLists_.push_front(missionList); missionListMgr->launcherList_ = missionList; + missionListMgr->defaultStandardList_ = missionList; missionListMgr->defaultSingleList_ = missionList; auto testRet = missionListMgr->GetAbilityRecordByName(element); @@ -582,5 +583,153 @@ HWTEST_F(MissionListManagerTest, MissionListManager_014, Function | MediumTest | EXPECT_EQ(ERR_OK, testRet); GTEST_LOG_(INFO) << "MissionListManager_014 end"; } + +/** + * @tc.number: MissionListManager_015 + * @tc.name: CallAbilityLocked + * @tc.desc: MissionListManager test CallAbilityLocked is not SINGLETON. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_015, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_015 begin"; + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + abilityInfo.applicationInfo = applicationInfo; + want.SetElementName("test.bundle.name", "test.ability.name"); + AbilityRequest abilityRequest; + abilityRequest.want = want; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.callType = AbilityCallType::CALL_REQUEST_TYPE; + abilityRequest.abilityInfo.bundleName = "test_bundle"; + abilityRequest.abilityInfo.name = "test_name"; + abilityRequest.abilityInfo.moduleName = "test_moduleName"; + abilityRequest.abilityInfo.launchMode = AppExecFwk::LaunchMode::STANDARD; + abilityRequest.startRecent = true; + std::shared_ptr abilityRecord = + std::make_shared(want, abilityInfo, abilityInfo.applicationInfo); + abilityRecord->isReady_ = true; + std::shared_ptr missionList = std::make_shared(); + std::shared_ptr missionListMgr = std::make_shared(0); + missionListMgr->defaultStandardList_ = missionList; + std::shared_ptr mission = + std::make_shared(0, abilityRecord, missionListMgr->GetMissionName(abilityRequest)); + missionList->AddMissionToTop(mission); + EXPECT_EQ(RESOLVE_CALL_ABILITY_INNER_ERR, missionListMgr->CallAbilityLocked(abilityRequest)); + GTEST_LOG_(INFO) << "MissionListManager_015 end"; +} + +/** + * @tc.number: MissionListManager_016 + * @tc.name: GetAbilityRecordsByName + * @tc.desc: MissionListManager to process GetAbilityRecordsByName success. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_016, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_016 begin"; + AppExecFwk::ElementName element; + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + std::shared_ptr missionListMgr = std::make_shared(0); + std::shared_ptr abilityRecord = + std::make_shared(want, abilityInfo, applicationInfo); + std::shared_ptr missionList = std::make_shared(); + std::shared_ptr mission = std::make_shared(0, abilityRecord, ""); + missionList->AddMissionToTop(mission); + missionListMgr->currentMissionLists_.push_front(missionList); + missionListMgr->currentMissionLists_.push_front(nullptr); + missionListMgr->launcherList_ = missionList; + missionListMgr->defaultStandardList_ = missionList; + auto ret = missionListMgr->GetAbilityRecordsByName(element); + EXPECT_FALSE(ret.empty()); + GTEST_LOG_(INFO) << "MissionListManager_016 end"; +} + +/** + * @tc.number: MissionListManager_017 + * @tc.name: GetAbilityRecordsByName + * @tc.desc: MissionListManager to process GetAbilityRecordsByName success. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_017, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_017 begin"; + AppExecFwk::ElementName element; + std::shared_ptr missionListMgr = std::make_shared(0); + auto ret = missionListMgr->GetAbilityRecordsByName(element); + EXPECT_TRUE(ret.empty()); + GTEST_LOG_(INFO) << "MissionListManager_017 end"; +} + +/** + * @tc.number: MissionListManager_018 + * @tc.name: GetAbilityRecordsByName + * @tc.desc: MissionListManager to process GetAbilityRecordsByName success. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_018, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_018 begin"; + AppExecFwk::ElementName element; + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + std::shared_ptr missionListMgr = std::make_shared(0); + std::shared_ptr abilityRecord = + std::make_shared(want, abilityInfo, applicationInfo); + std::shared_ptr missionList = std::make_shared(); + std::shared_ptr mission = std::make_shared(0, abilityRecord, ""); + missionListMgr->defaultSingleList_ = missionList; + auto ret = missionListMgr->GetAbilityRecordsByName(element); + EXPECT_TRUE(ret.empty()); + GTEST_LOG_(INFO) << "MissionListManager_018 end"; +} + +/** + * @tc.number: MissionListManager_019 + * @tc.name: ReleaseCallLocked + * @tc.desc: call ReleaseCallLocked interface and find_if fails and return RELEASE_CALL_ABILITY_INNER_ERR. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_019, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_019 begin"; + sptr connect = new (std::nothrow) MissionListManagerTestStub(); + AppExecFwk::ElementName element; + std::shared_ptr missionListMgr = std::make_shared(0); + missionListMgr->currentMissionLists_.push_front(nullptr); + auto ret = missionListMgr->ReleaseCallLocked(connect, element); + EXPECT_EQ(ret, RELEASE_CALL_ABILITY_INNER_ERR); + GTEST_LOG_(INFO) << "MissionListManager_019 end"; +} + +/** + * @tc.number: MissionListManager_020 + * @tc.name: ReleaseCallLocked + * @tc.desc: call ReleaseCallLocked interface and return ERR_OK. + */ +HWTEST_F(MissionListManagerTest, MissionListManager_020, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "MissionListManager_020 begin"; + sptr connect = new (std::nothrow) MissionListManagerTestStub(); + sptr callToken = nullptr; + AppExecFwk::ElementName element; + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + std::shared_ptr missionListMgr = std::make_shared(0); + std::shared_ptr abilityRecord = + std::make_shared(want, abilityInfo, applicationInfo); + std::shared_ptr callRecord = + std::make_shared(2, abilityRecord, connect, callToken); + std::shared_ptr callContainer = std::make_shared(); + std::shared_ptr missionList = std::make_shared(); + std::shared_ptr mission = std::make_shared(0, abilityRecord, ""); + abilityRecord->callContainer_ = callContainer; + callContainer->AddCallRecord(connect, callRecord); + missionList->AddMissionToTop(mission); + missionListMgr->currentMissionLists_.push_front(missionList); + auto ret = missionListMgr->ReleaseCallLocked(connect, element); + EXPECT_EQ(ret, ERR_OK); + GTEST_LOG_(INFO) << "MissionListManager_020 end"; +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/mission_list_test/mission_list_test.cpp b/test/unittest/mission_list_test/mission_list_test.cpp index 08f6baf1eb..74857787ec 100644 --- a/test/unittest/mission_list_test/mission_list_test.cpp +++ b/test/unittest/mission_list_test/mission_list_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1008,5 +1008,42 @@ HWTEST_F(MissionListTest, mission_list_get_mission_count_by_uid_001, TestSize.Le int32_t res2 = missionList->GetMissionCountByUid(1); EXPECT_EQ(res2, 1); } + +/* + * Feature: MissionList + * Function: GetAbilityRecordsByName + * SubFunction: NA + * FunctionPoints: MissionList GetAbilityRecordsByName + * EnvConditions: NA + * CaseDescription: Verify GetAbilityRecordsByName + */ +HWTEST_F(MissionListTest, mission_list_get_ability_records_by_name_001, TestSize.Level1) +{ + Want want; + AppExecFwk::AbilityInfo abilityInfo; + AppExecFwk::ApplicationInfo applicationInfo; + abilityInfo.deviceId = "deviceId1"; + abilityInfo.bundleName = "bundle"; + abilityInfo.name = "name"; + abilityInfo.moduleName = "bundle"; + std::shared_ptr abilityRecord = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord->Init(); + auto mission = std::make_shared(1, abilityRecord, "name"); + auto missionList = std::make_shared(); + ElementName elementEmpty("", "", ""); + std::vector> records; + missionList->missions_.push_front(mission); + missionList->missions_.push_front(nullptr); + missionList->GetAbilityRecordsByName(elementEmpty, records); + EXPECT_TRUE(records.empty()); + + ElementName element1(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name, abilityInfo.moduleName); + missionList->GetAbilityRecordsByName(element1, records); + EXPECT_FALSE(records.empty()); + + ElementName element2(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); + missionList->GetAbilityRecordsByName(element2, records); + EXPECT_FALSE(records.empty()); +} } // namespace AAFwk } // namespace OHOS