mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
+14
@@ -233,6 +233,20 @@
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:cj_abilitykit_native_ffi"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/insight_intent_executor",
|
||||
"header_files": []
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:cj_insight_intent_executor"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/insight_intent/insight_intent_context",
|
||||
"header_files": []
|
||||
},
|
||||
"name": "//foundation/ability/ability_runtime/frameworks/native/insight_intent/insight_intent_context:cj_insightintentcontext"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include",
|
||||
|
||||
@@ -16,6 +16,7 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
group("cj_ability_packages") {
|
||||
deps = [
|
||||
"${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi/app/app_manager:cj_app_manager_ffi",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi/app/errormanager:cj_errormanager_ffi",
|
||||
@@ -28,6 +29,7 @@ group("cj_ability_packages") {
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_action_extension",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_embedded_ui_extension",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_extensionkit_native",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_insight_intent_executor",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_form_extension",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_photo_editor_extension",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:cj_share_extension",
|
||||
|
||||
@@ -743,6 +743,59 @@ ohos_shared_library("insight_intent_executor") {
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
ohos_shared_library("cj_insight_intent_executor") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
sources = [
|
||||
"${ability_runtime_native_path}/ability/native/insight_intent_executor/cj_insight_intent_executor.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.cpp",
|
||||
"${ability_runtime_native_path}/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.cpp",
|
||||
]
|
||||
|
||||
public_configs = [ ":insight_intent_executor_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${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/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/insight_intent/insight_intent_context:insightintentcontext",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi",
|
||||
"${ability_runtime_services_path}/common:event_report",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:session_info",
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"c_utils:utils",
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"hisysevent:libhisysevent",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_napi",
|
||||
"napi:ace_napi",
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
"window_manager:libwm",
|
||||
]
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
config("uiability_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
@@ -1794,6 +1847,7 @@ ohos_shared_library("cj_ui_extension") {
|
||||
"${ability_runtime_native_path}/ability:ability_context_native",
|
||||
"${ability_runtime_native_path}/ability:cj_ability_context_native",
|
||||
"${ability_runtime_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/ability/native:cj_insight_intent_executor",
|
||||
"${ability_runtime_native_path}/ability/native:insight_intent_executor",
|
||||
"${ability_runtime_native_path}/appkit:app_context",
|
||||
"${ability_runtime_native_path}/appkit:app_context_utils",
|
||||
|
||||
@@ -15,28 +15,28 @@
|
||||
|
||||
#include "cj_ui_ability.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <dlfcn.h>
|
||||
#include <regex>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "ability_business_error.h"
|
||||
#include "ability_delegator_registry.h"
|
||||
#include "ability_recovery.h"
|
||||
#include "ability_start_setting.h"
|
||||
#include "app_recovery.h"
|
||||
#include "context/application_context.h"
|
||||
#include "cj_ability_context.h"
|
||||
#include "cj_ability_object.h"
|
||||
#include "cj_insight_intent_executor_info.h"
|
||||
#include "cj_insight_intent_executor_mgr.h"
|
||||
#include "cj_runtime.h"
|
||||
#include "connection_manager.h"
|
||||
#include "context/application_context.h"
|
||||
#include "context/context.h"
|
||||
#include "display_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "insight_intent_executor_info.h"
|
||||
#include "insight_intent_executor_mgr.h"
|
||||
#include "insight_intent_execute_param.h"
|
||||
#include "cj_runtime.h"
|
||||
#include "cj_ability_object.h"
|
||||
#include "cj_ability_context.h"
|
||||
#include "time_util.h"
|
||||
#ifdef SUPPORT_SCREEN
|
||||
#include "scene_board_judgement.h"
|
||||
@@ -69,6 +69,10 @@ const char* CJ_APP_CTX_WINDOW_FUNC = "OHOS_CjAppCtxWindowFunc";
|
||||
const char* CJ_IPC_LIBNAME = "libcj_ipc_ffi.z.so";
|
||||
const char* FUNC_GET_NATIVE_REMOTEOBJECT = "OHOS_CallGetNativeRemoteObject";
|
||||
|
||||
const char* CJ_INSIGHT_LIBNAME = "libcj_insight_intent_executor.z.so";
|
||||
const char* FUNC_TRIGGER_CALLBACK_INNER = "OHOS_CallTriggerCallbackInner";
|
||||
const char* FUNC_EXECUTE_INSIGHT_INTENT = "OHOS_CallExecuteInsightIntent";
|
||||
|
||||
sptr<Rosen::CJWindowStageImpl> CreateCJWindowStage(std::shared_ptr<Rosen::WindowScene> windowScene)
|
||||
{
|
||||
static void* handle = nullptr;
|
||||
@@ -662,6 +666,44 @@ const CJRuntime &CJUIAbility::GetCJRuntime()
|
||||
return cjRuntime_;
|
||||
}
|
||||
|
||||
void CallTriggerCallbackInner(std::unique_ptr<InsightIntentExecutorAsyncCallback> callback, int32_t errCode)
|
||||
{
|
||||
void* handle = dlopen(CJ_INSIGHT_LIBNAME, RTLD_LAZY);
|
||||
if (handle == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "null handle");
|
||||
return;
|
||||
}
|
||||
using TriggerCallbackInnerFunc = void (*)(void*, int32_t);
|
||||
auto func = reinterpret_cast<TriggerCallbackInnerFunc>(dlsym(handle, FUNC_TRIGGER_CALLBACK_INNER));
|
||||
if (func == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "null func");
|
||||
dlclose(handle);
|
||||
return;
|
||||
}
|
||||
func(&callback, errCode);
|
||||
dlclose(handle);
|
||||
}
|
||||
|
||||
bool CallExecuteInsightIntent(Runtime& runtime, CJInsightIntentExecutorInfo& executeInfo,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
void* handle = dlopen(CJ_INSIGHT_LIBNAME, RTLD_LAZY);
|
||||
if (handle == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "null handle");
|
||||
return false;
|
||||
}
|
||||
using ExecuteInsightIntentFunc = bool (*)(void*, void*, void*);
|
||||
auto func = reinterpret_cast<ExecuteInsightIntentFunc>(dlsym(handle, FUNC_EXECUTE_INSIGHT_INTENT));
|
||||
if (func == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::CONTEXT, "null func");
|
||||
dlclose(handle);
|
||||
return false;
|
||||
}
|
||||
auto ret = func(&runtime, &executeInfo, &callback);
|
||||
dlclose(handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
@@ -670,7 +712,8 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
if (executeParam == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::UIABILITY, "invalid param");
|
||||
RequestFocus(want);
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
// CJInsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
CallTriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -685,14 +728,20 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want,
|
||||
};
|
||||
callback->Push(asyncCallback);
|
||||
|
||||
InsightIntentExecutorInfo executeInfo;
|
||||
CJInsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "get intention executor failed");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
CallTriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
// ret = DelayedSingleton<CJInsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
// cjRuntime_, executeInfo, std::move(callback));
|
||||
ret = CallExecuteInsightIntent(cjRuntime_, executeInfo, std::move(callback));
|
||||
if (!ret) {
|
||||
// callback has removed, release in insight intent executor.
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "execute insightIntent failed");
|
||||
}
|
||||
}
|
||||
|
||||
void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
@@ -703,7 +752,8 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
if (executeParam == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::UIABILITY, "param invalid");
|
||||
OnForeground(want);
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
// CJInsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
CallTriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -720,19 +770,55 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want,
|
||||
};
|
||||
callback->Push(asyncCallback);
|
||||
|
||||
InsightIntentExecutorInfo executeInfo;
|
||||
CJInsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "get Intention executor failed");
|
||||
InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
CallTriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
// ret = DelayedSingleton<CJInsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
// cjRuntime_, executeInfo, std::move(callback));
|
||||
ret = CallExecuteInsightIntent(cjRuntime_, executeInfo, std::move(callback));
|
||||
if (!ret) {
|
||||
// callback has removed, release in insight intent executor.
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "execute insightIntent failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool CJUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
void CJUIAbility::ExecuteInsightIntentBackground(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
InsightIntentExecutorInfo& executeInfo)
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::UIABILITY, "executeInsightIntentBackground");
|
||||
if (executeParam == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::UIABILITY, "null executePara");
|
||||
// CJInsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
CallTriggerCallbackInner(std::move(callback), ERR_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
CJInsightIntentExecutorInfo executeInfo;
|
||||
auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo);
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "get intentExecutor failed");
|
||||
// CJInsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback),
|
||||
// static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
CallTriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return;
|
||||
}
|
||||
|
||||
// auto ret = DelayedSingleton<CJInsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
// cjRuntime_, executeInfo, std::move(callback));
|
||||
ret = CallExecuteInsightIntent(cjRuntime_, executeInfo, std::move(callback));
|
||||
if (!ret) {
|
||||
// callback has removed, release in insight intent executor.
|
||||
TAG_LOGE(AAFwkTag::UIABILITY, "execute insightIntent failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool CJUIAbility::GetInsightIntentExecutorInfo(const Want& want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam>& executeParam, CJInsightIntentExecutorInfo& executeInfo)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::UIABILITY, "called");
|
||||
auto context = GetAbilityContext();
|
||||
@@ -747,6 +833,9 @@ bool CJUIAbility::GetInsightIntentExecutorInfo(const Want &want,
|
||||
executeInfo.esmodule = abilityInfo_->compileMode == AppExecFwk::CompileMode::ES_MODULE;
|
||||
executeInfo.windowMode = windowMode_;
|
||||
executeInfo.token = context->GetToken();
|
||||
if (cjWindowStage_ != nullptr) {
|
||||
executeInfo.pageLoader.windowPageLoader = cjWindowStage_.GetRefPtr();
|
||||
}
|
||||
executeInfo.executeParam = executeParam;
|
||||
return true;
|
||||
}
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2025 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 "cj_insight_intent_executor.h"
|
||||
|
||||
#include "cj_insight_intent_executor_impl.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "runtime.h"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
std::shared_ptr<CJInsightIntentExecutor> CJInsightIntentExecutor::Create(Runtime& runtime)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
switch (runtime.GetLanguage()) {
|
||||
case Runtime::Language::CJ:
|
||||
return static_cast<std::shared_ptr<CJInsightIntentExecutorImpl>>(CJInsightIntentExecutorImpl::Create());
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutor::Init(const CJInsightIntentExecutorInfo& intentInfo)
|
||||
{
|
||||
auto executeParam = intentInfo.executeParam;
|
||||
if (executeParam == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null executeParam");
|
||||
return false;
|
||||
}
|
||||
|
||||
context_ = std::make_shared<InsightIntentContext>(
|
||||
intentInfo.token, executeParam->bundleName_, intentInfo.windowMode, executeParam->insightIntentId_);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<InsightIntentContext> CJInsightIntentExecutor::GetContext()
|
||||
{
|
||||
return context_;
|
||||
}
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2025 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 "cj_insight_intent_executor_impl.h"
|
||||
|
||||
#include <want_params.h>
|
||||
|
||||
#include "ability_transaction_callback_info.h"
|
||||
#include "cj_insight_intent_executor_impl_object.h"
|
||||
#include "event_report.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "insight_intent_constant.h"
|
||||
#include "insight_intent_execute_result.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
#undef STATE_PATTERN_NAIVE_H
|
||||
#define STATE_PATTERN_NAIVE_STATE state_
|
||||
#include "state_pattern_naive.h"
|
||||
|
||||
#define TMP_NAPI_ANONYMOUS_FUNC "_"
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
|
||||
std::shared_ptr<CJInsightIntentExecutorImpl> CJInsightIntentExecutorImpl::Create()
|
||||
{
|
||||
std::shared_ptr<CJInsightIntentExecutorImpl> ptr(new (std::nothrow) CJInsightIntentExecutorImpl());
|
||||
return ptr;
|
||||
}
|
||||
|
||||
using State = CJInsightIntentExecutorImpl::State;
|
||||
|
||||
CJInsightIntentExecutorImpl::CJInsightIntentExecutorImpl() {}
|
||||
|
||||
CJInsightIntentExecutorImpl::~CJInsightIntentExecutorImpl()
|
||||
{
|
||||
state_ = State::DESTROYED;
|
||||
TAG_LOGI(AAFwkTag::INTENT, "called");
|
||||
cjObj_.Destroy();
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::Init(const CJInsightIntentExecutorInfo& insightIntentInfo)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
STATE_PATTERN_NAIVE_ACCEPT(State::CREATED, false);
|
||||
state_ = State::INITIALIZED;
|
||||
CJInsightIntentExecutor::Init(insightIntentInfo);
|
||||
auto pos = insightIntentInfo.srcEntry.rfind('.');
|
||||
if (pos == std::string::npos) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "Init failed");
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
auto executorName = insightIntentInfo.srcEntry.substr(pos + 1);
|
||||
|
||||
auto context = GetContext();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null Context");
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
|
||||
int32_t ret = cjObj_.Init(executorName, this);
|
||||
if (ret != 0) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null cjObj_");
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
|
||||
if (contextObj_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null contextObj_");
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::ExecuteIntentCheckError()
|
||||
{
|
||||
ReplyFailedInner();
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::HandleExecuteIntent(InsightIntentExecuteMode mode, const std::string& name,
|
||||
const AAFwk::WantParams& param, CJPageLoader pageLoader,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
STATE_PATTERN_NAIVE_ACCEPT(State::INITIALIZED, false);
|
||||
state_ = State::EXECUTING;
|
||||
|
||||
if (callback == nullptr || callback->IsEmpty()) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null callback");
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
callback_ = std::move(callback);
|
||||
bool successful = false;
|
||||
switch (mode) {
|
||||
case InsightIntentExecuteMode::UIABILITY_FOREGROUND:
|
||||
if (!CJInsightIntentExecutorImpl::CheckParametersUIAbilityForeground(pageLoader.windowPageLoader)) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "CheckParametersUIAbilityForeground error");
|
||||
return ExecuteIntentCheckError();
|
||||
}
|
||||
successful = ExecuteInsightIntentUIAbilityForeground(name, param, pageLoader.windowPageLoader);
|
||||
break;
|
||||
case InsightIntentExecuteMode::UIABILITY_BACKGROUND:
|
||||
if (!CJInsightIntentExecutorImpl::CheckParametersUIAbilityBackground()) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "CheckParametersUIAbilityBackground error");
|
||||
return ExecuteIntentCheckError();
|
||||
}
|
||||
successful = ExecuteInsightIntentUIAbilityBackground(name, param);
|
||||
break;
|
||||
case InsightIntentExecuteMode::UIEXTENSION_ABILITY:
|
||||
if (!CJInsightIntentExecutorImpl::CheckParametersUIExtension(pageLoader.sessionPageLoader)) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "CheckParametersUIExtension error");
|
||||
return ExecuteIntentCheckError();
|
||||
}
|
||||
successful = ExecuteInsightIntentUIExtension(name, param, pageLoader.sessionPageLoader);
|
||||
break;
|
||||
default:
|
||||
TAG_LOGE(AAFwkTag::INTENT, "InsightIntentExecuteMode not supported yet");
|
||||
return ExecuteIntentCheckError();
|
||||
}
|
||||
return successful;
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> CJInsightIntentExecutorImpl::GetResultFromCj(
|
||||
CJExecuteResult resultCj)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto resultCpp = std::make_shared<AppExecFwk::InsightIntentExecuteResult>();
|
||||
if (resultCpp == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
resultCpp->code = resultCj.code;
|
||||
auto resultString = std::string(resultCj.result);
|
||||
AAFwk::WantParams wantParams = OHOS::AAFwk::WantParamWrapper::ParseWantParamsWithBrackets(resultString);
|
||||
resultCpp->result = std::make_shared<AAFwk::WantParams>(wantParams);
|
||||
if (resultCj.uris.head != nullptr && resultCj.uris.size > 0) {
|
||||
std::vector<std::string> uris;
|
||||
for (int64_t i = 0; i < resultCj.uris.size; i++) {
|
||||
uris.push_back(std::string(resultCj.uris.head[i]));
|
||||
}
|
||||
resultCpp->uris = uris;
|
||||
}
|
||||
resultCpp->flags = resultCj.flags;
|
||||
return resultCpp;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImpl::ReplyFailed(
|
||||
InsightIntentExecutorAsyncCallback* callback, InsightIntentInnerErr innerErr)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
AppExecFwk::InsightIntentExecuteResult errorResult {};
|
||||
errorResult.innerErr = innerErr;
|
||||
AAFwk::EventInfo eventInfo;
|
||||
eventInfo.errCode = innerErr;
|
||||
eventInfo.errReason = "ReplyFailed";
|
||||
AAFwk::EventReport::SendExecuteIntentEvent(
|
||||
AAFwk::EventName::EXECUTE_INSIGHT_INTENT_ERROR, HiSysEventType::FAULT, eventInfo);
|
||||
callback->Call(errorResult);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImpl::ReplySucceeded(
|
||||
InsightIntentExecutorAsyncCallback* callback, std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> resultCpp)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
if (callback == nullptr) {
|
||||
return;
|
||||
}
|
||||
if (resultCpp == nullptr) {
|
||||
ReplyFailed(callback);
|
||||
return;
|
||||
}
|
||||
resultCpp->innerErr = InsightIntentInnerErr::INSIGHT_INTENT_ERR_OK;
|
||||
callback->Call(*resultCpp);
|
||||
delete callback;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImpl::ReplyFailedInner(InsightIntentInnerErr innerErr)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
state_ = CJInsightIntentExecutorImpl::State::INVALID;
|
||||
auto* callback = callback_.release();
|
||||
CJInsightIntentExecutorImpl::ReplyFailed(callback, innerErr);
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImpl::ReplySucceededInner(std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> resultCpp)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
state_ = CJInsightIntentExecutorImpl::State::EXECUTATION_DONE;
|
||||
auto* callback = callback_.release();
|
||||
CJInsightIntentExecutorImpl::ReplySucceeded(callback, resultCpp);
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::HandleResultReturnedFromCjFunc(CJExecuteResult resultJs)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
|
||||
// TAG_LOGI(AAFwkTag::INTENT, "Not promise");
|
||||
auto resultCpp = CJInsightIntentExecutorImpl::GetResultFromCj(resultJs);
|
||||
if (resultCpp == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null resultCpp");
|
||||
ReplyFailedInner();
|
||||
STATE_PATTERN_NAIVE_STATE_SET_AND_RETURN(State::INVALID, false);
|
||||
}
|
||||
// TAG_LOGD(AAFwkTag::INTENT, "Call succeed");
|
||||
ReplySucceededInner(resultCpp);
|
||||
cjObj_.FreeCJExecuteResult(resultJs);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::CheckParametersUIAbilityForeground(Rosen::CJWindowStageImpl* windowStage)
|
||||
{
|
||||
return windowStage != nullptr;
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::ExecuteInsightIntentUIAbilityForeground(
|
||||
const std::string& name, const AAFwk::WantParams& param, Rosen::CJWindowStageImpl* cjWindowStage)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto result = cjObj_.OnExecuteInUIAbilityForegroundMode(name, param, cjWindowStage);
|
||||
if (result.code == CALL_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return HandleResultReturnedFromCjFunc(result);
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::CheckParametersUIAbilityBackground()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::ExecuteInsightIntentUIAbilityBackground(
|
||||
const std::string& name, const AAFwk::WantParams& param)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto result = cjObj_.OnExecuteInUIAbilityBackgroundMode(name, param);
|
||||
if (result.code == CALL_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return HandleResultReturnedFromCjFunc(result);
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::CheckParametersUIExtension(int64_t sessionId)
|
||||
{
|
||||
return sessionId > 0;
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorImpl::ExecuteInsightIntentUIExtension(
|
||||
const std::string& name, const AAFwk::WantParams& param, int64_t sessionId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto result = cjObj_.OnExecuteInsightIntentUIExtension(name, param, sessionId);
|
||||
if (result.code == CALL_ERROR) {
|
||||
return false;
|
||||
}
|
||||
return HandleResultReturnedFromCjFunc(result);
|
||||
}
|
||||
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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 "cj_insight_intent_executor_impl_object.h"
|
||||
|
||||
#include <want_params.h>
|
||||
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "securec.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
using WindowStagePtr = void*;
|
||||
|
||||
struct CJInsightIntentExecutorFuncs {
|
||||
int64_t (*createCjInsightIntentExecutor)(const char* name, CJInsightIntentExecutorHandle executorHandle);
|
||||
void (*releaseCjInsightIntentExecutor)(int64_t id);
|
||||
CJExecuteResult (*cjInsightIntentExecutorOnExecuteInUIAbilityForegroundMode)(
|
||||
int64_t id, const char* name, const char* param, WindowStagePtr cjWindowStage);
|
||||
CJExecuteResult (*cjInsightIntentExecutorOnExecuteInUIAbilityBackgroundMode)(
|
||||
int64_t id, const char* name, const char* param);
|
||||
CJExecuteResult (*cjInsightIntentExecutorOnExecuteInUIExtensionAbility)(
|
||||
int64_t id, const char* name, const char* param, int64_t sessionId);
|
||||
void (*cjInsightIntentExecutorFreeCJExecuteResult)(CJExecuteResult result);
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
namespace {
|
||||
static OHOS::AbilityRuntime::CJInsightIntentExecutorFuncs g_cjFuncs {};
|
||||
static const int32_t CJ_OBJECT_ERR_CODE = -1;
|
||||
} // namespace
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
char* CreateCStringFromString(const std::string& source)
|
||||
{
|
||||
if (source.size() == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
size_t length = source.size() + 1;
|
||||
auto res = static_cast<char*>(malloc(length));
|
||||
if (res == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "null res");
|
||||
return nullptr;
|
||||
}
|
||||
if (strcpy_s(res, length, source.c_str()) != 0) {
|
||||
free(res);
|
||||
TAG_LOGE(AAFwkTag::DEFAULT, "Strcpy failed");
|
||||
return nullptr;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int32_t CJInsightIntentExecutorImplObj::Init(
|
||||
const std::string& abilityName, CJInsightIntentExecutorHandle executorHandle)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
|
||||
if (g_cjFuncs.createCjInsightIntentExecutor == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "createCjInsightIntentExecutor is not registered");
|
||||
return CJ_OBJECT_ERR_CODE;
|
||||
}
|
||||
|
||||
cjID_ = g_cjFuncs.createCjInsightIntentExecutor(abilityName.c_str(), executorHandle);
|
||||
if (cjID_ == 0) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "Failed to Init CJUIExtensionObject. CJExtAbility: %{public}s is not registered",
|
||||
abilityName.c_str());
|
||||
return CJ_OBJECT_ERR_CODE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImplObj::Destroy()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
if (cjID_ != 0) {
|
||||
if (g_cjFuncs.releaseCjInsightIntentExecutor == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "releaseCjInsightIntentExecutor is not registered");
|
||||
return;
|
||||
}
|
||||
g_cjFuncs.releaseCjInsightIntentExecutor(cjID_);
|
||||
cjID_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
CJExecuteResult CJInsightIntentExecutorImplObj::OnExecuteInUIAbilityForegroundMode(
|
||||
const std::string& name, const AAFwk::WantParams& wantParams, OHOS::Rosen::CJWindowStageImpl* cjWindowStage)
|
||||
{
|
||||
if (g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIAbilityForegroundMode == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "cjInsightIntentExecutorOnExecuteInUIAbilityForegroundMode is not registered");
|
||||
return CJExecuteResult {};
|
||||
}
|
||||
auto nameCStr = CreateCStringFromString(name);
|
||||
auto paramsCStr = CreateCStringFromString(OHOS::AAFwk::WantParamWrapper(wantParams).ToString());
|
||||
WindowStagePtr windowStage = reinterpret_cast<WindowStagePtr>(cjWindowStage);
|
||||
auto ret =
|
||||
g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIAbilityForegroundMode(cjID_, nameCStr, paramsCStr, windowStage);
|
||||
free(nameCStr);
|
||||
free(paramsCStr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CJExecuteResult CJInsightIntentExecutorImplObj::OnExecuteInUIAbilityBackgroundMode(
|
||||
const std::string& name, const AAFwk::WantParams& wantParams)
|
||||
{
|
||||
if (g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIAbilityBackgroundMode == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "cjInsightIntentExecutorOnExecuteInUIAbilityBackgroundMode is not registered");
|
||||
return CJExecuteResult {};
|
||||
}
|
||||
auto nameCStr = CreateCStringFromString(name);
|
||||
auto paramsCStr = CreateCStringFromString(OHOS::AAFwk::WantParamWrapper(wantParams).ToString());
|
||||
auto ret = g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIAbilityBackgroundMode(cjID_, nameCStr, paramsCStr);
|
||||
free(nameCStr);
|
||||
free(paramsCStr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
CJExecuteResult CJInsightIntentExecutorImplObj::OnExecuteInsightIntentUIExtension(
|
||||
const std::string& name, const AAFwk::WantParams& wantParams, int64_t sessionId)
|
||||
{
|
||||
if (g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIExtensionAbility == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "cjInsightIntentExecutorOnExecuteInUIExtensionAbility is not registered");
|
||||
return CJExecuteResult {};
|
||||
}
|
||||
auto nameCStr = CreateCStringFromString(name);
|
||||
auto paramsCStr = CreateCStringFromString(OHOS::AAFwk::WantParamWrapper(wantParams).ToString());
|
||||
auto ret = g_cjFuncs.cjInsightIntentExecutorOnExecuteInUIExtensionAbility(cjID_, nameCStr, paramsCStr, sessionId);
|
||||
free(nameCStr);
|
||||
free(paramsCStr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorImplObj::FreeCJExecuteResult(CJExecuteResult result)
|
||||
{
|
||||
if (g_cjFuncs.cjInsightIntentExecutorFreeCJExecuteResult == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "cjInsightIntentExecutorFreeCJExecuteResult is not registered");
|
||||
return;
|
||||
}
|
||||
g_cjFuncs.cjInsightIntentExecutorFreeCJExecuteResult(result);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
CJ_EXPORT void FFIRegisterCJInsightIntentExecutorFuncs(void (*registerFunc)(CJInsightIntentExecutorFuncs*))
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "FFIRegisterCJExtAbilityFuncs start");
|
||||
if (g_cjFuncs.createCjInsightIntentExecutor != nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "Repeated registration for cj functions of CJInsightIntentExecutor");
|
||||
return;
|
||||
}
|
||||
|
||||
if (registerFunc == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "FFIRegisterCJInsightIntentExecutorFuncs failed, registerFunc is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
registerFunc(&g_cjFuncs);
|
||||
TAG_LOGD(AAFwkTag::INTENT, "FFIRegisterCJInsightIntentExecutorFuncs end");
|
||||
}
|
||||
} // extern "C"
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2025 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 "cj_insight_intent_executor_mgr.h"
|
||||
|
||||
#include "ability_business_error.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
CJInsightIntentExecutorMgr::CJInsightIntentExecutorMgr()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
}
|
||||
|
||||
CJInsightIntentExecutorMgr::~CJInsightIntentExecutorMgr()
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::INTENT, "called");
|
||||
}
|
||||
|
||||
bool CJInsightIntentExecutorMgr::ExecuteInsightIntent(Runtime& runtime, const CJInsightIntentExecutorInfo& executeInfo,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto executeParam = executeInfo.executeParam;
|
||||
if (callback == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (executeParam == nullptr || executeParam->insightIntentParam_ == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null executeParam or insightIntentParam_");
|
||||
TriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return false;
|
||||
}
|
||||
|
||||
auto asyncCallback = [weak = weak_from_this(), intentId = executeParam->insightIntentId_](
|
||||
InsightIntentExecuteResult result) {
|
||||
// erase map when called
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
auto executorMgr = weak.lock();
|
||||
if (executorMgr == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null executorMgr");
|
||||
return;
|
||||
}
|
||||
executorMgr->RemoveInsightIntentExecutor(intentId);
|
||||
};
|
||||
callback->Push(asyncCallback);
|
||||
|
||||
// Create insight intent executor
|
||||
auto intentExecutor = CJInsightIntentExecutor::Create(runtime);
|
||||
if (intentExecutor == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null intentExecutor");
|
||||
TriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!intentExecutor->Init(executeInfo)) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "Init intent executor failed");
|
||||
TriggerCallbackInner(std::move(callback), static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INVALID_PARAM));
|
||||
return false;
|
||||
}
|
||||
AddInsightIntentExecutor(executeParam->insightIntentId_, intentExecutor);
|
||||
|
||||
auto ret = intentExecutor->HandleExecuteIntent(static_cast<InsightIntentExecuteMode>(executeParam->executeMode_),
|
||||
executeParam->insightIntentName_, *executeParam->insightIntentParam_, executeInfo.pageLoader,
|
||||
std::move(callback));
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "Handle Execute intent failed");
|
||||
// callback has removed, if execute insight intent failed, call in sub function.
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorMgr::AddInsightIntentExecutor(
|
||||
uint64_t intentId, const std::shared_ptr<CJInsightIntentExecutor>& executor)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
insightIntentExecutors_[intentId] = executor;
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorMgr::RemoveInsightIntentExecutor(uint64_t intentId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
insightIntentExecutors_.erase(intentId);
|
||||
}
|
||||
|
||||
void CJInsightIntentExecutorMgr::TriggerCallbackInner(
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback, int32_t errCode)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
AppExecFwk::InsightIntentExecuteResult result;
|
||||
result.innerErr = errCode;
|
||||
if (callback) {
|
||||
callback->Call(result);
|
||||
}
|
||||
callback.reset();
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void OHOS_CallTriggerCallbackInner(void* callbackPtr, int32_t errCode)
|
||||
{
|
||||
if (callbackPtr == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto& callback = *reinterpret_cast<std::unique_ptr<InsightIntentExecutorAsyncCallback>*>(callbackPtr);
|
||||
CJInsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), errCode);
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) bool OHOS_CallExecuteInsightIntent(
|
||||
void* runtimePtr, void* executeInfoPtr, void* callbackPtr)
|
||||
{
|
||||
if (runtimePtr == nullptr || executeInfoPtr == nullptr || callbackPtr == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto& runtime = *reinterpret_cast<Runtime*>(runtimePtr);
|
||||
auto& executeInfo = *reinterpret_cast<CJInsightIntentExecutorInfo*>(executeInfoPtr);
|
||||
auto& callback = *reinterpret_cast<std::unique_ptr<InsightIntentExecutorAsyncCallback>*>(callbackPtr);
|
||||
return DelayedSingleton<CJInsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
runtime, executeInfo, std::move(callback));
|
||||
}
|
||||
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
@@ -20,19 +20,19 @@
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "ability_manager_client.h"
|
||||
#include "cj_application_context.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "cj_extension_common.h"
|
||||
#include "cj_insight_intent_executor_info.h"
|
||||
#include "cj_insight_intent_executor_mgr.h"
|
||||
#include "cj_runtime.h"
|
||||
#include "configuration_utils.h"
|
||||
#include "connection_manager.h"
|
||||
#include "context.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "insight_intent_executor_info.h"
|
||||
#include "insight_intent_executor_mgr.h"
|
||||
#include "int_wrapper.h"
|
||||
#include "cj_runtime.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "cj_extension_common.h"
|
||||
#include "cj_application_context.h"
|
||||
#include "ui_extension_window_command.h"
|
||||
#include "want_params_wrapper.h"
|
||||
|
||||
@@ -202,20 +202,21 @@ bool CJUIExtensionBase::ForegroundWindowWithInsightIntent(const AAFwk::Want &wan
|
||||
extension->PostInsightIntentExecuted(sessionInfo, result, needForeground);
|
||||
});
|
||||
|
||||
InsightIntentExecutorInfo executorInfo;
|
||||
CJInsightIntentExecutorInfo executorInfo;
|
||||
std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = context_->GetAbilityInfo();
|
||||
if (abilityInfo != nullptr) {
|
||||
executorInfo.hapPath = abilityInfo->hapPath;
|
||||
executorInfo.windowMode = abilityInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE;
|
||||
}
|
||||
executorInfo.token = context_->GetToken();
|
||||
executorInfo.pageLoader.sessionPageLoader = contentSessions_[sessionInfo->uiExtensionComponentId]->GetID();
|
||||
executorInfo.executeParam = std::make_shared<InsightIntentExecuteParam>();
|
||||
InsightIntentExecuteParam::GenerateFromWant(want, *executorInfo.executeParam);
|
||||
executorInfo.executeParam->executeMode_ = UI_EXTENSION_ABILITY;
|
||||
executorInfo.srcEntry = want.GetStringParam(INSIGHT_INTENT_SRC_ENTRY);
|
||||
TAG_LOGD(AAFwkTag::UI_EXT, "executorInfo, insightIntentId: %{public}" PRIu64,
|
||||
executorInfo.executeParam->insightIntentId_);
|
||||
int32_t ret = DelayedSingleton<InsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
int32_t ret = DelayedSingleton<CJInsightIntentExecutorMgr>::GetInstance()->ExecuteInsightIntent(
|
||||
cjRuntime_, executorInfo, std::move(executorCallback));
|
||||
if (!ret) {
|
||||
TAG_LOGE(AAFwkTag::UI_EXT, "Execute insight intent failed");
|
||||
|
||||
@@ -54,3 +54,49 @@ ohos_shared_library("insightintentcontext") {
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
ohos_shared_library("cj_insightintentcontext") {
|
||||
sanitize = {
|
||||
integer_overflow = true
|
||||
ubsan = true
|
||||
boundary_sanitize = true
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
cfi_vcall_icall_only = true
|
||||
debug = false
|
||||
}
|
||||
sources = [
|
||||
"cj_insight_intent_context.cpp",
|
||||
"insight_intent_context.cpp",
|
||||
]
|
||||
|
||||
defines = [ "AMS_LOG_TAG = \"InsigtIntent\"" ]
|
||||
defines += [ "AMS_LOG_DOMAIN = 0xD001308" ]
|
||||
|
||||
public_configs = [ ":insight_intent_context_public_config" ]
|
||||
|
||||
deps = [
|
||||
"${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_native_path}/ability/native:ability_business_error",
|
||||
"${ability_runtime_native_path}/ability/native:cj_insight_intent_executor",
|
||||
"${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"image_framework:image_native",
|
||||
"ipc:ipc_core",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
"napi:cj_bind_ffi",
|
||||
"napi:cj_bind_native",
|
||||
]
|
||||
innerapi_tags = [ "platformsdk" ]
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_runtime"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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 "cj_insight_intent_context.h"
|
||||
|
||||
#include "ability_business_error.h"
|
||||
#include "ability_window_configuration.h"
|
||||
#include "cj_common_ffi.h"
|
||||
#include "cj_insight_intent_executor_impl.h"
|
||||
#include "cj_insight_intent_executor_impl_object.h"
|
||||
#include "ffi_remote_data.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "hitrace_meter.h"
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
using WantHandle = void*;
|
||||
|
||||
int32_t CjInsightIntentContext::OnStartAbility(AAFwk::Want& want)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::INTENT, "called");
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
auto context = context_.lock();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null context");
|
||||
return static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER);
|
||||
}
|
||||
// verify if bundleName is empty or invalid
|
||||
auto bundleNameFromWant = want.GetElement().GetBundleName();
|
||||
if (bundleNameFromWant.empty() || bundleNameFromWant != context->GetBundleName()) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "bundleName empty or invalid");
|
||||
return static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_OPERATION_NOT_SUPPORTED);
|
||||
}
|
||||
// modify windowmode setting
|
||||
auto windowMode = context->GetCurrentWindowMode();
|
||||
if (windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_PRIMARY ||
|
||||
windowMode == AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_SECONDARY) {
|
||||
want.SetParam(AAFwk::Want::PARAM_RESV_WINDOW_MODE, windowMode);
|
||||
}
|
||||
auto innerErrCode = context->StartAbilityByInsightIntent(want);
|
||||
return static_cast<int32_t>(GetJsErrorCodeByNativeError(innerErrCode));
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
CJ_EXPORT int32_t FFIInsightIntentGetContext(CJInsightIntentExecutorHandle executorHandle, int64_t* id)
|
||||
{
|
||||
auto executor = static_cast<CJInsightIntentExecutorImpl*>(executorHandle);
|
||||
if (executor == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "GetCjInsightIntentContext failed, executor is nullptr");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
if (id == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "GetCjInsightIntentContext failed, param id is nullptr");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto context = executor->GetContext();
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "GetCjInsightIntentContext failed, context is nullptr");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto cjContext = OHOS::FFI::FFIData::Create<CjInsightIntentContext>(context);
|
||||
if (cjContext == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "GetCjInsightIntentContext failed, extAbilityContext is nullptr");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
executor->SetCjContext(cjContext);
|
||||
*id = cjContext->GetID();
|
||||
return SUCCESS_CODE;
|
||||
}
|
||||
|
||||
CJ_EXPORT int32_t FFIInsightIntentContextStartAbility(int64_t id, WantHandle want)
|
||||
{
|
||||
auto context = OHOS::FFI::FFIData::GetData<CjInsightIntentContext>(id);
|
||||
if (context == nullptr) {
|
||||
TAG_LOGE(AAFwkTag::INTENT, "null context");
|
||||
return ERR_INVALID_INSTANCE_CODE;
|
||||
}
|
||||
auto actualWant = reinterpret_cast<AAFwk::Want*>(want);
|
||||
return context->OnStartAbility(*actualWant);
|
||||
}
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_CONTEXT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_CONTEXT_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "insight_intent_context.h"
|
||||
#include "want.h"
|
||||
#include "want_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
/**
|
||||
* @class CjInsightIntentContext
|
||||
* CjInsightIntentContext provides a context for insightintent to execute certain tasks.
|
||||
*/
|
||||
class CjInsightIntentContext : public FFI::FFIData {
|
||||
public:
|
||||
explicit CjInsightIntentContext(const std::shared_ptr<InsightIntentContext>& context) : context_(context) {}
|
||||
~CjInsightIntentContext() = default;
|
||||
|
||||
/**
|
||||
* Starts a new ability. Only such ability in the same application with the caller
|
||||
* can be started.
|
||||
*
|
||||
* @param env, the napi environment.
|
||||
* @param info, the params passed from js caller.
|
||||
*
|
||||
* @return result of StartAbility.
|
||||
*/
|
||||
int32_t OnStartAbility(AAFwk::Want& want);
|
||||
|
||||
private:
|
||||
std::weak_ptr<InsightIntentContext> context_;
|
||||
};
|
||||
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_CONTEXT_H
|
||||
@@ -30,7 +30,7 @@ namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
class CJRuntime;
|
||||
class CJAbilityObject;
|
||||
struct InsightIntentExecutorInfo;
|
||||
struct CJInsightIntentExecutorInfo;
|
||||
using AbilityHandler = AppExecFwk::AbilityHandler;
|
||||
using AbilityInfo = AppExecFwk::AbilityInfo;
|
||||
using OHOSApplication = AppExecFwk::OHOSApplication;
|
||||
@@ -270,6 +270,17 @@ public:
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback) override;
|
||||
|
||||
/**
|
||||
* @brief Execute insight intent when an ability didn't started, schedule it to background.
|
||||
*
|
||||
* @param want Want.
|
||||
* @param executeParam insight intent execute param.
|
||||
* @param callback insight intent async callback.
|
||||
*/
|
||||
virtual void ExecuteInsightIntentBackground(const AAFwk::Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback) override;
|
||||
|
||||
protected:
|
||||
void DoOnForeground(const Want &want) override;
|
||||
void ContinuationRestore(const Want &want) override;
|
||||
@@ -279,9 +290,8 @@ private:
|
||||
void RestorePageStack(const Want &want);
|
||||
void GetPageStackFromWant(const Want &want, std::string &pageStack);
|
||||
void AbilityContinuationOrRecover(const Want &want);
|
||||
inline bool GetInsightIntentExecutorInfo(const Want &want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam> &executeParam,
|
||||
InsightIntentExecutorInfo& executeInfo);
|
||||
inline bool GetInsightIntentExecutorInfo(const Want& want,
|
||||
const std::shared_ptr<InsightIntentExecuteParam>& executeParam, CJInsightIntentExecutorInfo& executeInfo);
|
||||
|
||||
sptr<Rosen::CJWindowStageImpl> cjWindowStage_;
|
||||
int32_t windowMode_ = 0;
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "cj_insight_intent_executor_info.h"
|
||||
#include "insight_intent_constant.h"
|
||||
#include "insight_intent_context.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class CJWindowStageImpl;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class WantParams;
|
||||
} // namespace AAFwk
|
||||
namespace AppExecFwk {
|
||||
struct InsightIntentExecuteResult;
|
||||
template<typename>
|
||||
class AbilityTransactionCallbackInfo;
|
||||
} // namespace AppExecFwk
|
||||
namespace AbilityRuntime {
|
||||
class Runtime;
|
||||
using InsightIntentExecutorAsyncCallback =
|
||||
AppExecFwk::AbilityTransactionCallbackInfo<AppExecFwk::InsightIntentExecuteResult>;
|
||||
class CJInsightIntentExecutor {
|
||||
public:
|
||||
static std::shared_ptr<CJInsightIntentExecutor> Create(Runtime& runtime);
|
||||
|
||||
protected:
|
||||
CJInsightIntentExecutor() = default;
|
||||
|
||||
public:
|
||||
CJInsightIntentExecutor(const CJInsightIntentExecutor&) = delete;
|
||||
CJInsightIntentExecutor(const CJInsightIntentExecutor&&) = delete;
|
||||
CJInsightIntentExecutor& operator=(const CJInsightIntentExecutor&) = delete;
|
||||
CJInsightIntentExecutor& operator=(const CJInsightIntentExecutor&&) = delete;
|
||||
virtual ~CJInsightIntentExecutor() = default;
|
||||
|
||||
/**
|
||||
* @brief Init the insight intent executor and insight intent context.
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
virtual bool Init(const CJInsightIntentExecutorInfo& intentInfo) = 0;
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle execute insight intent.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
*/
|
||||
virtual bool HandleExecuteIntent(InsightIntentExecuteMode mode, const std::string& name,
|
||||
const AAFwk::WantParams& params, CJPageLoader pageLoader,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get current insight intent context.
|
||||
*
|
||||
* @return std::shared_ptr<InsightIntentContext>
|
||||
*/
|
||||
std::shared_ptr<InsightIntentContext> GetContext();
|
||||
|
||||
private:
|
||||
std::shared_ptr<InsightIntentContext> context_ = nullptr;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_CJ_RUNTIME_INSIGHT_INTENT_EXECUTOR_H
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_H
|
||||
|
||||
#include "cj_insight_intent_context.h"
|
||||
#include "cj_insight_intent_executor.h"
|
||||
#include "cj_insight_intent_executor_impl_object.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class CJWindowStageImpl;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
struct InsightIntentExecuteResult;
|
||||
} // namespace AppExecFwk
|
||||
namespace AbilityRuntime {
|
||||
|
||||
class CJInsightIntentExecutorImpl final : public CJInsightIntentExecutor {
|
||||
public:
|
||||
static std::shared_ptr<CJInsightIntentExecutorImpl> Create();
|
||||
enum class State { INVALID, CREATED, INITIALIZED, EXECUTING, EXECUTATION_DONE, DESTROYED };
|
||||
|
||||
private:
|
||||
explicit CJInsightIntentExecutorImpl();
|
||||
|
||||
public:
|
||||
CJInsightIntentExecutorImpl(const CJInsightIntentExecutorImpl&) = delete;
|
||||
CJInsightIntentExecutorImpl(const CJInsightIntentExecutorImpl&&) = delete;
|
||||
CJInsightIntentExecutorImpl& operator=(const CJInsightIntentExecutorImpl&) = delete;
|
||||
CJInsightIntentExecutorImpl& operator=(const CJInsightIntentExecutorImpl&&) = delete;
|
||||
~CJInsightIntentExecutorImpl() override;
|
||||
|
||||
/**
|
||||
* @brief Init the intent executor and intent context.
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
bool Init(const CJInsightIntentExecutorInfo& insightIntentInfo) override;
|
||||
|
||||
/**
|
||||
* @brief Handling the life cycle execute intent.
|
||||
*
|
||||
* @param
|
||||
*
|
||||
*/
|
||||
bool HandleExecuteIntent(InsightIntentExecuteMode mode, const std::string& name, const AAFwk::WantParams& param,
|
||||
CJPageLoader pageLoader, std::unique_ptr<InsightIntentExecutorAsyncCallback> callback) override;
|
||||
|
||||
inline State GetState() const
|
||||
{
|
||||
return state_;
|
||||
}
|
||||
|
||||
void SetCjContext(sptr<CjInsightIntentContext> cjContext)
|
||||
{
|
||||
contextObj_ = cjContext;
|
||||
}
|
||||
|
||||
private:
|
||||
static std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> GetResultFromCj(CJExecuteResult resultCj);
|
||||
static void ReplyFailed(InsightIntentExecutorAsyncCallback* callback,
|
||||
InsightIntentInnerErr innerErr = InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED);
|
||||
static void ReplySucceeded(InsightIntentExecutorAsyncCallback* callback,
|
||||
std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> resultCpp);
|
||||
void ReplyFailedInner(InsightIntentInnerErr innerErr = InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED);
|
||||
void ReplySucceededInner(std::shared_ptr<AppExecFwk::InsightIntentExecuteResult> resultCpp);
|
||||
bool ExecuteIntentCheckError();
|
||||
|
||||
bool HandleResultReturnedFromCjFunc(CJExecuteResult resultCj);
|
||||
|
||||
static bool CheckParametersUIAbilityForeground(Rosen::CJWindowStageImpl* windowStage);
|
||||
bool ExecuteInsightIntentUIAbilityForeground(
|
||||
const std::string& name, const AAFwk::WantParams& param, Rosen::CJWindowStageImpl* windowStage);
|
||||
|
||||
static bool CheckParametersUIAbilityBackground();
|
||||
bool ExecuteInsightIntentUIAbilityBackground(const std::string& name, const AAFwk::WantParams& param);
|
||||
|
||||
static bool CheckParametersUIExtension(int64_t sessionId);
|
||||
bool ExecuteInsightIntentUIExtension(const std::string& name, const AAFwk::WantParams& param, int64_t sessionId);
|
||||
|
||||
State state_ = State::CREATED;
|
||||
CJInsightIntentExecutorImplObj cjObj_;
|
||||
sptr<CjInsightIntentContext> contextObj_ = nullptr;
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_H
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_OBJECT_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_OBJECT_H
|
||||
|
||||
#include "cj_insight_intent_executor_info.h"
|
||||
#include "configuration.h"
|
||||
#include "want.h"
|
||||
|
||||
#ifdef WINDOWS_PLATFORM
|
||||
#define CJ_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define CJ_EXPORT __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class CJWindowStageImpl;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
|
||||
using CJInsightIntentExecutorHandle = void*;
|
||||
|
||||
/**
|
||||
* @brief cj insightIntentExecutor object.
|
||||
*/
|
||||
class CJInsightIntentExecutorImplObj {
|
||||
public:
|
||||
CJInsightIntentExecutorImplObj() : cjID_(0) {}
|
||||
~CJInsightIntentExecutorImplObj() = default;
|
||||
|
||||
int32_t Init(const std::string& abilityName, CJInsightIntentExecutorHandle executorHandle);
|
||||
void Destroy();
|
||||
int64_t GetID() const
|
||||
{
|
||||
return cjID_;
|
||||
}
|
||||
|
||||
CJExecuteResult OnExecuteInUIAbilityForegroundMode(
|
||||
const std::string& name, const AAFwk::WantParams& wantParams, OHOS::Rosen::CJWindowStageImpl* cjWindowStage);
|
||||
|
||||
CJExecuteResult OnExecuteInUIAbilityBackgroundMode(const std::string& name, const AAFwk::WantParams& wantParams);
|
||||
|
||||
CJExecuteResult OnExecuteInsightIntentUIExtension(
|
||||
const std::string& name, const AAFwk::WantParams& wantParams, int64_t sessionId);
|
||||
|
||||
void FreeCJExecuteResult(CJExecuteResult result);
|
||||
|
||||
protected:
|
||||
int64_t cjID_;
|
||||
};
|
||||
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_OBJECT_H
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_INFO_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_INFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "cj_utils_ffi.h"
|
||||
#include "insight_intent_execute_param.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class CJWindowStageImpl;
|
||||
}
|
||||
|
||||
namespace OHOS::AbilityRuntime {
|
||||
const int32_t CALL_ERROR = -1;
|
||||
using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam;
|
||||
|
||||
struct CJExecuteResult {
|
||||
int32_t code = CALL_ERROR;
|
||||
char* result;
|
||||
CArrString uris;
|
||||
int32_t flags;
|
||||
};
|
||||
|
||||
struct CJPageLoader {
|
||||
Rosen::CJWindowStageImpl* windowPageLoader = nullptr;
|
||||
int64_t sessionPageLoader = 0;
|
||||
};
|
||||
|
||||
struct CJInsightIntentExecutorInfo {
|
||||
std::string srcEntry;
|
||||
std::string hapPath;
|
||||
bool esmodule = true;
|
||||
int32_t windowMode = 0;
|
||||
sptr<IRemoteObject> token = nullptr;
|
||||
CJPageLoader pageLoader = {};
|
||||
std::shared_ptr<InsightIntentExecuteParam> executeParam = nullptr;
|
||||
};
|
||||
} // namespace OHOS::AbilityRuntime
|
||||
#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_INFO_H
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_MGR_H
|
||||
#define OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_MGR_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ability_transaction_callback_info.h"
|
||||
#include "cj_insight_intent_executor.h"
|
||||
#include "cj_insight_intent_executor_info.h"
|
||||
#include "insight_intent_execute_result.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult;
|
||||
using InsightIntentExecutorAsyncCallback = AppExecFwk::AbilityTransactionCallbackInfo<InsightIntentExecuteResult>;
|
||||
|
||||
class CJInsightIntentExecutorMgr : public std::enable_shared_from_this<CJInsightIntentExecutorMgr> {
|
||||
DECLARE_DELAYED_SINGLETON(CJInsightIntentExecutorMgr)
|
||||
|
||||
public:
|
||||
bool ExecuteInsightIntent(Runtime& runtime, const CJInsightIntentExecutorInfo& executeInfo,
|
||||
std::unique_ptr<InsightIntentExecutorAsyncCallback> callback);
|
||||
static void TriggerCallbackInner(std::unique_ptr<InsightIntentExecutorAsyncCallback> callback, int32_t errCode);
|
||||
|
||||
private:
|
||||
void AddInsightIntentExecutor(uint64_t intentId, const std::shared_ptr<CJInsightIntentExecutor>& executor);
|
||||
void RemoveInsightIntentExecutor(uint64_t intentId);
|
||||
|
||||
std::mutex mutex_;
|
||||
std::map<uint64_t, std::shared_ptr<CJInsightIntentExecutor>> insightIntentExecutors_;
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTOR_MGR_H
|
||||
Reference in New Issue
Block a user