multi call ability commit

Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
xinking129
2023-04-17 12:04:56 +08:00
parent 32314f9ec5
commit 9085ede95e
26 changed files with 1101 additions and 173 deletions
@@ -46,8 +46,6 @@ int LocalCallContainer::StartAbilityByCallInner(
std::shared_ptr<LocalCallRecord> localCallRecord;
if (!GetCallLocalRecord(element, localCallRecord)) {
localCallRecord = std::make_shared<LocalCallRecord>(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<IAbilityConnection> connect = iface_cast<IAbilityConnection>(this->AsObject());
HILOG_DEBUG("start ability by call, abilityClient->StartAbilityByCall call");
sptr<CallerConnection> connect = new (std::nothrow) CallerConnection();
connections_.emplace(connect);
connect->SetRecordAndContainer(localCallRecord, this->AsObject());
HILOG_DEBUG("LocalCallContainer::StartAbilityByCallInner connections_.size is %{public}d",
static_cast<int32_t>(connections_.size()));
return abilityClient->StartAbilityByCall(want, connect, callerToken);
}
int LocalCallContainer::ReleaseCall(const std::shared_ptr<CallerCallBack>& 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<LocalCallRecord> 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<CallerConnection>(localCallRecord->GetConnection());
if (connect == nullptr) {
HILOG_ERROR("LocalCallContainer::ReleaseCall connection conversion failed.");
return ERR_INVALID_VALUE;
}
sptr<IAbilityConnection> connect = iface_cast<IAbilityConnection>(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<LocalCallRecord> &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<LocalCallRecord> &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<std::string>& info) const
{
HILOG_DEBUG("LocalCallContainer::DumpCalls called.");
@@ -148,27 +187,11 @@ void LocalCallContainer::DumpCalls(std::vector<std::string>& info) const
}
void LocalCallContainer::OnAbilityConnectDone(
const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& 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> 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<IRemoteObject>& 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<IRemoteObject>& 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> &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> &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<std::shared_ptr<LocalCallRecord>> records = { localCallRecord };
multipleCallProxyRecords_.emplace(strKey, records);
return;
}
iter->second.emplace(localCallRecord);
}
void CallerConnection::SetRecordAndContainer(const std::shared_ptr<LocalCallRecord> &localCallRecord,
const sptr<IRemoteObject> &container)
{
localCallRecord_ = localCallRecord;
container_ = iface_cast<LocalCallContainer>(container);
localCallRecord_->SetConnection(this->AsObject());
}
void CallerConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &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<int32_t>(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
@@ -77,6 +77,8 @@ void LocalCallRecord::SetRemoteObject(const sptr<IRemoteObject>& call,
void LocalCallRecord::AddCaller(const std::shared_ptr<CallerCallBack>& callback)
{
std::shared_ptr<CallerCallBack> caller = callback;
caller->SetRecord(weak_from_this());
callers_.emplace_back(callback);
}
@@ -184,5 +186,25 @@ bool LocalCallRecord::IsSameObject(const sptr<IRemoteObject>& 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<IRemoteObject> &connect)
{
connection_ = connect;
}
sptr<IRemoteObject> LocalCallRecord::GetConnection()
{
return connection_.promote();
}
} // namespace AbilityRuntime
} // namespace OHOS
@@ -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_ = localCallRecord;
}
std::shared_ptr<LocalCallRecord> GetRecord()
{
return localCallRecord_.lock();
}
private:
CallBackClosure callback_ = {};
OnReleaseClosure onRelease_ = {};
OnRemoteStateChangedClosure onRemoteStateChanged_ = {};
bool isCallBack_ = false;
std::weak_ptr<LocalCallRecord> localCallRecord_;
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -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<std::string> &info) const;
virtual void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &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> &localCallRecord);
void SetMultipleCallLocalRecord(
const AppExecFwk::ElementName& element, const std::shared_ptr<LocalCallRecord> &localCallRecord);
void OnCallStubDied(const wptr<IRemoteObject> &remote);
void OnRemoteStateChanged(const AppExecFwk::ElementName &element, int32_t abilityState) override;
private:
bool GetCallLocalRecord(
const AppExecFwk::ElementName &elementName, std::shared_ptr<LocalCallRecord> &localCallRecord);
void OnCallStubDied(const wptr<IRemoteObject> &remote);
void OnSingletonCallStubDied(const wptr<IRemoteObject> &remote);
int32_t RemoveSingletonCallLocalRecord(std::shared_ptr<LocalCallRecord> &record);
int32_t RemoveMultipleCallLocalRecord(std::shared_ptr<LocalCallRecord> &record);
private:
std::map<std::string, std::shared_ptr<LocalCallRecord>> callProxyRecords_;
std::map<std::string, std::set<std::shared_ptr<LocalCallRecord>>> multipleCallProxyRecords_;
std::set<sptr<CallerConnection>> connections_;
};
class CallerConnection : public AbilityConnectionStub {
public:
CallerConnection() = default;
virtual ~CallerConnection() = default;
void SetRecordAndContainer(const std::shared_ptr<LocalCallRecord> &localCallRecord,
const sptr<IRemoteObject> &container);
virtual void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int code) override;
virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int code) override;
private:
std::shared_ptr<LocalCallRecord> localCallRecord_;
wptr<LocalCallContainer> container_;
};
} // namespace AbilityRuntime
} // namespace OHOS
@@ -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<std::shared_ptr<CallerCallBack>> GetCallers() const;
bool IsSameObject(const sptr<IRemoteObject> &remote) const;
void SetIsSingleton(bool flag);
bool IsSingletonRemote();
void SetConnection(const sptr<IRemoteObject> &connect);
sptr<IRemoteObject> GetConnection();
private:
static int64_t callRecordId;
int recordId_ = 0;
sptr<IRemoteObject> remoteObject_ = nullptr;
wptr<IRemoteObject> connection_ = nullptr;
sptr<IRemoteObject::DeathRecipient> callRecipient_ = nullptr;
std::vector<std::shared_ptr<CallerCallBack>> callers_;
AppExecFwk::ElementName elementName_ = {};
bool isSingleton_ = false;
};
/**
@@ -845,6 +845,7 @@ public:
void SetOtherMissionStackAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
void RevokeUriPermission();
void RemoveAbilityDeathRecipient() const;
bool IsExistConnection(const sptr<IAbilityConnection> &connect);
protected:
void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1);
@@ -47,6 +47,7 @@ public:
bool CallRequestDone(const sptr<IRemoteObject> & callStub);
void Dump(std::vector<std::string> &info) const;
bool IsNeedToCallRequest() const;
bool IsExistConnection(const sptr<IAbilityConnection> &connect);
private:
void RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &connect);
@@ -171,6 +171,16 @@ public:
*/
std::shared_ptr<AbilityRecord> 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<std::shared_ptr<AbilityRecord>> &records);
/**
* Get ability token by target mission id.
*
@@ -458,6 +458,7 @@ private:
void CompleteForegroundFailed(const std::shared_ptr<AbilityRecord> &abilityRecord, AbilityState state);
int ResolveAbility(const std::shared_ptr<AbilityRecord> &targetAbility, const AbilityRequest &abilityRequest);
std::shared_ptr<AbilityRecord> GetAbilityRecordByName(const AppExecFwk::ElementName &element);
std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
int CallAbilityLocked(const AbilityRequest &abilityRequest);
void UpdateMissionSnapshot(const std::shared_ptr<AbilityRecord> &abilityRecord) const;
void AddUninstallTags(const std::string &bundleName, int32_t uid);
@@ -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;
}
@@ -2190,6 +2190,14 @@ bool AbilityRecord::ReleaseCall(const sptr<IAbilityConnection>& connect)
return callContainer_->RemoveCallRecord(connect);
}
bool AbilityRecord::IsExistConnection(const sptr<IAbilityConnection> &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.");
@@ -199,5 +199,10 @@ void CallContainer::RemoveConnectDeathRecipient(const sptr<IAbilityConnection> &
return;
}
}
bool CallContainer::IsExistConnection(const sptr<IAbilityConnection> &connect)
{
return callRecordMap_.find(connect->AsObject()) != callRecordMap_.end();
}
} // namespace AAFwk
} // namesspace OHOS
+3 -3
View File
@@ -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<int32_t>(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<int32_t>(abilityInfo.launchMode), state_);
return true;
}
+18
View File
@@ -263,6 +263,24 @@ std::shared_ptr<AbilityRecord> MissionList::GetAbilityRecordByName(const AppExec
return nullptr;
}
void MissionList::GetAbilityRecordsByName(
const AppExecFwk::ElementName &element, std::vector<std::shared_ptr<AbilityRecord>> &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<IRemoteObject> MissionList::GetAbilityTokenByMissionId(int32_t missionId)
{
for (auto mission : missions_) {
@@ -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<std::recursive_mutex> guard(managerLock_);
std::shared_ptr<AbilityRecord> abilityRecord = GetAbilityRecordByName(element);
auto abilityRecords = GetAbilityRecordsByName(element);
auto isExist = [connect] (const std::shared_ptr<AbilityRecord> &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<AbilityRecord> MissionListManager::GetAbilityRecordByName(const
return defaultSingleList_->GetAbilityRecordByName(element);
}
std::vector<std::shared_ptr<AbilityRecord>> MissionListManager::GetAbilityRecordsByName(
const AppExecFwk::ElementName &element)
{
std::vector<std::shared_ptr<AbilityRecord>> 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> &callRecord)
{
HILOG_INFO("On callConnect died.");
@@ -2870,7 +2915,16 @@ void MissionListManager::OnCallConnectDied(const std::shared_ptr<CallRecord> &ca
std::lock_guard<std::recursive_mutex> guard(managerLock_);
AppExecFwk::ElementName element = callRecord->GetTargetServiceName();
auto abilityRecord = GetAbilityRecordByName(element);
auto abilityRecords = GetAbilityRecordsByName(element);
auto isExist = [callRecord] (const std::shared_ptr<AbilityRecord> &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());
}
+1
View File
@@ -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",
@@ -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");
}
@@ -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> callContainer = get();
sptr<IAbilityConnection> connect = new AbilityConnectCallback();
EXPECT_FALSE(callContainer->IsExistConnection(connect));
}
} // namespace AAFwk
} // namespace OHOS
+77
View File
@@ -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" ]
}
@@ -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 <gtest/gtest.h>
#include <gmock/gmock.h>
#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<IRemoteObject>& remoteObject, int resultCode) override
{}
void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override
{}
sptr<IRemoteObject> 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> 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<AbilityRecord>(want, abilityInfo, applicationInfo);
std::shared_ptr<CallRecord> callRecord = CallRecord::CreateCallRecord(
abilityRequest.callerUid, abilityRecord->shared_from_this(),
abilityRequest.connect, abilityRequest.callerToken);
OHOS::sptr<OHOS::IRemoteObject> 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
@@ -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") {
@@ -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> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
callerCallBack.SetRecord(localCallRecord);
EXPECT_NE(callerCallBack.GetRecord(), nullptr);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -159,12 +159,15 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_Release_0100, Function | M
want.SetElementName("DemoDeviceId", "DemoBundleName", "");
std::shared_ptr<CallerCallBack> callback = std::make_shared<CallerCallBack>();
std::shared_ptr<CallerCallBack> callbackSec = std::make_shared<CallerCallBack>();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
localCallRecord->AddCaller(callbackSec);
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
callbackSec->SetCallBack([](const sptr<IRemoteObject>&) {});
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> 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> 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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> LocalCallRecordFirst = std::make_shared<LocalCallRecord>(elementName);
std::weak_ptr<LocalCallRecord> LocalCallRecordSec = LocalCallRecordFirst;
std::shared_ptr<CallerCallBack> callback = std::make_shared<CallerCallBack>();
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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> LocalCallRecordFirst = std::make_shared<LocalCallRecord>(elementName);
std::weak_ptr<LocalCallRecord> LocalCallRecordSec = LocalCallRecordFirst;
LocalCallRecordFirst->SetIsSingleton(true);
LocalCallRecordFirst->SetConnection(localCallContainer);
std::shared_ptr<CallerCallBack> callback = std::make_shared<CallerCallBack>();
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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> LocalCallRecordFirst = std::make_shared<LocalCallRecord>(elementName);
std::weak_ptr<LocalCallRecord> LocalCallRecordSec = LocalCallRecordFirst;
LocalCallRecordFirst->SetConnection(localCallContainer);
std::shared_ptr<CallerCallBack> callback = std::make_shared<CallerCallBack>();
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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> LocalCallRecordFirst = std::make_shared<LocalCallRecord>(elementName);
std::weak_ptr<LocalCallRecord> LocalCallRecordSec = LocalCallRecordFirst;
LocalCallRecordFirst->SetConnection(localCallContainer);
std::shared_ptr<CallerCallBack> callback = std::make_shared<CallerCallBack>();
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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(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> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecordFirst = std::make_shared<LocalCallRecord>(elementName);
constexpr int32_t COUNT_NUM = 1;
localCallContainer->SetMultipleCallLocalRecord(elementName, localCallRecordFirst);
EXPECT_EQ(
COUNT_NUM, localCallContainer->multipleCallProxyRecords_[elementName.GetURI()].count(localCallRecordFirst));
std::shared_ptr<LocalCallRecord> localCallRecordSecond = std::make_shared<LocalCallRecord>(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<CallerConnection> Container = new CallerConnection();
sptr<IRemoteObject> callRemoteObject =
OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
Container->SetRecordAndContainer(localCallRecord,callRemoteObject);
EXPECT_EQ(Container->localCallRecord_, localCallRecord);
EXPECT_EQ(Container->container_, iface_cast<LocalCallContainer>(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<CallerConnection> Container = new CallerConnection();
sptr<IRemoteObject> callRemoteObject =
OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
Container->OnAbilityConnectDone(elementName, callRemoteObject,
static_cast<int32_t>(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<CallerConnection> Connection = new CallerConnection();
sptr<LocalCallContainer> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
Connection->container_ = localCallContainer;
constexpr int32_t code = 0;
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
sptr<CallerConnection> Connection = new CallerConnection();
sptr<LocalCallContainer> localCallContainer = new (std::nothrow)LocalCallContainer();
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
Connection->container_ = localCallContainer;
constexpr int32_t code = 1;
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(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<CallerConnection> 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<CallerConnection> Connection = new CallerConnection();
sptr<LocalCallContainer> 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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
localCallRecord->callers_.emplace_back(callback);
std::string uri = elementName.GetURI();
localCallContainer.callProxyRecords_.emplace(uri, localCallRecord);
OHOS::sptr<OHOS::IRemoteObject> 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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
localCallRecord->callers_.emplace_back(callback);
std::string uri = elementName.GetURI();
localCallContainer.callProxyRecords_.emplace(uri, localCallRecord);
OHOS::sptr<OHOS::IRemoteObject> 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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
EXPECT_EQ(callback->isCallBack_, false);
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
OHOS::sptr<OHOS::IRemoteObject> 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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
localCallRecord->callers_.emplace_back(callback);
sptr<CallerConnection> Connection = new CallerConnection();
sptr<LocalCallContainer> 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<OHOS::IRemoteObject> 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<CallerCallBack> callback = std::make_shared<CallerCallBack>();
callback->SetCallBack([](const sptr<IRemoteObject>&) {});
AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
localCallRecord->AddCaller(callback);
localCallRecord->callers_.emplace_back(callback);
sptr<CallerConnection> Connection = new CallerConnection();
sptr<LocalCallContainer> 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<OHOS::IRemoteObject> 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> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
sptr<IRemoteObject> remoteObject = new (std::nothrow) MockServiceAbilityManagerService();
wptr<IRemoteObject> 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> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
AppExecFwk::ElementName elementNameSec("DemoDeviceIdSec", "DemoBundleName", "DemoAbilityName");
std::shared_ptr<LocalCallRecord> localCallRecordSec = std::make_shared<LocalCallRecord>(elementNameSec);
localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecord);
localCallContainer.SetMultipleCallLocalRecord(elementNameSec, localCallRecordSec);
sptr<IRemoteObject> remoteObject = new (std::nothrow) MockServiceAbilityManagerService();
wptr<IRemoteObject> 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> localCallRecord = std::make_shared<LocalCallRecord>(elementName);
std::shared_ptr<LocalCallRecord> localCallRecordSec = std::make_shared<LocalCallRecord>(elementName);
localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecord);
localCallContainer.SetMultipleCallLocalRecord(elementName, localCallRecordSec);
sptr<IRemoteObject> remoteObject = new (std::nothrow) MockServiceAbilityManagerService();
wptr<IRemoteObject> remote(remoteObject);
localCallRecordSec->SetRemoteObject(remoteObject);
localCallContainer.OnCallStubDied(remote);
EXPECT_FALSE(localCallContainer.multipleCallProxyRecords_.empty());
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -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<IRemoteObject> connect = new (std::nothrow) MockServiceAbilityManagerService();
localCallRecord.SetConnection(connect);
EXPECT_EQ(localCallRecord.GetConnection(), connect);
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -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> abilityRecord =
std::make_shared<AbilityRecord>(want, abilityInfo, abilityInfo.applicationInfo);
abilityRecord->isReady_ = true;
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
missionListMgr->defaultStandardList_ = missionList;
std::shared_ptr<Mission> mission =
std::make_shared<Mission>(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<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
std::shared_ptr<AbilityRecord> abilityRecord =
std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
std::shared_ptr<Mission> mission = std::make_shared<Mission>(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<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(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<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
std::shared_ptr<AbilityRecord> abilityRecord =
std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
std::shared_ptr<Mission> mission = std::make_shared<Mission>(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<IAbilityConnection> connect = new (std::nothrow) MissionListManagerTestStub();
AppExecFwk::ElementName element;
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(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<IAbilityConnection> connect = new (std::nothrow) MissionListManagerTestStub();
sptr<IRemoteObject> callToken = nullptr;
AppExecFwk::ElementName element;
Want want;
AppExecFwk::AbilityInfo abilityInfo;
AppExecFwk::ApplicationInfo applicationInfo;
std::shared_ptr<MissionListManager> missionListMgr = std::make_shared<MissionListManager>(0);
std::shared_ptr<AbilityRecord> abilityRecord =
std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
std::shared_ptr<CallRecord> callRecord =
std::make_shared<CallRecord>(2, abilityRecord, connect, callToken);
std::shared_ptr<CallContainer> callContainer = std::make_shared<CallContainer>();
std::shared_ptr<MissionList> missionList = std::make_shared<MissionList>();
std::shared_ptr<Mission> mission = std::make_shared<Mission>(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
@@ -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> abilityRecord = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
abilityRecord->Init();
auto mission = std::make_shared<Mission>(1, abilityRecord, "name");
auto missionList = std::make_shared<MissionList>();
ElementName elementEmpty("", "", "");
std::vector<std::shared_ptr<AbilityRecord>> 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