diff --git a/bundle.json b/bundle.json index 17ebcf99463fb2d3ed137bc618d513135a8ef1a9..9d7ed55efd13e9e624dcc7e90f97530f95a6748a 100644 --- a/bundle.json +++ b/bundle.json @@ -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", diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index 7c2829ce80980e223b7f1907be73be593c2d251c..acf1ae704844ec72f451ed8e4923956b8b44c13b 100755 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -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", diff --git a/frameworks/cj/ffi/application_context/include/cj_application_context.h b/frameworks/cj/ffi/application_context/include/cj_application_context.h index 221dfb7c0cef765b2e168211827a57927cffe003..86b0a346cef0530c55352df19c16928858233c4f 100644 --- a/frameworks/cj/ffi/application_context/include/cj_application_context.h +++ b/frameworks/cj/ffi/application_context/include/cj_application_context.h @@ -112,6 +112,7 @@ public: void OnRestartApp(AAFwk::Want want, int32_t *errCode); void OnClearUpApplicationData(int32_t *errCode); void OnSetSupportedProcessCacheSelf(bool isSupported, int32_t *errCode); + int32_t OnSetFontSizeScale(double fontSizeScale); int32_t OnOnEnvironment(void (*cfgCallback)(AbilityRuntime::CConfiguration), void (*memCallback)(int32_t), bool isSync, int32_t *errCode); diff --git a/frameworks/cj/ffi/application_context/src/cj_application_context.cpp b/frameworks/cj/ffi/application_context/src/cj_application_context.cpp index 48547390fe02abec5faa1a2069824195757f32cc..102e7ac821538c4c4040529b6969b5e24f4399d7 100644 --- a/frameworks/cj/ffi/application_context/src/cj_application_context.cpp +++ b/frameworks/cj/ffi/application_context/src/cj_application_context.cpp @@ -686,6 +686,20 @@ void CJApplicationContext::OnSetSupportedProcessCacheSelf(bool isSupported, int3 } } +int32_t CJApplicationContext::OnSetFontSizeScale(double fontSizeScale) +{ + auto context = applicationContext_.lock(); + if (!context) { + TAG_LOGE(AAFwkTag::APPKIT, "applicationContext is released"); + return ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST; + } + if (context->SetFontSizeScale(fontSizeScale)) { + return ERR_OK; + } else { + return ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR; + } +} + extern "C" { CJ_EXPORT void OHOS_CjAppCtxFunc(int32_t type, int64_t id) { diff --git a/frameworks/cj/ffi/cj_application_context_ffi.cpp b/frameworks/cj/ffi/cj_application_context_ffi.cpp index 0ffa87a22c95cac84631defe6ecd3ad019ce5c95..f4572400f5fc3d8041e32e4cfc6313055c1d1d96 100644 --- a/frameworks/cj/ffi/cj_application_context_ffi.cpp +++ b/frameworks/cj/ffi/cj_application_context_ffi.cpp @@ -273,6 +273,16 @@ void FfiCJApplicationContextSetSupportedProcessCache(int64_t id, bool isSupporte return context->OnSetSupportedProcessCacheSelf(isSupported, errCode); } +int32_t FfiCJApplicationContextSetFontSizeScale(int64_t id, double fontSizeScale) +{ + auto context = FFI::FFIData::GetData(id); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "null context"); + return ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER; + } + return context->OnSetFontSizeScale(fontSizeScale); +} + CJ_EXPORT napi_value FfiConvertApplicationContext2Napi(napi_env env, int64_t id) { napi_value undefined = nullptr; diff --git a/frameworks/cj/ffi/cj_application_context_ffi.h b/frameworks/cj/ffi/cj_application_context_ffi.h index 7878a1a2a2de0fd1aeb2cf1cc492f1482d011639..c42d9e9d6b993c4c43c709ae064dc47c88b3ce63 100644 --- a/frameworks/cj/ffi/cj_application_context_ffi.h +++ b/frameworks/cj/ffi/cj_application_context_ffi.h @@ -59,6 +59,7 @@ CJ_EXPORT int32_t FfiCJApplicationContextGetCurrentAppCloneIndex(int64_t id, int CJ_EXPORT void FfiCJApplicationContextRestartApp(int64_t id, WantHandle want, int32_t *errCode); CJ_EXPORT void FfiCJApplicationContextClearUpApplicationData(int64_t id, int32_t *errCode); CJ_EXPORT void FfiCJApplicationContextSetSupportedProcessCache(int64_t id, bool isSupported, int32_t *errCode); +CJ_EXPORT int32_t FfiCJApplicationContextSetFontSizeScale(int64_t id, double fontSizeScale); }; } // namespace ApplicationContextCJ } // namespace OHOS diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index d74769b20b175e496d97098d1ad261ef911b9f3f..02f96babaf3475aa9db8957d40226e888c018218 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -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", diff --git a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp index 5c4776729e700b05abdca5dfe945cb060d07d08d..dfb22e785f8ecf5581776aeb17047ebed754e73d 100644 --- a/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/cj_ui_ability.cpp @@ -15,28 +15,28 @@ #include "cj_ui_ability.h" +#include #include #include -#include #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 CreateCJWindowStage(std::shared_ptr windowScene) { static void* handle = nullptr; @@ -662,6 +666,44 @@ const CJRuntime &CJUIAbility::GetCJRuntime() return cjRuntime_; } +void CallTriggerCallbackInner(std::unique_ptr 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(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 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(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 &executeParam, std::unique_ptr callback) @@ -670,7 +712,7 @@ void CJUIAbility::ExecuteInsightIntentRepeateForeground(const Want &want, if (executeParam == nullptr) { TAG_LOGW(AAFwkTag::UIABILITY, "invalid param"); RequestFocus(want); - InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK); + CallTriggerCallbackInner(std::move(callback), ERR_OK); return; } @@ -685,14 +727,18 @@ 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(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + CallTriggerCallbackInner(std::move(callback), static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); return; } + 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 +749,7 @@ void CJUIAbility::ExecuteInsightIntentMoveToForeground(const Want &want, if (executeParam == nullptr) { TAG_LOGW(AAFwkTag::UIABILITY, "param invalid"); OnForeground(want); - InsightIntentExecutorMgr::TriggerCallbackInner(std::move(callback), ERR_OK); + CallTriggerCallbackInner(std::move(callback), ERR_OK); return; } @@ -720,19 +766,48 @@ 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(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + CallTriggerCallbackInner(std::move(callback), static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); return; } + 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 &executeParam, - InsightIntentExecutorInfo& executeInfo) + std::unique_ptr callback) +{ + TAG_LOGI(AAFwkTag::UIABILITY, "executeInsightIntentBackground"); + if (executeParam == nullptr) { + TAG_LOGW(AAFwkTag::UIABILITY, "null executePara"); + CallTriggerCallbackInner(std::move(callback), ERR_OK); + return; + } + + CJInsightIntentExecutorInfo executeInfo; + auto ret = GetInsightIntentExecutorInfo(want, executeParam, executeInfo); + if (!ret) { + TAG_LOGE(AAFwkTag::UIABILITY, "get intentExecutor failed"); + CallTriggerCallbackInner(std::move(callback), static_cast(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + return; + } + + 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& executeParam, CJInsightIntentExecutorInfo& executeInfo) { TAG_LOGD(AAFwkTag::UIABILITY, "called"); auto context = GetAbilityContext(); @@ -747,6 +822,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; } diff --git a/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor.cpp b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ea240b65d37028a794aafa9afdab55f4159ba37 --- /dev/null +++ b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor.cpp @@ -0,0 +1,46 @@ +/* + * 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.h" + +#include "cj_insight_intent_executor_impl.h" +#include "hilog_tag_wrapper.h" +#include "runtime.h" + +namespace OHOS::AbilityRuntime { +std::shared_ptr CJInsightIntentExecutor::Create(Runtime& runtime) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + return CJInsightIntentExecutorImpl::Create(); +} + +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( + intentInfo.token, executeParam->bundleName_, intentInfo.windowMode, executeParam->insightIntentId_); + return true; +} + +std::shared_ptr CJInsightIntentExecutor::GetContext() +{ + return context_; +} +} // namespace OHOS::AbilityRuntime diff --git a/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.cpp b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f09009960cd1cb88cd6576a445ec75adeb5b2780 --- /dev/null +++ b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.cpp @@ -0,0 +1,266 @@ +/* + * 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.h" + +#include + +#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::Create() +{ + return std::make_shared(); +} + +using State = CJInsightIntentExecutorImpl::State; + +CJInsightIntentExecutorImpl::CJInsightIntentExecutorImpl() {} + +CJInsightIntentExecutorImpl::~CJInsightIntentExecutorImpl() +{ + state_ = State::DESTROYED; + TAG_LOGD(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 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 CJInsightIntentExecutorImpl::GetResultFromCj( + CJExecuteResult resultCj) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + auto resultCpp = std::make_shared(); + 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(wantParams); + if (resultCj.uris.head != nullptr && resultCj.uris.size > 0) { + std::vector 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( + std::unique_ptr 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); +} + +void CJInsightIntentExecutorImpl::ReplySucceeded( + std::unique_ptr callback, + std::shared_ptr resultCpp) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + if (callback == nullptr) { + return; + } + if (resultCpp == nullptr) { + ReplyFailed(std::move(callback)); + return; + } + resultCpp->innerErr = InsightIntentInnerErr::INSIGHT_INTENT_ERR_OK; + callback->Call(*resultCpp); +} + +void CJInsightIntentExecutorImpl::ReplyFailedInner(InsightIntentInnerErr innerErr) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + state_ = CJInsightIntentExecutorImpl::State::INVALID; + CJInsightIntentExecutorImpl::ReplyFailed(std::move(callback_), innerErr); +} + +void CJInsightIntentExecutorImpl::ReplySucceededInner(std::shared_ptr resultCpp) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + state_ = CJInsightIntentExecutorImpl::State::EXECUTATION_DONE; + CJInsightIntentExecutorImpl::ReplySucceeded(std::move(callback_), resultCpp); +} + +bool CJInsightIntentExecutorImpl::HandleResultReturnedFromCjFunc(CJExecuteResult resultJs) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + 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 diff --git a/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.cpp b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d7c602bfc5b81e13ff380eb25fc952a10e797f3 --- /dev/null +++ b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.cpp @@ -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 + +#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(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(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 diff --git a/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.cpp b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..447a32ca861bd836717f77654ad9c83c8a773710 --- /dev/null +++ b/frameworks/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.cpp @@ -0,0 +1,137 @@ +/* + * 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_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 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(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(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(AbilityErrorCode::ERROR_CODE_INVALID_PARAM)); + return false; + } + AddInsightIntentExecutor(executeParam->insightIntentId_, intentExecutor); + + auto ret = intentExecutor->HandleExecuteIntent(static_cast(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& executor) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + std::lock_guard lock(mutex_); + insightIntentExecutors_[intentId] = executor; +} + +void CJInsightIntentExecutorMgr::RemoveInsightIntentExecutor(uint64_t intentId) +{ + TAG_LOGD(AAFwkTag::INTENT, "called"); + std::lock_guard lock(mutex_); + insightIntentExecutors_.erase(intentId); +} + +void CJInsightIntentExecutorMgr::TriggerCallbackInner( + std::unique_ptr 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*>(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(runtimePtr); + auto& executeInfo = *reinterpret_cast(executeInfoPtr); + auto& callback = *reinterpret_cast*>(callbackPtr); + return DelayedSingleton::GetInstance()->ExecuteInsightIntent( + runtime, executeInfo, std::move(callback)); +} + +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/native/ability/native/ui_extension_base/cj_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_base/cj_ui_extension_base.cpp index b71b78172bd12ed1138b856b8824e30f0554c029..c49ed67433b5aa990ce640662493a0f87034d834 100644 --- a/frameworks/native/ability/native/ui_extension_base/cj_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_base/cj_ui_extension_base.cpp @@ -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,23 +202,25 @@ bool CJUIExtensionBase::ForegroundWindowWithInsightIntent(const AAFwk::Want &wan extension->PostInsightIntentExecuted(sessionInfo, result, needForeground); }); - InsightIntentExecutorInfo executorInfo; + CJInsightIntentExecutorInfo executorInfo; std::shared_ptr 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::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::GetInstance()->ExecuteInsightIntent( + int32_t ret = DelayedSingleton::GetInstance()->ExecuteInsightIntent( cjRuntime_, executorInfo, std::move(executorCallback)); if (!ret) { TAG_LOGE(AAFwkTag::UI_EXT, "Execute insight intent failed"); + return false; } TAG_LOGD(AAFwkTag::UI_EXT, "end"); return true; diff --git a/frameworks/native/insight_intent/insight_intent_context/BUILD.gn b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn index 972a829e85edba6c6fd1cdfaec822b239cc3e0d3..4900a2fafaa39f0929d95c5a8fc64d4f85cd0d3f 100644 --- a/frameworks/native/insight_intent/insight_intent_context/BUILD.gn +++ b/frameworks/native/insight_intent/insight_intent_context/BUILD.gn @@ -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" +} diff --git a/frameworks/native/insight_intent/insight_intent_context/cj_insight_intent_context.cpp b/frameworks/native/insight_intent/insight_intent_context/cj_insight_intent_context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3bc2107c255604b3376acc4eb9b711c0eeeaaee5 --- /dev/null +++ b/frameworks/native/insight_intent/insight_intent_context/cj_insight_intent_context.cpp @@ -0,0 +1,102 @@ +/* + * 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(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(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(GetJsErrorCodeByNativeError(innerErrCode)); +} + +extern "C" { +CJ_EXPORT int32_t FfiInsightIntentGetContext(CJInsightIntentExecutorHandle executorHandle, int64_t* id) +{ + auto executor = static_cast(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(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(id); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "null context"); + return ERR_INVALID_INSTANCE_CODE; + } + if (want == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "null want"); + return ERR_INVALID_INSTANCE_CODE; + } + auto actualWant = reinterpret_cast(want); + return context->OnStartAbility(*actualWant); +} +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/interfaces/inner_api/insight_intent/insight_intent_context/cj_insight_intent_context.h b/interfaces/inner_api/insight_intent/insight_intent_context/cj_insight_intent_context.h new file mode 100644 index 0000000000000000000000000000000000000000..fe9d5a5c0de23d4c0b27fa4c83917a90d2df8b78 --- /dev/null +++ b/interfaces/inner_api/insight_intent/insight_intent_context/cj_insight_intent_context.h @@ -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& 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 context_; +}; + +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_CONTEXT_H diff --git a/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h b/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h index 9db6f85ef13327562763cb9d6094236833f3cf1e..b004a320f5b7486054068b946d94f6a6e08eafa0 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.h +++ b/interfaces/kits/native/ability/native/ability_runtime/cj_ui_ability.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 &executeParam, std::unique_ptr 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 &executeParam, + std::unique_ptr 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 &executeParam, - InsightIntentExecutorInfo& executeInfo); + inline bool GetInsightIntentExecutorInfo(const Want& want, + const std::shared_ptr& executeParam, CJInsightIntentExecutorInfo& executeInfo); sptr cjWindowStage_; int32_t windowMode_ = 0; diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor.h b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor.h new file mode 100644 index 0000000000000000000000000000000000000000..9eedf2abea06fd7778ee799817786c7115893d67 --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor.h @@ -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 +#include + +#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 +class AbilityTransactionCallbackInfo; +} // namespace AppExecFwk +namespace AbilityRuntime { +class Runtime; +using InsightIntentExecutorAsyncCallback = + AppExecFwk::AbilityTransactionCallbackInfo; +class CJInsightIntentExecutor { +public: + static std::shared_ptr 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 callback) = 0; + + /** + * @brief Get current insight intent context. + * + * @return std::shared_ptr + */ + std::shared_ptr GetContext(); + +private: + std::shared_ptr context_ = nullptr; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_CJ_RUNTIME_INSIGHT_INTENT_EXECUTOR_H diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.h b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..884be873e1673afc469c11dc5c49bc23b720a52c --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl.h @@ -0,0 +1,101 @@ +/* + * 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 Create(); + enum class State { INVALID, CREATED, INITIALIZED, EXECUTING, EXECUTATION_DONE, DESTROYED }; + +public: + CJInsightIntentExecutorImpl(); + CJInsightIntentExecutorImpl(const CJInsightIntentExecutorImpl&) = delete; + CJInsightIntentExecutorImpl(CJInsightIntentExecutorImpl&&) = delete; + CJInsightIntentExecutorImpl& operator=(const CJInsightIntentExecutorImpl&) = delete; + CJInsightIntentExecutorImpl& operator=(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 callback) override; + + inline State GetState() const + { + return state_; + } + + void SetCjContext(sptr cjContext) + { + contextObj_ = cjContext; + } + +private: + static std::shared_ptr GetResultFromCj(CJExecuteResult resultCj); + static void ReplyFailed(std::unique_ptr callback, + InsightIntentInnerErr innerErr = InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED); + static void ReplySucceeded(std::unique_ptr callback, + std::shared_ptr resultCpp); + void ReplyFailedInner(InsightIntentInnerErr innerErr = InsightIntentInnerErr::INSIGHT_INTENT_EXECUTE_REPLY_FAILED); + void ReplySucceededInner(std::shared_ptr 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 contextObj_ = nullptr; + std::unique_ptr callback_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_IMPL_H diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.h b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.h new file mode 100644 index 0000000000000000000000000000000000000000..1de5ecf1dc79b1c6f3dfaa3bbb84c2ae27576991 --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_impl_object.h @@ -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 diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_info.h b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_info.h new file mode 100644 index 0000000000000000000000000000000000000000..ff08e9582e20dd19a2bfbb290d8d69b4c3aafbf3 --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_info.h @@ -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 + +#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 token = nullptr; + CJPageLoader pageLoader = {}; + std::shared_ptr executeParam = nullptr; +}; +} // namespace OHOS::AbilityRuntime +#endif // OHOS_ABILITY_RUNTIME_CJ_INSIGHT_INTENT_EXECUTOR_INFO_H diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.h b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.h new file mode 100644 index 0000000000000000000000000000000000000000..dca53a729853b33851b3fd5a61e7f5d6a69f92ff --- /dev/null +++ b/interfaces/kits/native/ability/native/insight_intent_executor/cj_insight_intent_executor_mgr.h @@ -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 + +#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; + +class CJInsightIntentExecutorMgr : public std::enable_shared_from_this { + DECLARE_DELAYED_SINGLETON(CJInsightIntentExecutorMgr) + +public: + bool ExecuteInsightIntent(Runtime& runtime, const CJInsightIntentExecutorInfo& executeInfo, + std::unique_ptr callback); + static void TriggerCallbackInner(std::unique_ptr callback, int32_t errCode); + +private: + void AddInsightIntentExecutor(uint64_t intentId, const std::shared_ptr& executor); + void RemoveInsightIntentExecutor(uint64_t intentId); + + std::mutex mutex_; + std::map> insightIntentExecutors_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_INSIGHT_INTENT_EXECUTOR_MGR_H