mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-25 12:23:20 -04:00
@@ -21,6 +21,8 @@
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
#include "ability_config.h"
|
||||
#include "ability_info.h"
|
||||
#include "ability_record.h"
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
@@ -31,6 +33,7 @@ namespace AAFwk {
|
||||
class AbilityCacheManager {
|
||||
public:
|
||||
using AbilityInfo = OHOS::AppExecFwk::AbilityInfo;
|
||||
using AbilityType = OHOS::AppExecFwk::AbilityType;
|
||||
/**
|
||||
* Get ability cache manager.
|
||||
* @return AbilityCacheManager
|
||||
@@ -70,6 +73,43 @@ public:
|
||||
* @return AbilityRecord if one is matched, otherwise nullptr.
|
||||
*/
|
||||
std::shared_ptr<AbilityRecord> FindRecordByToken(const sptr<IRemoteObject> &token);
|
||||
|
||||
/**
|
||||
* Get all the abilities of current ability cache manager.
|
||||
* @return AbilityRecord list.
|
||||
*/
|
||||
std::list<std::shared_ptr<AbilityRecord>> GetAbilityList();
|
||||
|
||||
/**
|
||||
* Get a single ability by sessionId from ability cache manager.
|
||||
* @param assertSessionId the ability assertSessionId to be searched in cache manager.
|
||||
* @return AbilityRecord if one is matched, otherwise nullptr.
|
||||
*/
|
||||
std::shared_ptr<AbilityRecord> FindRecordBySessionId(const std::string &assertSessionId);
|
||||
|
||||
/**
|
||||
* Get a single ability by serviceKey from ability cache manager.
|
||||
* @param serviceKey the ability serviceKey to be searched in cache manager.
|
||||
* @return AbilityRecord if one is matched, otherwise nullptr.
|
||||
*/
|
||||
std::shared_ptr<AbilityRecord> FindRecordByServiceKey(const std::string &serviceKey);
|
||||
|
||||
/**
|
||||
* Remove the launcher death recipient from ability cache manager.
|
||||
*/
|
||||
void RemoveLauncherDeathRecipient();
|
||||
|
||||
/**
|
||||
* Sign the restart flag by bundleName of ability from ability cache manager.
|
||||
* @param bundleName the ability bundleName to be searched in cache manager.
|
||||
*/
|
||||
void SignRestartAppFlag(const std::string &bundleName);
|
||||
|
||||
/**
|
||||
* Delete the invalid ability by bundleName from ability cache manager.
|
||||
* @param bundleName the ability bundleName to be searched in cache manager.
|
||||
*/
|
||||
void DeleteInvalidServiceRecord(const std::string &bundleName);
|
||||
private:
|
||||
AbilityCacheManager();
|
||||
~AbilityCacheManager();
|
||||
|
||||
@@ -601,6 +601,7 @@ private:
|
||||
|
||||
void KeepAbilityAlive(const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t currentUserId);
|
||||
void ProcessEliminateAbilityRecord(std::shared_ptr<AbilityRecord> eliminateRecord);
|
||||
std::string GetServiceKey(const std::shared_ptr<AbilityRecord> &service);
|
||||
|
||||
private:
|
||||
const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
const std::string FRS_APP_INDEX = "ohos.extra.param.key.frs_index";
|
||||
const std::string FRS_BUNDLE_NAME = "com.ohos.formrenderservice";
|
||||
|
||||
AbilityCacheManager::AbilityCacheManager() {}
|
||||
|
||||
@@ -194,12 +196,14 @@ std::shared_ptr<AbilityRecord> AbilityCacheManager::FindRecordByToken(const sptr
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "The param token is nullptr for FindRecordByToken operation.");
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
sptr<IRemoteObject> srcToken = (*it)->GetToken();
|
||||
if (srcToken == token) {
|
||||
std::shared_ptr<AbilityRecord> &abilityRecord = *it;
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Find the ability from lru, service:%{public}s, extension type %{public}d",
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR,
|
||||
"Find the ability by token from lru, service:%{public}s, extension type %{public}d",
|
||||
abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType);
|
||||
return abilityRecord;
|
||||
} else {
|
||||
@@ -208,5 +212,96 @@ std::shared_ptr<AbilityRecord> AbilityCacheManager::FindRecordByToken(const sptr
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<AbilityRecord>> AbilityCacheManager::GetAbilityList()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return devRecLru_;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRecord> AbilityCacheManager::FindRecordBySessionId(const std::string &assertSessionId)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
auto assertSessionStr = (*it)->GetWant().GetStringParam(Want::PARAM_ASSERT_FAULT_SESSION_ID);
|
||||
if (assertSessionStr == assertSessionId) {
|
||||
std::shared_ptr<AbilityRecord> &abilityRecord = *it;
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR,
|
||||
"Find the ability by sessionId from lru, service:%{public}s, extension type %{public}d",
|
||||
abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType);
|
||||
return abilityRecord;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<AbilityRecord> AbilityCacheManager::FindRecordByServiceKey(const std::string &serviceKey)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
std::string curServiceKey = (*it)->GetURI();
|
||||
if (FRS_BUNDLE_NAME == (*it)->GetAbilityInfo().bundleName) {
|
||||
curServiceKey = curServiceKey + std::to_string((*it)->GetWant().GetIntParam(FRS_APP_INDEX, 0));
|
||||
}
|
||||
if (curServiceKey.compare(serviceKey) == 0) {
|
||||
std::shared_ptr<AbilityRecord> &abilityRecord = *it;
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR,
|
||||
"Find the ability by serviceKey from lru, service:%{public}s, extension type %{public}d",
|
||||
abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType);
|
||||
return abilityRecord;
|
||||
} else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AbilityCacheManager::RemoveLauncherDeathRecipient()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
auto targetExtension = *it;
|
||||
if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION &&
|
||||
((targetExtension->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME &&
|
||||
targetExtension->GetAbilityInfo().bundleName == AbilityConfig::LAUNCHER_BUNDLE_NAME) ||
|
||||
targetExtension->IsSceneBoard())) {
|
||||
targetExtension->RemoveAbilityDeathRecipient();
|
||||
return;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityCacheManager::SignRestartAppFlag(const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
auto abilityRecord = *it;
|
||||
if (abilityRecord != nullptr && abilityRecord->GetApplicationInfo().bundleName == bundleName) {
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityCacheManager::DeleteInvalidServiceRecord(const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = devRecLru_.begin();
|
||||
while (it != devRecLru_.end()) {
|
||||
auto abilityRecord = *it;
|
||||
if (abilityRecord != nullptr && abilityRecord->GetApplicationInfo().bundleName == bundleName) {
|
||||
RemoveAbilityRecInProcList(abilityRecord);
|
||||
RemoveAbilityRecInDevList(abilityRecord);
|
||||
}
|
||||
it++;
|
||||
}
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
@@ -765,7 +765,8 @@ int AbilityConnectManager::DisconnectAbilityLocked(const sptr<IAbilityConnection
|
||||
void AbilityConnectManager::TerminateRecord(std::shared_ptr<AbilityRecord> abilityRecord)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "terminate record called.");
|
||||
if (!GetAbilityRecordById(abilityRecord->GetRecordId())) {
|
||||
if (!GetAbilityRecordById(abilityRecord->GetRecordId()) &&
|
||||
!AbilityCacheManager::GetInstance().FindRecordByToken(abilityRecord->GetToken())) {
|
||||
return;
|
||||
}
|
||||
auto timeoutTask = [abilityRecord, connectManager = shared_from_this()]() {
|
||||
@@ -892,6 +893,22 @@ void AbilityConnectManager::OnAppStateChanged(const AppInfo &info)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
auto cacheAbilityList = AbilityCacheManager::GetInstance().GetAbilityList();
|
||||
std::for_each(cacheAbilityList.begin(), cacheAbilityList.end(), [&info](std::shared_ptr<AbilityRecord> &service) {
|
||||
if (service && (info.processName == service->GetAbilityInfo().process ||
|
||||
info.processName == service->GetApplicationInfo().bundleName)) {
|
||||
auto appName = service->GetApplicationInfo().name;
|
||||
auto uid = service->GetAbilityInfo().applicationInfo.uid;
|
||||
auto isExist = [&appName, &uid](const AppData &appData) {
|
||||
return appData.appName == appName && appData.uid == uid;
|
||||
};
|
||||
auto iter = std::find_if(info.appData.begin(), info.appData.end(), isExist);
|
||||
if (iter != info.appData.end()) {
|
||||
service->SetAppState(info.state);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int AbilityConnectManager::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state)
|
||||
@@ -2175,7 +2192,7 @@ void AbilityConnectManager::HandleNotifyAssertFaultDialogDied(const std::shared_
|
||||
void AbilityConnectManager::CloseAssertDialog(const std::string &assertSessionId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Called");
|
||||
sptr<IRemoteObject> token;
|
||||
std::shared_ptr<AbilityRecord> abilityRecord = nullptr;
|
||||
{
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (const auto &item : serviceMap_) {
|
||||
@@ -2185,14 +2202,26 @@ void AbilityConnectManager::CloseAssertDialog(const std::string &assertSessionId
|
||||
|
||||
auto assertSessionStr = item.second->GetWant().GetStringParam(Want::PARAM_ASSERT_FAULT_SESSION_ID);
|
||||
if (assertSessionStr == assertSessionId) {
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate assert fault dialog called.");
|
||||
terminatingExtensionMap_.emplace(item.first, item.second);
|
||||
token = item.second->GetToken();
|
||||
abilityRecord = item.second;
|
||||
serviceMap_.erase(item.first);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (abilityRecord == nullptr) {
|
||||
abilityRecord = AbilityCacheManager::GetInstance().FindRecordBySessionId(assertSessionId);
|
||||
AbilityCacheManager::GetInstance().Remove(abilityRecord);
|
||||
}
|
||||
if (abilityRecord == nullptr) {
|
||||
return;
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate assert fault dialog called.");
|
||||
std::string serviceKey = abilityRecord->GetURI();
|
||||
if (FRS_BUNDLE_NAME == abilityRecord->GetAbilityInfo().bundleName) {
|
||||
serviceKey = serviceKey + std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0));
|
||||
}
|
||||
terminatingExtensionMap_.emplace(serviceKey, abilityRecord);
|
||||
sptr<IRemoteObject> token = abilityRecord->GetToken();
|
||||
if (token != nullptr) {
|
||||
std::lock_guard lock(serialMutex_);
|
||||
TerminateAbilityLocked(token);
|
||||
@@ -2273,10 +2302,20 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr<AbilityRecord>
|
||||
}
|
||||
}
|
||||
|
||||
std::string AbilityConnectManager::GetServiceKey(const std::shared_ptr<AbilityRecord> &service)
|
||||
{
|
||||
std::string serviceKey = service->GetURI();
|
||||
if (FRS_BUNDLE_NAME == service->GetAbilityInfo().bundleName) {
|
||||
serviceKey = serviceKey + std::to_string(service->GetWant().GetIntParam(FRS_APP_INDEX, 0));
|
||||
}
|
||||
return serviceKey;
|
||||
}
|
||||
|
||||
void AbilityConnectManager::DumpState(std::vector<std::string> &info, bool isClient, const std::string &args)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "args:%{public}s.", args.c_str());
|
||||
auto serviceMapBack = GetServiceMap();
|
||||
auto cacheList = AbilityCacheManager::GetInstance().GetAbilityList();
|
||||
if (!args.empty()) {
|
||||
auto it = std::find_if(serviceMapBack.begin(), serviceMapBack.end(), [&args](const auto &service) {
|
||||
return service.first.compare(args) == 0;
|
||||
@@ -2287,7 +2326,21 @@ void AbilityConnectManager::DumpState(std::vector<std::string> &info, bool isCli
|
||||
it->second->DumpService(info, isClient);
|
||||
}
|
||||
} else {
|
||||
info.emplace_back(args + ": Nothing to dump.");
|
||||
info.emplace_back(args + ": Nothing to dump from serviceMap.");
|
||||
}
|
||||
|
||||
std::string serviceKey;
|
||||
auto iter = std::find_if(cacheList.begin(), cacheList.end(), [&args, &serviceKey, this](const auto &service) {
|
||||
serviceKey = GetServiceKey(service);
|
||||
return serviceKey.compare(args) == 0;
|
||||
});
|
||||
if (iter != cacheList.end()) {
|
||||
info.emplace_back("uri [ " + serviceKey + " ]");
|
||||
if (*iter != nullptr) {
|
||||
(*iter)->DumpService(info, isClient);
|
||||
}
|
||||
} else {
|
||||
info.emplace_back(args + ": Nothing to dump from lru cache.");
|
||||
}
|
||||
} else {
|
||||
info.emplace_back(" ExtensionRecords:");
|
||||
@@ -2297,6 +2350,13 @@ void AbilityConnectManager::DumpState(std::vector<std::string> &info, bool isCli
|
||||
service.second->DumpService(info, isClient);
|
||||
}
|
||||
}
|
||||
for (auto &&service : cacheList) {
|
||||
std::string serviceKey = GetServiceKey(service);
|
||||
info.emplace_back(" uri [" + serviceKey + "]");
|
||||
if (service != nullptr) {
|
||||
service->DumpService(info, isClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2314,11 +2374,19 @@ void AbilityConnectManager::DumpStateByUri(std::vector<std::string> &info, bool
|
||||
info.emplace_back("uri [ " + it->first + " ]");
|
||||
extensionAbilityRecord = it->second;
|
||||
} else {
|
||||
info.emplace_back(args + ": Nothing to dump.");
|
||||
info.emplace_back(args + ": Nothing to dump from serviceMap.");
|
||||
}
|
||||
}
|
||||
if (extensionAbilityRecord != nullptr) {
|
||||
extensionAbilityRecord->DumpService(info, params, isClient);
|
||||
return;
|
||||
}
|
||||
extensionAbilityRecord = AbilityCacheManager::GetInstance().FindRecordByServiceKey(args);
|
||||
if (extensionAbilityRecord != nullptr) {
|
||||
info.emplace_back("uri [ " + args + " ]");
|
||||
extensionAbilityRecord->DumpService(info, params, isClient);
|
||||
} else {
|
||||
info.emplace_back(args + ": Nothing to dump from lru cache.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2345,6 +2413,25 @@ void AbilityConnectManager::GetExtensionRunningInfos(int upperLimit, std::vector
|
||||
}
|
||||
};
|
||||
std::for_each(serviceMapBack.begin(), serviceMapBack.end(), queryInfo);
|
||||
|
||||
auto cacheAbilityList = AbilityCacheManager::GetInstance().GetAbilityList();
|
||||
auto queryInfoForCache = [&](std::shared_ptr<AbilityRecord> &service) {
|
||||
if (static_cast<int>(info.size()) >= upperLimit) {
|
||||
return;
|
||||
}
|
||||
CHECK_POINTER(service);
|
||||
|
||||
if (isPerm) {
|
||||
GetExtensionRunningInfo(service, userId, info);
|
||||
} else {
|
||||
auto callingTokenId = IPCSkeleton::GetCallingTokenID();
|
||||
auto tokenID = service->GetApplicationInfo().accessTokenId;
|
||||
if (callingTokenId == tokenID) {
|
||||
GetExtensionRunningInfo(service, userId, info);
|
||||
}
|
||||
}
|
||||
};
|
||||
std::for_each(cacheAbilityList.begin(), cacheAbilityList.end(), queryInfoForCache);
|
||||
}
|
||||
|
||||
void AbilityConnectManager::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm)
|
||||
@@ -2429,15 +2516,18 @@ void AbilityConnectManager::PauseExtensions()
|
||||
void AbilityConnectManager::RemoveLauncherDeathRecipient()
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "Call.");
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (auto it = serviceMap_.begin(); it != serviceMap_.end(); ++it) {
|
||||
auto targetExtension = it->second;
|
||||
if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION &&
|
||||
(IsLauncher(targetExtension) || targetExtension->IsSceneBoard())) {
|
||||
targetExtension->RemoveAbilityDeathRecipient();
|
||||
break;
|
||||
{
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (auto it = serviceMap_.begin(); it != serviceMap_.end(); ++it) {
|
||||
auto targetExtension = it->second;
|
||||
if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION &&
|
||||
(IsLauncher(targetExtension) || targetExtension->IsSceneBoard())) {
|
||||
targetExtension->RemoveAbilityDeathRecipient();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
AbilityCacheManager::GetInstance().RemoveLauncherDeathRecipient();
|
||||
}
|
||||
|
||||
bool AbilityConnectManager::IsLauncher(std::shared_ptr<AbilityRecord> serviceExtension) const
|
||||
@@ -2946,13 +3036,16 @@ int32_t AbilityConnectManager::GetUIExtensionSessionInfo(const sptr<IRemoteObjec
|
||||
|
||||
void AbilityConnectManager::SignRestartAppFlag(const std::string &bundleName)
|
||||
{
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (auto &[key, abilityRecord] : serviceMap_) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetApplicationInfo().bundleName != bundleName) {
|
||||
continue;
|
||||
{
|
||||
std::lock_guard lock(serviceMapMutex_);
|
||||
for (auto &[key, abilityRecord] : serviceMap_) {
|
||||
if (abilityRecord == nullptr || abilityRecord->GetApplicationInfo().bundleName != bundleName) {
|
||||
continue;
|
||||
}
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
}
|
||||
abilityRecord->SetRestartAppFlag(true);
|
||||
}
|
||||
AbilityCacheManager::GetInstance().SignRestartAppFlag(bundleName);
|
||||
}
|
||||
|
||||
void AbilityConnectManager::DeleteInvalidServiceRecord(const std::string &bundleName)
|
||||
@@ -2967,6 +3060,7 @@ void AbilityConnectManager::DeleteInvalidServiceRecord(const std::string &bundle
|
||||
++it;
|
||||
}
|
||||
}
|
||||
AbilityCacheManager::GetInstance().DeleteInvalidServiceRecord(bundleName);
|
||||
}
|
||||
|
||||
bool AbilityConnectManager::AddToServiceMap(const std::string &key, std::shared_ptr<AbilityRecord> abilityRecord)
|
||||
|
||||
@@ -500,5 +500,169 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindByToken_001, TestSize.L
|
||||
EXPECT_EQ(recGet->GetRecordId(), recId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityCacheManagerGetAbilityList_001
|
||||
* @tc.desc: Put a single ability record into cache and get ability list
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerGetAbilityList_001, TestSize.Level0)
|
||||
{
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5);
|
||||
OHOS::AppExecFwk::AbilityInfo abilityInfo;
|
||||
abilityInfo.moduleName = "TestModuleName";
|
||||
abilityInfo.bundleName = "TestBundleName";
|
||||
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.accessTokenId = 0;
|
||||
Want want;
|
||||
auto abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
|
||||
abilityRecord_->Init();
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
auto abilityList = OHOS::AAFwk::AbilityCacheManager::GetInstance().GetAbilityList();
|
||||
EXPECT_EQ(abilityList.size(), 1);
|
||||
auto recordFind = *(abilityList.begin());
|
||||
EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(recordFind->GetRecordId(), recId);
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityCacheManagerFindBySessionId_001
|
||||
* @tc.desc: Put a single ability record into cache and find it, find will not remove cache
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindBySessionId_001, TestSize.Level0)
|
||||
{
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5);
|
||||
OHOS::AppExecFwk::AbilityInfo abilityInfo;
|
||||
std::string sessionId = "TestSessionId";
|
||||
abilityInfo.moduleName = "TestModuleName";
|
||||
abilityInfo.bundleName = "TestBundleName";
|
||||
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.accessTokenId = 0;
|
||||
Want want;
|
||||
want.SetParam(Want::PARAM_ASSERT_FAULT_SESSION_ID, sessionId);
|
||||
auto abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
|
||||
abilityRecord_->Init();
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().FindRecordBySessionId(sessionId);
|
||||
EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(recordFind->GetRecordId(), recId);
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.abilityInfo = abilityInfo;
|
||||
abilityRequest.appInfo = applicationInfo;
|
||||
auto recGet = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest);
|
||||
EXPECT_EQ(recGet->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(recGet->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(recGet->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(recGet->GetRecordId(), recId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityCacheManagerFindByServiceKey_001
|
||||
* @tc.desc: Put a single ability record into cache and find it, find will not remove cache
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindByServiceKey_001, TestSize.Level0)
|
||||
{
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5);
|
||||
OHOS::AppExecFwk::AbilityInfo abilityInfo;
|
||||
abilityInfo.moduleName = "TestModuleName";
|
||||
abilityInfo.bundleName = "TestBundleName";
|
||||
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.accessTokenId = 0;
|
||||
Want want;
|
||||
auto abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
|
||||
abilityRecord_->Init();
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::string serviceKey = abilityRecord_->GetURI();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().FindRecordByServiceKey(serviceKey);
|
||||
EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(recordFind->GetRecordId(), recId);
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.abilityInfo = abilityInfo;
|
||||
abilityRequest.appInfo = applicationInfo;
|
||||
auto recGet = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest);
|
||||
EXPECT_EQ(recGet->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(recGet->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(recGet->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(recGet->GetRecordId(), recId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityCacheManagerSignRestartAppFlag_001
|
||||
* @tc.desc: Put a single ability record into cache and sign restart app flag
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerSignRestartAppFlag_001, TestSize.Level0)
|
||||
{
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5);
|
||||
OHOS::AppExecFwk::AbilityInfo abilityInfo;
|
||||
abilityInfo.moduleName = "TestModuleName";
|
||||
abilityInfo.bundleName = "TestBundleName";
|
||||
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.accessTokenId = 0;
|
||||
applicationInfo.bundleName = abilityInfo.bundleName;
|
||||
Want want;
|
||||
auto abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
|
||||
abilityRecord_->Init();
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().SignRestartAppFlag(applicationInfo.bundleName);
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.abilityInfo = abilityInfo;
|
||||
abilityRequest.appInfo = applicationInfo;
|
||||
auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest);
|
||||
EXPECT_EQ(recordFind->GetRestartAppFlag(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AbilityCacheManagerDeleteInvalidRecord_001
|
||||
* @tc.desc: Put a single ability record into cache and delete it by bundleName
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerDeleteInvalidRecord_001, TestSize.Level0)
|
||||
{
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5);
|
||||
OHOS::AppExecFwk::AbilityInfo abilityInfo;
|
||||
abilityInfo.moduleName = "TestModuleName";
|
||||
abilityInfo.bundleName = "TestBundleName";
|
||||
OHOS::AppExecFwk::ApplicationInfo applicationInfo;
|
||||
applicationInfo.accessTokenId = 0;
|
||||
Want want;
|
||||
auto abilityRecord_ = std::make_shared<AbilityRecord>(want, abilityInfo, applicationInfo);
|
||||
abilityRecord_->Init();
|
||||
int recId = abilityRecord_->GetRecordId();
|
||||
std::shared_ptr<AbilityRecord> rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
AbilityRequest abilityRequest;
|
||||
abilityRequest.abilityInfo = abilityInfo;
|
||||
abilityRequest.appInfo = applicationInfo;
|
||||
rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest);
|
||||
EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId);
|
||||
EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName);
|
||||
EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName);
|
||||
EXPECT_EQ(rec->GetRecordId(), recId);
|
||||
OHOS::AAFwk::AbilityCacheManager::GetInstance().DeleteInvalidServiceRecord(abilityInfo.bundleName);
|
||||
rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest);
|
||||
EXPECT_EQ(rec, nullptr);
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user