add ui ability code seven

Signed-off-by: xinking129 <xinxin13@huawei.com>
This commit is contained in:
xinking129
2023-09-29 09:36:53 +08:00
parent 9d1adef12d
commit 73d643237b
37 changed files with 4845 additions and 180 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
# 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
@@ -35,7 +35,7 @@ ohos_shared_library("apprecovery_napi") {
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:appkit_native",
]
+98 -3
View File
@@ -216,9 +216,6 @@ ohos_shared_library("abilitykit_native") {
"${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp",
"${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp",
"${ability_runtime_native_path}/ability/native/new_ability_impl.cpp",
"${ability_runtime_native_path}/ability/native/recovery/ability_recovery.cpp",
"${ability_runtime_native_path}/ability/native/recovery/app_recovery.cpp",
"${ability_runtime_native_path}/ability/native/recovery/app_recovery_parcel_allocator.cpp",
"${ability_runtime_native_path}/ability/native/service_ability_impl.cpp",
"${ability_runtime_native_path}/appkit/app/app_context.cpp",
"${ability_runtime_native_path}/appkit/app/context_container.cpp",
@@ -407,6 +404,102 @@ ohos_shared_library("extensionkit_native") {
part_name = "ability_runtime"
}
config("uiability_config") {
visibility = [ ":*" ]
include_dirs = [
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_innerkits_path}/wantagent/include",
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed",
"${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits",
"${ability_runtime_path}/interfaces/kits/native/ability/native/recovery/",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_services_path}/abilitymgr/include",
"${arkui_path}/napi",
"${arkui_path}/napi/interfaces/kits",
"${bundlefwk_inner_api_path}/appexecfwk_base/include",
"${bundlefwk_inner_api_path}/appexecfwk_core/include/bundlemgr",
"//third_party/libuv/include",
"//third_party/node/src",
]
if (ability_runtime_graphics) {
include_dirs += [
"${form_fwk_path}/interfaces/inner_api/include",
"${multimedia_path}/interfaces/innerkits/include",
"${windowmanager_path}/interfaces/innerkits/dm",
"${windowmanager_path}/interfaces/innerkits/wm",
"${windowmanager_path}/utils/include",
]
defines = [ "SUPPORT_GRAPHICS" ]
}
}
ohos_shared_library("uiabilitykit_native") {
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
]
sources = [
"${ability_runtime_native_path}/ability/native/ability_runtime/js_ui_ability.cpp",
"${ability_runtime_native_path}/ability/native/continuation/distributed/continuation_handler_stage.cpp",
"${ability_runtime_native_path}/ability/native/continuation/distributed/continuation_manager_stage.cpp",
"${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stage.cpp",
"${ability_runtime_native_path}/ability/native/recovery/ability_recovery.cpp",
"${ability_runtime_native_path}/ability/native/recovery/app_recovery.cpp",
"${ability_runtime_native_path}/ability/native/recovery/app_recovery_parcel_allocator.cpp",
"${ability_runtime_native_path}/ability/native/ui_ability.cpp",
"${ability_runtime_native_path}/ability/native/ui_ability_impl.cpp",
]
public_configs = [ ":uiability_config" ]
deps = [
":abilitykit_native",
":continuation_ipc",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_delegator",
"${ability_runtime_services_path}/common:event_report",
]
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"ipc:ipc_napi_common",
"napi:ace_napi",
"resource_management:global_resmgr",
"window_manager:libwsutils",
"window_manager:windowstage_kit",
]
if (ability_runtime_graphics) {
deps += [ "//third_party/icu/icu4c:shared_icuuc" ]
external_deps += [
"ability_base:session_info",
"window_manager:libdm",
"window_manager:libwm",
]
}
innerapi_tags = [ "platformsdk" ]
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_shared_library("ability_thread") {
include_dirs =
[ "${ability_runtime_path}/interfaces/kits/native/ability/native" ]
@@ -415,11 +508,13 @@ ohos_shared_library("ability_thread") {
"${ability_runtime_native_path}/ability/native/ability_thread.cpp",
"${ability_runtime_native_path}/ability/native/extension_ability_thread.cpp",
"${ability_runtime_native_path}/ability/native/fa_ability_thread.cpp",
"${ability_runtime_native_path}/ability/native/ui_ability_thread.cpp",
]
deps = [
":abilitykit_native",
":extensionkit_native",
":uiabilitykit_native",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_native_path}/ability:ability_context_native",
+2 -21
View File
@@ -19,7 +19,6 @@
#include <thread>
#include "ability_post_event_timeout.h"
#include "ability_recovery.h"
#include "ability_runtime/js_ability.h"
#include "abs_shared_result_set.h"
#include "configuration_convertor.h"
@@ -253,9 +252,6 @@ void Ability::OnStop()
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
HILOG_DEBUG("called");
#ifdef SUPPORT_GRAPHICS
if (abilityRecovery_ != nullptr) {
abilityRecovery_->ScheduleSaveAbilityState(StateReason::LIFECYCLE);
}
(void)Rosen::DisplayManager::GetInstance().UnregisterDisplayListener(abilityDisplayListener_);
auto && window = GetWindow();
if (window != nullptr) {
@@ -402,11 +398,6 @@ bool Ability::ShouldRecoverState(const Want& want)
return false;
}
if (abilityRecovery_ == nullptr) {
HILOG_WARN("AppRecovery Not enable");
return false;
}
if (abilityContext_ == nullptr) {
HILOG_WARN("AppRecovery abilityContext_ is null");
return false;
@@ -1024,14 +1015,7 @@ void Ability::HandleCreateAsContinuation(const Want &want)
void Ability::HandleCreateAsRecovery(const Want &want)
{
if (!want.GetBoolParam(Want::PARAM_ABILITY_RECOVERY_RESTART, false)) {
HILOG_DEBUG("AppRecovery not recovery restart");
return;
}
if (abilityRecovery_ != nullptr) {
abilityRecovery_->ScheduleRestoreAbilityState(StateReason::DEVELOPER_REQUEST, want);
}
HILOG_DEBUG("called");
}
bool Ability::IsFlagExists(unsigned int flag, unsigned int flagSet)
@@ -1503,7 +1487,7 @@ bool Ability::IsUseNewStartUpRule()
void Ability::EnableAbilityRecovery(const std::shared_ptr<AbilityRecovery>& abilityRecovery)
{
abilityRecovery_ = abilityRecovery;
HILOG_DEBUG("called");
}
int32_t Ability::OnShare(WantParams &wantParams)
@@ -1567,9 +1551,6 @@ void Ability::OnBackground()
HILOG_DEBUG("GoBackground sceneFlag:%{public}d.", sceneFlag_);
scene_->GoBackground(sceneFlag_);
}
if (abilityRecovery_ != nullptr) {
abilityRecovery_->ScheduleSaveAbilityState(StateReason::LIFECYCLE);
}
} else {
if (abilityWindow_ == nullptr) {
HILOG_ERROR("Ability::OnBackground error. abilityWindow_ == nullptr.");
@@ -98,7 +98,6 @@ void AbilityImpl::Start(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
}
#endif
abilityLifecycleCallbacks_->OnAbilityStart(ability_);
HILOG_DEBUG("%{public}s end.", __func__);
}
@@ -168,7 +167,6 @@ void AbilityImpl::StopCallback()
#ifdef SUPPORT_GRAPHICS
}
#endif
abilityLifecycleCallbacks_->OnAbilityStop(ability_);
ability_->DestroyInstance(); // Release window and ability.
}
@@ -188,7 +186,6 @@ void AbilityImpl::Active()
}
#endif
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
abilityLifecycleCallbacks_->OnAbilityActive(ability_);
HILOG_DEBUG("%{public}s end.", __func__);
}
@@ -208,7 +205,6 @@ void AbilityImpl::Inactive()
}
#endif
lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE;
abilityLifecycleCallbacks_->OnAbilityInactive(ability_);
HILOG_DEBUG("%{public}s end.", __func__);
}
@@ -272,7 +268,6 @@ sptr<IRemoteObject> AbilityImpl::ConnectAbility(const Want &want)
}
sptr<IRemoteObject> object = ability_->OnConnect(want);
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
abilityLifecycleCallbacks_->OnAbilityActive(ability_);
HILOG_DEBUG("%{public}s end.", __func__);
return object;
@@ -297,7 +292,6 @@ void AbilityImpl::CommandAbility(const Want &want, bool restart, int startId)
}
ability_->OnCommand(want, restart, startId);
lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE;
abilityLifecycleCallbacks_->OnAbilityActive(ability_);
HILOG_DEBUG("%{public}s end.", __func__);
}
@@ -468,7 +462,6 @@ bool AbilityImpl::CheckAndSave()
}
ability_->OnSaveAbilityState(restoreData_);
abilityLifecycleCallbacks_->OnAbilitySaveState(restoreData_);
needSaveDate_ = false;
@@ -746,7 +739,6 @@ void AbilityImpl::Foreground(const Want &want)
std::lock_guard<std::mutex> lock(notifyForegroundLock_);
notifyForegroundByAbility_ = true;
}
abilityLifecycleCallbacks_->OnAbilityForeground(ability_);
HILOG_INFO("%{public}s end.", __func__);
}
@@ -775,7 +767,6 @@ void AbilityImpl::Background()
} else {
lifecycleState_ = AAFwk::ABILITY_STATE_BACKGROUND;
}
abilityLifecycleCallbacks_->OnAbilityBackground(ability_);
HILOG_INFO("%{public}s end.", __func__);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 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
@@ -36,6 +36,12 @@ void AbilityLoader::RegisterExtension(const std::string &abilityName, const Crea
HILOG_DEBUG("AbilityLoader::RegisterExtension:%{public}s", abilityName.c_str());
}
void AbilityLoader::RegisterUIAbility(const std::string &abilityName, const CreateUIAbility &createFunc)
{
HILOG_DEBUG("RegisterUIAbility: %{public}s", abilityName.c_str());
uiAbilities_.emplace(abilityName, createFunc);
}
Ability *AbilityLoader::GetAbilityByName(const std::string &abilityName)
{
auto it = abilities_.find(abilityName);
@@ -56,6 +62,16 @@ AbilityRuntime::Extension *AbilityLoader::GetExtensionByName(const std::string &
return nullptr;
}
AbilityRuntime::UIAbility *AbilityLoader::GetUIAbilityByName(const std::string &abilityName)
{
auto it = uiAbilities_.find(abilityName);
if (it != uiAbilities_.end()) {
return it->second();
}
HILOG_ERROR("GetAbilityByName failed: %{public}s", abilityName.c_str());
return nullptr;
}
#ifdef ABILITY_WINDOW_SUPPORT
void AbilityLoader::RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc)
{
@@ -22,9 +22,7 @@
#include "ability_runtime/js_ability.h"
#include "ability_runtime/js_ability_context.h"
#include "ability_recovery.h"
#include "ability_start_setting.h"
#include "app_recovery.h"
#include "connection_manager.h"
#include "hilog_wrapper.h"
#include "js_data_struct_converter.h"
@@ -120,13 +118,6 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
HILOG_ERROR("abilityInfo is nullptr");
return;
}
#ifdef SUPPORT_GRAPHICS
if (abilityInfo->type == AppExecFwk::AbilityType::PAGE && abilityInfo->isStageBasedModel &&
abilityContext_ != nullptr) {
AppExecFwk::AppRecovery::GetInstance().AddAbility(shared_from_this(), abilityContext_->GetAbilityInfo(),
abilityContext_->GetToken());
}
#endif
std::string srcPath(abilityInfo->package);
if (!abilityInfo->isModuleJson) {
/* temporary compatibility api8 + config.json */
@@ -182,9 +173,6 @@ void JsAbility::Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
napi_set_named_property(env, obj, "context", contextObj);
HILOG_DEBUG("Set ability context");
if (abilityRecovery_ != nullptr) {
abilityRecovery_->SetJsAbility(reinterpret_cast<uintptr_t>(workContext));
}
napi_wrap(env, contextObj, workContext,
[](napi_env, void *data, void *) {
HILOG_DEBUG("Finalizer for weak_ptr ability context is called");
@@ -581,15 +569,6 @@ void JsAbility::AbilityContinuationOrRecover(const Want &want)
OnSceneRestored();
NotifyContinuationResult(want, true);
} else if (ShouldRecoverState(want)) {
std::string pageStack = abilityRecovery_->GetSavedPageStack(AppExecFwk::StateReason::DEVELOPER_REQUEST);
HandleScope handleScope(jsRuntime_);
auto &engine = jsRuntime_.GetNativeEngine();
auto mainWindow = scene_->GetMainWindow();
if (mainWindow != nullptr) {
mainWindow->SetUIContent(pageStack, &engine, abilityContext_->GetContentStorage()->Get(), true);
} else {
HILOG_ERROR("AppRecovery:AbilityContinuationOrRecover mainWindow nullptr");
}
OnSceneRestored();
} else {
OnSceneCreated();
@@ -17,6 +17,7 @@
#include "extension_ability_thread.h"
#include "fa_ability_thread.h"
#include "ui_ability_thread.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
@@ -42,7 +43,9 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr<OHOSApplication> &ap
}
sptr<AbilityThread> thread = nullptr;
if (abilityInfo->type == AbilityType::EXTENSION) {
if (abilityInfo->type == AbilityType::PAGE && abilityInfo->isStageBasedModel) {
thread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
} else if (abilityInfo->type == AbilityType::EXTENSION) {
thread = new (std::nothrow) AbilityRuntime::ExtensionAbilityThread();
} else {
thread = new (std::nothrow) AbilityRuntime::FAAbilityThread();
@@ -73,7 +76,9 @@ void AbilityThread::AbilityThreadMain(const std::shared_ptr<OHOSApplication> &ap
}
sptr<AbilityThread> thread = nullptr;
if (abilityInfo->type == AbilityType::EXTENSION) {
if (abilityInfo->type == AbilityType::PAGE && abilityInfo->isStageBasedModel) {
thread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
} else if (abilityInfo->type == AbilityType::EXTENSION) {
thread = new (std::nothrow) AbilityRuntime::ExtensionAbilityThread();
} else {
thread = new (std::nothrow) AbilityRuntime::FAAbilityThread();
@@ -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
@@ -18,18 +18,17 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "file_ex.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "ability_manager_client.h"
#include "app_recovery_parcel_allocator.h"
#include "context/application_context.h"
#include "file_ex.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "parcel.h"
#include "recovery_param.h"
#include "string_ex.h"
@@ -67,7 +66,7 @@ AbilityRecovery::~AbilityRecovery()
{
}
bool AbilityRecovery::InitAbilityInfo(const std::shared_ptr<Ability> ability,
bool AbilityRecovery::InitAbilityInfo(const std::shared_ptr<AbilityRuntime::UIAbility> ability,
const std::shared_ptr<AbilityInfo>& abilityInfo, const sptr<IRemoteObject>& token)
{
isEnable_ = true;
@@ -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,24 +25,23 @@
#include <syscall.h>
#include <unistd.h>
#include "ability_runtime/js_ability.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "mission_info.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "ability_manager_client.h"
#include "context/application_context.h"
#include "directory_ex.h"
#include "file_ex.h"
#include "hilog_wrapper.h"
#include "js_runtime.h"
#include "js_runtime_utils.h"
#include "js_ui_ability.h"
#include "mission_info.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "ohos_application.h"
#include "parcel.h"
#include "want_params.h"
#include "recovery_param.h"
#include "string_ex.h"
#include "string_wrapper.h"
#include "ohos_application.h"
#include "want_params.h"
namespace OHOS {
namespace AppExecFwk {
@@ -113,7 +112,7 @@ bool AppRecovery::InitApplicationInfo(const std::shared_ptr<EventHandler>& mainH
return true;
}
bool AppRecovery::AddAbility(std::shared_ptr<Ability> ability,
bool AppRecovery::AddAbility(std::shared_ptr<AbilityRuntime::UIAbility> ability,
const std::shared_ptr<AbilityInfo>& abilityInfo, const sptr<IRemoteObject>& token)
{
if (!isEnable_) {
@@ -190,7 +189,7 @@ bool AppRecovery::ScheduleSaveAppState(StateReason reason, uintptr_t ability)
HILOG_ERROR("AppRecovery Failed to block main thread, skip save state when appfreeze");
return false;
}
OHOS::AbilityRuntime::JsAbility& jsAbility = static_cast<AbilityRuntime::JsAbility&>(*abilityPtr);
OHOS::AbilityRuntime::JsUIAbility& jsAbility = static_cast<AbilityRuntime::JsUIAbility&>(*abilityPtr);
AbilityRuntime::JsRuntime& runtime = const_cast<AbilityRuntime::JsRuntime&>(jsAbility.GetJsRuntime());
auto& nativeEngine = runtime.GetNativeEngine();
nativeEngine.AllowCrossThreadExecution();
+1
View File
@@ -134,6 +134,7 @@ ohos_shared_library("appkit_native") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_path}/js_environment/frameworks/js_environment:js_environment",
+3 -3
View File
@@ -1363,11 +1363,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con
application_->SetRuntime(std::move(runtime));
std::weak_ptr<OHOSApplication> wpApplication = application_;
AbilityLoader::GetInstance().RegisterAbility("Ability",
[wpApplication]() -> Ability* {
AbilityLoader::GetInstance().RegisterUIAbility("UIAbility",
[wpApplication]() -> AbilityRuntime::UIAbility* {
auto app = wpApplication.lock();
if (app != nullptr) {
return Ability::Create(app->GetRuntime());
return AbilityRuntime::UIAbility::Create(app->GetRuntime());
}
HILOG_ERROR("AbilityLoader::GetAbilityByName failed.");
return nullptr;
@@ -19,6 +19,7 @@
#include "ability_record_mgr.h"
#include "ability_thread.h"
#include "app_loader.h"
#include "application_context.h"
#include "application_impl.h"
#include "context_impl.h"
#include "hilog_wrapper.h"
@@ -26,6 +27,7 @@
#include "iservice_registry.h"
#include "runtime.h"
#include "system_ability_definition.h"
#include "ui_ability.h"
#ifdef SUPPORT_GRAPHICS
#include "window.h"
#endif
@@ -246,7 +248,7 @@ void OHOSApplication::UnregisterAbilityLifecycleCallbacks(const std::shared_ptr<
*
* @param Ability Indicates the ability object that calls the onStart() method.
*/
void OHOSApplication::OnAbilityStart(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityStart failed, ability is nullptr");
@@ -267,7 +269,7 @@ void OHOSApplication::OnAbilityStart(const std::shared_ptr<Ability> &ability)
*
* @param Ability Indicates the Ability object that calls the onInactive() method.
*/
void OHOSApplication::OnAbilityInactive(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityInactive failed, ability is nullptr");
@@ -288,7 +290,7 @@ void OHOSApplication::OnAbilityInactive(const std::shared_ptr<Ability> &ability)
*
* @param Ability Indicates the Ability object that calls the onBackground() method.
*/
void OHOSApplication::OnAbilityBackground(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityBackground failed, ability is nullptr");
@@ -309,7 +311,7 @@ void OHOSApplication::OnAbilityBackground(const std::shared_ptr<Ability> &abilit
*
* @param Ability Indicates the Ability object that calls the onForeground() method.
*/
void OHOSApplication::OnAbilityForeground(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityForeground failed, ability is nullptr");
@@ -330,7 +332,7 @@ void OHOSApplication::OnAbilityForeground(const std::shared_ptr<Ability> &abilit
*
* @param Ability Indicates the Ability object that calls the onActive() method.
*/
void OHOSApplication::OnAbilityActive(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityActive failed, ability is nullptr");
@@ -351,7 +353,7 @@ void OHOSApplication::OnAbilityActive(const std::shared_ptr<Ability> &ability)
*
* @param Ability Indicates the Ability object that calls the onStop() method.
*/
void OHOSApplication::OnAbilityStop(const std::shared_ptr<Ability> &ability)
void OHOSApplication::OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility> &ability)
{
if (ability == nullptr) {
HILOG_ERROR("ContextDeal::OnAbilityStop failed, ability is nullptr");
@@ -80,6 +80,7 @@ class AbilityWindow;
#endif
class ILifeCycle;
class ContinuationManager;
class ContinuationHandler;
class AbilityRecovery;
class ContinuationRegisterManager;
class Ability : public IAbilityEvent,
@@ -1273,7 +1274,6 @@ protected:
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_ = nullptr;
std::shared_ptr<AbilityStartSetting> setting_ = nullptr;
std::shared_ptr<AbilityRecovery> abilityRecovery_ = nullptr;
std::shared_ptr<AbilityInfo> abilityInfo_ = nullptr;
LaunchParam launchParam_;
int32_t appIndex_ = 0;
@@ -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
@@ -19,8 +19,10 @@
#include "pac_map.h"
namespace OHOS {
namespace AbilityRuntime {
class UIAbility;
}
namespace AppExecFwk {
class Ability;
class AbilityLifecycleCallbacks {
public:
AbilityLifecycleCallbacks() = default;
@@ -32,7 +34,7 @@ public:
*
* @param Ability Indicates the ability object that calls the onStart() method.
*/
virtual void OnAbilityStart(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -40,7 +42,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onInactive() method.
*/
virtual void OnAbilityInactive(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -48,7 +50,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onBackground() method.
*/
virtual void OnAbilityBackground(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -56,7 +58,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onForeground() method.
*/
virtual void OnAbilityForeground(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -64,7 +66,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onActive() method.
*/
virtual void OnAbilityActive(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -72,7 +74,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onStop() method.
*/
virtual void OnAbilityStop(const std::shared_ptr<Ability> &ability) = 0;
virtual void OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility> &ability) = 0;
/**
*
@@ -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
@@ -16,18 +16,21 @@
#ifndef OHOS_ABILITY_RUNTIME_ABILITY_LOADER_H
#define OHOS_ABILITY_RUNTIME_ABILITY_LOADER_H
#include <functional>
#include <string>
#include <unordered_map>
#include "ability.h"
#include "context.h"
#include "extension.h"
#include "ohos_application.h"
#include <functional>
#include <string>
#include <unordered_map>
#include "ui_ability.h"
namespace OHOS {
namespace AppExecFwk {
using CreateExtension = std::function<AbilityRuntime::Extension *(void)>;
using CreateAblity = std::function<Ability *(void)>;
using CreateUIAbility = std::function<AbilityRuntime::UIAbility *(void)>;
#ifdef ABILITY_WINDOW_SUPPORT
using CreateSlice = std::function<AbilitySlice *(void)>;
#endif
@@ -64,6 +67,13 @@ public:
*/
void RegisterExtension(const std::string &abilityName, const CreateExtension &createFunc);
/**
* @brief Register UIAbility Info
* @param abilityName UIAbility classname
* @param createFunc Constructor address
*/
void RegisterUIAbility(const std::string &abilityName, const CreateUIAbility &createFunc);
/**
* @brief Get Ability address
*
@@ -82,6 +92,13 @@ public:
*/
AbilityRuntime::Extension *GetExtensionByName(const std::string &abilityName);
/**
* @brief Get UIAbility address
* @param abilityName UIAbility classname
* @return return UIAbility address
*/
AbilityRuntime::UIAbility *GetUIAbilityByName(const std::string &abilityName);
#ifdef ABILITY_WINDOW_SUPPORT
void RegisterAbilitySlice(const std::string &sliceName, const CreateSlice &createFunc);
AbilitySlice *GetAbilitySliceByName(const std::string &sliceName);
@@ -96,6 +113,7 @@ private:
std::unordered_map<std::string, CreateAblity> abilities_;
std::unordered_map<std::string, CreateExtension> extensions_;
std::unordered_map<std::string, CreateUIAbility> uiAbilities_;
};
/**
* @brief Registers the class name of an {@link Ability} child class.
@@ -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
@@ -19,13 +19,13 @@
#include <memory>
#include <mutex>
#include "ability.h"
#include "ability_info.h"
#include "application_info.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "parcel.h"
#include "recovery_param.h"
#include "ui_ability.h"
#include "want.h"
#include "want_params.h"
@@ -36,8 +36,8 @@ public:
AbilityRecovery();
virtual ~AbilityRecovery();
void EnableAbilityRecovery(uint16_t restartFlag, uint16_t saveFlag, uint16_t saveMode);
bool InitAbilityInfo(const std::shared_ptr<Ability> ability,
const std::shared_ptr<AbilityInfo>& abilityInfo, const sptr<IRemoteObject>& token);
bool InitAbilityInfo(const std::shared_ptr<AbilityRuntime::UIAbility> ability,
const std::shared_ptr<AbilityInfo> &abilityInfo, const sptr<IRemoteObject> &token);
bool ScheduleSaveAbilityState(StateReason reason);
bool ScheduleRecoverAbility(StateReason reason, const Want *want = nullptr);
bool ScheduleRestoreAbilityState(StateReason reason, const Want &want);
@@ -67,7 +67,7 @@ private:
uint16_t restartFlag_;
uint16_t saveOccasion_;
uint16_t saveMode_;
std::weak_ptr<AppExecFwk::Ability> ability_;
std::weak_ptr<AbilityRuntime::UIAbility> ability_;
std::weak_ptr<AppExecFwk::AbilityInfo> abilityInfo_;
uintptr_t jsAbilityPtr_;
wptr<IRemoteObject> token_;
@@ -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
@@ -20,13 +20,13 @@
#include <mutex>
#include <vector>
#include "ability.h"
#include "ability_info.h"
#include "ability_recovery.h"
#include "application_info.h"
#include "event_handler.h"
#include "iremote_object.h"
#include "parcel.h"
#include "ui_ability.h"
#include "want.h"
#include "want_params.h"
@@ -38,8 +38,8 @@ public:
void EnableAppRecovery(uint16_t restartFlag, uint16_t saveFlag, uint16_t saveMode);
bool InitApplicationInfo(const std::shared_ptr<AppExecFwk::EventHandler>& mainHandler,
const std::shared_ptr<ApplicationInfo>& applicationInfo);
bool AddAbility(std::shared_ptr<Ability> ability,
const std::shared_ptr<AbilityInfo>& abilityInfo, const sptr<IRemoteObject>& token);
bool AddAbility(std::shared_ptr<AbilityRuntime::UIAbility> ability, const std::shared_ptr<AbilityInfo> &abilityInfo,
const sptr<IRemoteObject> &token);
bool RemoveAbility(const sptr<IRemoteObject>& tokenId);
bool IsEnabled() const;
@@ -71,7 +71,7 @@ private:
uint16_t saveMode_;
std::weak_ptr<AppExecFwk::EventHandler> mainHandler_;
std::weak_ptr<AppExecFwk::ApplicationInfo> applicationInfo_;
std::weak_ptr<AppExecFwk::Ability> ability_;
std::weak_ptr<AbilityRuntime::UIAbility> ability_;
std::vector<std::shared_ptr<AbilityRecovery>> abilityRecoverys_;
std::shared_ptr<AAFwk::Want> want_ = nullptr;
};
@@ -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
@@ -32,7 +32,7 @@ public:
* @param config Indicates the new Configuration object.
* @param ability Indicates the new Ability object.
*/
virtual void OnConfigurationUpdated(const std::shared_ptr<Ability> &ability, const Configuration &config) = 0;
virtual void OnConfigurationUpdated(const std::shared_ptr<AbilityRuntime::UIAbility> &ability, const Configuration &config) = 0;
/**
*
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 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
@@ -92,7 +92,7 @@ public:
*
* @param Ability Indicates the ability object that calls the onStart() method.
*/
void OnAbilityStart(const std::shared_ptr<Ability> &ability);
void OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -100,7 +100,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onInactive() method.
*/
void OnAbilityInactive(const std::shared_ptr<Ability> &ability);
void OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -108,7 +108,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onBackground() method.
*/
void OnAbilityBackground(const std::shared_ptr<Ability> &ability);
void OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -116,7 +116,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onForeground() method.
*/
void OnAbilityForeground(const std::shared_ptr<Ability> &ability);
void OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -124,7 +124,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onActive() method.
*/
void OnAbilityActive(const std::shared_ptr<Ability> &ability);
void OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -132,7 +132,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onStop() method.
*/
void OnAbilityStop(const std::shared_ptr<Ability> &ability);
void OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility> &ability);
/**
*
@@ -0,0 +1,96 @@
/*
* 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.
*/
#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H
#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H
#include <gtest/gtest.h>
#include "ui_ability.h"
namespace OHOS {
namespace AppExecFwk {
using namespace OHOS;
using Want = OHOS::AAFwk::Want;
class MockUIAbility : public AbilityRuntime::UIAbility {
public:
MockUIAbility() = default;
virtual ~MockUIAbility() = default;
enum Event { ON_ACTIVE = 0, ON_BACKGROUND, ON_FOREGROUND, ON_INACTIVE, ON_START, ON_STOP, UNDEFINED };
void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData)
{
GTEST_LOG_(INFO) << "MockUIAbility::OnAbilityResult called";
state_ = ON_ACTIVE;
}
void OnNewWant(const Want &want)
{
onNewWantCalled_ = true;
GTEST_LOG_(INFO) << "MockUIAbility::OnNewWant called";
}
void OnStart(const Want &want, sptr<AAFwk::SessionInfo> sessionInfo)
{
GTEST_LOG_(INFO) << "MockUIAbility::OnStart called";
state_ = ON_START;
}
void OnStop()
{
GTEST_LOG_(INFO) << "MockUIAbility::OnStop called";
state_ = ON_STOP;
}
void OnForeground(const Want &want)
{
GTEST_LOG_(INFO) << "MockUIAbility::OnForeground called";
state_ = ON_FOREGROUND;
}
void OnBackground()
{
GTEST_LOG_(INFO) << "MockUIAbility::OnBackground called";
state_ = ON_BACKGROUND;
}
void OnRestoreAbilityState(const PacMap &inState)
{
GTEST_LOG_(INFO) << "Mock UIAbility::OnRestoreAbilityState called";
}
void OnConfigurationUpdated(const Configuration &config)
{
GTEST_LOG_(INFO) << "Mock UIAbility::OnConfigurationUpdated called";
OnConfigurationUpdated_++;
}
void ContinuationRestore(const Want &want)
{
GTEST_LOG_(INFO) << "Mock UIAbility::ContinuationRestore called";
continueRestoreCalled_ = true;
}
MockUIAbility::Event state_ = UNDEFINED;
bool onNewWantCalled_ = false;
bool continueRestoreCalled_ = false;
int OnConfigurationUpdated_ = 0;
std::vector<std::string> value;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_H
@@ -0,0 +1,84 @@
/*
* 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.
*/
#ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H
#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H
#include <gtest/gtest.h>
#include "ui_ability_impl.h"
namespace OHOS {
namespace AbilityRuntime {
using Want = OHOS::AAFwk::Want;
class MockUIAbilityimpl : public UIAbilityImpl {
public:
MockUIAbilityimpl() = default;
virtual ~MockUIAbilityimpl() = default;
void ImplStart(const Want &want)
{
this->Start(want);
}
void ImplStop()
{
this->Stop();
}
void SetlifecycleState(int state)
{
this->lifecycleState_ = state;
}
int GetCurrentState()
{
return lifecycleState_;
}
sptr<IRemoteObject> GetToken()
{
return token_;
}
std::shared_ptr<UIAbility> GetAbility()
{
return ability_;
}
bool CheckAndRestore()
{
return UIAbilityImpl::CheckAndRestore();
}
#ifdef SUPPORT_GRAPHICS
void ImplForeground(const Want &want)
{
this->Foreground(want);
}
void ImplBackground()
{
this->Background();
}
#endif
private:
UIAbilityImpl AbilityImpl_;
};
} // namespace AbilityRuntime
} // namespace OHOS
#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_UI_ABILITY_IMPL_H
@@ -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
@@ -34,7 +34,7 @@ public:
*
* @param Ability Indicates the ability object that calls the onStart() method.
*/
virtual void OnAbilityStart(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityStart(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStart called";
}
@@ -45,7 +45,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onInactive() method.
*/
virtual void OnAbilityInactive(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityInactive(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityInactive called";
}
@@ -56,7 +56,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onBackground() method.
*/
virtual void OnAbilityBackground(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityBackground(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityBackground called";
}
@@ -67,7 +67,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onForeground() method.
*/
virtual void OnAbilityForeground(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityForeground(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityForeground called";
}
@@ -78,7 +78,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onActive() method.
*/
virtual void OnAbilityActive(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityActive(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityActive called";
}
@@ -89,7 +89,7 @@ public:
*
* @param Ability Indicates the Ability object that calls the onStop() method.
*/
virtual void OnAbilityStop(const std::shared_ptr<Ability>& ability)
virtual void OnAbilityStop(const std::shared_ptr<AbilityRuntime::UIAbility>& ability)
{
GTEST_LOG_(INFO) << "MockAbilityLifecycleCallbacks::OnAbilityStop called";
}
@@ -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
@@ -33,7 +33,7 @@ public:
* @param config Indicates the new Configuration object.
* @param ability Indicates the new Ability object.
*/
virtual void OnConfigurationUpdated(const std::shared_ptr<Ability>& ability, const Configuration& config)
virtual void OnConfigurationUpdated(const std::shared_ptr<AbilityRuntime::UIAbility>& ability, const Configuration& config)
{
GTEST_LOG_(INFO) << "MockElementsCallback::OnConfigurationUpdated called";
configurationUpdated_ = true;
+3 -1
View File
@@ -1,4 +1,4 @@
# 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
@@ -36,6 +36,7 @@ ohos_unittest("AppRecoveryUnitTest") {
deps = [
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_native_path}/appkit:appkit_delegator",
@@ -95,6 +96,7 @@ ohos_unittest("AbilityRecoveryUnitTest") {
deps = [
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_native_path}/appkit:appkit_delegator",
@@ -18,7 +18,6 @@
#define private public
#include "ability_recovery.h"
#undef private
#include "ability.h"
#include "ability_info.h"
#include "app_recovery_parcel_allocator.h"
#include "event_handler.h"
@@ -27,6 +26,7 @@
#include "mock_ability_token.h"
#include "mock_app_ability.h"
#include "recovery_param.h"
#include "ui_ability.h"
#include "want.h"
#include "want_params.h"
@@ -40,9 +40,9 @@ public:
void SetUp();
void TearDown();
std::shared_ptr<AbilityRecovery> abilityRecovery_ = std::make_shared<AbilityRecovery>();
std::shared_ptr<AppExecFwk::Ability> ability_ = std::make_shared<Ability>();
std::shared_ptr<AppExecFwk::Ability> mockAbility_ = std::make_shared<MockAbility>();
std::shared_ptr<AppExecFwk::Ability> mockAbility2_ = std::make_shared<MockAppAbility>();
std::shared_ptr<AbilityRuntime::UIAbility> ability_ = std::make_shared<AbilityRuntime::UIAbility>();
std::shared_ptr<AbilityRuntime::UIAbility> mockAbility_ = std::make_shared<MockAbility>();
std::shared_ptr<AbilityRuntime::UIAbility> mockAbility2_ = std::make_shared<MockAppAbility>();
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_ = std::make_shared<AbilityInfo>();
std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo_ = std::make_shared<ApplicationInfo>();
sptr<IRemoteObject> token_ = new MockAbilityToken();
@@ -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
@@ -22,14 +22,14 @@
#define private public
#include "app_recovery.h"
#undef private
#include "ability.h"
#include "ability_info.h"
#include "ability_runtime/js_ability.h"
#include "ability_runtime/js_ui_ability.h"
#include "event_handler.h"
#include "js_runtime.h"
#include "mock_ability_context.h"
#include "mock_ability_token.h"
#include "recovery_param.h"
#include "ui_ability.h"
using namespace testing::ext;
namespace OHOS {
@@ -40,7 +40,7 @@ public:
static void TearDownTestCase();
void SetUp();
void TearDown();
std::shared_ptr<AppExecFwk::Ability> ability_ = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability_ = std::make_shared<AbilityRuntime::UIAbility>();
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo_ = std::make_shared<AbilityInfo>();
std::shared_ptr<AppExecFwk::ApplicationInfo> applicationInfo_ = std::make_shared<ApplicationInfo>();
std::shared_ptr<AppExecFwk::EventHandler> testHandler_ = std::make_shared<EventHandler>();
@@ -321,7 +321,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleSaveAppState_003, TestSize.Level1)
AbilityRuntime::Runtime::Options options;
auto runtime = AbilityRuntime::JsRuntime::Create(options);
auto jsRuntime = static_cast<AbilityRuntime::JsRuntime*>(runtime.get());
std::shared_ptr<AppExecFwk::Ability> ability = std::make_shared<AbilityRuntime::JsAbility>(*jsRuntime);
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::JsUIAbility>(*jsRuntime);
ability->AttachAbilityContext(constContext);
AppRecovery::GetInstance().AddAbility(ability, abilityInfo_, token_);
// this call will block main thread, thus call it in new thread
@@ -504,7 +504,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_004, TestSize.Level1)
AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR,
SaveModeFlag::SAVE_WITH_FILE);
auto caseAbilityInfo = std::make_shared<AbilityInfo>();
auto ability = std::make_shared<Ability>();
auto ability = std::make_shared<AbilityRuntime::UIAbility>();
sptr<IRemoteObject> token = new MockAbilityToken();
EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_));
bool ret = AppRecovery::GetInstance().ScheduleRecoverApp(StateReason::APP_FREEZE);
@@ -522,7 +522,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_005, TestSize.Level1)
AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR,
SaveModeFlag::SAVE_WITH_FILE);
auto caseAbilityInfo = std::make_shared<AbilityInfo>();
auto ability = std::make_shared<Ability>();
auto ability = std::make_shared<AbilityRuntime::UIAbility>();
sptr<IRemoteObject> token = new MockAbilityToken();
EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_));
AppRecovery::GetInstance().mainHandler_.reset();
@@ -541,7 +541,7 @@ HWTEST_F(AppRecoveryUnitTest, ScheduleRecoverApp_006, TestSize.Level1)
AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR,
SaveModeFlag::SAVE_WITH_FILE);
auto caseAbilityInfo = std::make_shared<AbilityInfo>();
auto ability = std::make_shared<Ability>();
auto ability = std::make_shared<AbilityRuntime::UIAbility>();
sptr<IRemoteObject> token = new MockAbilityToken();
EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_));
bool ret = AppRecovery::GetInstance().ScheduleRecoverApp(StateReason::DEVELOPER_REQUEST);
@@ -571,7 +571,7 @@ HWTEST_F(AppRecoveryUnitTest, TryRecoverApp_002, TestSize.Level1)
AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR,
SaveModeFlag::SAVE_WITH_FILE);
auto caseAbilityInfo = std::make_shared<AbilityInfo>();
auto ability = std::make_shared<Ability>();
auto ability = std::make_shared<AbilityRuntime::UIAbility>();
sptr<IRemoteObject> token = new MockAbilityToken();
EXPECT_TRUE(AppRecovery::GetInstance().AddAbility(ability_, abilityInfo_, token_));
bool ret = AppRecovery::GetInstance().TryRecoverApp(StateReason::APP_FREEZE);
@@ -615,7 +615,7 @@ HWTEST_F(AppRecoveryUnitTest, PersistAppState_003, TestSize.Level1)
AppRecovery::GetInstance().EnableAppRecovery(RestartFlag::ALWAYS_RESTART, SaveOccasionFlag::SAVE_WHEN_ERROR,
SaveModeFlag::SAVE_WITH_SHARED_MEMORY);
auto constContext = std::static_pointer_cast<AbilityRuntime::AbilityContext>(context_);
std::shared_ptr<AppExecFwk::Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ability->AttachAbilityContext(constContext);
AppRecovery::GetInstance().AddAbility(ability, abilityInfo_, token_);
EXPECT_TRUE(AppRecovery::GetInstance().PersistAppState());
@@ -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
@@ -15,14 +15,14 @@
#ifndef MOCK_OHOS_ABILITY_RECOVERY_TEST_H
#define MOCK_OHOS_ABILITY_RECOVERY_TEST_H
#include "ability.h"
#include "ability_loader.h"
#include "want.h"
#include "recovery_param.h"
#include "ui_ability.h"
#include "want.h"
namespace OHOS {
namespace AppExecFwk {
class MockAbility : public Ability {
class MockAbility : public AbilityRuntime::UIAbility {
protected:
int32_t OnSaveState(int32_t reason, WantParams &wantParams) override
{
@@ -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
@@ -15,14 +15,14 @@
#ifndef MOCK_OHOS_APP_ABILITY_RECOVERY_TEST_H
#define MOCK_OHOS_APP_ABILITY_RECOVERY_TEST_H
#include "ability.h"
#include "ability_loader.h"
#include "want.h"
#include "recovery_param.h"
#include "ui_ability.h"
#include "want.h"
namespace OHOS {
namespace AppExecFwk {
class MockAppAbility : public Ability {
class MockAppAbility : public AbilityRuntime::UIAbility {
protected:
int32_t OnSaveState(int32_t reason, WantParams &wantParams) override
{
@@ -1,4 +1,4 @@
# 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
@@ -49,6 +49,7 @@ ohos_unittest("ohos_application_test") {
deps = [
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"../../../../frameworks/native/ability/native:abilitykit_native",
@@ -31,6 +31,7 @@
#include "ohos_application.h"
#include "pac_map.h"
#include "runtime.h"
#include "ui_ability.h"
#undef private
using namespace testing;
@@ -362,7 +363,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_UnregisterAbilityLi
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
EXPECT_TRUE(ability == nullptr);
ohosApplication_->OnAbilityStart(ability);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100 end.";
@@ -376,7 +377,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0100
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityStart(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -397,7 +398,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStart_0200
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
ohosApplication_->OnAbilityInactive(ability);
EXPECT_TRUE(ability == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0100 end.";
@@ -411,7 +412,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityInactive(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -432,7 +433,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityInactive_0
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
ohosApplication_->OnAbilityBackground(ability);
EXPECT_TRUE(ability == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0100 end.";
@@ -446,7 +447,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityBackground_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityBackground(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -465,7 +466,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityBackground
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
ohosApplication_->OnAbilityForeground(ability);
EXPECT_TRUE(ability == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0100 end.";
@@ -479,7 +480,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityForeground_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityForeground(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -498,7 +499,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityForeground
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
ohosApplication_->OnAbilityActive(ability);
EXPECT_TRUE(ability == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0100 end.";
@@ -512,7 +513,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_010
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityActive_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityActive(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -531,7 +532,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityActive_020
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100 start.";
std::shared_ptr<Ability> ability = nullptr;
std::shared_ptr<AbilityRuntime::UIAbility> ability = nullptr;
ohosApplication_->OnAbilityStop(ability);
EXPECT_TRUE(ability == nullptr);
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100 end.";
@@ -545,7 +546,7 @@ HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0100,
HWTEST_F(OHOSApplicationTest, AppExecFwk_OHOSApplicationTest_OnAbilityStop_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AppExecFwk_OHOSApplicationTest_OnAbilityStop_0200 start.";
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_TRUE(ability != nullptr);
ohosApplication_->OnAbilityStop(ability);
EXPECT_TRUE(ohosApplication_->abilityLifecycleCallbacks_.empty());
@@ -96,6 +96,7 @@ ohos_unittest("ability_test") {
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
@@ -623,6 +624,53 @@ ohos_unittest("ability_impl_test") {
}
}
ohos_unittest("ui_ability_impl_test") {
module_out_path = module_output_path
sources = [
"${ability_runtime_native_path}/appkit/app/app_context.cpp",
"${ability_runtime_native_path}/appkit/app/app_loader.cpp",
"${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:want",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
sources += [ "ui_ability_impl_test.cpp" ]
deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ]
external_deps += [
"input:libmmi-client",
"window_manager:libwm",
]
}
}
ohos_unittest("ability_thread_test") {
module_out_path = module_output_path
@@ -729,6 +777,59 @@ ohos_unittest("extension_ability_thread_test") {
}
}
ohos_unittest("ui_ability_thread_test") {
module_out_path = module_output_path
sources = [
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_info.cpp",
"${ability_runtime_native_path}/appkit/app/app_context.cpp",
"${ability_runtime_native_path}/appkit/app/app_loader.cpp",
"${ability_runtime_native_path}/appkit/app/context_container.cpp",
"${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
"ui_ability_thread_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/dataobs_manager:dataobs_manager",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${ability_runtime_services_path}/dataobsmgr:dataobsms_static",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:want",
"ability_runtime:ability_deps_wrapper",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"napi:ace_napi",
"resource_management:global_resmgr",
]
if (ability_runtime_graphics) {
external_deps += [
"ability_base:session_info",
"input:libmmi-client",
"window_manager:libwm",
]
}
}
ohos_unittest("service_extension_module_loader_test") {
module_out_path = module_output_path
include_dirs = [
@@ -1407,6 +1508,60 @@ ohos_unittest("task_handler_client_test") {
}
}
ohos_unittest("ui_ability_test") {
module_out_path = module_output_path
sources = [
"${ability_runtime_native_path}/appkit/app/ability_record_mgr.cpp",
"${ability_runtime_native_path}/appkit/app/app_context.cpp",
"${ability_runtime_native_path}/appkit/app/app_loader.cpp",
"${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
"ui_ability_test.cpp",
]
configs = [ ":module_private_config" ]
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_setting",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:base",
"ability_base:configuration",
"ability_base:session_info",
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:runtime",
"ability_runtime:wantagent_innerkits",
"bundle_framework:appexecfwk_base",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"eventhandler:libeventhandler",
"ffrt:libffrt",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:scene_session",
]
if (ability_runtime_graphics) {
external_deps += [
"image_framework:image_native",
"input:libmmi-client",
"window_manager:libwm",
]
}
}
ohos_unittest("ability_thread_for_ability_on_configuration_update") {
module_out_path = module_output_path
@@ -1888,6 +2043,7 @@ ohos_unittest("ability_loader_test") {
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"${global_path}/resource_management/frameworks/resmgr:global_resmgr",
@@ -2273,6 +2429,9 @@ group("unittest") {
":share_extension_module_loader_test",
":share_extension_test",
":task_handler_client_test",
":ui_ability_impl_test",
":ui_ability_test",
":ui_ability_thread_test",
]
if (ability_runtime_graphics) {
@@ -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
@@ -29,6 +29,7 @@ using namespace testing;
using namespace testing::ext;
using CreateAblity = std::function<Ability *(void)>;
using CreateExtension = std::function<AbilityRuntime::Extension *(void)>;
using CreateUIAblity = std::function<AbilityRuntime::UIAbility *(void)>;
class AbilityLoaderTest : public testing::Test {
public:
@@ -158,4 +159,59 @@ HWTEST_F(AbilityLoaderTest, GetExtensionByName_0200, TestSize.Level1)
AbilityLoader::GetInstance().extensions_.clear();
EXPECT_FALSE(AbilityLoader::GetInstance().GetExtensionByName(abilityName) != nullptr);
GTEST_LOG_(INFO) << "AbilityLoaderTest GetExtensionByName_0200 end";
}
/**
* @tc.number: RegisterUIAbility_0100
* @tc.name: RegisterUIAbility
* @tc.desc: RegisterUIAbility Test, return true.
*/
HWTEST_F(AbilityLoaderTest, RegisterUIAbility_0100, TestSize.Level0)
{
GTEST_LOG_(INFO) << "AbilityLoaderTest RegisterUIAbility_0100 start";
auto loader = std::make_shared<OHOS::AppExecFwk::AbilityLoader>();
std::string abilityName;
CreateUIAblity createFunc;
loader->RegisterUIAbility(abilityName, createFunc);
bool result = false;
auto it = loader->uiAbilities_.find(abilityName);
if (it != loader->uiAbilities_.end()) {
result = true;
}
EXPECT_TRUE(result);
GTEST_LOG_(INFO) << "AbilityLoaderTest RegisterUIAbility_0100 end";
}
/**
* @tc.number: GetUIAbilityByName_0100
* @tc.name: GetUIAbilityByName
* @tc.desc: GetUIAbilityByName Test When UIAbility is not nullptr.
*/
HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0100, TestSize.Level0)
{
GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 start";
std::string abilityName = "UIAbility";
CreateAblity createFunc;
auto createAblity = []() -> AbilityRuntime::UIAbility *{
AbilityRuntime::UIAbility *callBack = new (std::nothrow) AbilityRuntime::UIAbility;
return callBack;
};
AbilityLoader::GetInstance().uiAbilities_.clear();
AbilityLoader::GetInstance().RegisterUIAbility(abilityName, createAblity);
EXPECT_TRUE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr);
GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0100 end";
}
/**
* @tc.number: GetUIAbilityByName_0200
* @tc.name: GetUIAbilityByName
* @tc.desc: GetUIAbilityByName Test When UIAbility is nullptr.
*/
HWTEST_F(AbilityLoaderTest, GetUIAbilityByName_0200, TestSize.Level1)
{
GTEST_LOG_(INFO) << "AbilityLoaderTest GetAbilityByName_0200 start";
std::string abilityName = "UIAbilityName";
AbilityLoader::GetInstance().abilities_.clear();
EXPECT_FALSE(AbilityLoader::GetInstance().GetUIAbilityByName(abilityName) != nullptr);
GTEST_LOG_(INFO) << "AbilityLoaderTest GetUIAbilityByName_0200 start";
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,922 @@
/*
* 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 <functional>
#include <gtest/gtest.h>
#define private public
#define protected public
#include "ability_loader.h"
#include "ui_ability_thread.h"
#undef private
#undef protected
#include "ability_handler.h"
#include "ability_local_record.h"
#include "mock_ability_token.h"
#include "ohos_application.h"
#include "ui_ability_impl.h"
namespace OHOS {
namespace AppExecFwk {
using namespace testing::ext;
using namespace OHOS;
using Want = OHOS::AAFwk::Want;
static const int32_t STARTID = 0;
static const std::string DEVICE_ID = "deviceId";
static const std::string TEST = "test";
const unsigned int ZEROTAG = 0;
class UIAbilityThreadTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp() override;
void TearDown() override;
};
void UIAbilityThreadTest::SetUpTestCase(void) {}
void UIAbilityThreadTest::TearDownTestCase(void) {}
void UIAbilityThreadTest::SetUp(void) {}
void UIAbilityThreadTest::TearDown(void) {}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfo_0100
* @tc.name: DumpAbilityInfo
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfo(params, info);
EXPECT_EQ(info.size(), ZEROTAG);
GTEST_LOG_(INFO) << "info:";
for (auto item : info) {
GTEST_LOG_(INFO) << item;
}
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0100 end";
}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfo_0200
* @tc.name: DumpAbilityInfo
* @tc.desc: Test DumpAbilityInfo function when token_ and abilityHandler_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->token_ = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(abilitythread->token_, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfo(params, info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0200 end";
}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfo_0300
* @tc.name: DumpAbilityInfo
* @tc.desc: Test DumpAbilityInfo function when abilityHandler_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0300 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->token_ = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(abilitythread->token_, nullptr);
EXPECT_EQ(abilitythread->abilityHandler_, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfo(params, info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0300 end";
}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfo_0400
* @tc.name: DumpAbilityInfo
* @tc.desc: Test DumpAbilityInfo function when token_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfo_0400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0400 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->token_ = nullptr;
EXPECT_EQ(abilitythread->token_, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfo(params, info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfo_0400 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleSaveAbilityState_0100
* @tc.name: ScheduleSaveAbilityState
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleSaveAbilityState_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
abilitythread->ScheduleSaveAbilityState();
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0100 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleSaveAbilityState_0200
* @tc.name: ScheduleSaveAbilityState
* @tc.desc: Test ScheduleSaveAbilityState function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleSaveAbilityState_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
abilitythread->ScheduleSaveAbilityState();
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleSaveAbilityState_0200 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleRestoreAbilityState_0100
* @tc.name: ScheduleRestoreAbilityState
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleRestoreAbilityState_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
PacMap state;
abilitythread->ScheduleRestoreAbilityState(state);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0100 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleRestoreAbilityState_0200
* @tc.name: ScheduleRestoreAbilityState
* @tc.desc: Test Attach_3_Param function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleRestoreAbilityState_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
abilitythread->ScheduleSaveAbilityState();
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleRestoreAbilityState_0200 end";
}
/**
* @tc.number: AbilityRuntime_Attach_3_Param_0100
* @tc.name: Attach
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0100 end";
}
/**
* @tc.number: AbilityRuntime_Attach_3_Param_0200
* @tc.name: Attach
* @tc.desc: Test Attach_3_Param function when application is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_3_Param_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = nullptr;
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_3_Param_0200 end";
}
/**
* @tc.number: AbilityRuntime_Attach_2_Param_0100
* @tc.name: Attach
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
abilitythread->Attach(application, abilityRecord, nullptr);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0100 end";
}
/**
* @tc.number: AbilityRuntime_Attach_2_Param_0200
* @tc.name: Attach
* @tc.desc: Test Attach_2_Param function when application is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_Attach_2_Param_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = nullptr;
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, nullptr);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_Attach_2_Param_0200 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0100
* @tc.name: ScheduleAbilityTransaction
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0200
* @tc.name: ScheduleAbilityTransaction
* @tc.desc: Validate when normally entering a string
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
abilitythread->Attach(application, abilityRecord, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0200 end";
}
/*
* @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0300
* @tc.name: ScheduleAbilityTransaction
* @tc.desc: Test ScheduleAbilityTransaction function when token_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
abilitythread->token_ = nullptr;
EXPECT_EQ(abilitythread->token_, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo);
}
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0300 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0300
* @tc.name: ScheduleAbilityTransaction
* @tc.desc: Test ScheduleAbilityTransaction function when token_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0400, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0400 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->token_ = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(abilitythread->token_, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo);
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0400 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleAbilityTransaction_0400
* @tc.name: ScheduleAbilityTransaction
* @tc.desc: Test ScheduleAbilityTransaction function when abilityHandler_ and token_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleAbilityTransaction_0500, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0500 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->token_ = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(abilitythread->token_, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->ScheduleAbilityTransaction(want, lifeCycleStateInfo);
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleAbilityTransaction_0500 end";
}
/**
* @tc.number: AbilityRuntime_SendResult_0100
* @tc.name: SendResult
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(token, nullptr);
if (token != nullptr) {
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord =
std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
std::shared_ptr<AbilityRuntime::UIAbilityImpl> abilityimpl =
std::make_shared<AbilityRuntime::UIAbilityImpl>();
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
int requestCode = 0;
int resultCode = 0;
Want want;
abilitythread->SendResult(requestCode, resultCode, want);
sleep(1);
}
}
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0100 end";
}
/**
* @tc.number: AbilityRuntime_SendResult_0200
* @tc.name: SendResult
* @tc.desc: Test SendResult function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
if (abilitythread != nullptr) {
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
std::shared_ptr<AbilityLocalRecord> abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
int requestCode = 0;
int resultCode = 0;
Want want;
abilitythread->SendResult(requestCode, resultCode, want);
}
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0200 end";
}
/**
* @tc.number: AbilityRuntime_SendResult_0300
* @tc.name: SendResult
* @tc.desc: Simulate successful test cases
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_SendResult_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0300 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
auto abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
auto application = std::make_shared<OHOSApplication>();
auto abilityRecord = std::make_shared<AbilityLocalRecord>(abilityInfo, token);
std::shared_ptr<EventRunner> mainRunner = EventRunner::Create(abilityInfo->name);
abilitythread->Attach(application, abilityRecord, mainRunner, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
int requestCode = STARTID;
int resultCode = STARTID;
Want want;
abilitythread->SendResult(requestCode, resultCode, want);
GTEST_LOG_(INFO) << "AbilityRuntime_SendResult_0300 end";
}
/**
* @tc.number: AbilityRuntime_HandleAbilityTransaction_0100
* @tc.name: HandleAbilityTransaction
* @tc.desc: Test HandleAbilityTransaction function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleAbilityTransaction_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityImpl_, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->HandleAbilityTransaction(want, lifeCycleStateInfo);
GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0100 end";
}
/**
* @tc.number: AbilityRuntime_HandleAbilityTransaction_0200
* @tc.name: HandleAbilityTransaction
* @tc.desc: Test HandleAbilityTransaction function when abilityImpl_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleAbilityTransaction_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
Want want;
LifeCycleStateInfo lifeCycleStateInfo;
abilitythread->HandleAbilityTransaction(want, lifeCycleStateInfo);
GTEST_LOG_(INFO) << "AbilityRuntime_HandleAbilityTransaction_0200 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleUpdateConfiguration_0100
* @tc.name: ScheduleUpdateConfiguration
* @tc.desc: Test ScheduleUpdateConfiguration function when abilityHandler_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleUpdateConfiguration_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityHandler_, nullptr);
Configuration config;
abilitythread->ScheduleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0100 end";
}
/**
* @tc.number: AbilityRuntime_ScheduleUpdateConfiguration_0200
* @tc.name: ScheduleUpdateConfiguration
* @tc.desc: Test ScheduleUpdateConfiguration function when abilityHandler_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ScheduleUpdateConfiguration_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0200 start";
AbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
Configuration config;
abilitythread->ScheduleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_0200 end";
}
/**
* @tc.number: AbilityRuntime_HandleUpdateConfiguration_0100
* @tc.name: HandleUpdateConfiguration
* @tc.desc: Test HandleUpdateConfiguration function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleUpdateConfiguration_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityImpl_, nullptr);
Configuration config;
abilitythread->HandleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0100 end";
}
/**
* @tc.number: AbilityRuntime_HandleUpdateConfiguration_0200
* @tc.name: HandleUpdateConfiguration
* @tc.desc: Test HandleUpdateConfiguration function when abilityImpl_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_HandleUpdateConfiguration_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
Configuration config;
abilitythread->HandleUpdateConfiguration(config);
GTEST_LOG_(INFO) << "AbilityRuntime_HandleUpdateConfiguration_0200 end";
}
/**
* @tc.number: AbilityRuntime_ContinueAbility_0100
* @tc.name: ContinueAbility
* @tc.desc: Test ContinueAbility function when abilityImpl_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ContinueAbility_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
std::string deviceId = DEVICE_ID;
uint32_t versionCode = STARTID;
abilitythread->ContinueAbility(deviceId, versionCode);
GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0100 end";
}
/**
* @tc.number: AbilityRuntime_ContinueAbility_0200
* @tc.name: ContinueAbility
* @tc.desc: Test ContinueAbility function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_ContinueAbility_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityImpl_, nullptr);
std::string deviceId = DEVICE_ID;
uint32_t versionCode = STARTID;
abilitythread->ContinueAbility(deviceId, versionCode);
GTEST_LOG_(INFO) << "AbilityRuntime_ContinueAbility_0200 end";
}
/**
* @tc.number: AbilityRuntime_NotifyContinuationResult_0100
* @tc.name: NotifyContinuationResult
* @tc.desc: Test NotifyContinuationResult function when abilityImpl_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyContinuationResult_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
int32_t result = STARTID;
abilitythread->NotifyContinuationResult(result);
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0100 end";
}
/**
* @tc.number: AbilityRuntime_NotifyContinuationResult_0200
* @tc.name: NotifyContinuationResult
* @tc.desc: Test NotifyContinuationResult function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyContinuationResult_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityImpl_, nullptr);
int32_t result = STARTID;
abilitythread->NotifyContinuationResult(result);
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyContinuationResult_0200 end";
}
/**
* @tc.number: AbilityRuntime_NotifyMemoryLevel_0100
* @tc.name: NotifyMemoryLevel
* @tc.desc: Test NotifyMemoryLevel function when abilityImpl_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyMemoryLevel_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityImpl_, nullptr);
int32_t result = STARTID;
abilitythread->NotifyMemoryLevel(result);
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0100 end";
}
/**
* @tc.number: AbilityRuntime_NotifyMemoryLevel_0200
* @tc.name: NotifyMemoryLevel
* @tc.desc: Test NotifyMemoryLevel function when abilityImpl_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_NotifyMemoryLevel_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
int32_t result = STARTID;
abilitythread->NotifyMemoryLevel(result);
GTEST_LOG_(INFO) << "AbilityRuntime_NotifyMemoryLevel_0200 end";
}
/**
* @tc.number: AbilityRuntime_BuildAbilityContext_0100
* @tc.name: BuildAbilityContext
* @tc.desc: Test BuildAbilityContext function when Parameters is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_BuildAbilityContext_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_BuildAbilityContext_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
std::shared_ptr<AbilityInfo> abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
std::shared_ptr<OHOSApplication> application = std::make_shared<OHOSApplication>();
sptr<IRemoteObject> token = sptr<IRemoteObject>(new (std::nothrow) MockAbilityToken());
EXPECT_NE(abilityInfo, nullptr);
EXPECT_NE(application, nullptr);
EXPECT_NE(token, nullptr);
abilitythread->BuildAbilityContext(abilityInfo, application, token, nullptr);
GTEST_LOG_(INFO) << "AbilityRuntime_BuildAbilityContext_0100 end";
}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfoInner_0100
* @tc.name: DumpAbilityInfoInner
* @tc.desc: Test DumpAbilityInfoInner function when currentAbility_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfoInner_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->currentAbility_ = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_NE(abilitythread->currentAbility_, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfoInner(params, info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0100 end";
}
/**
* @tc.number: AbilityRuntime_DumpAbilityInfoInner_0200
* @tc.name: DumpAbilityInfoInner
* @tc.desc: Test DumpAbilityInfoInner function when currentAbility_ is nulllptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpAbilityInfoInner_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->currentAbility_, nullptr);
abilitythread->abilityImpl_ = std::make_shared<AbilityRuntime::UIAbilityImpl>();
EXPECT_NE(abilitythread->abilityImpl_, nullptr);
std::vector<std::string> params;
std::vector<std::string> info;
abilitythread->DumpAbilityInfoInner(params, info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpAbilityInfoInner_0200 end";
}
/**
* @tc.number: AbilityRuntime_DumpOtherInfo_0100
* @tc.name: DumpOtherInfo
* @tc.desc: Test DumpOtherInfo function when abilityHandler_ and currentAbility_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
auto abilityInfo = std::make_shared<AbilityInfo>();
abilityInfo->name = "MockUIAbility";
abilityInfo->type = AbilityType::PAGE;
auto setRunner = EventRunner::Create(abilityInfo->name);
abilitythread->abilityHandler_->SetEventRunner(setRunner);
auto getRunner = abilitythread->abilityHandler_->GetEventRunner();
EXPECT_NE(getRunner, nullptr);
abilitythread->currentAbility_ = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_NE(abilitythread->currentAbility_, nullptr);
std::vector<std::string> info;
abilitythread->DumpOtherInfo(info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0100 end";
}
/**
* @tc.number: AbilityRuntime_DumpOtherInfo_0200
* @tc.name: DumpOtherInfo
* @tc.desc: Test DumpOtherInfo function when abilityHandler_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
EXPECT_EQ(abilitythread->abilityHandler_, nullptr);
std::vector<std::string> info;
abilitythread->DumpOtherInfo(info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0200 end";
}
/**
* @tc.number: AbilityRuntime_DumpOtherInfo_0300
* @tc.name: DumpOtherInfo
* @tc.desc: Test DumpOtherInfo function when currentAbility_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_DumpOtherInfo_0300, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0300 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
EXPECT_EQ(abilitythread->currentAbility_, nullptr);
std::vector<std::string> info;
abilitythread->DumpOtherInfo(info);
GTEST_LOG_(INFO) << "AbilityRuntime_DumpOtherInfo_0300 end";
}
/**
* @tc.number: AbilityRuntime_CallRequest_0100
* @tc.name: CallRequest
* @tc.desc: Test CallRequest function when abilityHandler_ and currentAbility_ is not nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CallRequest_0100, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0100 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
std::vector<std::string> info;
abilitythread->abilityHandler_ = std::make_shared<AbilityHandler>(nullptr);
EXPECT_NE(abilitythread->abilityHandler_, nullptr);
abilitythread->currentAbility_ = std::make_shared<AbilityRuntime::UIAbility>();
EXPECT_NE(abilitythread->currentAbility_, nullptr);
abilitythread->CallRequest();
GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0100 end";
}
/**
* @tc.number: AbilityRuntime_CallRequest_0200
* @tc.name: CallRequest
* @tc.desc: Test CallRequest function when abilityHandler_ and currentAbility_ is nullptr
*/
HWTEST_F(UIAbilityThreadTest, AbilityRuntime_CallRequest_0200, Function | MediumTest | Level1)
{
GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0200 start";
AbilityRuntime::UIAbilityThread *abilitythread = new (std::nothrow) AbilityRuntime::UIAbilityThread();
EXPECT_NE(abilitythread, nullptr);
std::vector<std::string> info;
EXPECT_EQ(abilitythread->abilityHandler_, nullptr);
EXPECT_EQ(abilitythread->currentAbility_, nullptr);
abilitythread->CallRequest();
GTEST_LOG_(INFO) << "AbilityRuntime_CallRequest_0200 end";
}
} // namespace AppExecFwk
} // namespace OHOS
@@ -109,6 +109,7 @@ ohos_unittest("application_test") {
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
@@ -401,6 +402,7 @@ ohos_unittest("ability_stage_test") {
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_native",
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
@@ -498,6 +500,7 @@ ohos_unittest("appfreeze_inner_test") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_native_path}/ability/native:ability_thread",
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:uiabilitykit_native",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:app_context_utils",
"${ability_runtime_native_path}/appkit:appkit_native",
@@ -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
@@ -16,9 +16,9 @@
#include <gtest/gtest.h>
#include "ohos_application.h"
#include "ability.h"
#include "mock_ability_lifecycle_callbacks.h"
#include "mock_element_callback.h"
#include "ui_ability.h"
using namespace testing::ext;
using namespace OHOS;
@@ -67,7 +67,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_RegisterAbilityLifecycleCallbac
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityActive(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -88,7 +88,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_RegisterAbilityLifecycleCallbac
if (ApplicationTest_ != nullptr) {
ApplicationTest_->RegisterAbilityLifecycleCallbacks(nullptr);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityActive(ability);
}
GTEST_LOG_(INFO) << "AppExecFwk_Application_RegisterAbilityLifecycleCallbacks_0200 end";
@@ -110,7 +110,7 @@ HWTEST_F(
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityActive(ability);
}
GTEST_LOG_(INFO) << "AppExecFwk_Application_UnregisterAbilityLifecycleCallbacks_0100 end";
@@ -132,7 +132,7 @@ HWTEST_F(
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(nullptr);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityActive(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -154,7 +154,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityStart_0100, Function |
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityStart(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -176,7 +176,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityInactive_0100, Functio
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityInactive(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -198,7 +198,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityBackground_0100, Funct
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityBackground(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -220,7 +220,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityForeground_0100, Funct
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityForeground(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -242,7 +242,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityActive_0100, Function
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityActive(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);
@@ -264,7 +264,7 @@ HWTEST_F(ApplicationTest, AppExecFwk_Application_OnAbilityStop_0100, Function |
std::shared_ptr<MockAbilityLifecycleCallbacks> callback = std::make_shared<MockAbilityLifecycleCallbacks>();
ApplicationTest_->RegisterAbilityLifecycleCallbacks(callback);
std::shared_ptr<Ability> ability = std::make_shared<Ability>();
std::shared_ptr<AbilityRuntime::UIAbility> ability = std::make_shared<AbilityRuntime::UIAbility>();
ApplicationTest_->OnAbilityStop(ability);
ApplicationTest_->UnregisterAbilityLifecycleCallbacks(callback);