add agentuiextenion

Signed-off-by: zexin_c <chenzexin14@huawei.com>
This commit is contained in:
zexin_c
2026-02-02 16:07:55 +08:00
parent b6bcb6d90f
commit 8a671fd37c
12 changed files with 617 additions and 1 deletions
@@ -18,5 +18,6 @@ group("agent_runtime_napi_packages") {
deps = [
"${agent_runtime_framework_path}/frameworks/js/napi/agent_extension_ability:agentextensionability",
"${agent_runtime_framework_path}/frameworks/js/napi/agent_extension_context:agentextensioncontext_napi",
"${agent_runtime_framework_path}/frameworks/js/napi/agent_ui_extension_ability:agentuiextensionability",
]
}
@@ -0,0 +1,60 @@
# Copyright (c) 2026 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/config/components/ets_frontend/es2abc_config.gni")
import("//build/ohos.gni")
es2abc_gen_abc("gen_agent_ui_extension_ability_abc") {
src_js = rebase_path("agent_ui_extension_ability.js")
dst_file = rebase_path(target_out_dir + "/agent_ui_extension_ability.abc")
in_puts = [ "agent_ui_extension_ability.js" ]
out_puts = [ target_out_dir + "/agent_ui_extension_ability.abc" ]
extra_args = [ "--module" ]
}
gen_js_obj("agent_ui_extension_ability_js") {
input = "agent_ui_extension_ability.js"
output = target_out_dir + "/agent_ui_extension_ability.o"
}
gen_js_obj("agent_ui_extension_ability_abc") {
input = get_label_info(":gen_agent_ui_extension_ability_abc",
"target_out_dir") + "/agent_ui_extension_ability.abc"
output = target_out_dir + "/agent_ui_extension_ability_abc.o"
dep = ":gen_agent_ui_extension_ability_abc"
}
ohos_shared_library("agentuiextensionability") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
cfi_vcall_icall_only = true
debug = false
}
branch_protector_ret = "pac_ret"
sources = [ "agent_ui_extension_module.cpp" ]
deps = [
":agent_ui_extension_ability_abc",
":agent_ui_extension_ability_js",
]
external_deps = [ "napi:ace_napi" ]
relative_install_dir = "module/app/ability"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2026 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.
*/
let UIExtensionAbility = requireNapi('app.ability.UIExtensionAbility');
export default class AgentUIExtensionAbility extends UIExtensionAbility {}
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2026 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 "native_engine/native_engine.h"
extern const char _binary_agent_ui_extension_ability_js_start[];
extern const char _binary_agent_ui_extension_ability_js_end[];
extern const char _binary_agent_ui_extension_ability_abc_start[];
extern const char _binary_agent_ui_extension_ability_abc_end[];
static napi_module _module = {
.nm_version = 0,
.nm_filename = "app/ability/libagentuiextensionability.so/agent_ui_extension_ability.js",
.nm_modname = "app.ability.AgentUIExtensionAbility",
};
extern "C" __attribute__((constructor)) void NAPI_app_ability_AgentUIExtensionAbility_AutoRegister()
{
napi_module_register(&_module);
}
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_AgentUIExtensionAbility_GetJSCode(
const char **buf, int *bufLen)
{
if (buf != nullptr) {
*buf = _binary_agent_ui_extension_ability_js_start;
}
if (bufLen != nullptr) {
*bufLen = _binary_agent_ui_extension_ability_js_end - _binary_agent_ui_extension_ability_js_start;
}
}
extern "C" __attribute__((visibility("default"))) void NAPI_app_ability_AgentUIExtensionAbility_GetABCCode(
const char **buf, int *buflen)
{
if (buf != nullptr) {
*buf = _binary_agent_ui_extension_ability_abc_start;
}
if (buflen != nullptr) {
*buflen = _binary_agent_ui_extension_ability_abc_end - _binary_agent_ui_extension_ability_abc_start;
}
}
@@ -0,0 +1,193 @@
# Copyright (c) 2026 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
config("ability_config") {
visibility = [ ":*" ]
visibility += [
"${ability_runtime_native_path}/ability/native/*",
"${ability_runtime_test_path}/*",
"${distributeddatamgr_path}/data_share/interfaces/inner_api/*",
"${imf_path}/frameworks/kits/extension/*",
"${print_fwk_path}/frameworks/kits/extension/*",
"${user_file_service_innerkits_path}/file_access/*",
"${wallpaper_mgr_path}/frameworks/kits/extension/*",
]
include_dirs = [
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${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/continuation/remote_register_service",
"${ability_runtime_path}/interfaces/kits/native/ability/native/distributed_ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/appkit/app",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_innerkits_path}/uri/include",
"${ability_runtime_services_path}/abilitymgr/include/utils",
"${ability_runtime_services_path}/abilitymgr/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
"${ability_runtime_innerkits_path}/ability_manager/include/continuation",
"${ability_runtime_path}/interfaces/kits/native/appkit/app/task",
"${ability_runtime_napi_path}/inner/napi_common",
"${ability_runtime_napi_path}/featureAbility",
]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
defines = [ "AMS_LOG_TAG = \"Ability\"" ]
defines += [ "AMS_LOG_DOMAIN = 0xD001300" ]
if (target_cpu == "arm64") {
defines += [ "_ARM64_" ]
}
if (target_cpu == "arm64") {
defines += [ "APP_USE_ARM64" ]
} else if (target_cpu == "arm") {
defines += [ "APP_USE_ARM" ]
} else if (target_cpu == "x86_64") {
defines += [ "APP_USE_X86_64" ]
}
if (ability_runtime_graphics) {
defines += [
"SUPPORT_GRAPHICS",
"SUPPORT_SCREEN",
]
}
}
config("agent_ui_extension_config") {
visibility = [ ":*" ]
include_dirs = [
"${agent_runtime_framework_path}/interfaces/kits/native/ability/native/agent_ui_extension_ability",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_base",
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/ability/native",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
]
}
ohos_shared_library("agent_ui_extension") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
cfi_vcall_icall_only = true
debug = false
}
branch_protector_ret = "pac_ret"
configs = [
":agent_ui_extension_config",
"${ability_runtime_services_path}/common:optimize_config",
]
include_dirs = [ "${agent_runtime_framework_path}/interfaces/kits/native/agent_ui_extension", ]
sources = [
"${agent_runtime_framework_path}/frameworks/native/agent_ui_extension_ability/agent_ui_extension.cpp",
"${agent_runtime_framework_path}/frameworks/native/agent_ui_extension_ability/js_agent_ui_extension.cpp",
]
deps = [
"${ability_runtime_native_path}/ability/native:abilitykit_native",
"${ability_runtime_native_path}/ability/native:abilitykit_utils",
"${ability_runtime_native_path}/ability/native:extensionkit_native",
"${ability_runtime_native_path}/ability/native:ui_extension",
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
"${ability_runtime_native_path}/ability:ability_context_native",
"${ability_runtime_native_path}/ability/native:ability_business_error",
"${ability_runtime_native_path}/appkit:app_context",
]
external_deps = [
"ability_base:want",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"hitrace:hitrace_meter",
"ipc:ipc_napi",
"ipc:ipc_single",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
external_deps += [ "window_manager:libwm" ]
}
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_shared_library("agent_ui_extension_module") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
cfi_vcall_icall_only = true
debug = false
}
branch_protector_ret = "pac_ret"
include_dirs = [
"${agent_runtime_framework_path}/interfaces/kits/native/agent_ui_extension",
]
sources = [ "${agent_runtime_framework_path}/frameworks/native/agent_ui_extension_ability/agent_ui_extension_module_loader.cpp" ]
configs = [
":ability_config",
":agent_ui_extension_config",
]
deps = [
":agent_ui_extension",
"${ability_runtime_innerkits_path}/runtime:runtime",
]
external_deps = [
"ability_base:configuration",
"ability_base:session_info",
"ability_base:want",
"bundle_framework:appexecfwk_core",
"hilog:libhilog",
"ipc:ipc_napi",
"ipc:ipc_single",
"napi:ace_napi",
]
if (ability_runtime_graphics) {
external_deps += [
"form_fwk:form_manager",
"window_manager:libwm",
]
}
relative_install_dir = "extensionability/"
subsystem_name = "ability"
part_name = "ability_runtime"
}
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2026 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 "agent_ui_extension.h"
#include "hilog_tag_wrapper.h"
#include "js_agent_ui_extension.h"
#include "runtime.h"
#include "ui_extension_context.h"
namespace OHOS {
namespace AgentRuntime {
AgentUIExtension *AgentUIExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime)
{
TAG_LOGD(AAFwkTag::SER_ROUTER, "called");
if (!runtime) {
return new AgentUIExtension();
}
switch (runtime->GetLanguage()) {
case AbilityRuntime::Runtime::Language::JS:
return JsAgentUIExtension::Create(runtime);
default:
return new AgentUIExtension();
}
}
} // namespace AgentRuntime
} // namespace OHOS
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2023-2024 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 "agent_ui_extension_module_loader.h"
#include "agent_ui_extension.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AgentRuntime {
AgentUIExtensionModuleLoader::AgentUIExtensionModuleLoader() = default;
AgentUIExtensionModuleLoader::~AgentUIExtensionModuleLoader() = default;
AbilityRuntime::Extension *AgentUIExtensionModuleLoader::Create(
const std::unique_ptr<AbilityRuntime::Runtime> &runtime) const
{
TAG_LOGD(AAFwkTag::SER_ROUTER, "called");
return AgentUIExtension::Create(runtime);
}
std::map<std::string, std::string> AgentUIExtensionModuleLoader::GetParams()
{
TAG_LOGD(AAFwkTag::SER_ROUTER, "called");
std::map<std::string, std::string> params;
// type means extension type in ExtensionAbilityType of extension_ability_info.h, 38 means agent ui extension.
params.insert(std::pair<std::string, std::string>("type", "38"));
params.insert(std::pair<std::string, std::string>("name", "AgentUIExtensionAbility"));
return params;
}
extern "C" __attribute__((visibility("default"))) void *OHOS_EXTENSION_GetExtensionModule()
{
return &AgentUIExtensionModuleLoader::GetInstance();
}
} // namespace AgentRuntime
} // namespace OHOS
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2026 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 "agent_ui_extension.h"
#include "hilog_tag_wrapper.h"
#include "js_agent_ui_extension.h"
#include "runtime.h"
#include "ui_extension_context.h"
namespace OHOS {
namespace AgentRuntime {
AgentUIExtension *AgentUIExtension::Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime)
{
TAG_LOGD(AAFwkTag::SER_ROUTER, "called");
if (!runtime) {
return new AgentUIExtension();
}
switch (runtime->GetLanguage()) {
case AbilityRuntime::Runtime::Language::JS:
return JsAgentUIExtension::Create(runtime);
default:
return new AgentUIExtension();
}
}
} // namespace AgentRuntime
} // namespace OHOS
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2026 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 OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_H
#define OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_H
#include <memory>
#include "ui_extension_base.h"
namespace OHOS {
namespace AbilityRuntime {
class Runtime;
} // namespace AbilityRuntime
namespace AgentRuntime {
/**
* @brief Agent UI Extension base class.
*
* This class provides the base functionality for Agent UI Extension abilities.
* It extends UIExtensionBase and provides factory methods for creating
* language-specific implementations.
*/
class AgentUIExtension : public AbilityRuntime::UIExtensionBase<> {
public:
AgentUIExtension() = default;
virtual ~AgentUIExtension() = default;
/**
* @brief Create an AgentUIExtension instance based on the runtime language.
*
* @param runtime The runtime instance used to determine the language implementation.
* @return Returns a pointer to the created AgentUIExtension instance.
*/
static AgentUIExtension *Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
};
} // namespace AgentRuntime
} // namespace OHOS
#endif // OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_H
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2026 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 OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_MODULE_LOADER_H
#define OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_MODULE_LOADER_H
#include <map>
#include <memory>
#include <string>
#include "extension_module_loader.h"
namespace OHOS {
namespace AbilityRuntime {
class Runtime;
} // namespace AbilityRuntime
namespace AgentRuntime {
/**
* @brief Module loader for Agent UI Extension.
*
* This class is responsible for loading Agent UI Extension modules and
* providing the necessary parameters for extension registration.
*/
class AgentUIExtensionModuleLoader : public AbilityRuntime::ExtensionModuleLoader {
public:
AgentUIExtensionModuleLoader();
virtual ~AgentUIExtensionModuleLoader();
/**
* @brief Create an Extension instance based on the runtime.
*
* @param runtime The runtime instance used to create the extension.
* @return Returns a pointer to the created Extension instance.
*/
AbilityRuntime::Extension *Create(
const std::unique_ptr<AbilityRuntime::Runtime> &runtime) const override;
/**
* @brief Get the parameters for the Agent UI Extension module.
*
* @return Returns a map containing the module parameters including type and name.
*/
std::map<std::string, std::string> GetParams() override;
};
} // namespace AgentRuntime
} // namespace OHOS
#endif // OHOS_AGENT_RUNTIME_AGENT_UI_EXTENSION_MODULE_LOADER_H
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2026 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 OHOS_AGENT_RUNTIME_JS_AGENT_UI_EXTENSION_H
#define OHOS_AGENT_RUNTIME_JS_AGENT_UI_EXTENSION_H
#include <memory>
#include "agent_ui_extension.h"
namespace OHOS::AbilityRuntime {
class Runtime;
class JsUIExtensionBase;
}
namespace OHOS {
namespace AgentRuntime {
class AgentUIExtension;
/**
* @brief Basic action extension components.
*/
class JsAgentUIExtension : public AgentUIExtension, public std::enable_shared_from_this<JsAgentUIExtension> {
public:
explicit JsAgentUIExtension(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
virtual ~JsAgentUIExtension() override;
/**
* @brief Create JsAgentUIExtension.
*
* @param runtime The runtime.
* @return The JsAgentUIExtension instance.
*/
static JsAgentUIExtension *Create(const std::unique_ptr<AbilityRuntime::Runtime> &runtime);
};
} // namespace AgentRuntime
} // namespace OHOS
#endif // OHOS_AGENT_RUNTIME_JS_AGENT_UI_EXTENSION_H
+2 -1
View File
@@ -156,7 +156,8 @@
"//foundation/ability/ability_runtime/service_router_framework:srms_target",
"//foundation/ability/ability_runtime/service_router_framework:jsapi_target",
"//foundation/ability/ability_runtime/agent_runtime_framework/frameworks/js/napi:agent_runtime_napi_packages",
"//foundation/ability/ability_runtime/agent_runtime_framework/frameworks/native/agent_extension:agent_extension_module"
"//foundation/ability/ability_runtime/agent_runtime_framework/frameworks/native/agent_extension:agent_extension_module",
"//foundation/ability/ability_runtime/agent_runtime_framework/frameworks/native/agent_ui_extension_ability:agent_ui_extension_module"
],
"inner_api": [
{