mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
!18848 merge master into master
增加获取全量ability信息接口 Created-by: muxiggg Commit-by: muxiggg Merged-by: openharmony_ci Description: **IssueNo**: **Description**:增加获取全量ability信息接口 **稳定性自检:** | 自检项 | 自检结果 | | ------------------------------------------------------------ | -------- | | 涉及跨进程调用的相关操作需要抛至主线程或加锁防止并发 | Y | | 成员变量进行赋值或创建需要排查并发 | Y | | 谨慎在lambda表达式中使用引用捕获 | Y | | 谨慎在未经拷贝的情况下使用外部传入的string、C字符串 | Y | | map\vector\list\set等stl模板类使用时需要排查并发 | Y | | 谨慎考虑加锁范围 | Y | | 在IPC通信中谨慎使用同步通信方式 | Y | | 禁止传递this指针至其他模块或线程(特别是eventhandler任务) | Y | | 禁止将外部传入的裸指针在内部直接构造智能指针 | Y | | 禁止多个独立创建的智能指针管理同一地址 | Y | | 禁止在析构函数中抛异步任务 | Y | | 禁止js对象在非js线程(例如在IPC线程)创建、使用或销毁 | Y | | 禁止在对外接口中未经判空直接使用外部传入的指针 | Y | | 禁止接口返回局部变量引用 | Y | | 禁止在信号函数中加锁 | Y | | 禁止在关键流程(SA启动、应用启动等主流程)执行耗时的操作 | Y | | 禁止将同一个cpp编译在不同的so中 | Y | **安全编码自检:** | 自检项 | 自检结果 | | -------------------------------------------------------------- | -------- | | 裸指针避免通过隐式转换构造为sptr | Y | | json对象在取值之前必须先判断类型,避免类型不匹配 | Y | | 序列化时必须对传入的数组大小进行校验,避免出现超大数组 | Y | | 避免使用未明确位宽的整型,选择使用int8_t、uint8_t等类型 | Y | | 外部传入的路径要做规范化校验,对路径中的.、..、../等特殊字符严格校验 | Y | | 指针变量、表示资源描述符的变量、bool变量必须赋初值 | Y | | readParcelable获取的对象使用前需要判空 | Y | | 分配和释放内存的函数需要成对出现 | Y | | 申请内存后异常退出前需要及时进行内存释放 | Y | | 内存申请前必须对内存大小进行合法性校验 | Y | | 内存分配后必须判断是否成功 | Y | | 禁止使用realloc、alloca函数 | Y | | 禁止打印文件路径、口令等敏感信息,如有需要,使用private修饰 | Y | | 禁止打印内存地址 | Y | | 整数之间运算时必须严格检查,确保不会出现溢出、反转、除0 | Y | | 禁止对有符号整数进行位操作符运算 | Y | | 禁止对指针进行逻辑或位运算 | Y | | 循环次数如果收外部数据控制,需要检验其合法性 | Y | | 禁止使用内存操作类危险函数,需要使用安全函数 | Y | | 谨慎使用不可重入函数 | Y | | 必须检查安全函数的返回值,并进行正确处理 | Y | | 禁止仅通过TokenType类型判断绕过权限校验 | Y | **TDD Result**: **XTS Result**: ### 是否已执行L0用例 - [Y ] 已验证 - [ ] 不涉及。如不涉及,请写明理由 See merge request: openharmony/ability_ability_runtime!18848
This commit is contained in:
@@ -1113,6 +1113,15 @@ public:
|
||||
*/
|
||||
int32_t PreloadExtension(const AAFwk::Want &want, int32_t appIndex, int32_t userId);
|
||||
|
||||
/**
|
||||
* Get all ability infos
|
||||
*
|
||||
* @param pid if pid is -1, query all ability infos, otherwise query ability infos for this pid
|
||||
* @param infos ability infos
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos);
|
||||
|
||||
private:
|
||||
void SetServiceManager(std::unique_ptr<AppServiceManager> serviceMgr);
|
||||
/**
|
||||
|
||||
@@ -1154,6 +1154,18 @@ public:
|
||||
}
|
||||
|
||||
virtual void SetProcessPrepareExit(int32_t pid) {}
|
||||
|
||||
/**
|
||||
* Get all ability infos
|
||||
*
|
||||
* @param pid if pid is -1, query all ability infos, otherwise query ability infos for this pid
|
||||
* @param infos ability infos
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -151,7 +151,8 @@ enum class AppMgrInterfaceCode {
|
||||
DESTROY_IMAGE = 126,
|
||||
NOTIFY_TEMPLATE_PROCESS_DEEP_FROZEN = 127,
|
||||
REGISTER_IMAGE_PROCESS_STATE_OBSERVER = 128,
|
||||
UNREGISTER_IMAGE_PROCESS_STATE_OBSERVER = 129
|
||||
UNREGISTER_IMAGE_PROCESS_STATE_OBSERVER = 129,
|
||||
GET_ALL_ABILITY_INFOS = 130,
|
||||
};
|
||||
} // AppExecFwk
|
||||
} // OHOS
|
||||
|
||||
@@ -930,6 +930,15 @@ public:
|
||||
virtual int32_t PreloadExtension(const AAFwk::Want &want, int32_t appIndex, int32_t userId) override;
|
||||
|
||||
void SetProcessPrepareExit(int32_t pid) override;
|
||||
|
||||
/**
|
||||
* Get all ability infos
|
||||
*
|
||||
* @param pid if pid is -1, query all ability infos, otherwise query ability infos for this pid
|
||||
* @param infos ability infos
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos) override;
|
||||
private:
|
||||
bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply);
|
||||
bool WriteInterfaceToken(MessageParcel &data);
|
||||
|
||||
@@ -216,6 +216,7 @@ private:
|
||||
int32_t HandleKillChildProcessByPid(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandlePreloadExtension(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleSetProcessPrepareExit(MessageParcel &data, MessageParcel &reply);
|
||||
int32_t HandleGetAllAbilityInfos(MessageParcel &data, MessageParcel &reply);
|
||||
DISALLOW_COPY_AND_MOVE(AppMgrStub);
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
|
||||
@@ -1943,5 +1943,18 @@ int32_t AppMgrClient::PreloadExtension(const AAFwk::Want &want, int32_t appIndex
|
||||
return service->PreloadExtension(want, appIndex, userId);
|
||||
}
|
||||
|
||||
int32_t AppMgrClient::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
if (mgrHolder_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "mgrHolder is nullptr.");
|
||||
return ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr.");
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
return service->GetAllAbilityInfos(pid, infos);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -2865,5 +2865,42 @@ void AppMgrProxy::SetProcessPrepareExit(int32_t pid)
|
||||
PARCEL_UTIL_WRITE_NORET(data, Int32, pid);
|
||||
PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::SET_PROCESS_PREPARE_EXIT, data, reply, option);
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
MessageParcel data;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
|
||||
return AAFwk::ERR_WRITE_INTERFACE_TOKEN_FAILED;
|
||||
}
|
||||
PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid);
|
||||
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS, data, reply, option);
|
||||
|
||||
int32_t ret = reply.ReadInt32();
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "GetAllAbilityInfos failed, error code: %{public}d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t infosSize = reply.ReadInt32();
|
||||
if (infosSize < 0) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infosSize failed, size: %{public}d", infosSize);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
for (int32_t idx = 0; idx < infosSize; idx++) {
|
||||
std::unique_ptr<AppExecFwk::AbilityStateData> info(reply.ReadParcelable<AppExecFwk::AbilityStateData>());
|
||||
if (!info) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable info failed at index: %{public}d", idx);
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
infos.emplace_back(*info);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -253,6 +253,8 @@ int32_t AppMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &dat
|
||||
return HandleIsSpecifiedModuleLoaded(data, reply);
|
||||
case static_cast<uint32_t>(AppMgrInterfaceCode::SIGN_RESTART_PROCESS):
|
||||
return HandleSignRestartProcess(data, reply);
|
||||
case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS):
|
||||
return HandleGetAllAbilityInfos(data, reply);
|
||||
}
|
||||
return INVALID_FD;
|
||||
}
|
||||
@@ -2360,5 +2362,32 @@ int32_t AppMgrStub::HandleSetProcessPrepareExit(MessageParcel &data, MessageParc
|
||||
SetProcessPrepareExit(pid);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int32_t AppMgrStub::HandleGetAllAbilityInfos(MessageParcel &data, MessageParcel &reply)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "HandleGetAllAbilityInfos call");
|
||||
int32_t pid = data.ReadInt32();
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t ret = GetAllAbilityInfos(pid, infos);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (ret != ERR_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!reply.WriteInt32(infos.size())) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write info size.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
for (auto &info : infos) {
|
||||
if (!reply.WriteParcelable(&info)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "fail to write info.");
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -944,6 +944,15 @@ public:
|
||||
*/
|
||||
virtual int32_t PreloadExtension(const AAFwk::Want &want, int32_t appIndex, int32_t userId) override;
|
||||
|
||||
/**
|
||||
* Get all ability infos
|
||||
*
|
||||
* @param pid if pid is -1, query all ability infos, otherwise query ability infos for this pid
|
||||
* @param infos ability infos
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Init, Initialize application services.
|
||||
|
||||
@@ -1730,6 +1730,15 @@ public:
|
||||
|
||||
void NotifyTerminateAbility(const sptr<IRemoteObject> token);
|
||||
|
||||
/**
|
||||
* Get all ability infos
|
||||
*
|
||||
* @param pid if pid is -1, query all ability infos, otherwise query ability infos for this pid
|
||||
* @param infos ability infos
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos);
|
||||
|
||||
private:
|
||||
int32_t ForceKillApplicationInner(const std::string &bundleName, const int userId = -1,
|
||||
const int appIndex = 0);
|
||||
|
||||
@@ -451,6 +451,7 @@ public:
|
||||
std::shared_ptr<ChildProcessRecord> childRecord, std::shared_ptr<AppRunningRecord> appRecord);
|
||||
std::shared_ptr<AppRunningRecord> CheckAppRunningRecordForUIExtension(
|
||||
int32_t uid, const std::string &instanceKey, const std::string &customProcessFlag);
|
||||
int32_t GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityRunningRecord> GetAbilityRunningRecord(const int64_t eventId);
|
||||
|
||||
@@ -1098,6 +1098,8 @@ public:
|
||||
*/
|
||||
void SetWatchdogBackgroundStatusRunning(bool status);
|
||||
|
||||
void GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos);
|
||||
|
||||
void SetUserRequestCleaning();
|
||||
bool IsUserRequestCleaning() const;
|
||||
bool IsAllAbilityReadyToCleanedByUserRequest();
|
||||
|
||||
@@ -2250,5 +2250,21 @@ void AppMgrService::SetProcessPrepareExit(int32_t pid)
|
||||
}
|
||||
appMgrServiceInner_->SetProcessPrepareExit(pid);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
bool isRssCalling = AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(
|
||||
BS_PROCESS_NAME) && (callingUid == RESOURCE_MANAGER_UID);
|
||||
if (!isRssCalling) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Permission denied");
|
||||
return ERR_PERMISSION_DENIED;
|
||||
}
|
||||
if (!appMgrServiceInner_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr");
|
||||
return AAFwk::ERR_APP_MGR_SERVICE_NOT_READY;
|
||||
}
|
||||
return appMgrServiceInner_->GetAllAbilityInfos(pid, infos);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -12617,5 +12617,14 @@ void AppMgrServiceInner::HandleForegroundAbilityDied(
|
||||
AppRecoveryMgr::AppRecoveryMgr::GetInstance().HandleAppDied(token);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
if (!appRunningManager_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
return appRunningManager_->GetAllAbilityInfos(pid, infos);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -2363,5 +2363,27 @@ int32_t AppRunningManager::QueryUIExtensionBindItemById(
|
||||
}
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
std::lock_guard guard(runningRecordMapMutex_);
|
||||
if (pid != -1) {
|
||||
for (const auto &[recordId, appRecord] : appRunningRecordMap_) {
|
||||
if (appRecord != nullptr && appRecord->GetPid() == pid) {
|
||||
appRecord->GetAllAbilityInfos(infos);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "not find pid:%{public}d appRecord", pid);
|
||||
return ERR_INVALID_VALUE;
|
||||
} else {
|
||||
for (const auto &[recordId, appRecord] : appRunningRecordMap_) {
|
||||
if (appRecord != nullptr) {
|
||||
appRecord->GetAllAbilityInfos(infos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -2982,5 +2982,23 @@ void AppRunningRecord::SetSupportMultiProcessDeviceFeature(bool support)
|
||||
std::lock_guard<ffrt::mutex> supportLock(supportMultiProcessDeviceFeatureLock_);
|
||||
supportMultiProcessDeviceFeature_ = support;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
auto abilitiesMap = GetAbilities();
|
||||
for (const auto &pair : abilitiesMap) {
|
||||
const auto &abilityRecord = pair.second;
|
||||
if (abilityRecord == nullptr || abilityRecord->GetAbilityInfo() == nullptr) {
|
||||
continue;
|
||||
}
|
||||
AbilityStateData info;
|
||||
info.abilityRecordId = abilityRecord->GetAbilityRecordId();
|
||||
info.pid = GetPid();
|
||||
info.uid = abilityRecord->GetAbilityInfo()->applicationInfo.uid;
|
||||
info.abilityType = static_cast<int32_t>(abilityRecord->GetAbilityInfo()->type);
|
||||
info.extensionAbilityType = static_cast<int32_t>(abilityRecord->GetAbilityInfo()->extensionAbilityType);
|
||||
infos.emplace_back(info);
|
||||
}
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -103,6 +103,7 @@ public:
|
||||
MOCK_METHOD2(DestroyImage, int32_t(uint64_t checkpointId, sptr<IImageErrorHandler>));
|
||||
MOCK_METHOD1(RegisterImageProcessStateObserver, int32_t(const sptr<IImageProcessStateObserver> &observer));
|
||||
MOCK_METHOD1(UnregisterImageProcessStateObserver, int32_t(const sptr<IImageProcessStateObserver> &observer));
|
||||
MOCK_METHOD2(GetAllAbilityInfos, int32_t(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos));
|
||||
|
||||
void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t, const std::string&)
|
||||
{}
|
||||
|
||||
@@ -144,6 +144,7 @@ public:
|
||||
MOCK_METHOD2(DestroyImage, int32_t(uint64_t checkpointId, sptr<IImageErrorHandler>));
|
||||
MOCK_METHOD1(RegisterImageProcessStateObserver, int32_t(const sptr<IImageProcessStateObserver> &observer));
|
||||
MOCK_METHOD1(UnregisterImageProcessStateObserver, int32_t(const sptr<IImageProcessStateObserver> &observer));
|
||||
MOCK_METHOD2(GetAllAbilityInfos, int32_t(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos));
|
||||
virtual int StartUserTestProcess(
|
||||
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId)
|
||||
{
|
||||
|
||||
@@ -87,6 +87,7 @@ public:
|
||||
MOCK_METHOD3(CheckPreloadAppRecordExist, bool(const std::string&, int32_t, int32_t));
|
||||
MOCK_CONST_METHOD0(IsFoundationCall, bool());
|
||||
MOCK_METHOD2(QueryRunningSharedBundles, int32_t(pid_t pid, std::map<std::string, uint32_t> &sharedBundles));
|
||||
MOCK_METHOD2(GetAllAbilityInfos, int32_t(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos));
|
||||
|
||||
void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t, const std::string&)
|
||||
{}
|
||||
|
||||
@@ -853,5 +853,67 @@ HWTEST_F(AmsAppMgrClientTest, QueryRunningSharedBundles_003, TestSize.Level1)
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
TAG_LOGI(AAFwkTag::TEST, "QueryRunningSharedBundles_003 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AppMgrService
|
||||
* Function: AppMgrClient::GetAllAbilityInfos
|
||||
* SubFunction: GetAllAbilityInfos
|
||||
* FunctionPoints: AppMgrClient GetAllAbilityInfos interface
|
||||
* EnvConditions: Mobile that can run ohos test framework
|
||||
* CaseDescription: Test GetAllAbilityInfos with invalid parameters.
|
||||
*/
|
||||
HWTEST_F(AmsAppMgrClientTest, GetAllAbilityInfos_001, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_001 start");
|
||||
client_->mgrHolder_ = nullptr;
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t result = client_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(result, AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_001 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AppMgrService
|
||||
* Function: AppMgrClient::GetAllAbilityInfos
|
||||
* SubFunction: GetAllAbilityInfos
|
||||
* FunctionPoints: AppMgrClient GetAllAbilityInfos interface
|
||||
* EnvConditions: Mobile that can run ohos test framework
|
||||
* CaseDescription: Test GetAllAbilityInfos with invalid parameters.
|
||||
*/
|
||||
HWTEST_F(AmsAppMgrClientTest, GetAllAbilityInfos_002, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_002 start");
|
||||
client_->SetServiceManager(nullptr);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t result = client_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(result, AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_002 end");
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AppMgrService
|
||||
* Function: AppMgrClient::GetAllAbilityInfos
|
||||
* SubFunction: GetAllAbilityInfos
|
||||
* FunctionPoints: AppMgrClient GetAllAbilityInfos interface
|
||||
* EnvConditions: Mobile that can run ohos test framework
|
||||
* CaseDescription: Test GetAllAbilityInfos with valid parameters.
|
||||
*/
|
||||
HWTEST_F(AmsAppMgrClientTest, GetAllAbilityInfos_003, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_003 start");
|
||||
EXPECT_EQ(client_->ConnectAppMgrService(), AppMgrResultCode::RESULT_OK);
|
||||
|
||||
EXPECT_CALL(*(static_cast<MockAppMgrService*>((iface_cast<IAppMgr>(client_->GetRemoteObject())).GetRefPtr())),
|
||||
GetAllAbilityInfos(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(Return(ERR_OK));
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t result = client_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(result, ERR_OK);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_003 end");
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1409,5 +1409,129 @@ HWTEST_F(AppMgrProxyTest, UnregisterImageProcessStateObserver_0100, TestSize.Lev
|
||||
auto result = appMgrProxy_->UnregisterImageProcessStateObserver(observer);
|
||||
EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0100
|
||||
* @tc.desc: Test GetAllAbilityInfos when SendRequest fails.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0100, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce(Return(ERR_INVALID_VALUE));
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0200
|
||||
* @tc.desc: Test GetAllAbilityInfos when service returns error.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0200, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce([](uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) {
|
||||
reply.WriteInt32(ERR_PERMISSION_DENIED);
|
||||
return NO_ERROR;
|
||||
});
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0300
|
||||
* @tc.desc: Test GetAllAbilityInfos when reading infos size fails.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0300, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce([](uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) {
|
||||
reply.WriteInt32(ERR_OK);
|
||||
reply.WriteInt32(-1);
|
||||
return NO_ERROR;
|
||||
});
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0400
|
||||
* @tc.desc: Test GetAllAbilityInfos when reading Parcelable fails.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0400, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce([](uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) {
|
||||
reply.WriteInt32(ERR_OK);
|
||||
reply.WriteInt32(1);
|
||||
return NO_ERROR;
|
||||
});
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0500
|
||||
* @tc.desc: Test GetAllAbilityInfos when reading empty info list.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0500, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce([](uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) {
|
||||
reply.WriteInt32(ERR_OK);
|
||||
reply.WriteInt32(0);
|
||||
return NO_ERROR;
|
||||
});
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_TRUE(infos.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0600
|
||||
* @tc.desc: Test GetAllAbilityInfos when reading one ability info.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrProxyTest, GetAllAbilityInfos_0600, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
|
||||
.Times(1)
|
||||
.WillOnce([](uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) {
|
||||
reply.WriteInt32(ERR_OK);
|
||||
reply.WriteInt32(1);
|
||||
AppExecFwk::AbilityStateData info;
|
||||
info.abilityRecordId = 1001;
|
||||
info.pid = 1001;
|
||||
info.uid = 1001;
|
||||
info.abilityType = 1;
|
||||
info.extensionAbilityType = 0;
|
||||
reply.WriteParcelable(&info);
|
||||
return NO_ERROR;
|
||||
});
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrProxy_->GetAllAbilityInfos(1001, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_EQ(infos.size(), 1);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -39,6 +39,7 @@ namespace {
|
||||
const std::string BUNDLE_NAME = "com.example.test";
|
||||
constexpr int UID = 1000;
|
||||
constexpr pid_t PID = 1000;
|
||||
constexpr pid_t RSS_UID = 1096;
|
||||
}
|
||||
|
||||
class MockTaskHandlerWrap : public TaskHandlerWrap {
|
||||
@@ -325,5 +326,38 @@ HWTEST_F(AppMgrServiceFourthTest, StartUserTestProcess_0100, TestSize.Level1)
|
||||
EXPECT_EQ(result, ERR_INVALID_OPERATION);
|
||||
TAG_LOGI(AAFwkTag::TEST, "StartUserTestProcess_0100 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_001
|
||||
* @tc.desc: verify GetAllAbilityInfos works when inner service is null
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceFourthTest, GetAllAbilityInfos_001, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_001 start");
|
||||
appMgrService_->appMgrServiceInner_ = nullptr;
|
||||
AAFwk::MyStatus::GetInstance().isCheckSpecificSystemAbilityAccessPermission_ = true;
|
||||
IPCSkeleton::SetCallingUid(RSS_UID);
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t result = appMgrService_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(result, AAFwk::ERR_APP_MGR_SERVICE_NOT_READY);
|
||||
AAFwk::MyStatus::GetInstance().isCheckSpecificSystemAbilityAccessPermission_ = false;
|
||||
appMgrService_->appMgrServiceInner_ = mockAppMgrServiceInner_;
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_001 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_002
|
||||
* @tc.desc: verify GetAllAbilityInfos works when permission denied
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceFourthTest, GetAllAbilityInfos_002, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_002 start");
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t result = appMgrService_->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(result, ERR_PERMISSION_DENIED);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_002 end");
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
@@ -1399,5 +1399,9 @@ bool AppRunningRecord::HasAgentExtensionAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -494,5 +494,10 @@ bool AppRunningManager::CheckAppRunningRecordIsLast(const std::shared_ptr<AppRun
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1419,5 +1419,9 @@ bool AppRunningRecord::HasAgentExtensionAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -574,5 +574,10 @@ int32_t AppRunningManager::SignRestartProcess(int32_t)
|
||||
{
|
||||
return AAFwk::MyStatus::GetInstance().signRestartProcessStatus_;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1519,5 +1519,9 @@ bool AppRunningRecord::HasAgentExtensionAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -484,5 +484,10 @@ bool AppRunningManager::CheckAppRunningRecordIsLast(const std::shared_ptr<AppRun
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::GetAllAbilityInfos(const int32_t pid, std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1419,5 +1419,9 @@ bool AppRunningRecord::HasAgentExtensionAbility()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -6490,5 +6490,60 @@ HWTEST_F(AppMgrServiceInnerTest, UpdateConfigurationByUserIds_0002, TestSize.Lev
|
||||
EXPECT_EQ(res, ERR_OK);
|
||||
TAG_LOGI(AAFwkTag::TEST, "UpdateConfigurationByUserIds_0002 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0001
|
||||
* @tc.desc: GetAllAbilityInfos when appRunningManager is null
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, GetAllAbilityInfos_0001, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0001 start");
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
appMgrServiceInner->appRunningManager_ = nullptr;
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrServiceInner->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_NO_INIT);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0001 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0002
|
||||
* @tc.desc: GetAllAbilityInfos with valid appRunningManager
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, GetAllAbilityInfos_0002, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0002 start");
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appMgrServiceInner->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0002 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0003
|
||||
* @tc.desc: GetAllAbilityInfos with valid appRunningManager
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrServiceInnerTest, GetAllAbilityInfos_0003, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0003 start");
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
EXPECT_NE(appMgrServiceInner, nullptr);
|
||||
appMgrServiceInner->appRunningManager_ = std::make_shared<AppRunningManager>();
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t pid = 1001;
|
||||
auto ret = appMgrServiceInner->GetAllAbilityInfos(pid, infos);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetAllAbilityInfos_0003 end");
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1254,5 +1254,122 @@ HWTEST_F(AppMgrStubTest, HandleDestroyImage_ShouldReturnNoErrorWhenFlagIsTrueAnd
|
||||
auto result = mockAppMgrService_->HandleDestroyImage(data, reply);
|
||||
EXPECT_EQ(result, NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleGetAllAbilityInfos_0100
|
||||
* @tc.desc: Test HandleGetAllAbilityInfos when service returns error.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrStubTest, HandleGetAllAbilityInfos_0100, TestSize.Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
WriteInterfaceToken(data);
|
||||
int32_t pid = 1001;
|
||||
data.WriteInt32(pid);
|
||||
|
||||
EXPECT_CALL(*mockAppMgrService_, GetAllAbilityInfos(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(Return(ERR_PERMISSION_DENIED));
|
||||
|
||||
mockAppMgrService_->OnRemoteRequest(
|
||||
static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS), data, reply, option);
|
||||
auto replyResult = reply.ReadInt32();
|
||||
EXPECT_EQ(replyResult, ERR_PERMISSION_DENIED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleGetAllAbilityInfos_0200
|
||||
* @tc.desc: Test HandleGetAllAbilityInfos when write result fails.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrStubTest, HandleGetAllAbilityInfos_0200, TestSize.Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
WriteInterfaceToken(data);
|
||||
int32_t pid = 1001;
|
||||
data.WriteInt32(pid);
|
||||
|
||||
EXPECT_CALL(*mockAppMgrService_, GetAllAbilityInfos(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgReferee<1>(std::vector<AppExecFwk::AbilityStateData>()), Return(ERR_OK)));
|
||||
|
||||
auto ret = mockAppMgrService_->OnRemoteRequest(
|
||||
static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS), data, reply, option);
|
||||
EXPECT_EQ(ret, NO_ERROR);
|
||||
auto replyResult = reply.ReadInt32();
|
||||
EXPECT_EQ(replyResult, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleGetAllAbilityInfos_0300
|
||||
* @tc.desc: Test HandleGetAllAbilityInfos with empty info list.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrStubTest, HandleGetAllAbilityInfos_0300, TestSize.Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
WriteInterfaceToken(data);
|
||||
int32_t pid = -1;
|
||||
data.WriteInt32(pid);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
EXPECT_CALL(*mockAppMgrService_, GetAllAbilityInfos(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgReferee<1>(infos), Return(ERR_OK)));
|
||||
|
||||
auto ret = mockAppMgrService_->OnRemoteRequest(
|
||||
static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS), data, reply, option);
|
||||
EXPECT_EQ(ret, NO_ERROR);
|
||||
auto replyResult = reply.ReadInt32();
|
||||
EXPECT_EQ(replyResult, ERR_OK);
|
||||
int32_t infoSize = reply.ReadInt32();
|
||||
EXPECT_EQ(infoSize, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleGetAllAbilityInfos_0400
|
||||
* @tc.desc: Test HandleGetAllAbilityInfos with one ability info.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppMgrStubTest, HandleGetAllAbilityInfos_0400, TestSize.Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
WriteInterfaceToken(data);
|
||||
int32_t pid = 1001;
|
||||
data.WriteInt32(pid);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
AppExecFwk::AbilityStateData info;
|
||||
info.abilityRecordId = 1001;
|
||||
info.pid = 1001;
|
||||
info.uid = 1001;
|
||||
info.abilityType = 1;
|
||||
info.extensionAbilityType = 0;
|
||||
infos.push_back(info);
|
||||
|
||||
EXPECT_CALL(*mockAppMgrService_, GetAllAbilityInfos(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgReferee<1>(infos), Return(ERR_OK)));
|
||||
|
||||
auto ret = mockAppMgrService_->OnRemoteRequest(
|
||||
static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_ABILITY_INFOS), data, reply, option);
|
||||
EXPECT_EQ(ret, NO_ERROR);
|
||||
auto replyResult = reply.ReadInt32();
|
||||
EXPECT_EQ(replyResult, ERR_OK);
|
||||
int32_t infoSize = reply.ReadInt32();
|
||||
EXPECT_EQ(infoSize, 1);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1048,5 +1048,84 @@ HWTEST_F(AppRunningManagerTest, AppRunningManager_ProcessExitByBundleNameAndUid_
|
||||
bool result = appRunningManager->ProcessExitByBundleNameAndUid(bundleName, uid, pids, config);
|
||||
EXPECT_EQ(result, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0100
|
||||
* @tc.desc: Test GetAllAbilityInfos with empty map
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningManagerTest, GetAllAbilityInfos_0100, TestSize.Level1)
|
||||
{
|
||||
auto appRunningManager = std::make_shared<AppRunningManager>();
|
||||
EXPECT_NE(appRunningManager, nullptr);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appRunningManager->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
EXPECT_TRUE(infos.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0200
|
||||
* @tc.desc: Test GetAllAbilityInfos with specific pid not found
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningManagerTest, GetAllAbilityInfos_0200, TestSize.Level1)
|
||||
{
|
||||
auto appRunningManager = std::make_shared<AppRunningManager>();
|
||||
EXPECT_NE(appRunningManager, nullptr);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t pid = 1001;
|
||||
auto ret = appRunningManager->GetAllAbilityInfos(pid, infos);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0300
|
||||
* @tc.desc: Test GetAllAbilityInfos with specific pid found
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningManagerTest, GetAllAbilityInfos_0300, TestSize.Level1)
|
||||
{
|
||||
auto appRunningManager = std::make_shared<AppRunningManager>();
|
||||
EXPECT_NE(appRunningManager, nullptr);
|
||||
|
||||
auto appInfo = std::make_shared<ApplicationInfo>();
|
||||
appInfo->name = "test.app";
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "test.app";
|
||||
auto appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
appRecord->GetPriorityObject()->SetPid(1001);
|
||||
appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
int32_t pid = 1001;
|
||||
auto ret = appRunningManager->GetAllAbilityInfos(pid, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0400
|
||||
* @tc.desc: Test GetAllAbilityInfos with pid=-1 to get all
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningManagerTest, GetAllAbilityInfos_0400, TestSize.Level1)
|
||||
{
|
||||
auto appRunningManager = std::make_shared<AppRunningManager>();
|
||||
EXPECT_NE(appRunningManager, nullptr);
|
||||
|
||||
auto appInfo = std::make_shared<ApplicationInfo>();
|
||||
appInfo->name = "test.app";
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "test.app";
|
||||
auto appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
appRecord->GetPriorityObject()->SetPid(1001);
|
||||
appRunningManager->appRunningRecordMap_.emplace(recordId, appRecord);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
auto ret = appRunningManager->GetAllAbilityInfos(-1, infos);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1855,5 +1855,55 @@ HWTEST_F(AppRunningRecordTest, AppRunningRecord_SetKillAppReason_0100, TestSize.
|
||||
appRunningRecord->SetInnerMsg(reason);
|
||||
EXPECT_EQ(appRunningRecord->GetInnerMsg(), reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0100
|
||||
* @tc.desc: Test GetAllAbilityInfos with empty ability list
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, GetAllAbilityInfos_0100, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
ASSERT_NE(appInfo, nullptr);
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "test.process";
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
ASSERT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->GetPriorityObject()->SetPid(1001);
|
||||
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
appRunningRecord->GetAllAbilityInfos(infos);
|
||||
EXPECT_TRUE(infos.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetAllAbilityInfos_0200
|
||||
* @tc.desc: Test GetAllAbilityInfos with empty ability list
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(AppRunningRecordTest, GetAllAbilityInfos_0200, TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
|
||||
appInfo->bundleName = "com.test.bundle";
|
||||
ASSERT_NE(appInfo, nullptr);
|
||||
int32_t recordId = RECORD_ID;
|
||||
std::string processName = "com.test.bundle";
|
||||
auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, recordId, processName);
|
||||
ASSERT_NE(appRunningRecord, nullptr);
|
||||
appRunningRecord->GetPriorityObject()->SetPid(1001);
|
||||
|
||||
auto moduleRecord = std::make_shared<ModuleRunningRecord>(appInfo, nullptr);
|
||||
ASSERT_NE(moduleRecord, nullptr);
|
||||
auto abilityInfo = std::make_shared<AbilityInfo>();
|
||||
abilityInfo->type = AbilityType::EXTENSION;
|
||||
abilityInfo->extensionAbilityType = ExtensionAbilityType::SERVICE;
|
||||
sptr<IRemoteObject> token = new (std::nothrow) MockAbilityToken();
|
||||
ASSERT_NE(token, nullptr);
|
||||
ASSERT_NE(moduleRecord->AddAbility(token, abilityInfo, nullptr, RECORD_ID), nullptr);
|
||||
appRunningRecord->hapModules_[appInfo->bundleName].emplace_back(moduleRecord);
|
||||
std::vector<AppExecFwk::AbilityStateData> infos;
|
||||
appRunningRecord->GetAllAbilityInfos(infos);
|
||||
EXPECT_EQ(infos.size(), 1);
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -1461,5 +1461,9 @@ bool AppRunningRecord::IsLastAgentExtensionAbility(const sptr<IRemoteObject> &to
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppRunningRecord::GetAllAbilityInfos(std::vector<AppExecFwk::AbilityStateData> &infos)
|
||||
{
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
Reference in New Issue
Block a user