123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_container.h" 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include <cerrno> 1923b3eb3cSopenharmony_ci#include <fstream> 2023b3eb3cSopenharmony_ci#include <functional> 2123b3eb3cSopenharmony_ci#include <memory> 2223b3eb3cSopenharmony_ci#include <regex> 2323b3eb3cSopenharmony_ci 2423b3eb3cSopenharmony_ci#include "ability_context.h" 2523b3eb3cSopenharmony_ci#include "ability_info.h" 2623b3eb3cSopenharmony_ci#include "auto_fill_manager.h" 2723b3eb3cSopenharmony_ci#include "js_native_api.h" 2823b3eb3cSopenharmony_ci#include "pointer_event.h" 2923b3eb3cSopenharmony_ci#include "scene_board_judgement.h" 3023b3eb3cSopenharmony_ci#include "ui_extension_context.h" 3123b3eb3cSopenharmony_ci#include "window_manager.h" 3223b3eb3cSopenharmony_ci#include "wm/wm_common.h" 3323b3eb3cSopenharmony_ci#include "root_scene.h" 3423b3eb3cSopenharmony_ci#include "ws_common.h" 3523b3eb3cSopenharmony_ci 3623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_application_info.h" 3723b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_view_ohos.h" 3823b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/cj_utils/cj_utils.h" 3923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/data_ability_helper_standard.h" 4023b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/file_asset_provider_impl.h" 4123b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/hap_asset_provider_impl.h" 4223b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ui_content_impl.h" 4323b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/utils.h" 4423b3eb3cSopenharmony_ci#include "adapter/ohos/osal/resource_adapter_impl_v2.h" 4523b3eb3cSopenharmony_ci#include "adapter/ohos/osal/system_bar_style_ohos.h" 4623b3eb3cSopenharmony_ci#include "adapter/ohos/osal/view_data_wrap_ohos.h" 4723b3eb3cSopenharmony_ci#include "adapter/ohos/osal/window_utils.h" 4823b3eb3cSopenharmony_ci#include "base/i18n/localization.h" 4923b3eb3cSopenharmony_ci#include "base/json/json_util.h" 5023b3eb3cSopenharmony_ci#include "base/log/ace_trace.h" 5123b3eb3cSopenharmony_ci#include "base/log/dump_log.h" 5223b3eb3cSopenharmony_ci#include "base/log/event_report.h" 5323b3eb3cSopenharmony_ci#include "base/log/frame_report.h" 5423b3eb3cSopenharmony_ci#include "base/log/jank_frame_report.h" 5523b3eb3cSopenharmony_ci#include "base/log/log.h" 5623b3eb3cSopenharmony_ci#include "base/log/log_wrapper.h" 5723b3eb3cSopenharmony_ci#include "base/subwindow/subwindow_manager.h" 5823b3eb3cSopenharmony_ci#include "base/thread/background_task_executor.h" 5923b3eb3cSopenharmony_ci#include "base/thread/task_executor.h" 6023b3eb3cSopenharmony_ci#include "base/utils/device_config.h" 6123b3eb3cSopenharmony_ci#include "base/utils/system_properties.h" 6223b3eb3cSopenharmony_ci#include "base/utils/time_util.h" 6323b3eb3cSopenharmony_ci#include "base/utils/utils.h" 6423b3eb3cSopenharmony_ci#include "bridge/card_frontend/card_frontend.h" 6523b3eb3cSopenharmony_ci#include "bridge/card_frontend/form_frontend_declarative.h" 6623b3eb3cSopenharmony_ci#include "bridge/common/utils/engine_helper.h" 6723b3eb3cSopenharmony_ci#include "bridge/declarative_frontend/declarative_frontend.h" 6823b3eb3cSopenharmony_ci#include "bridge/declarative_frontend/engine/jsi/jsi_declarative_engine.h" 6923b3eb3cSopenharmony_ci#include "bridge/js_frontend/engine/common/js_engine_loader.h" 7023b3eb3cSopenharmony_ci#include "bridge/js_frontend/js_frontend.h" 7123b3eb3cSopenharmony_ci#include "core/common/ace_application_info.h" 7223b3eb3cSopenharmony_ci#include "core/common/ace_engine.h" 7323b3eb3cSopenharmony_ci#include "core/common/asset_manager_impl.h" 7423b3eb3cSopenharmony_ci#include "core/common/container.h" 7523b3eb3cSopenharmony_ci#include "core/common/container_consts.h" 7623b3eb3cSopenharmony_ci#include "core/common/container_scope.h" 7723b3eb3cSopenharmony_ci#include "core/common/platform_window.h" 7823b3eb3cSopenharmony_ci#include "core/common/plugin_manager.h" 7923b3eb3cSopenharmony_ci#include "core/common/resource/resource_manager.h" 8023b3eb3cSopenharmony_ci#include "core/common/task_executor_impl.h" 8123b3eb3cSopenharmony_ci#include "core/common/text_field_manager.h" 8223b3eb3cSopenharmony_ci#include "core/common/window.h" 8323b3eb3cSopenharmony_ci#include "core/components/theme/theme_constants.h" 8423b3eb3cSopenharmony_ci#include "core/components/theme/theme_manager_impl.h" 8523b3eb3cSopenharmony_ci#include "core/components_ng/pattern/text_field/text_field_manager.h" 8623b3eb3cSopenharmony_ci#include "core/components_ng/pattern/text_field/text_field_pattern.h" 8723b3eb3cSopenharmony_ci#include "core/components_ng/render/adapter/form_render_window.h" 8823b3eb3cSopenharmony_ci#include "core/components_ng/render/adapter/rosen_window.h" 8923b3eb3cSopenharmony_ci 9023b3eb3cSopenharmony_ci#if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED) 9123b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_rosen_sync_task.h" 9223b3eb3cSopenharmony_ci#endif 9323b3eb3cSopenharmony_ci 9423b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform { 9523b3eb3cSopenharmony_cinamespace { 9623b3eb3cSopenharmony_ciconstexpr uint32_t DIRECTION_KEY = 0b1000; 9723b3eb3cSopenharmony_ciconstexpr uint32_t DENSITY_KEY = 0b0100; 9823b3eb3cSopenharmony_ciconstexpr uint32_t POPUPSIZE_HEIGHT = 0; 9923b3eb3cSopenharmony_ciconstexpr uint32_t POPUPSIZE_WIDTH = 0; 10023b3eb3cSopenharmony_ciconstexpr int32_t SEARCH_ELEMENT_TIMEOUT_TIME = 1500; 10123b3eb3cSopenharmony_ciconstexpr int32_t POPUP_CALCULATE_RATIO = 2; 10223b3eb3cSopenharmony_ciconstexpr int32_t POPUP_EDGE_INTERVAL = 48; 10323b3eb3cSopenharmony_ciconstexpr uint32_t DEFAULT_WINDOW_TYPE = 1; 10423b3eb3cSopenharmony_ciconst char ENABLE_DEBUG_BOUNDARY_KEY[] = "persist.ace.debug.boundary.enabled"; 10523b3eb3cSopenharmony_ciconst char ENABLE_TRACE_LAYOUT_KEY[] = "persist.ace.trace.layout.enabled"; 10623b3eb3cSopenharmony_ciconst char ENABLE_TRACE_INPUTEVENT_KEY[] = "persist.ace.trace.inputevent.enabled"; 10723b3eb3cSopenharmony_ciconst char ENABLE_SECURITY_DEVELOPERMODE_KEY[] = "const.security.developermode.state"; 10823b3eb3cSopenharmony_ciconst char ENABLE_DEBUG_STATEMGR_KEY[] = "persist.ace.debug.statemgr.enabled"; 10923b3eb3cSopenharmony_ciconst char ENABLE_PERFORMANCE_MONITOR_KEY[] = "persist.ace.performance.monitor.enabled"; 11023b3eb3cSopenharmony_cistd::mutex g_mutexFormRenderFontFamily; 11123b3eb3cSopenharmony_ci 11223b3eb3cSopenharmony_ci#ifdef _ARM64_ 11323b3eb3cSopenharmony_ciconst std::string ASSET_LIBARCH_PATH = "/lib/arm64"; 11423b3eb3cSopenharmony_ci#else 11523b3eb3cSopenharmony_ciconst std::string ASSET_LIBARCH_PATH = "/lib/arm"; 11623b3eb3cSopenharmony_ci#endif 11723b3eb3cSopenharmony_ci 11823b3eb3cSopenharmony_ci#ifndef NG_BUILD 11923b3eb3cSopenharmony_ciconstexpr char ARK_ENGINE_SHARED_LIB[] = "libace_engine_ark.z.so"; 12023b3eb3cSopenharmony_ciconst char* GetEngineSharedLibrary() 12123b3eb3cSopenharmony_ci{ 12223b3eb3cSopenharmony_ci return ARK_ENGINE_SHARED_LIB; 12323b3eb3cSopenharmony_ci} 12423b3eb3cSopenharmony_ci#endif 12523b3eb3cSopenharmony_ci 12623b3eb3cSopenharmony_ciconstexpr char DECLARATIVE_ARK_ENGINE_SHARED_LIB[] = "libace_engine_declarative_ark.z.so"; 12723b3eb3cSopenharmony_ciconst char* GetDeclarativeSharedLibrary() 12823b3eb3cSopenharmony_ci{ 12923b3eb3cSopenharmony_ci return DECLARATIVE_ARK_ENGINE_SHARED_LIB; 13023b3eb3cSopenharmony_ci} 13123b3eb3cSopenharmony_ci 13223b3eb3cSopenharmony_civoid InitResourceAndThemeManager(const RefPtr<PipelineBase>& pipelineContext, const RefPtr<AssetManager>& assetManager, 13323b3eb3cSopenharmony_ci const ColorScheme& colorScheme, const ResourceInfo& resourceInfo, 13423b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::AbilityRuntime::Context>& context, 13523b3eb3cSopenharmony_ci const std::shared_ptr<OHOS::AppExecFwk::AbilityInfo>& abilityInfo, bool clearCache = false) 13623b3eb3cSopenharmony_ci{ 13723b3eb3cSopenharmony_ci std::string bundleName = ""; 13823b3eb3cSopenharmony_ci std::string moduleName = ""; 13923b3eb3cSopenharmony_ci if (context) { 14023b3eb3cSopenharmony_ci bundleName = context->GetBundleName(); 14123b3eb3cSopenharmony_ci moduleName = context->GetHapModuleInfo()->name; 14223b3eb3cSopenharmony_ci } else if (abilityInfo) { 14323b3eb3cSopenharmony_ci bundleName = abilityInfo->bundleName; 14423b3eb3cSopenharmony_ci moduleName = abilityInfo->moduleName; 14523b3eb3cSopenharmony_ci } 14623b3eb3cSopenharmony_ci 14723b3eb3cSopenharmony_ci RefPtr<ResourceAdapter> resourceAdapter = nullptr; 14823b3eb3cSopenharmony_ci if (context && context->GetResourceManager()) { 14923b3eb3cSopenharmony_ci resourceAdapter = AceType::MakeRefPtr<ResourceAdapterImplV2>(context->GetResourceManager(), resourceInfo); 15023b3eb3cSopenharmony_ci } else if (ResourceManager::GetInstance().IsResourceAdapterRecord(bundleName, moduleName)) { 15123b3eb3cSopenharmony_ci resourceAdapter = ResourceManager::GetInstance().GetResourceAdapter(bundleName, moduleName); 15223b3eb3cSopenharmony_ci } 15323b3eb3cSopenharmony_ci 15423b3eb3cSopenharmony_ci if (resourceAdapter == nullptr) { 15523b3eb3cSopenharmony_ci resourceAdapter = ResourceAdapter::CreateV2(); 15623b3eb3cSopenharmony_ci resourceAdapter->Init(resourceInfo); 15723b3eb3cSopenharmony_ci } 15823b3eb3cSopenharmony_ci 15923b3eb3cSopenharmony_ci ThemeConstants::InitDeviceType(); 16023b3eb3cSopenharmony_ci auto themeManager = AceType::MakeRefPtr<ThemeManagerImpl>(resourceAdapter); 16123b3eb3cSopenharmony_ci pipelineContext->SetThemeManager(themeManager); 16223b3eb3cSopenharmony_ci themeManager->SetColorScheme(colorScheme); 16323b3eb3cSopenharmony_ci themeManager->LoadCustomTheme(assetManager); 16423b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 16523b3eb3cSopenharmony_ci 16623b3eb3cSopenharmony_ci if (clearCache) { 16723b3eb3cSopenharmony_ci ResourceManager::GetInstance().Reset(); 16823b3eb3cSopenharmony_ci } 16923b3eb3cSopenharmony_ci 17023b3eb3cSopenharmony_ci auto defaultBundleName = ""; 17123b3eb3cSopenharmony_ci auto defaultModuleName = ""; 17223b3eb3cSopenharmony_ci ResourceManager::GetInstance().AddResourceAdapter(defaultBundleName, defaultModuleName, resourceAdapter, true); 17323b3eb3cSopenharmony_ci if (!bundleName.empty() && !moduleName.empty()) { 17423b3eb3cSopenharmony_ci ResourceManager::GetInstance().RegisterMainResourceAdapter(bundleName, moduleName, resourceAdapter); 17523b3eb3cSopenharmony_ci } 17623b3eb3cSopenharmony_ci} 17723b3eb3cSopenharmony_ci 17823b3eb3cSopenharmony_cistd::string EncodeBundleAndModule(const std::string& bundleName, const std::string& moduleName) 17923b3eb3cSopenharmony_ci{ 18023b3eb3cSopenharmony_ci return bundleName + " " + moduleName; 18123b3eb3cSopenharmony_ci} 18223b3eb3cSopenharmony_ci 18323b3eb3cSopenharmony_civoid DecodeBundleAndModule(const std::string& encode, std::string& bundleName, std::string& moduleName) 18423b3eb3cSopenharmony_ci{ 18523b3eb3cSopenharmony_ci std::vector<std::string> tokens; 18623b3eb3cSopenharmony_ci StringUtils::StringSplitter(encode, ' ', tokens); 18723b3eb3cSopenharmony_ci bundleName = tokens[0]; 18823b3eb3cSopenharmony_ci moduleName = tokens[1]; 18923b3eb3cSopenharmony_ci} 19023b3eb3cSopenharmony_ci 19123b3eb3cSopenharmony_civoid ReleaseStorageReference(void* sharedRuntime, NativeReference* storage) 19223b3eb3cSopenharmony_ci{ 19323b3eb3cSopenharmony_ci if (sharedRuntime && storage) { 19423b3eb3cSopenharmony_ci auto nativeEngine = reinterpret_cast<NativeEngine*>(sharedRuntime); 19523b3eb3cSopenharmony_ci auto env = reinterpret_cast<napi_env>(nativeEngine); 19623b3eb3cSopenharmony_ci napi_delete_reference(env, reinterpret_cast<napi_ref>(storage)); 19723b3eb3cSopenharmony_ci } 19823b3eb3cSopenharmony_ci} 19923b3eb3cSopenharmony_ci} // namespace 20023b3eb3cSopenharmony_ci 20123b3eb3cSopenharmony_ciAceContainer::AceContainer(int32_t instanceId, FrontendType type, std::shared_ptr<OHOS::AppExecFwk::Ability> aceAbility, 20223b3eb3cSopenharmony_ci std::unique_ptr<PlatformEventCallback> callback, bool useCurrentEventRunner, bool useNewPipeline) 20323b3eb3cSopenharmony_ci : instanceId_(instanceId), type_(type), aceAbility_(aceAbility), useCurrentEventRunner_(useCurrentEventRunner) 20423b3eb3cSopenharmony_ci{ 20523b3eb3cSopenharmony_ci ACE_DCHECK(callback); 20623b3eb3cSopenharmony_ci if (useNewPipeline) { 20723b3eb3cSopenharmony_ci SetUseNewPipeline(); 20823b3eb3cSopenharmony_ci if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 20923b3eb3cSopenharmony_ci SetUsePartialUpdate(); 21023b3eb3cSopenharmony_ci } 21123b3eb3cSopenharmony_ci } 21223b3eb3cSopenharmony_ci InitializeTask(); 21323b3eb3cSopenharmony_ci platformEventCallback_ = std::move(callback); 21423b3eb3cSopenharmony_ci useStageModel_ = false; 21523b3eb3cSopenharmony_ci auto ability = aceAbility_.lock(); 21623b3eb3cSopenharmony_ci if (ability) { 21723b3eb3cSopenharmony_ci abilityInfo_ = ability->GetAbilityInfo(); 21823b3eb3cSopenharmony_ci } 21923b3eb3cSopenharmony_ci} 22023b3eb3cSopenharmony_ci 22123b3eb3cSopenharmony_ciAceContainer::AceContainer(int32_t instanceId, FrontendType type, 22223b3eb3cSopenharmony_ci std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext, 22323b3eb3cSopenharmony_ci std::weak_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo, std::unique_ptr<PlatformEventCallback> callback, 22423b3eb3cSopenharmony_ci bool useCurrentEventRunner, bool isSubAceContainer, bool useNewPipeline) 22523b3eb3cSopenharmony_ci : instanceId_(instanceId), type_(type), runtimeContext_(std::move(runtimeContext)), 22623b3eb3cSopenharmony_ci abilityInfo_(std::move(abilityInfo)), useCurrentEventRunner_(useCurrentEventRunner), 22723b3eb3cSopenharmony_ci isSubContainer_(isSubAceContainer) 22823b3eb3cSopenharmony_ci{ 22923b3eb3cSopenharmony_ci ACE_DCHECK(callback); 23023b3eb3cSopenharmony_ci if (useNewPipeline) { 23123b3eb3cSopenharmony_ci SetUseNewPipeline(); 23223b3eb3cSopenharmony_ci if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 23323b3eb3cSopenharmony_ci SetUsePartialUpdate(); 23423b3eb3cSopenharmony_ci } 23523b3eb3cSopenharmony_ci } 23623b3eb3cSopenharmony_ci if (!isSubContainer_) { 23723b3eb3cSopenharmony_ci InitializeTask(); 23823b3eb3cSopenharmony_ci } 23923b3eb3cSopenharmony_ci platformEventCallback_ = std::move(callback); 24023b3eb3cSopenharmony_ci useStageModel_ = true; 24123b3eb3cSopenharmony_ci} 24223b3eb3cSopenharmony_ci 24323b3eb3cSopenharmony_ci// for DynamicComponent 24423b3eb3cSopenharmony_ciAceContainer::AceContainer(int32_t instanceId, FrontendType type, 24523b3eb3cSopenharmony_ci std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext, 24623b3eb3cSopenharmony_ci std::weak_ptr<OHOS::AppExecFwk::AbilityInfo> abilityInfo, std::unique_ptr<PlatformEventCallback> callback, 24723b3eb3cSopenharmony_ci std::shared_ptr<TaskWrapper> taskWrapper, 24823b3eb3cSopenharmony_ci bool useCurrentEventRunner, bool isSubAceContainer, bool useNewPipeline) 24923b3eb3cSopenharmony_ci : instanceId_(instanceId), type_(type), runtimeContext_(std::move(runtimeContext)), 25023b3eb3cSopenharmony_ci abilityInfo_(std::move(abilityInfo)), useCurrentEventRunner_(useCurrentEventRunner), 25123b3eb3cSopenharmony_ci isSubContainer_(isSubAceContainer) 25223b3eb3cSopenharmony_ci{ 25323b3eb3cSopenharmony_ci ACE_DCHECK(callback); 25423b3eb3cSopenharmony_ci if (useNewPipeline) { 25523b3eb3cSopenharmony_ci SetUseNewPipeline(); 25623b3eb3cSopenharmony_ci if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_ELEVEN)) { 25723b3eb3cSopenharmony_ci SetUsePartialUpdate(); 25823b3eb3cSopenharmony_ci } 25923b3eb3cSopenharmony_ci } 26023b3eb3cSopenharmony_ci if (!isSubContainer_) { 26123b3eb3cSopenharmony_ci InitializeTask(taskWrapper); 26223b3eb3cSopenharmony_ci } 26323b3eb3cSopenharmony_ci platformEventCallback_ = std::move(callback); 26423b3eb3cSopenharmony_ci useStageModel_ = true; 26523b3eb3cSopenharmony_ci} 26623b3eb3cSopenharmony_ci 26723b3eb3cSopenharmony_ciAceContainer::~AceContainer() 26823b3eb3cSopenharmony_ci{ 26923b3eb3cSopenharmony_ci std::lock_guard lock(destructMutex_); 27023b3eb3cSopenharmony_ci LOGI("Container Destroyed"); 27123b3eb3cSopenharmony_ci} 27223b3eb3cSopenharmony_ci 27323b3eb3cSopenharmony_civoid AceContainer::InitializeTask(std::shared_ptr<TaskWrapper> taskWrapper) 27423b3eb3cSopenharmony_ci{ 27523b3eb3cSopenharmony_ci RefPtr<TaskExecutorImpl> taskExecutorImpl; 27623b3eb3cSopenharmony_ci if (taskWrapper != nullptr) { 27723b3eb3cSopenharmony_ci taskExecutorImpl = Referenced::MakeRefPtr<TaskExecutorImpl>(taskWrapper); 27823b3eb3cSopenharmony_ci } else { 27923b3eb3cSopenharmony_ci taskExecutorImpl = Referenced::MakeRefPtr<TaskExecutorImpl>(); 28023b3eb3cSopenharmony_ci } 28123b3eb3cSopenharmony_ci taskExecutorImpl->InitPlatformThread(useCurrentEventRunner_); 28223b3eb3cSopenharmony_ci taskExecutor_ = taskExecutorImpl; 28323b3eb3cSopenharmony_ci // No need to create JS Thread for DECLARATIVE_JS 28423b3eb3cSopenharmony_ci if (type_ == FrontendType::DECLARATIVE_JS || type_ == FrontendType::DECLARATIVE_CJ) { 28523b3eb3cSopenharmony_ci GetSettings().useUIAsJSThread = true; 28623b3eb3cSopenharmony_ci } else { 28723b3eb3cSopenharmony_ci taskExecutorImpl->InitJsThread(); 28823b3eb3cSopenharmony_ci } 28923b3eb3cSopenharmony_ci} 29023b3eb3cSopenharmony_ci 29123b3eb3cSopenharmony_cibool AceContainer::IsKeyboard() 29223b3eb3cSopenharmony_ci{ 29323b3eb3cSopenharmony_ci if (uiWindow_ == nullptr) { 29423b3eb3cSopenharmony_ci return false; 29523b3eb3cSopenharmony_ci } 29623b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT; 29723b3eb3cSopenharmony_ci} 29823b3eb3cSopenharmony_ci 29923b3eb3cSopenharmony_civoid AceContainer::Initialize() 30023b3eb3cSopenharmony_ci{ 30123b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 30223b3eb3cSopenharmony_ci // For DECLARATIVE_JS frontend use UI as JS Thread, so InitializeFrontend after UI thread created. 30323b3eb3cSopenharmony_ci if (type_ != FrontendType::DECLARATIVE_JS && type_ != FrontendType::DECLARATIVE_CJ) { 30423b3eb3cSopenharmony_ci InitializeFrontend(); 30523b3eb3cSopenharmony_ci } 30623b3eb3cSopenharmony_ci} 30723b3eb3cSopenharmony_ci 30823b3eb3cSopenharmony_cibool AceContainer::MaybeRelease() 30923b3eb3cSopenharmony_ci{ 31023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(taskExecutor_, true); 31123b3eb3cSopenharmony_ci if (taskExecutor_->WillRunOnCurrentThread(TaskExecutor::TaskType::PLATFORM)) { 31223b3eb3cSopenharmony_ci LOGI("Destroy AceContainer on PLATFORM thread."); 31323b3eb3cSopenharmony_ci return true; 31423b3eb3cSopenharmony_ci } else { 31523b3eb3cSopenharmony_ci std::lock_guard lock(destructMutex_); 31623b3eb3cSopenharmony_ci LOGI("Post Destroy AceContainer Task to PLATFORM thread."); 31723b3eb3cSopenharmony_ci return !taskExecutor_->PostTask( 31823b3eb3cSopenharmony_ci [this] { delete this; }, TaskExecutor::TaskType::PLATFORM, "ArkUIAceContainerDestroy"); 31923b3eb3cSopenharmony_ci } 32023b3eb3cSopenharmony_ci} 32123b3eb3cSopenharmony_ci 32223b3eb3cSopenharmony_civoid AceContainer::Destroy() 32323b3eb3cSopenharmony_ci{ 32423b3eb3cSopenharmony_ci LOGI("AceContainer Destroy begin"); 32523b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 32623b3eb3cSopenharmony_ci RemoveWatchSystemParameter(); 32723b3eb3cSopenharmony_ci 32823b3eb3cSopenharmony_ci ReleaseResourceAdapter(); 32923b3eb3cSopenharmony_ci if (pipelineContext_ && taskExecutor_) { 33023b3eb3cSopenharmony_ci // 1. Destroy Pipeline on UI thread. 33123b3eb3cSopenharmony_ci RefPtr<PipelineBase> context; 33223b3eb3cSopenharmony_ci { 33323b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(pipelineMutex_); 33423b3eb3cSopenharmony_ci context.Swap(pipelineContext_); 33523b3eb3cSopenharmony_ci } 33623b3eb3cSopenharmony_ci auto uiTask = [context]() { context->Destroy(); }; 33723b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread) { 33823b3eb3cSopenharmony_ci uiTask(); 33923b3eb3cSopenharmony_ci } else { 34023b3eb3cSopenharmony_ci taskExecutor_->PostTask(uiTask, TaskExecutor::TaskType::UI, "ArkUIPipelineDestroy"); 34123b3eb3cSopenharmony_ci } 34223b3eb3cSopenharmony_ci 34323b3eb3cSopenharmony_ci if (isSubContainer_) { 34423b3eb3cSopenharmony_ci // SubAceContainer just return. 34523b3eb3cSopenharmony_ci return; 34623b3eb3cSopenharmony_ci } 34723b3eb3cSopenharmony_ci 34823b3eb3cSopenharmony_ci // 2. Destroy Frontend on JS thread. 34923b3eb3cSopenharmony_ci RefPtr<Frontend> frontend; 35023b3eb3cSopenharmony_ci { 35123b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(frontendMutex_); 35223b3eb3cSopenharmony_ci frontend.Swap(frontend_); 35323b3eb3cSopenharmony_ci } 35423b3eb3cSopenharmony_ci auto jsTask = [frontend]() { 35523b3eb3cSopenharmony_ci auto lock = frontend->GetLock(); 35623b3eb3cSopenharmony_ci frontend->Destroy(); 35723b3eb3cSopenharmony_ci }; 35823b3eb3cSopenharmony_ci frontend->UpdateState(Frontend::State::ON_DESTROY); 35923b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread && GetSettings().useUIAsJSThread) { 36023b3eb3cSopenharmony_ci jsTask(); 36123b3eb3cSopenharmony_ci } else { 36223b3eb3cSopenharmony_ci taskExecutor_->PostTask(jsTask, TaskExecutor::TaskType::JS, "ArkUIFrontendDestroy"); 36323b3eb3cSopenharmony_ci } 36423b3eb3cSopenharmony_ci } 36523b3eb3cSopenharmony_ci DestroyToastSubwindow(instanceId_); 36623b3eb3cSopenharmony_ci resRegister_.Reset(); 36723b3eb3cSopenharmony_ci assetManager_.Reset(); 36823b3eb3cSopenharmony_ci} 36923b3eb3cSopenharmony_ci 37023b3eb3cSopenharmony_civoid AceContainer::DestroyView() 37123b3eb3cSopenharmony_ci{ 37223b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 37323b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(viewMutex_); 37423b3eb3cSopenharmony_ci aceView_ = nullptr; 37523b3eb3cSopenharmony_ci} 37623b3eb3cSopenharmony_ci 37723b3eb3cSopenharmony_civoid AceContainer::InitializeFrontend() 37823b3eb3cSopenharmony_ci{ 37923b3eb3cSopenharmony_ci auto aceAbility = aceAbility_.lock(); 38023b3eb3cSopenharmony_ci if (type_ == FrontendType::JS) { 38123b3eb3cSopenharmony_ci#ifndef NG_BUILD 38223b3eb3cSopenharmony_ci frontend_ = Frontend::Create(); 38323b3eb3cSopenharmony_ci auto jsFrontend = AceType::DynamicCast<JsFrontend>(frontend_); 38423b3eb3cSopenharmony_ci auto& loader = Framework::JsEngineLoader::Get(GetEngineSharedLibrary()); 38523b3eb3cSopenharmony_ci auto jsEngine = loader.CreateJsEngine(instanceId_); 38623b3eb3cSopenharmony_ci jsEngine->AddExtraNativeObject("ability", aceAbility.get()); 38723b3eb3cSopenharmony_ci EngineHelper::AddEngine(instanceId_, jsEngine); 38823b3eb3cSopenharmony_ci jsFrontend->SetJsEngine(jsEngine); 38923b3eb3cSopenharmony_ci jsFrontend->SetNeedDebugBreakPoint(AceApplicationInfo::GetInstance().IsNeedDebugBreakPoint()); 39023b3eb3cSopenharmony_ci jsFrontend->SetDebugVersion(AceApplicationInfo::GetInstance().IsDebugVersion()); 39123b3eb3cSopenharmony_ci#endif 39223b3eb3cSopenharmony_ci } else if (type_ == FrontendType::JS_CARD) { 39323b3eb3cSopenharmony_ci#ifndef NG_BUILD 39423b3eb3cSopenharmony_ci AceApplicationInfo::GetInstance().SetCardType(); 39523b3eb3cSopenharmony_ci frontend_ = AceType::MakeRefPtr<CardFrontend>(); 39623b3eb3cSopenharmony_ci#endif 39723b3eb3cSopenharmony_ci } else if (type_ == FrontendType::DECLARATIVE_JS) { 39823b3eb3cSopenharmony_ci if (isFormRender_) { 39923b3eb3cSopenharmony_ci#ifdef FORM_SUPPORTED 40023b3eb3cSopenharmony_ci LOGI("Init Form Frontend"); 40123b3eb3cSopenharmony_ci frontend_ = AceType::MakeRefPtr<FormFrontendDeclarative>(); 40223b3eb3cSopenharmony_ci auto cardFrontend = AceType::DynamicCast<FormFrontendDeclarative>(frontend_); 40323b3eb3cSopenharmony_ci auto& loader = Framework::JsEngineLoader::GetDeclarative(GetDeclarativeSharedLibrary()); 40423b3eb3cSopenharmony_ci RefPtr<Framework::JsEngine> jsEngine; 40523b3eb3cSopenharmony_ci if (GetSettings().usingSharedRuntime) { 40623b3eb3cSopenharmony_ci jsEngine = loader.CreateJsEngineUsingSharedRuntime(instanceId_, sharedRuntime_); 40723b3eb3cSopenharmony_ci } else { 40823b3eb3cSopenharmony_ci jsEngine = loader.CreateJsEngine(instanceId_); 40923b3eb3cSopenharmony_ci } 41023b3eb3cSopenharmony_ci jsEngine->AddExtraNativeObject("ability", aceAbility.get()); 41123b3eb3cSopenharmony_ci EngineHelper::AddEngine(instanceId_, jsEngine); 41223b3eb3cSopenharmony_ci cardFrontend->SetJsEngine(jsEngine); 41323b3eb3cSopenharmony_ci cardFrontend->SetPageProfile(pageProfile_); 41423b3eb3cSopenharmony_ci cardFrontend->SetNeedDebugBreakPoint(AceApplicationInfo::GetInstance().IsNeedDebugBreakPoint()); 41523b3eb3cSopenharmony_ci cardFrontend->SetDebugVersion(AceApplicationInfo::GetInstance().IsDebugVersion()); 41623b3eb3cSopenharmony_ci // Card front 41723b3eb3cSopenharmony_ci cardFrontend->SetRunningCardId(0); // ArkTsCard : nodeId, Host->FMS->FRS->innersdk 41823b3eb3cSopenharmony_ci cardFrontend->SetIsFormRender(true); 41923b3eb3cSopenharmony_ci#endif 42023b3eb3cSopenharmony_ci } else if (!isSubContainer_) { 42123b3eb3cSopenharmony_ci#ifdef NG_BUILD 42223b3eb3cSopenharmony_ci frontend_ = AceType::MakeRefPtr<DeclarativeFrontendNG>(); 42323b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontendNG>(frontend_); 42423b3eb3cSopenharmony_ci#else 42523b3eb3cSopenharmony_ci frontend_ = AceType::MakeRefPtr<DeclarativeFrontend>(); 42623b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontend>(frontend_); 42723b3eb3cSopenharmony_ci#endif 42823b3eb3cSopenharmony_ci auto& loader = Framework::JsEngineLoader::GetDeclarative(GetDeclarativeSharedLibrary()); 42923b3eb3cSopenharmony_ci RefPtr<Framework::JsEngine> jsEngine; 43023b3eb3cSopenharmony_ci if (GetSettings().usingSharedRuntime) { 43123b3eb3cSopenharmony_ci jsEngine = loader.CreateJsEngineUsingSharedRuntime(instanceId_, sharedRuntime_); 43223b3eb3cSopenharmony_ci } else { 43323b3eb3cSopenharmony_ci jsEngine = loader.CreateJsEngine(instanceId_); 43423b3eb3cSopenharmony_ci } 43523b3eb3cSopenharmony_ci jsEngine->AddExtraNativeObject("ability", aceAbility.get()); 43623b3eb3cSopenharmony_ci auto pageUrlCheckFunc = [id = instanceId_](const std::string& url, const std::function<void()>& callback, 43723b3eb3cSopenharmony_ci const std::function<void(int32_t, const std::string&)>& silentInstallErrorCallBack) { 43823b3eb3cSopenharmony_ci ContainerScope scope(id); 43923b3eb3cSopenharmony_ci auto container = Container::Current(); 44023b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 44123b3eb3cSopenharmony_ci auto pageUrlChecker = container->GetPageUrlChecker(); 44223b3eb3cSopenharmony_ci CHECK_NULL_VOID(pageUrlChecker); 44323b3eb3cSopenharmony_ci pageUrlChecker->LoadPageUrl(url, callback, silentInstallErrorCallBack); 44423b3eb3cSopenharmony_ci }; 44523b3eb3cSopenharmony_ci jsEngine->SetPageUrlCheckFunc(std::move(pageUrlCheckFunc)); 44623b3eb3cSopenharmony_ci EngineHelper::AddEngine(instanceId_, jsEngine); 44723b3eb3cSopenharmony_ci declarativeFrontend->SetJsEngine(jsEngine); 44823b3eb3cSopenharmony_ci declarativeFrontend->SetPageProfile(pageProfile_); 44923b3eb3cSopenharmony_ci declarativeFrontend->SetNeedDebugBreakPoint(AceApplicationInfo::GetInstance().IsNeedDebugBreakPoint()); 45023b3eb3cSopenharmony_ci declarativeFrontend->SetDebugVersion(AceApplicationInfo::GetInstance().IsDebugVersion()); 45123b3eb3cSopenharmony_ci } else { 45223b3eb3cSopenharmony_ci frontend_ = OHOS::Ace::Platform::AceContainer::GetContainer(parentId_)->GetFrontend(); 45323b3eb3cSopenharmony_ci return; 45423b3eb3cSopenharmony_ci } 45523b3eb3cSopenharmony_ci } else if (type_ == FrontendType::DECLARATIVE_CJ) { 45623b3eb3cSopenharmony_ci LOGD("cj Frontend"); 45723b3eb3cSopenharmony_ci if (!isSubContainer_) { 45823b3eb3cSopenharmony_ci auto cjFrontend = CJUtils::LoadCjFrontend(useNewPipeline_, useStageModel_); 45923b3eb3cSopenharmony_ci if (cjFrontend == nullptr) { 46023b3eb3cSopenharmony_ci LOGE("Create cj frontend failed."); 46123b3eb3cSopenharmony_ci } 46223b3eb3cSopenharmony_ci frontend_ = AceType::Claim(reinterpret_cast<Frontend*>(cjFrontend)); 46323b3eb3cSopenharmony_ci } else { 46423b3eb3cSopenharmony_ci frontend_ = OHOS::Ace::Platform::AceContainer::GetContainer(parentId_)->GetFrontend(); 46523b3eb3cSopenharmony_ci return; 46623b3eb3cSopenharmony_ci } 46723b3eb3cSopenharmony_ci } else { 46823b3eb3cSopenharmony_ci LOGE("Frontend type not supported"); 46923b3eb3cSopenharmony_ci EventReport::SendAppStartException(AppStartExcepType::FRONTEND_TYPE_ERR); 47023b3eb3cSopenharmony_ci return; 47123b3eb3cSopenharmony_ci } 47223b3eb3cSopenharmony_ci ACE_DCHECK(frontend_); 47323b3eb3cSopenharmony_ci auto abilityInfo = abilityInfo_.lock(); 47423b3eb3cSopenharmony_ci std::shared_ptr<AppExecFwk::AbilityInfo> info = aceAbility ? aceAbility->GetAbilityInfo() : abilityInfo; 47523b3eb3cSopenharmony_ci if (info && info->isLauncherAbility) { 47623b3eb3cSopenharmony_ci frontend_->DisallowPopLastPage(); 47723b3eb3cSopenharmony_ci } 47823b3eb3cSopenharmony_ci frontend_->Initialize(type_, taskExecutor_); 47923b3eb3cSopenharmony_ci} 48023b3eb3cSopenharmony_ci 48123b3eb3cSopenharmony_ciRefPtr<AceContainer> AceContainer::GetContainer(int32_t instanceId) 48223b3eb3cSopenharmony_ci{ 48323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 48423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 48523b3eb3cSopenharmony_ci auto aceContainer = AceType::DynamicCast<AceContainer>(container); 48623b3eb3cSopenharmony_ci return aceContainer; 48723b3eb3cSopenharmony_ci} 48823b3eb3cSopenharmony_ci 48923b3eb3cSopenharmony_cibool AceContainer::RemoveOverlayBySubwindowManager(int32_t instanceId) 49023b3eb3cSopenharmony_ci{ 49123b3eb3cSopenharmony_ci auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(instanceId); 49223b3eb3cSopenharmony_ci if (subwindow) { 49323b3eb3cSopenharmony_ci if (subwindow->GetShown()) { 49423b3eb3cSopenharmony_ci auto subContainerId = SubwindowManager::GetInstance()->GetSubContainerId(instanceId); 49523b3eb3cSopenharmony_ci if (subContainerId < 0) { 49623b3eb3cSopenharmony_ci return false; 49723b3eb3cSopenharmony_ci } 49823b3eb3cSopenharmony_ci ContainerScope scope(subContainerId); 49923b3eb3cSopenharmony_ci auto overlayManager = subwindow->GetOverlayManager(); 50023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlayManager, false); 50123b3eb3cSopenharmony_ci return overlayManager->RemoveOverlayInSubwindow(); 50223b3eb3cSopenharmony_ci } 50323b3eb3cSopenharmony_ci } 50423b3eb3cSopenharmony_ci return false; 50523b3eb3cSopenharmony_ci} 50623b3eb3cSopenharmony_ci 50723b3eb3cSopenharmony_cibool AceContainer::OnBackPressed(int32_t instanceId) 50823b3eb3cSopenharmony_ci{ 50923b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 51023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 51123b3eb3cSopenharmony_ci // When the container is for overlay, it need close the overlay first. 51223b3eb3cSopenharmony_ci if (container->IsSubContainer()) { 51323b3eb3cSopenharmony_ci#ifdef NG_BUILD 51423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_UIEVENT, "back press for remove overlay node"); 51523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 51623b3eb3cSopenharmony_ci auto subPipelineContext = DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 51723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(subPipelineContext, false); 51823b3eb3cSopenharmony_ci auto overlayManager = subPipelineContext->GetOverlayManager(); 51923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlayManager, false); 52023b3eb3cSopenharmony_ci return overlayManager->RemoveOverlayInSubwindow(); 52123b3eb3cSopenharmony_ci#else 52223b3eb3cSopenharmony_ci if (container->IsUseNewPipeline()) { 52323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_UIEVENT, "back press for remove overlay node"); 52423b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 52523b3eb3cSopenharmony_ci auto subPipelineContext = DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 52623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(subPipelineContext, false); 52723b3eb3cSopenharmony_ci auto textfieldMgr = DynamicCast<NG::TextFieldManagerNG>(subPipelineContext->GetTextFieldManager()); 52823b3eb3cSopenharmony_ci if (textfieldMgr) { 52923b3eb3cSopenharmony_ci auto lastRequestKeyboardNodeId = textfieldMgr->GetLastRequestKeyboardId(); 53023b3eb3cSopenharmony_ci auto lastRequestKeyboardNode = DynamicCast<NG::FrameNode>( 53123b3eb3cSopenharmony_ci ElementRegister::GetInstance()->GetUINodeById(lastRequestKeyboardNodeId)); 53223b3eb3cSopenharmony_ci if (lastRequestKeyboardNode && lastRequestKeyboardNode->GetPageId() == -1 && 53323b3eb3cSopenharmony_ci textfieldMgr->OnBackPressed()) { 53423b3eb3cSopenharmony_ci LOGI("textfield consumed backpressed event"); 53523b3eb3cSopenharmony_ci return true; 53623b3eb3cSopenharmony_ci } 53723b3eb3cSopenharmony_ci } 53823b3eb3cSopenharmony_ci auto overlayManager = subPipelineContext->GetOverlayManager(); 53923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(overlayManager, false); 54023b3eb3cSopenharmony_ci if (overlayManager->RemoveOverlayInSubwindow()) { 54123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_UIEVENT, "subwindow consumed backpressed event"); 54223b3eb3cSopenharmony_ci return true; 54323b3eb3cSopenharmony_ci } 54423b3eb3cSopenharmony_ci instanceId = SubwindowManager::GetInstance()->GetParentContainerId(instanceId); 54523b3eb3cSopenharmony_ci } else { 54623b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->CloseMenu(); 54723b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_UIEVENT, "Menu consumed backpressed event"); 54823b3eb3cSopenharmony_ci return true; 54923b3eb3cSopenharmony_ci } 55023b3eb3cSopenharmony_ci#endif 55123b3eb3cSopenharmony_ci } 55223b3eb3cSopenharmony_ci // remove overlay through SubwindowManager if subwindow unfocused. 55323b3eb3cSopenharmony_ci if (RemoveOverlayBySubwindowManager(instanceId)) { 55423b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_UIEVENT, "subwindow consumed backpressed event"); 55523b3eb3cSopenharmony_ci return true; 55623b3eb3cSopenharmony_ci } 55723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 55823b3eb3cSopenharmony_ci auto context = container->GetPipelineContext(); 55923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, false); 56023b3eb3cSopenharmony_ci if (context->PopPageStackOverlay()) { 56123b3eb3cSopenharmony_ci return true; 56223b3eb3cSopenharmony_ci } 56323b3eb3cSopenharmony_ci return context->CallRouterBackToPopPage(); 56423b3eb3cSopenharmony_ci} 56523b3eb3cSopenharmony_ci 56623b3eb3cSopenharmony_civoid AceContainer::OnShow(int32_t instanceId) 56723b3eb3cSopenharmony_ci{ 56823b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 56923b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 57023b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 57123b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 57223b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 57323b3eb3cSopenharmony_ci if (!container->UpdateState(Frontend::State::ON_SHOW)) { 57423b3eb3cSopenharmony_ci return; 57523b3eb3cSopenharmony_ci } 57623b3eb3cSopenharmony_ci 57723b3eb3cSopenharmony_ci auto jsTask = [container, front = container->GetFrontend()]() { 57823b3eb3cSopenharmony_ci if (front && !container->IsSubContainer()) { 57923b3eb3cSopenharmony_ci front->UpdateState(Frontend::State::ON_SHOW); 58023b3eb3cSopenharmony_ci front->OnShow(); 58123b3eb3cSopenharmony_ci } 58223b3eb3cSopenharmony_ci }; 58323b3eb3cSopenharmony_ci 58423b3eb3cSopenharmony_ci auto uiTask = [container]() { 58523b3eb3cSopenharmony_ci std::unordered_map<int64_t, WeakPtr<Frontend>> cardFrontendMap; 58623b3eb3cSopenharmony_ci container->GetCardFrontendMap(cardFrontendMap); 58723b3eb3cSopenharmony_ci for (const auto& [_, weakCardFront] : cardFrontendMap) { 58823b3eb3cSopenharmony_ci auto cardFront = weakCardFront.Upgrade(); 58923b3eb3cSopenharmony_ci if (!cardFront) { 59023b3eb3cSopenharmony_ci LOGE("cardFront is null"); 59123b3eb3cSopenharmony_ci continue; 59223b3eb3cSopenharmony_ci } 59323b3eb3cSopenharmony_ci cardFront->OnShow(); 59423b3eb3cSopenharmony_ci } 59523b3eb3cSopenharmony_ci auto pipelineBase = container->GetPipelineContext(); 59623b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineBase); 59723b3eb3cSopenharmony_ci pipelineBase->OnShow(); 59823b3eb3cSopenharmony_ci pipelineBase->SetForegroundCalled(true); 59923b3eb3cSopenharmony_ci }; 60023b3eb3cSopenharmony_ci 60123b3eb3cSopenharmony_ci // stege model needn't post task when already run on UI 60223b3eb3cSopenharmony_ci if (container->GetSettings().useUIAsJSThread && taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 60323b3eb3cSopenharmony_ci jsTask(); 60423b3eb3cSopenharmony_ci uiTask(); 60523b3eb3cSopenharmony_ci } else { 60623b3eb3cSopenharmony_ci taskExecutor->PostTask(jsTask, TaskExecutor::TaskType::JS, "ArkUIFrontendShow"); 60723b3eb3cSopenharmony_ci taskExecutor->PostTask(uiTask, TaskExecutor::TaskType::UI, "ArkUICardFrontendShow"); 60823b3eb3cSopenharmony_ci } 60923b3eb3cSopenharmony_ci} 61023b3eb3cSopenharmony_ci 61123b3eb3cSopenharmony_civoid AceContainer::OnHide(int32_t instanceId) 61223b3eb3cSopenharmony_ci{ 61323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 61423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 61523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 61623b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 61723b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 61823b3eb3cSopenharmony_ci if (!container->UpdateState(Frontend::State::ON_HIDE)) { 61923b3eb3cSopenharmony_ci return; 62023b3eb3cSopenharmony_ci } 62123b3eb3cSopenharmony_ci std::unordered_map<int64_t, WeakPtr<Frontend>> cardFrontendMap; 62223b3eb3cSopenharmony_ci container->GetCardFrontendMap(cardFrontendMap); 62323b3eb3cSopenharmony_ci 62423b3eb3cSopenharmony_ci auto jsTask = [container, front = container->GetFrontend(), cardFrontendMap]() { 62523b3eb3cSopenharmony_ci if (front && !container->IsSubContainer()) { 62623b3eb3cSopenharmony_ci front->UpdateState(Frontend::State::ON_HIDE); 62723b3eb3cSopenharmony_ci front->OnHide(); 62823b3eb3cSopenharmony_ci front->TriggerGarbageCollection(); 62923b3eb3cSopenharmony_ci } 63023b3eb3cSopenharmony_ci for (const auto& [_, weakCardFront] : cardFrontendMap) { 63123b3eb3cSopenharmony_ci auto cardFront = weakCardFront.Upgrade(); 63223b3eb3cSopenharmony_ci if (!cardFront) { 63323b3eb3cSopenharmony_ci LOGE("cardFront is null"); 63423b3eb3cSopenharmony_ci continue; 63523b3eb3cSopenharmony_ci } 63623b3eb3cSopenharmony_ci cardFront->TriggerGarbageCollection(); 63723b3eb3cSopenharmony_ci } 63823b3eb3cSopenharmony_ci }; 63923b3eb3cSopenharmony_ci 64023b3eb3cSopenharmony_ci auto uiTask = [container, cardFrontendMap]() { 64123b3eb3cSopenharmony_ci for (const auto& [_, weakCardFront] : cardFrontendMap) { 64223b3eb3cSopenharmony_ci auto cardFront = weakCardFront.Upgrade(); 64323b3eb3cSopenharmony_ci if (!cardFront) { 64423b3eb3cSopenharmony_ci LOGE("cardFront is null"); 64523b3eb3cSopenharmony_ci continue; 64623b3eb3cSopenharmony_ci } 64723b3eb3cSopenharmony_ci cardFront->OnHide(); 64823b3eb3cSopenharmony_ci } 64923b3eb3cSopenharmony_ci auto pipelineBase = container->GetPipelineContext(); 65023b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineBase); 65123b3eb3cSopenharmony_ci pipelineBase->OnHide(); 65223b3eb3cSopenharmony_ci }; 65323b3eb3cSopenharmony_ci 65423b3eb3cSopenharmony_ci // stege model needn't post task when already run on UI 65523b3eb3cSopenharmony_ci if (container->GetSettings().useUIAsJSThread && taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 65623b3eb3cSopenharmony_ci jsTask(); 65723b3eb3cSopenharmony_ci uiTask(); 65823b3eb3cSopenharmony_ci } else { 65923b3eb3cSopenharmony_ci taskExecutor->PostTask(jsTask, TaskExecutor::TaskType::JS, "ArkUIFrontendHide"); 66023b3eb3cSopenharmony_ci taskExecutor->PostTask(uiTask, TaskExecutor::TaskType::UI, "ArkUICardFrontendHide"); 66123b3eb3cSopenharmony_ci } 66223b3eb3cSopenharmony_ci} 66323b3eb3cSopenharmony_ci 66423b3eb3cSopenharmony_civoid AceContainer::OnActive(int32_t instanceId) 66523b3eb3cSopenharmony_ci{ 66623b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 66723b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 66823b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 66923b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 67023b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 67123b3eb3cSopenharmony_ci 67223b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 67323b3eb3cSopenharmony_ci if (front && !container->IsSubContainer()) { 67423b3eb3cSopenharmony_ci WeakPtr<Frontend> weakFrontend = front; 67523b3eb3cSopenharmony_ci taskExecutor->PostTask( 67623b3eb3cSopenharmony_ci [weakFrontend, instanceId]() { 67723b3eb3cSopenharmony_ci auto frontend = weakFrontend.Upgrade(); 67823b3eb3cSopenharmony_ci if (frontend) { 67923b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 68023b3eb3cSopenharmony_ci frontend->UpdateState(Frontend::State::ON_ACTIVE); 68123b3eb3cSopenharmony_ci frontend->OnActive(); 68223b3eb3cSopenharmony_ci } 68323b3eb3cSopenharmony_ci }, 68423b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIFrontendActive"); 68523b3eb3cSopenharmony_ci } 68623b3eb3cSopenharmony_ci 68723b3eb3cSopenharmony_ci taskExecutor->PostTask( 68823b3eb3cSopenharmony_ci [container]() { 68923b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 69023b3eb3cSopenharmony_ci if (!pipelineContext) { 69123b3eb3cSopenharmony_ci LOGE("pipeline context is null, OnActive failed."); 69223b3eb3cSopenharmony_ci return; 69323b3eb3cSopenharmony_ci } 69423b3eb3cSopenharmony_ci ContainerScope scope(container->GetInstanceId()); 69523b3eb3cSopenharmony_ci pipelineContext->WindowFocus(true); 69623b3eb3cSopenharmony_ci pipelineContext->ChangeDarkModeBrightness(); 69723b3eb3cSopenharmony_ci }, 69823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIWindowFocus"); 69923b3eb3cSopenharmony_ci} 70023b3eb3cSopenharmony_ci 70123b3eb3cSopenharmony_civoid AceContainer::OnInactive(int32_t instanceId) 70223b3eb3cSopenharmony_ci{ 70323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 70423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 70523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 70623b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 70723b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 70823b3eb3cSopenharmony_ci 70923b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 71023b3eb3cSopenharmony_ci if (front && !container->IsSubContainer()) { 71123b3eb3cSopenharmony_ci WeakPtr<Frontend> weakFrontend = front; 71223b3eb3cSopenharmony_ci taskExecutor->PostTask( 71323b3eb3cSopenharmony_ci [weakFrontend, instanceId]() { 71423b3eb3cSopenharmony_ci auto frontend = weakFrontend.Upgrade(); 71523b3eb3cSopenharmony_ci if (frontend) { 71623b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 71723b3eb3cSopenharmony_ci frontend->UpdateState(Frontend::State::ON_INACTIVE); 71823b3eb3cSopenharmony_ci frontend->OnInactive(); 71923b3eb3cSopenharmony_ci } 72023b3eb3cSopenharmony_ci }, 72123b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIFrontendInactive"); 72223b3eb3cSopenharmony_ci } 72323b3eb3cSopenharmony_ci 72423b3eb3cSopenharmony_ci taskExecutor->PostTask( 72523b3eb3cSopenharmony_ci [container]() { 72623b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 72723b3eb3cSopenharmony_ci if (!pipelineContext) { 72823b3eb3cSopenharmony_ci LOGE("pipeline context is null, OnInactive failed."); 72923b3eb3cSopenharmony_ci return; 73023b3eb3cSopenharmony_ci } 73123b3eb3cSopenharmony_ci ContainerScope scope(container->GetInstanceId()); 73223b3eb3cSopenharmony_ci pipelineContext->WindowFocus(false); 73323b3eb3cSopenharmony_ci pipelineContext->ChangeDarkModeBrightness(); 73423b3eb3cSopenharmony_ci if (container->IsScenceBoardWindow()) { 73523b3eb3cSopenharmony_ci JankFrameReport::GetInstance().FlushRecord(); 73623b3eb3cSopenharmony_ci } 73723b3eb3cSopenharmony_ci }, 73823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIWindowUnfocus"); 73923b3eb3cSopenharmony_ci} 74023b3eb3cSopenharmony_ci 74123b3eb3cSopenharmony_civoid AceContainer::OnNewWant(int32_t instanceId, const std::string& data) 74223b3eb3cSopenharmony_ci{ 74323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 74423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 74523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 74623b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 74723b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 74823b3eb3cSopenharmony_ci front->OnNewWant(data); 74923b3eb3cSopenharmony_ci} 75023b3eb3cSopenharmony_ci 75123b3eb3cSopenharmony_cibool AceContainer::OnStartContinuation(int32_t instanceId) 75223b3eb3cSopenharmony_ci{ 75323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 75423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 75523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 75623b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 75723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, false); 75823b3eb3cSopenharmony_ci return front->OnStartContinuation(); 75923b3eb3cSopenharmony_ci} 76023b3eb3cSopenharmony_ci 76123b3eb3cSopenharmony_cistd::string AceContainer::OnSaveData(int32_t instanceId) 76223b3eb3cSopenharmony_ci{ 76323b3eb3cSopenharmony_ci std::string result = "false"; 76423b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 76523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, result); 76623b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 76723b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 76823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, result); 76923b3eb3cSopenharmony_ci front->OnSaveData(result); 77023b3eb3cSopenharmony_ci return result; 77123b3eb3cSopenharmony_ci} 77223b3eb3cSopenharmony_ci 77323b3eb3cSopenharmony_cibool AceContainer::OnRestoreData(int32_t instanceId, const std::string& data) 77423b3eb3cSopenharmony_ci{ 77523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 77623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 77723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 77823b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 77923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, false); 78023b3eb3cSopenharmony_ci return front->OnRestoreData(data); 78123b3eb3cSopenharmony_ci} 78223b3eb3cSopenharmony_ci 78323b3eb3cSopenharmony_civoid AceContainer::OnCompleteContinuation(int32_t instanceId, int result) 78423b3eb3cSopenharmony_ci{ 78523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 78623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 78723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 78823b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 78923b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 79023b3eb3cSopenharmony_ci front->OnCompleteContinuation(result); 79123b3eb3cSopenharmony_ci} 79223b3eb3cSopenharmony_ci 79323b3eb3cSopenharmony_civoid AceContainer::OnRemoteTerminated(int32_t instanceId) 79423b3eb3cSopenharmony_ci{ 79523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 79623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 79723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 79823b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 79923b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 80023b3eb3cSopenharmony_ci front->OnRemoteTerminated(); 80123b3eb3cSopenharmony_ci} 80223b3eb3cSopenharmony_ci 80323b3eb3cSopenharmony_civoid AceContainer::OnConfigurationUpdated(int32_t instanceId, const std::string& configuration) 80423b3eb3cSopenharmony_ci{ 80523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 80623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 80723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 80823b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 80923b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 81023b3eb3cSopenharmony_ci front->OnConfigurationUpdated(configuration); 81123b3eb3cSopenharmony_ci} 81223b3eb3cSopenharmony_ci 81323b3eb3cSopenharmony_civoid AceContainer::OnNewRequest(int32_t instanceId, const std::string& data) 81423b3eb3cSopenharmony_ci{ 81523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 81623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 81723b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 81823b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 81923b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 82023b3eb3cSopenharmony_ci front->OnNewRequest(data); 82123b3eb3cSopenharmony_ci} 82223b3eb3cSopenharmony_ci 82323b3eb3cSopenharmony_civoid AceContainer::InitializeCallback() 82423b3eb3cSopenharmony_ci{ 82523b3eb3cSopenharmony_ci ACE_FUNCTION_TRACE(); 82623b3eb3cSopenharmony_ci 82723b3eb3cSopenharmony_ci ACE_DCHECK(aceView_ && taskExecutor_ && pipelineContext_); 82823b3eb3cSopenharmony_ci auto&& touchEventCallback = [context = pipelineContext_, id = instanceId_]( 82923b3eb3cSopenharmony_ci const TouchEvent& event, const std::function<void()>& markProcess, 83023b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 83123b3eb3cSopenharmony_ci ContainerScope scope(id); 83223b3eb3cSopenharmony_ci context->CheckAndLogLastReceivedTouchEventInfo(event.touchEventId, event.type); 83323b3eb3cSopenharmony_ci auto touchTask = [context, event, markProcess, node]() { 83423b3eb3cSopenharmony_ci if (event.type == TouchType::HOVER_ENTER || event.type == TouchType::HOVER_MOVE || 83523b3eb3cSopenharmony_ci event.type == TouchType::HOVER_EXIT || event.type == TouchType::HOVER_CANCEL) { 83623b3eb3cSopenharmony_ci context->OnAccessibilityHoverEvent(event, node); 83723b3eb3cSopenharmony_ci } else if (event.IsPenHoverEvent()) { 83823b3eb3cSopenharmony_ci context->OnPenHoverEvent(event, node); 83923b3eb3cSopenharmony_ci } else { 84023b3eb3cSopenharmony_ci if (node) { 84123b3eb3cSopenharmony_ci context->OnTouchEvent(event, node); 84223b3eb3cSopenharmony_ci } else { 84323b3eb3cSopenharmony_ci context->OnTouchEvent(event); 84423b3eb3cSopenharmony_ci } 84523b3eb3cSopenharmony_ci } 84623b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 84723b3eb3cSopenharmony_ci markProcess(); 84823b3eb3cSopenharmony_ci context->CheckAndLogLastConsumedTouchEventInfo(event.touchEventId, event.type); 84923b3eb3cSopenharmony_ci }; 85023b3eb3cSopenharmony_ci auto uiTaskRunner = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI); 85123b3eb3cSopenharmony_ci if (uiTaskRunner.IsRunOnCurrentThread()) { 85223b3eb3cSopenharmony_ci touchTask(); 85323b3eb3cSopenharmony_ci return; 85423b3eb3cSopenharmony_ci } 85523b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 85623b3eb3cSopenharmony_ci touchTask, TaskExecutor::TaskType::UI, "ArkUIAceContainerTouchEvent", PriorityType::VIP); 85723b3eb3cSopenharmony_ci }; 85823b3eb3cSopenharmony_ci aceView_->RegisterTouchEventCallback(touchEventCallback); 85923b3eb3cSopenharmony_ci 86023b3eb3cSopenharmony_ci auto&& mouseEventCallback = [context = pipelineContext_, id = instanceId_]( 86123b3eb3cSopenharmony_ci const MouseEvent& event, const std::function<void()>& markProcess, 86223b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 86323b3eb3cSopenharmony_ci ContainerScope scope(id); 86423b3eb3cSopenharmony_ci context->CheckAndLogLastReceivedMouseEventInfo(event.touchEventId, event.action); 86523b3eb3cSopenharmony_ci auto mouseTask = [context, event, markProcess, node]() { 86623b3eb3cSopenharmony_ci if (node) { 86723b3eb3cSopenharmony_ci context->OnMouseEvent(event, node); 86823b3eb3cSopenharmony_ci } else { 86923b3eb3cSopenharmony_ci context->OnMouseEvent(event); 87023b3eb3cSopenharmony_ci } 87123b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 87223b3eb3cSopenharmony_ci markProcess(); 87323b3eb3cSopenharmony_ci context->CheckAndLogLastConsumedMouseEventInfo(event.touchEventId, event.action); 87423b3eb3cSopenharmony_ci }; 87523b3eb3cSopenharmony_ci auto uiTaskRunner = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI); 87623b3eb3cSopenharmony_ci if (uiTaskRunner.IsRunOnCurrentThread()) { 87723b3eb3cSopenharmony_ci mouseTask(); 87823b3eb3cSopenharmony_ci return; 87923b3eb3cSopenharmony_ci } 88023b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 88123b3eb3cSopenharmony_ci mouseTask, TaskExecutor::TaskType::UI, "ArkUIAceContainerMouseEvent", PriorityType::VIP); 88223b3eb3cSopenharmony_ci }; 88323b3eb3cSopenharmony_ci aceView_->RegisterMouseEventCallback(mouseEventCallback); 88423b3eb3cSopenharmony_ci 88523b3eb3cSopenharmony_ci auto&& axisEventCallback = [context = pipelineContext_, id = instanceId_]( 88623b3eb3cSopenharmony_ci const AxisEvent& event, const std::function<void()>& markProcess, 88723b3eb3cSopenharmony_ci const RefPtr<OHOS::Ace::NG::FrameNode>& node) { 88823b3eb3cSopenharmony_ci ContainerScope scope(id); 88923b3eb3cSopenharmony_ci context->CheckAndLogLastReceivedAxisEventInfo(event.touchEventId, event.action); 89023b3eb3cSopenharmony_ci auto axisTask = [context, event, markProcess, node]() { 89123b3eb3cSopenharmony_ci if (node) { 89223b3eb3cSopenharmony_ci context->OnAxisEvent(event, node); 89323b3eb3cSopenharmony_ci } else { 89423b3eb3cSopenharmony_ci context->OnAxisEvent(event); 89523b3eb3cSopenharmony_ci } 89623b3eb3cSopenharmony_ci CHECK_NULL_VOID(markProcess); 89723b3eb3cSopenharmony_ci markProcess(); 89823b3eb3cSopenharmony_ci context->CheckAndLogLastConsumedAxisEventInfo(event.touchEventId, event.action); 89923b3eb3cSopenharmony_ci }; 90023b3eb3cSopenharmony_ci auto uiTaskRunner = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI); 90123b3eb3cSopenharmony_ci if (uiTaskRunner.IsRunOnCurrentThread()) { 90223b3eb3cSopenharmony_ci axisTask(); 90323b3eb3cSopenharmony_ci return; 90423b3eb3cSopenharmony_ci } 90523b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 90623b3eb3cSopenharmony_ci axisTask, TaskExecutor::TaskType::UI, "ArkUIAceContainerAxisEvent", PriorityType::VIP); 90723b3eb3cSopenharmony_ci }; 90823b3eb3cSopenharmony_ci aceView_->RegisterAxisEventCallback(axisEventCallback); 90923b3eb3cSopenharmony_ci 91023b3eb3cSopenharmony_ci auto&& keyEventCallback = [context = pipelineContext_, id = instanceId_](const KeyEvent& event) { 91123b3eb3cSopenharmony_ci ContainerScope scope(id); 91223b3eb3cSopenharmony_ci bool result = false; 91323b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostSyncTask( 91423b3eb3cSopenharmony_ci [context, event, &result, id]() { 91523b3eb3cSopenharmony_ci ContainerScope scope(id); 91623b3eb3cSopenharmony_ci result = context->OnKeyEvent(event); 91723b3eb3cSopenharmony_ci }, 91823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIAceContainerKeyEvent", PriorityType::VIP); 91923b3eb3cSopenharmony_ci return result; 92023b3eb3cSopenharmony_ci }; 92123b3eb3cSopenharmony_ci aceView_->RegisterKeyEventCallback(keyEventCallback); 92223b3eb3cSopenharmony_ci 92323b3eb3cSopenharmony_ci auto&& rotationEventCallback = [context = pipelineContext_, id = instanceId_](const RotationEvent& event) { 92423b3eb3cSopenharmony_ci ContainerScope scope(id); 92523b3eb3cSopenharmony_ci bool result = false; 92623b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostSyncTask( 92723b3eb3cSopenharmony_ci [context, event, &result]() { result = context->OnRotationEvent(event); }, 92823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIAceContainerRotationEvent"); 92923b3eb3cSopenharmony_ci return result; 93023b3eb3cSopenharmony_ci }; 93123b3eb3cSopenharmony_ci aceView_->RegisterRotationEventCallback(rotationEventCallback); 93223b3eb3cSopenharmony_ci 93323b3eb3cSopenharmony_ci auto&& viewChangeCallback = [context = pipelineContext_, id = instanceId_](int32_t width, int32_t height, 93423b3eb3cSopenharmony_ci WindowSizeChangeReason type, 93523b3eb3cSopenharmony_ci const std::shared_ptr<Rosen::RSTransaction>& rsTransaction) { 93623b3eb3cSopenharmony_ci ContainerScope scope(id); 93723b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("ViewChangeCallback(%d, %d)", width, height); 93823b3eb3cSopenharmony_ci 93923b3eb3cSopenharmony_ci if (type != WindowSizeChangeReason::ROTATION) { 94023b3eb3cSopenharmony_ci context->SetSurfaceChangeMsg(width, height, type, rsTransaction); 94123b3eb3cSopenharmony_ci context->RequestFrame(); 94223b3eb3cSopenharmony_ci return; 94323b3eb3cSopenharmony_ci } 94423b3eb3cSopenharmony_ci context->ResetSurfaceChangeMsg(); 94523b3eb3cSopenharmony_ci 94623b3eb3cSopenharmony_ci auto callback = [context, width, height, type, rsTransaction, id]() { 94723b3eb3cSopenharmony_ci context->OnSurfaceChanged(width, height, type, rsTransaction); 94823b3eb3cSopenharmony_ci if (type == WindowSizeChangeReason::ROTATION) { 94923b3eb3cSopenharmony_ci auto subwindow = SubwindowManager::GetInstance()->GetSubwindow(id); 95023b3eb3cSopenharmony_ci CHECK_NULL_VOID(subwindow); 95123b3eb3cSopenharmony_ci subwindow->ResizeWindow(); 95223b3eb3cSopenharmony_ci } 95323b3eb3cSopenharmony_ci }; 95423b3eb3cSopenharmony_ci auto container = Container::Current(); 95523b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 95623b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 95723b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 95823b3eb3cSopenharmony_ci if ((container->IsUseStageModel() && type == WindowSizeChangeReason::ROTATION) || 95923b3eb3cSopenharmony_ci taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 96023b3eb3cSopenharmony_ci callback(); 96123b3eb3cSopenharmony_ci } else { 96223b3eb3cSopenharmony_ci taskExecutor->PostTask(callback, TaskExecutor::TaskType::UI, "ArkUISubwindowResizeWindow"); 96323b3eb3cSopenharmony_ci } 96423b3eb3cSopenharmony_ci }; 96523b3eb3cSopenharmony_ci aceView_->RegisterViewChangeCallback(viewChangeCallback); 96623b3eb3cSopenharmony_ci 96723b3eb3cSopenharmony_ci auto&& viewPositionChangeCallback = [context = pipelineContext_, id = instanceId_](int32_t posX, int32_t posY) { 96823b3eb3cSopenharmony_ci ContainerScope scope(id); 96923b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("ViewPositionChangeCallback(%d, %d)", posX, posY); 97023b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 97123b3eb3cSopenharmony_ci [context, posX, posY]() { context->OnSurfacePositionChanged(posX, posY); }, 97223b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUISurfacePositionChanged"); 97323b3eb3cSopenharmony_ci }; 97423b3eb3cSopenharmony_ci aceView_->RegisterViewPositionChangeCallback(viewPositionChangeCallback); 97523b3eb3cSopenharmony_ci 97623b3eb3cSopenharmony_ci auto&& densityChangeCallback = [context = pipelineContext_, id = instanceId_](double density) { 97723b3eb3cSopenharmony_ci ContainerScope scope(id); 97823b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("DensityChangeCallback(%lf)", density); 97923b3eb3cSopenharmony_ci auto callback = [context, density, id]() { 98023b3eb3cSopenharmony_ci context->OnSurfaceDensityChanged(density); 98123b3eb3cSopenharmony_ci if (context->IsDensityChanged()) { 98223b3eb3cSopenharmony_ci auto container = Container::GetContainer(id); 98323b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 98423b3eb3cSopenharmony_ci auto aceContainer = DynamicCast<AceContainer>(container); 98523b3eb3cSopenharmony_ci CHECK_NULL_VOID(aceContainer); 98623b3eb3cSopenharmony_ci aceContainer->UpdateResourceDensity(density); 98723b3eb3cSopenharmony_ci aceContainer->NotifyDensityUpdate(); 98823b3eb3cSopenharmony_ci } 98923b3eb3cSopenharmony_ci }; 99023b3eb3cSopenharmony_ci auto taskExecutor = context->GetTaskExecutor(); 99123b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 99223b3eb3cSopenharmony_ci if (taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 99323b3eb3cSopenharmony_ci callback(); 99423b3eb3cSopenharmony_ci } else { 99523b3eb3cSopenharmony_ci taskExecutor->PostTask(callback, TaskExecutor::TaskType::UI, "ArkUISurfaceDensityChanged"); 99623b3eb3cSopenharmony_ci } 99723b3eb3cSopenharmony_ci }; 99823b3eb3cSopenharmony_ci aceView_->RegisterDensityChangeCallback(densityChangeCallback); 99923b3eb3cSopenharmony_ci 100023b3eb3cSopenharmony_ci auto&& transformHintChangeCallback = [context = pipelineContext_, id = instanceId_](uint32_t transform) { 100123b3eb3cSopenharmony_ci ContainerScope scope(id); 100223b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("TransformHintChangeCallback(%d)", transform); 100323b3eb3cSopenharmony_ci auto callback = [context, transform]() { context->OnTransformHintChanged(transform); }; 100423b3eb3cSopenharmony_ci auto taskExecutor = context->GetTaskExecutor(); 100523b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 100623b3eb3cSopenharmony_ci if (taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 100723b3eb3cSopenharmony_ci callback(); 100823b3eb3cSopenharmony_ci } else { 100923b3eb3cSopenharmony_ci taskExecutor->PostTask(callback, TaskExecutor::TaskType::UI, "ArkUITransformHintChanged"); 101023b3eb3cSopenharmony_ci } 101123b3eb3cSopenharmony_ci }; 101223b3eb3cSopenharmony_ci aceView_->RegisterTransformHintChangeCallback(transformHintChangeCallback); 101323b3eb3cSopenharmony_ci 101423b3eb3cSopenharmony_ci auto&& systemBarHeightChangeCallback = [context = pipelineContext_, id = instanceId_]( 101523b3eb3cSopenharmony_ci double statusBar, double navigationBar) { 101623b3eb3cSopenharmony_ci ContainerScope scope(id); 101723b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("SystemBarHeightChangeCallback(%lf, %lf)", statusBar, navigationBar); 101823b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 101923b3eb3cSopenharmony_ci [context, statusBar, navigationBar]() { context->OnSystemBarHeightChanged(statusBar, navigationBar); }, 102023b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUISystemBarHeightChanged"); 102123b3eb3cSopenharmony_ci }; 102223b3eb3cSopenharmony_ci aceView_->RegisterSystemBarHeightChangeCallback(systemBarHeightChangeCallback); 102323b3eb3cSopenharmony_ci 102423b3eb3cSopenharmony_ci auto&& surfaceDestroyCallback = [context = pipelineContext_, id = instanceId_]() { 102523b3eb3cSopenharmony_ci ContainerScope scope(id); 102623b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 102723b3eb3cSopenharmony_ci [context]() { context->OnSurfaceDestroyed(); }, TaskExecutor::TaskType::UI, "ArkUISurfaceDestroyed"); 102823b3eb3cSopenharmony_ci }; 102923b3eb3cSopenharmony_ci aceView_->RegisterSurfaceDestroyCallback(surfaceDestroyCallback); 103023b3eb3cSopenharmony_ci InitDragEventCallback(); 103123b3eb3cSopenharmony_ci} 103223b3eb3cSopenharmony_ci 103323b3eb3cSopenharmony_civoid AceContainer::InitDragEventCallback() 103423b3eb3cSopenharmony_ci{ 103523b3eb3cSopenharmony_ci if (!isFormRender_) { 103623b3eb3cSopenharmony_ci auto&& dragEventCallback = [context = pipelineContext_, id = instanceId_](const PointerEvent& pointerEvent, 103723b3eb3cSopenharmony_ci const DragEventAction& action, const RefPtr<NG::FrameNode>& node) { 103823b3eb3cSopenharmony_ci ContainerScope scope(id); 103923b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 104023b3eb3cSopenharmony_ci auto callback = [context, pointerEvent, action, node]() { 104123b3eb3cSopenharmony_ci context->OnDragEvent(pointerEvent, action, node); 104223b3eb3cSopenharmony_ci }; 104323b3eb3cSopenharmony_ci auto taskExecutor = context->GetTaskExecutor(); 104423b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 104523b3eb3cSopenharmony_ci auto uiTaskRunner = SingleTaskExecutor::Make(taskExecutor, TaskExecutor::TaskType::UI); 104623b3eb3cSopenharmony_ci if (uiTaskRunner.IsRunOnCurrentThread()) { 104723b3eb3cSopenharmony_ci callback(); 104823b3eb3cSopenharmony_ci return; 104923b3eb3cSopenharmony_ci } 105023b3eb3cSopenharmony_ci taskExecutor->PostTask( 105123b3eb3cSopenharmony_ci callback, TaskExecutor::TaskType::UI, "ArkUIAceContainerDragEvent", PriorityType::VIP); 105223b3eb3cSopenharmony_ci }; 105323b3eb3cSopenharmony_ci aceView_->RegisterDragEventCallback(dragEventCallback); 105423b3eb3cSopenharmony_ci } 105523b3eb3cSopenharmony_ci} 105623b3eb3cSopenharmony_ci 105723b3eb3cSopenharmony_civoid AceContainer::CreateContainer(int32_t instanceId, FrontendType type, const std::string& instanceName, 105823b3eb3cSopenharmony_ci std::shared_ptr<OHOS::AppExecFwk::Ability> aceAbility, std::unique_ptr<PlatformEventCallback> callback, 105923b3eb3cSopenharmony_ci bool useCurrentEventRunner, bool useNewPipeline) 106023b3eb3cSopenharmony_ci{ 106123b3eb3cSopenharmony_ci auto aceContainer = AceType::MakeRefPtr<AceContainer>( 106223b3eb3cSopenharmony_ci instanceId, type, aceAbility, std::move(callback), useCurrentEventRunner, useNewPipeline); 106323b3eb3cSopenharmony_ci AceEngine::Get().AddContainer(instanceId, aceContainer); 106423b3eb3cSopenharmony_ci aceContainer->Initialize(); 106523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 106623b3eb3cSopenharmony_ci auto front = aceContainer->GetFrontend(); 106723b3eb3cSopenharmony_ci if (front) { 106823b3eb3cSopenharmony_ci front->UpdateState(Frontend::State::ON_CREATE); 106923b3eb3cSopenharmony_ci front->SetJsMessageDispatcher(aceContainer); 107023b3eb3cSopenharmony_ci } 107123b3eb3cSopenharmony_ci 107223b3eb3cSopenharmony_ci auto jsFront = AceType::DynamicCast<JsFrontend>(front); 107323b3eb3cSopenharmony_ci CHECK_NULL_VOID(jsFront); 107423b3eb3cSopenharmony_ci jsFront->SetInstanceName(instanceName); 107523b3eb3cSopenharmony_ci} 107623b3eb3cSopenharmony_ci 107723b3eb3cSopenharmony_civoid AceContainer::DestroyContainer(int32_t instanceId, const std::function<void()>& destroyCallback) 107823b3eb3cSopenharmony_ci{ 107923b3eb3cSopenharmony_ci SubwindowManager::GetInstance()->CloseDialog(instanceId); 108023b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 108123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 108223b3eb3cSopenharmony_ci container->Destroy(); 108323b3eb3cSopenharmony_ci // unregister watchdog before stop thread to avoid UI_BLOCK report 108423b3eb3cSopenharmony_ci AceEngine::Get().UnRegisterFromWatchDog(instanceId); 108523b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 108623b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 108723b3eb3cSopenharmony_ci 108823b3eb3cSopenharmony_ci taskExecutor->PostSyncTask([] { LOGI("Wait UI thread..."); }, TaskExecutor::TaskType::UI, "ArkUIWaitLog"); 108923b3eb3cSopenharmony_ci taskExecutor->PostSyncTask([] { LOGI("Wait JS thread..."); }, TaskExecutor::TaskType::JS, "ArkUIWaitLog"); 109023b3eb3cSopenharmony_ci 109123b3eb3cSopenharmony_ci container->DestroyView(); // Stop all threads(ui,gpu,io) for current ability. 109223b3eb3cSopenharmony_ci auto removeContainerTask = [instanceId, destroyCallback] { 109323b3eb3cSopenharmony_ci LOGI("Remove on Platform thread..."); 109423b3eb3cSopenharmony_ci EngineHelper::RemoveEngine(instanceId); 109523b3eb3cSopenharmony_ci AceEngine::Get().RemoveContainer(instanceId); 109623b3eb3cSopenharmony_ci CHECK_NULL_VOID(destroyCallback); 109723b3eb3cSopenharmony_ci destroyCallback(); 109823b3eb3cSopenharmony_ci }; 109923b3eb3cSopenharmony_ci if (container->GetSettings().usePlatformAsUIThread) { 110023b3eb3cSopenharmony_ci removeContainerTask(); 110123b3eb3cSopenharmony_ci } else { 110223b3eb3cSopenharmony_ci taskExecutor->PostTask(removeContainerTask, TaskExecutor::TaskType::PLATFORM, "ArkUIAceContainerRemove"); 110323b3eb3cSopenharmony_ci } 110423b3eb3cSopenharmony_ci} 110523b3eb3cSopenharmony_ci 110623b3eb3cSopenharmony_civoid AceContainer::SetView(const RefPtr<AceView>& view, double density, int32_t width, int32_t height, 110723b3eb3cSopenharmony_ci sptr<OHOS::Rosen::Window> rsWindow, UIEnvCallback callback) 110823b3eb3cSopenharmony_ci{ 110923b3eb3cSopenharmony_ci CHECK_NULL_VOID(view); 111023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(view->GetInstanceId())); 111123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 111223b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 111323b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 111423b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 111523b3eb3cSopenharmony_ci auto window = std::make_shared<NG::RosenWindow>(rsWindow, taskExecutor, view->GetInstanceId()); 111623b3eb3cSopenharmony_ci#else 111723b3eb3cSopenharmony_ci auto platformWindow = PlatformWindow::Create(view); 111823b3eb3cSopenharmony_ci CHECK_NULL_VOID(platformWindow); 111923b3eb3cSopenharmony_ci auto window = std::make_shared<Window>(std::move(platformWindow)); 112023b3eb3cSopenharmony_ci#endif 112123b3eb3cSopenharmony_ci AceContainer::SetUIWindow(view->GetInstanceId(), rsWindow); 112223b3eb3cSopenharmony_ci container->AttachView(window, view, density, width, height, rsWindow->GetWindowId(), callback); 112323b3eb3cSopenharmony_ci} 112423b3eb3cSopenharmony_ci 112523b3eb3cSopenharmony_ciUIContentErrorCode AceContainer::SetViewNew( 112623b3eb3cSopenharmony_ci const RefPtr<AceView>& view, double density, float width, float height, sptr<OHOS::Rosen::Window> rsWindow) 112723b3eb3cSopenharmony_ci{ 112823b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND 112923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(view, UIContentErrorCode::NULL_POINTER); 113023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(view->GetInstanceId())); 113123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, UIContentErrorCode::NULL_POINTER); 113223b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 113323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(taskExecutor, UIContentErrorCode::NULL_POINTER); 113423b3eb3cSopenharmony_ci AceContainer::SetUIWindow(view->GetInstanceId(), rsWindow); 113523b3eb3cSopenharmony_ci 113623b3eb3cSopenharmony_ci if (container->isFormRender_) { 113723b3eb3cSopenharmony_ci auto window = std::make_shared<FormRenderWindow>(taskExecutor, view->GetInstanceId()); 113823b3eb3cSopenharmony_ci container->AttachView(window, view, density, width, height, view->GetInstanceId(), nullptr); 113923b3eb3cSopenharmony_ci } else { 114023b3eb3cSopenharmony_ci auto window = std::make_shared<NG::RosenWindow>(rsWindow, taskExecutor, view->GetInstanceId()); 114123b3eb3cSopenharmony_ci container->AttachView(window, view, density, width, height, rsWindow->GetWindowId(), nullptr); 114223b3eb3cSopenharmony_ci } 114323b3eb3cSopenharmony_ci 114423b3eb3cSopenharmony_ci return UIContentErrorCode::NO_ERRORS; 114523b3eb3cSopenharmony_ci#endif 114623b3eb3cSopenharmony_ci} 114723b3eb3cSopenharmony_ci 114823b3eb3cSopenharmony_civoid AceContainer::SetUIWindow(int32_t instanceId, sptr<OHOS::Rosen::Window> uiWindow) 114923b3eb3cSopenharmony_ci{ 115023b3eb3cSopenharmony_ci CHECK_NULL_VOID(uiWindow); 115123b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 115223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 115323b3eb3cSopenharmony_ci container->SetUIWindowInner(uiWindow); 115423b3eb3cSopenharmony_ci} 115523b3eb3cSopenharmony_ci 115623b3eb3cSopenharmony_cisptr<OHOS::Rosen::Window> AceContainer::GetUIWindow(int32_t instanceId) 115723b3eb3cSopenharmony_ci{ 115823b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 115923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 116023b3eb3cSopenharmony_ci return container->GetUIWindowInner(); 116123b3eb3cSopenharmony_ci} 116223b3eb3cSopenharmony_ci 116323b3eb3cSopenharmony_ciOHOS::AppExecFwk::Ability* AceContainer::GetAbility(int32_t instanceId) 116423b3eb3cSopenharmony_ci{ 116523b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 116623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 116723b3eb3cSopenharmony_ci return container->GetAbilityInner().lock().get(); 116823b3eb3cSopenharmony_ci} 116923b3eb3cSopenharmony_ci 117023b3eb3cSopenharmony_ciOHOS::AbilityRuntime::Context* AceContainer::GetRuntimeContext(int32_t instanceId) 117123b3eb3cSopenharmony_ci{ 117223b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 117323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 117423b3eb3cSopenharmony_ci return container->GetRuntimeContextInner().lock().get(); 117523b3eb3cSopenharmony_ci} 117623b3eb3cSopenharmony_ci 117723b3eb3cSopenharmony_ciUIContentErrorCode AceContainer::RunPage( 117823b3eb3cSopenharmony_ci int32_t instanceId, const std::string& content, const std::string& params, bool isNamedRouter) 117923b3eb3cSopenharmony_ci{ 118023b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 118123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, UIContentErrorCode::NULL_POINTER); 118223b3eb3cSopenharmony_ci 118323b3eb3cSopenharmony_ci auto aceContainer = DynamicCast<AceContainer>(container); 118423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(aceContainer, UIContentErrorCode::NULL_POINTER); 118523b3eb3cSopenharmony_ci bool isStageModel = aceContainer->IsUseStageModel(); 118623b3eb3cSopenharmony_ci bool isFormRender = aceContainer->IsFormRender(); 118723b3eb3cSopenharmony_ci if (isStageModel && content.size() == 0) { 118823b3eb3cSopenharmony_ci return UIContentErrorCode::NULL_URL; 118923b3eb3cSopenharmony_ci } 119023b3eb3cSopenharmony_ci 119123b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 119223b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 119323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, UIContentErrorCode::NULL_POINTER); 119423b3eb3cSopenharmony_ci 119523b3eb3cSopenharmony_ci if (front->GetType() != FrontendType::DECLARATIVE_CJ && !isFormRender && !isNamedRouter && 119623b3eb3cSopenharmony_ci isStageModel && !CheckUrlValid(content, container->GetHapPath())) { 119723b3eb3cSopenharmony_ci return UIContentErrorCode::INVALID_URL; 119823b3eb3cSopenharmony_ci } 119923b3eb3cSopenharmony_ci 120023b3eb3cSopenharmony_ci if (isNamedRouter) { 120123b3eb3cSopenharmony_ci return front->RunPageByNamedRouter(content, params); 120223b3eb3cSopenharmony_ci } 120323b3eb3cSopenharmony_ci 120423b3eb3cSopenharmony_ci return front->RunPage(content, params); 120523b3eb3cSopenharmony_ci} 120623b3eb3cSopenharmony_ci 120723b3eb3cSopenharmony_ciUIContentErrorCode AceContainer::RunPage( 120823b3eb3cSopenharmony_ci int32_t instanceId, const std::shared_ptr<std::vector<uint8_t>>& content, const std::string& params) 120923b3eb3cSopenharmony_ci{ 121023b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 121123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, UIContentErrorCode::NULL_POINTER); 121223b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 121323b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 121423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, UIContentErrorCode::NULL_POINTER); 121523b3eb3cSopenharmony_ci return front->RunPage(content, params); 121623b3eb3cSopenharmony_ci} 121723b3eb3cSopenharmony_ci 121823b3eb3cSopenharmony_cibool AceContainer::RunDynamicPage( 121923b3eb3cSopenharmony_ci int32_t instanceId, const std::string& content, const std::string& params, const std::string& entryPoint) 122023b3eb3cSopenharmony_ci{ 122123b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 122223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 122323b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 122423b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 122523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, false); 122623b3eb3cSopenharmony_ci front->RunDynamicPage(content, params, entryPoint); 122723b3eb3cSopenharmony_ci return true; 122823b3eb3cSopenharmony_ci} 122923b3eb3cSopenharmony_ci 123023b3eb3cSopenharmony_cibool AceContainer::PushPage(int32_t instanceId, const std::string& content, const std::string& params) 123123b3eb3cSopenharmony_ci{ 123223b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 123323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 123423b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 123523b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 123623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, false); 123723b3eb3cSopenharmony_ci front->PushPage(content, params); 123823b3eb3cSopenharmony_ci return true; 123923b3eb3cSopenharmony_ci} 124023b3eb3cSopenharmony_ci 124123b3eb3cSopenharmony_cibool AceContainer::UpdatePage(int32_t instanceId, int32_t pageId, const std::string& content) 124223b3eb3cSopenharmony_ci{ 124323b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 124423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, false); 124523b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 124623b3eb3cSopenharmony_ci auto context = container->GetPipelineContext(); 124723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, false); 124823b3eb3cSopenharmony_ci return context->CallRouterBackToPopPage(); 124923b3eb3cSopenharmony_ci} 125023b3eb3cSopenharmony_ci 125123b3eb3cSopenharmony_ciclass FillRequestCallback : public AbilityRuntime::IFillRequestCallback { 125223b3eb3cSopenharmony_cipublic: 125323b3eb3cSopenharmony_ci FillRequestCallback(WeakPtr<NG::PipelineContext> pipelineContext, const RefPtr<NG::FrameNode>& node, 125423b3eb3cSopenharmony_ci AceAutoFillType autoFillType, bool isNative = true) 125523b3eb3cSopenharmony_ci : pipelineContext_(pipelineContext), node_(node), autoFillType_(autoFillType), isNative_(isNative) {} 125623b3eb3cSopenharmony_ci virtual ~FillRequestCallback() = default; 125723b3eb3cSopenharmony_ci void OnFillRequestSuccess(const AbilityBase::ViewData& viewData) override 125823b3eb3cSopenharmony_ci { 125923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called, pageUrl=[%{private}s]", viewData.pageUrl.c_str()); 126023b3eb3cSopenharmony_ci auto pipelineContext = pipelineContext_.Upgrade(); 126123b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 126223b3eb3cSopenharmony_ci auto taskExecutor = pipelineContext->GetTaskExecutor(); 126323b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 126423b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(viewData); 126523b3eb3cSopenharmony_ci CHECK_NULL_VOID(viewDataWrap); 126623b3eb3cSopenharmony_ci if (!isNative_) { 126723b3eb3cSopenharmony_ci auto node = node_.Upgrade(); 126823b3eb3cSopenharmony_ci CHECK_NULL_VOID(node); 126923b3eb3cSopenharmony_ci taskExecutor->PostTask( 127023b3eb3cSopenharmony_ci [viewDataWrap, node, autoFillType = autoFillType_]() { 127123b3eb3cSopenharmony_ci if (node) { 127223b3eb3cSopenharmony_ci node->NotifyFillRequestSuccess(viewDataWrap, nullptr, autoFillType); 127323b3eb3cSopenharmony_ci } 127423b3eb3cSopenharmony_ci }, 127523b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUINotifyWebFillRequestSuccess"); 127623b3eb3cSopenharmony_ci return; 127723b3eb3cSopenharmony_ci } 127823b3eb3cSopenharmony_ci 127923b3eb3cSopenharmony_ci taskExecutor->PostTask( 128023b3eb3cSopenharmony_ci [viewDataWrap, pipelineContext, autoFillType = autoFillType_]() { 128123b3eb3cSopenharmony_ci if (pipelineContext) { 128223b3eb3cSopenharmony_ci pipelineContext->NotifyFillRequestSuccess(autoFillType, viewDataWrap); 128323b3eb3cSopenharmony_ci } 128423b3eb3cSopenharmony_ci }, 128523b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUINotifyFillRequestSuccess"); 128623b3eb3cSopenharmony_ci } 128723b3eb3cSopenharmony_ci 128823b3eb3cSopenharmony_ci void OnFillRequestFailed(int32_t errCode, const std::string& fillContent, bool isPopup) override 128923b3eb3cSopenharmony_ci { 129023b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called, errCode: %{public}d", errCode); 129123b3eb3cSopenharmony_ci auto pipelineContext = pipelineContext_.Upgrade(); 129223b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 129323b3eb3cSopenharmony_ci auto node = node_.Upgrade(); 129423b3eb3cSopenharmony_ci CHECK_NULL_VOID(node); 129523b3eb3cSopenharmony_ci auto taskExecutor = pipelineContext->GetTaskExecutor(); 129623b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 129723b3eb3cSopenharmony_ci taskExecutor->PostTask( 129823b3eb3cSopenharmony_ci [errCode, pipelineContext, node, fillContent, isPopup]() { 129923b3eb3cSopenharmony_ci if (pipelineContext) { 130023b3eb3cSopenharmony_ci pipelineContext->NotifyFillRequestFailed(node, errCode, fillContent, isPopup); 130123b3eb3cSopenharmony_ci } 130223b3eb3cSopenharmony_ci }, 130323b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUINotifyFillRequestFailed"); 130423b3eb3cSopenharmony_ci } 130523b3eb3cSopenharmony_ci 130623b3eb3cSopenharmony_ci void onPopupConfigWillUpdate(AbilityRuntime::AutoFill::AutoFillCustomConfig& config) override 130723b3eb3cSopenharmony_ci { 130823b3eb3cSopenharmony_ci // Non-native component like web/xcomponent 130923b3eb3cSopenharmony_ci // The offset needs to be calculated based on the placement 131023b3eb3cSopenharmony_ci if (isNative_ || !config.targetSize.has_value() || !config.placement.has_value()) { 131123b3eb3cSopenharmony_ci return; 131223b3eb3cSopenharmony_ci } 131323b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupOffset offset; 131423b3eb3cSopenharmony_ci offset.deltaX = GetPopupConfigWillUpdateX(config); 131523b3eb3cSopenharmony_ci offset.deltaY = GetPopupConfigWillUpdateY(config); 131623b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "PopupOffset x:%{public}f,y:%{public}f", offset.deltaX, offset.deltaY); 131723b3eb3cSopenharmony_ci config.targetOffset = offset; 131823b3eb3cSopenharmony_ci config.placement = AbilityRuntime::AutoFill::PopupPlacement::BOTTOM; 131923b3eb3cSopenharmony_ci } 132023b3eb3cSopenharmony_ci 132123b3eb3cSopenharmony_ci void SetFocusedRect(AbilityBase::Rect rect) 132223b3eb3cSopenharmony_ci { 132323b3eb3cSopenharmony_ci rect_ = rect; 132423b3eb3cSopenharmony_ci } 132523b3eb3cSopenharmony_ci 132623b3eb3cSopenharmony_ci void SetWindowRect(Rosen::Rect rect) 132723b3eb3cSopenharmony_ci { 132823b3eb3cSopenharmony_ci windowRect_ = rect; 132923b3eb3cSopenharmony_ci } 133023b3eb3cSopenharmony_ciprivate: 133123b3eb3cSopenharmony_ci double GetPopupConfigWillUpdateY(AbilityRuntime::AutoFill::AutoFillCustomConfig& config) 133223b3eb3cSopenharmony_ci { 133323b3eb3cSopenharmony_ci auto node = node_.Upgrade(); 133423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, 0); 133523b3eb3cSopenharmony_ci auto rectf = node->GetRectWithRender(); 133623b3eb3cSopenharmony_ci double deltaY = 0; 133723b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupPlacement placement = config.placement.value(); 133823b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupSize size = config.targetSize.value(); 133923b3eb3cSopenharmony_ci 134023b3eb3cSopenharmony_ci auto trans = node->GetTransformRelativeOffset(); 134123b3eb3cSopenharmony_ci auto bottomAvoidHeight = GetBottomAvoidHeight(); 134223b3eb3cSopenharmony_ci 134323b3eb3cSopenharmony_ci bool isBottom = placement == AbilityRuntime::AutoFill::PopupPlacement::BOTTOM || 134423b3eb3cSopenharmony_ci placement == AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_LEFT || 134523b3eb3cSopenharmony_ci placement == AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_RIGHT; 134623b3eb3cSopenharmony_ci 134723b3eb3cSopenharmony_ci if ((windowRect_.height_ - rectf.Height() - trans.GetY()) > 134823b3eb3cSopenharmony_ci (size.height + POPUP_EDGE_INTERVAL + bottomAvoidHeight)) { 134923b3eb3cSopenharmony_ci // popup will display at the bottom of the container 135023b3eb3cSopenharmony_ci if (isBottom) { 135123b3eb3cSopenharmony_ci deltaY = rect_.top + rect_.height - rectf.Height() - trans.GetY(); 135223b3eb3cSopenharmony_ci } else { 135323b3eb3cSopenharmony_ci deltaY = rect_.top - rectf.Height() - size.height - trans.GetY() - POPUP_EDGE_INTERVAL; 135423b3eb3cSopenharmony_ci } 135523b3eb3cSopenharmony_ci } else { 135623b3eb3cSopenharmony_ci // popup will display in the middle of the container 135723b3eb3cSopenharmony_ci if (isBottom) { 135823b3eb3cSopenharmony_ci deltaY = rect_.top + rect_.height - 135923b3eb3cSopenharmony_ci ((rectf.Height() - size.height) / POPUP_CALCULATE_RATIO) - trans.GetY(); 136023b3eb3cSopenharmony_ci } else { 136123b3eb3cSopenharmony_ci deltaY = rect_.top - ((rectf.Height() + size.height) / POPUP_CALCULATE_RATIO) - trans.GetY(); 136223b3eb3cSopenharmony_ci } 136323b3eb3cSopenharmony_ci } 136423b3eb3cSopenharmony_ci return deltaY; 136523b3eb3cSopenharmony_ci } 136623b3eb3cSopenharmony_ci 136723b3eb3cSopenharmony_ci double GetPopupConfigWillUpdateX(AbilityRuntime::AutoFill::AutoFillCustomConfig& config) 136823b3eb3cSopenharmony_ci { 136923b3eb3cSopenharmony_ci auto node = node_.Upgrade(); 137023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, 0); 137123b3eb3cSopenharmony_ci auto rectf = node->GetRectWithRender(); 137223b3eb3cSopenharmony_ci double deltaX = 0; 137323b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupPlacement placement = config.placement.value(); 137423b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupSize size = config.targetSize.value(); 137523b3eb3cSopenharmony_ci 137623b3eb3cSopenharmony_ci if (placement == AbilityRuntime::AutoFill::PopupPlacement::TOP_LEFT || 137723b3eb3cSopenharmony_ci placement == AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_LEFT) { 137823b3eb3cSopenharmony_ci double edgeDist = (rectf.Width() - size.width) / POPUP_CALCULATE_RATIO; 137923b3eb3cSopenharmony_ci deltaX = rect_.left - edgeDist; 138023b3eb3cSopenharmony_ci if (deltaX > edgeDist) { 138123b3eb3cSopenharmony_ci deltaX = edgeDist; 138223b3eb3cSopenharmony_ci } 138323b3eb3cSopenharmony_ci if (rect_.left + size.width > windowRect_.width_) { 138423b3eb3cSopenharmony_ci deltaX = windowRect_.width_ - size.width - edgeDist; 138523b3eb3cSopenharmony_ci } 138623b3eb3cSopenharmony_ci if (edgeDist + size.width > windowRect_.width_) { 138723b3eb3cSopenharmony_ci deltaX = 0; 138823b3eb3cSopenharmony_ci } 138923b3eb3cSopenharmony_ci } 139023b3eb3cSopenharmony_ci 139123b3eb3cSopenharmony_ci if (placement == AbilityRuntime::AutoFill::PopupPlacement::TOP_RIGHT || 139223b3eb3cSopenharmony_ci placement == AbilityRuntime::AutoFill::PopupPlacement::BOTTOM_RIGHT) { 139323b3eb3cSopenharmony_ci double edgeDist = (rectf.Width() - size.width) / POPUP_CALCULATE_RATIO; 139423b3eb3cSopenharmony_ci deltaX = edgeDist + rect_.left + rect_.width - rectf.Width(); 139523b3eb3cSopenharmony_ci if ((deltaX < -DBL_EPSILON) && (std::fabs(deltaX) > edgeDist)) { 139623b3eb3cSopenharmony_ci deltaX = -edgeDist; 139723b3eb3cSopenharmony_ci } 139823b3eb3cSopenharmony_ci } 139923b3eb3cSopenharmony_ci return deltaX; 140023b3eb3cSopenharmony_ci } 140123b3eb3cSopenharmony_ci 140223b3eb3cSopenharmony_ci uint32_t GetBottomAvoidHeight() 140323b3eb3cSopenharmony_ci { 140423b3eb3cSopenharmony_ci auto containerId = Container::CurrentId(); 140523b3eb3cSopenharmony_ci RefPtr<NG::PipelineContext> pipelineContext; 140623b3eb3cSopenharmony_ci if (containerId >= MIN_SUBCONTAINER_ID) { 140723b3eb3cSopenharmony_ci auto parentContainerId = SubwindowManager::GetInstance()->GetParentContainerId(containerId); 140823b3eb3cSopenharmony_ci auto parentContainer = AceEngine::Get().GetContainer(parentContainerId); 140923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(parentContainer, 0); 141023b3eb3cSopenharmony_ci pipelineContext = AceType::DynamicCast<NG::PipelineContext>(parentContainer->GetPipelineContext()); 141123b3eb3cSopenharmony_ci } else { 141223b3eb3cSopenharmony_ci pipelineContext = NG::PipelineContext::GetCurrentContext(); 141323b3eb3cSopenharmony_ci } 141423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, 0); 141523b3eb3cSopenharmony_ci auto safeAreaManager = pipelineContext->GetSafeAreaManager(); 141623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(safeAreaManager, 0); 141723b3eb3cSopenharmony_ci return safeAreaManager->GetSystemSafeArea().bottom_.Length(); 141823b3eb3cSopenharmony_ci } 141923b3eb3cSopenharmony_ci 142023b3eb3cSopenharmony_ci WeakPtr<NG::PipelineContext> pipelineContext_ = nullptr; 142123b3eb3cSopenharmony_ci WeakPtr<NG::FrameNode> node_ = nullptr; 142223b3eb3cSopenharmony_ci AceAutoFillType autoFillType_ = AceAutoFillType::ACE_UNSPECIFIED; 142323b3eb3cSopenharmony_ci bool isNative_ = true; 142423b3eb3cSopenharmony_ci AbilityBase::Rect rect_; 142523b3eb3cSopenharmony_ci Rosen::Rect windowRect_ { 0, 0, 0, 0 }; 142623b3eb3cSopenharmony_ci}; 142723b3eb3cSopenharmony_ci 142823b3eb3cSopenharmony_cibool AceContainer::UpdatePopupUIExtension(const RefPtr<NG::FrameNode>& node, 142923b3eb3cSopenharmony_ci uint32_t autoFillSessionId, bool isNative) 143023b3eb3cSopenharmony_ci{ 143123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, false); 143223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 143323b3eb3cSopenharmony_ci auto uiContent = uiWindow_->GetUIContent(); 143423b3eb3cSopenharmony_ci auto uiContentImpl = reinterpret_cast<UIContentImpl*>(uiContent); 143523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiContentImpl, false); 143623b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 143723b3eb3cSopenharmony_ci auto autoFillContainerNode = node->GetFirstAutoFillContainerNode(); 143823b3eb3cSopenharmony_ci uiContentImpl->DumpViewData(autoFillContainerNode, viewDataWrap, true); 143923b3eb3cSopenharmony_ci auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap); 144023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrapOhos, false); 144123b3eb3cSopenharmony_ci auto viewData = viewDataWrapOhos->GetViewData(); 144223b3eb3cSopenharmony_ci if (!isNative) { 144323b3eb3cSopenharmony_ci OverwritePageNodeInfo(node, viewData); 144423b3eb3cSopenharmony_ci } 144523b3eb3cSopenharmony_ci AbilityRuntime::AutoFillManager::GetInstance().UpdateCustomPopupUIExtension(autoFillSessionId, viewData); 144623b3eb3cSopenharmony_ci return true; 144723b3eb3cSopenharmony_ci} 144823b3eb3cSopenharmony_ci 144923b3eb3cSopenharmony_cibool AceContainer::ClosePopupUIExtension(uint32_t autoFillSessionId) 145023b3eb3cSopenharmony_ci{ 145123b3eb3cSopenharmony_ci AbilityRuntime::AutoFillManager::GetInstance().CloseUIExtension(autoFillSessionId); 145223b3eb3cSopenharmony_ci return true; 145323b3eb3cSopenharmony_ci} 145423b3eb3cSopenharmony_ci 145523b3eb3cSopenharmony_ciHintToTypeWrap AceContainer::PlaceHolderToType(const std::string& onePlaceHolder) 145623b3eb3cSopenharmony_ci{ 145723b3eb3cSopenharmony_ci HintToTypeWrap hintToTypeWrap; 145823b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 145923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrap, hintToTypeWrap); 146023b3eb3cSopenharmony_ci auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap); 146123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrapOhos, hintToTypeWrap); 146223b3eb3cSopenharmony_ci std::vector<std::string> placeHolder; 146323b3eb3cSopenharmony_ci std::vector<int> intType; 146423b3eb3cSopenharmony_ci std::vector<std::string> metadata; 146523b3eb3cSopenharmony_ci placeHolder.push_back(onePlaceHolder); 146623b3eb3cSopenharmony_ci auto isSuccess = viewDataWrapOhos->LoadHint2Type(placeHolder, intType, metadata); 146723b3eb3cSopenharmony_ci if (!isSuccess) { 146823b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_AUTO_FILL, "Load Hint2Type Failed !"); 146923b3eb3cSopenharmony_ci return hintToTypeWrap; 147023b3eb3cSopenharmony_ci } 147123b3eb3cSopenharmony_ci if (intType.empty()) { 147223b3eb3cSopenharmony_ci return hintToTypeWrap; 147323b3eb3cSopenharmony_ci } 147423b3eb3cSopenharmony_ci hintToTypeWrap.autoFillType = static_cast<AceAutoFillType>(viewDataWrapOhos->HintToAutoFillType(intType[0])); 147523b3eb3cSopenharmony_ci if (!metadata.empty()) { 147623b3eb3cSopenharmony_ci hintToTypeWrap.metadata = metadata[0]; 147723b3eb3cSopenharmony_ci } 147823b3eb3cSopenharmony_ci return hintToTypeWrap; 147923b3eb3cSopenharmony_ci} 148023b3eb3cSopenharmony_ci 148123b3eb3cSopenharmony_civoid AceContainer::FillAutoFillViewData(const RefPtr<NG::FrameNode> &node, RefPtr<ViewDataWrap> &viewDataWrap) 148223b3eb3cSopenharmony_ci{ 148323b3eb3cSopenharmony_ci CHECK_NULL_VOID(node); 148423b3eb3cSopenharmony_ci CHECK_NULL_VOID(viewDataWrap); 148523b3eb3cSopenharmony_ci auto nodeInfoWraps = viewDataWrap->GetPageNodeInfoWraps(); 148623b3eb3cSopenharmony_ci auto pattern = node->GetPattern<NG::TextFieldPattern>(); 148723b3eb3cSopenharmony_ci CHECK_NULL_VOID(pattern); 148823b3eb3cSopenharmony_ci auto autoFillUserName = pattern->GetAutoFillUserName(); 148923b3eb3cSopenharmony_ci auto autoFillNewPassword = pattern->GetAutoFillNewPassword(); 149023b3eb3cSopenharmony_ci if (!autoFillUserName.empty()) { 149123b3eb3cSopenharmony_ci for (auto nodeInfoWrap : nodeInfoWraps) { 149223b3eb3cSopenharmony_ci if (!nodeInfoWrap) { 149323b3eb3cSopenharmony_ci continue; 149423b3eb3cSopenharmony_ci } 149523b3eb3cSopenharmony_ci auto metadataObject = JsonUtil::ParseJsonString(nodeInfoWrap->GetMetadata()); 149623b3eb3cSopenharmony_ci if (nodeInfoWrap->GetAutoFillType() == AceAutoFillType::ACE_USER_NAME) { 149723b3eb3cSopenharmony_ci nodeInfoWrap->SetValue(autoFillUserName); 149823b3eb3cSopenharmony_ci viewDataWrap->SetUserSelected(true); 149923b3eb3cSopenharmony_ci break; 150023b3eb3cSopenharmony_ci } else if (nodeInfoWrap->GetAutoFillType() == AceAutoFillType::ACE_UNSPECIFIED && metadataObject && 150123b3eb3cSopenharmony_ci metadataObject->Contains("type")) { 150223b3eb3cSopenharmony_ci metadataObject->Put("username", autoFillUserName.c_str()); 150323b3eb3cSopenharmony_ci nodeInfoWrap->SetMetadata(metadataObject->ToString()); 150423b3eb3cSopenharmony_ci viewDataWrap->SetUserSelected(true); 150523b3eb3cSopenharmony_ci } 150623b3eb3cSopenharmony_ci } 150723b3eb3cSopenharmony_ci pattern->SetAutoFillUserName(""); 150823b3eb3cSopenharmony_ci } 150923b3eb3cSopenharmony_ci if (!autoFillNewPassword.empty()) { 151023b3eb3cSopenharmony_ci for (auto nodeInfoWrap : nodeInfoWraps) { 151123b3eb3cSopenharmony_ci if (nodeInfoWrap && nodeInfoWrap->GetAutoFillType() == AceAutoFillType::ACE_NEW_PASSWORD) { 151223b3eb3cSopenharmony_ci nodeInfoWrap->SetValue(autoFillNewPassword); 151323b3eb3cSopenharmony_ci pattern->SetAutoFillNewPassword(""); 151423b3eb3cSopenharmony_ci break; 151523b3eb3cSopenharmony_ci } 151623b3eb3cSopenharmony_ci } 151723b3eb3cSopenharmony_ci } 151823b3eb3cSopenharmony_ci} 151923b3eb3cSopenharmony_ci 152023b3eb3cSopenharmony_civoid AceContainer::OverwritePageNodeInfo(const RefPtr<NG::FrameNode>& frameNode, 152123b3eb3cSopenharmony_ci AbilityBase::ViewData& viewData) 152223b3eb3cSopenharmony_ci{ 152323b3eb3cSopenharmony_ci // Non-native component like web/xcomponent, does not have PageNodeInfo 152423b3eb3cSopenharmony_ci CHECK_NULL_VOID(frameNode); 152523b3eb3cSopenharmony_ci auto pattern = frameNode->GetPattern(); 152623b3eb3cSopenharmony_ci CHECK_NULL_VOID(pattern); 152723b3eb3cSopenharmony_ci std::vector<AbilityBase::PageNodeInfo> nodeInfos; 152823b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 152923b3eb3cSopenharmony_ci pattern->DumpViewDataPageNode(viewDataWrap); 153023b3eb3cSopenharmony_ci auto infos = viewDataWrap->GetPageNodeInfoWraps(); 153123b3eb3cSopenharmony_ci for (const auto& info : infos) { 153223b3eb3cSopenharmony_ci if (!info) { 153323b3eb3cSopenharmony_ci continue; 153423b3eb3cSopenharmony_ci } 153523b3eb3cSopenharmony_ci AbilityBase::PageNodeInfo node; 153623b3eb3cSopenharmony_ci node.id = info->GetId(); 153723b3eb3cSopenharmony_ci node.depth = -1; 153823b3eb3cSopenharmony_ci node.autoFillType = static_cast<AbilityBase::AutoFillType>(info->GetAutoFillType()); 153923b3eb3cSopenharmony_ci node.isFocus = info->GetIsFocus(); 154023b3eb3cSopenharmony_ci node.value = info->GetValue(); 154123b3eb3cSopenharmony_ci node.placeholder = info->GetPlaceholder(); 154223b3eb3cSopenharmony_ci node.metadata = info->GetMetadata(); 154323b3eb3cSopenharmony_ci NG::RectF rectF = info->GetPageNodeRect(); 154423b3eb3cSopenharmony_ci node.rect.left = rectF.GetX(); 154523b3eb3cSopenharmony_ci node.rect.top = rectF.GetY(); 154623b3eb3cSopenharmony_ci node.rect.width = rectF.Width(); 154723b3eb3cSopenharmony_ci node.rect.height = rectF.Height(); 154823b3eb3cSopenharmony_ci nodeInfos.emplace_back(node); 154923b3eb3cSopenharmony_ci } 155023b3eb3cSopenharmony_ci viewData.nodes = nodeInfos; 155123b3eb3cSopenharmony_ci viewData.pageUrl = viewDataWrap->GetPageUrl(); 155223b3eb3cSopenharmony_ci} 155323b3eb3cSopenharmony_ci 155423b3eb3cSopenharmony_civoid FillAutoFillCustomConfig(const RefPtr<NG::FrameNode>& node, 155523b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillCustomConfig& customConfig, bool isNative) 155623b3eb3cSopenharmony_ci{ 155723b3eb3cSopenharmony_ci CHECK_NULL_VOID(node); 155823b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::PopupSize popupSize; 155923b3eb3cSopenharmony_ci popupSize.height = POPUPSIZE_HEIGHT; 156023b3eb3cSopenharmony_ci popupSize.width = POPUPSIZE_WIDTH; 156123b3eb3cSopenharmony_ci customConfig.targetSize = popupSize; 156223b3eb3cSopenharmony_ci customConfig.isShowInSubWindow = false; 156323b3eb3cSopenharmony_ci customConfig.nodeId = node->GetId(); 156423b3eb3cSopenharmony_ci customConfig.isEnableArrow = false; 156523b3eb3cSopenharmony_ci if (!isNative) { 156623b3eb3cSopenharmony_ci // web component will manually destroy the popup 156723b3eb3cSopenharmony_ci customConfig.isAutoCancel = true; 156823b3eb3cSopenharmony_ci } 156923b3eb3cSopenharmony_ci} 157023b3eb3cSopenharmony_ci 157123b3eb3cSopenharmony_civoid GetFocusedElementRect(const AbilityBase::ViewData& viewData, AbilityBase::Rect& rect) 157223b3eb3cSopenharmony_ci{ 157323b3eb3cSopenharmony_ci for (const auto& info : viewData.nodes) { 157423b3eb3cSopenharmony_ci if (info.isFocus) { 157523b3eb3cSopenharmony_ci rect = info.rect; 157623b3eb3cSopenharmony_ci } 157723b3eb3cSopenharmony_ci } 157823b3eb3cSopenharmony_ci} 157923b3eb3cSopenharmony_ci 158023b3eb3cSopenharmony_cibool AceContainer::RequestAutoFill(const RefPtr<NG::FrameNode>& node, AceAutoFillType autoFillType, 158123b3eb3cSopenharmony_ci bool isNewPassWord, bool& isPopup, uint32_t& autoFillSessionId, bool isNative) 158223b3eb3cSopenharmony_ci{ 158323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called, autoFillType: %{public}d", static_cast<int32_t>(autoFillType)); 158423b3eb3cSopenharmony_ci auto pipelineContext = AceType::DynamicCast<NG::PipelineContext>(pipelineContext_); 158523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(node, false); 158623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, false); 158723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 158823b3eb3cSopenharmony_ci auto uiContent = uiWindow_->GetUIContent(); 158923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiContent, false); 159023b3eb3cSopenharmony_ci auto uiContentImpl = reinterpret_cast<UIContentImpl*>(uiContent); 159123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiContentImpl, false); 159223b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 159323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrap, false); 159423b3eb3cSopenharmony_ci auto autoFillContainerNode = node->GetFirstAutoFillContainerNode(); 159523b3eb3cSopenharmony_ci uiContentImpl->DumpViewData(autoFillContainerNode, viewDataWrap, true); 159623b3eb3cSopenharmony_ci FillAutoFillViewData(node, viewDataWrap); 159723b3eb3cSopenharmony_ci auto callback = std::make_shared<FillRequestCallback>(pipelineContext, node, autoFillType, isNative); 159823b3eb3cSopenharmony_ci auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap); 159923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrapOhos, false); 160023b3eb3cSopenharmony_ci auto viewData = viewDataWrapOhos->GetViewData(); 160123b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "isNewPassWord is: %{public}d", isNewPassWord); 160223b3eb3cSopenharmony_ci if (isNewPassWord) { 160323b3eb3cSopenharmony_ci callback->OnFillRequestSuccess(viewData); 160423b3eb3cSopenharmony_ci return true; 160523b3eb3cSopenharmony_ci } 160623b3eb3cSopenharmony_ci if (!isNative) { 160723b3eb3cSopenharmony_ci OverwritePageNodeInfo(node, viewData); 160823b3eb3cSopenharmony_ci AbilityBase::Rect rect; 160923b3eb3cSopenharmony_ci GetFocusedElementRect(viewData, rect); 161023b3eb3cSopenharmony_ci callback->SetFocusedRect(rect); 161123b3eb3cSopenharmony_ci callback->SetWindowRect(uiWindow_->GetRect()); 161223b3eb3cSopenharmony_ci } 161323b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillCustomConfig customConfig; 161423b3eb3cSopenharmony_ci FillAutoFillCustomConfig(node, customConfig, isNative); 161523b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillRequest autoFillRequest; 161623b3eb3cSopenharmony_ci autoFillRequest.config = customConfig; 161723b3eb3cSopenharmony_ci autoFillRequest.autoFillType = static_cast<AbilityBase::AutoFillType>(autoFillType); 161823b3eb3cSopenharmony_ci autoFillRequest.autoFillCommand = AbilityRuntime::AutoFill::AutoFillCommand::FILL; 161923b3eb3cSopenharmony_ci autoFillRequest.viewData = viewData; 162023b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillResult result; 162123b3eb3cSopenharmony_ci if (AbilityRuntime::AutoFillManager::GetInstance().RequestAutoFill( 162223b3eb3cSopenharmony_ci uiContent, autoFillRequest, callback, result) != 0) { 162323b3eb3cSopenharmony_ci return false; 162423b3eb3cSopenharmony_ci } 162523b3eb3cSopenharmony_ci isPopup = result.isPopup; 162623b3eb3cSopenharmony_ci autoFillSessionId = result.autoFillSessionId; 162723b3eb3cSopenharmony_ci return true; 162823b3eb3cSopenharmony_ci} 162923b3eb3cSopenharmony_ci 163023b3eb3cSopenharmony_cibool AceContainer::IsNeedToCreatePopupWindow(const AceAutoFillType& autoFillType) 163123b3eb3cSopenharmony_ci{ 163223b3eb3cSopenharmony_ci return AbilityRuntime::AutoFillManager::GetInstance().IsNeedToCreatePopupWindow( 163323b3eb3cSopenharmony_ci static_cast<AbilityBase::AutoFillType>(autoFillType)); 163423b3eb3cSopenharmony_ci} 163523b3eb3cSopenharmony_ci 163623b3eb3cSopenharmony_ciclass SaveRequestCallback : public AbilityRuntime::ISaveRequestCallback { 163723b3eb3cSopenharmony_cipublic: 163823b3eb3cSopenharmony_ci SaveRequestCallback(WeakPtr<NG::PipelineContext> pipelineContext, const std::function<void()>& onFinish) 163923b3eb3cSopenharmony_ci : pipelineContext_(pipelineContext), onFinish_(onFinish) {} 164023b3eb3cSopenharmony_ci virtual ~SaveRequestCallback() = default; 164123b3eb3cSopenharmony_ci void OnSaveRequestSuccess() override 164223b3eb3cSopenharmony_ci { 164323b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called"); 164423b3eb3cSopenharmony_ci ProcessOnFinish(); 164523b3eb3cSopenharmony_ci } 164623b3eb3cSopenharmony_ci 164723b3eb3cSopenharmony_ci void OnSaveRequestFailed() override 164823b3eb3cSopenharmony_ci { 164923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called"); 165023b3eb3cSopenharmony_ci ProcessOnFinish(); 165123b3eb3cSopenharmony_ci } 165223b3eb3cSopenharmony_ci 165323b3eb3cSopenharmony_ci void ProcessOnFinish() 165423b3eb3cSopenharmony_ci { 165523b3eb3cSopenharmony_ci if (!onFinish_) { 165623b3eb3cSopenharmony_ci return; 165723b3eb3cSopenharmony_ci } 165823b3eb3cSopenharmony_ci auto pipelineContext = pipelineContext_.Upgrade(); 165923b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext); 166023b3eb3cSopenharmony_ci auto taskExecutor = pipelineContext->GetTaskExecutor(); 166123b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 166223b3eb3cSopenharmony_ci taskExecutor->PostTask( 166323b3eb3cSopenharmony_ci [onFinish = std::move(onFinish_)]() mutable { 166423b3eb3cSopenharmony_ci if (onFinish) { 166523b3eb3cSopenharmony_ci onFinish(); 166623b3eb3cSopenharmony_ci onFinish = nullptr; 166723b3eb3cSopenharmony_ci } 166823b3eb3cSopenharmony_ci }, 166923b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ProcessOnFinish"); 167023b3eb3cSopenharmony_ci } 167123b3eb3cSopenharmony_ciprivate: 167223b3eb3cSopenharmony_ci WeakPtr<NG::PipelineContext> pipelineContext_ = nullptr; 167323b3eb3cSopenharmony_ci std::function<void()> onFinish_; 167423b3eb3cSopenharmony_ci}; 167523b3eb3cSopenharmony_ci 167623b3eb3cSopenharmony_cibool AceContainer::RequestAutoSave(const RefPtr<NG::FrameNode>& node, const std::function<void()>& onFinish, 167723b3eb3cSopenharmony_ci const std::function<void()>& onUIExtNodeBindingCompleted, bool isNative, int32_t instanceId) 167823b3eb3cSopenharmony_ci{ 167923b3eb3cSopenharmony_ci TAG_LOGI(AceLogTag::ACE_AUTO_FILL, "called"); 168023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 168123b3eb3cSopenharmony_ci auto uiContent = uiWindow_->GetUIContent(); 168223b3eb3cSopenharmony_ci auto uiContentImpl = reinterpret_cast<UIContentImpl*>(uiContent); 168323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiContentImpl, false); 168423b3eb3cSopenharmony_ci auto viewDataWrap = ViewDataWrap::CreateViewDataWrap(); 168523b3eb3cSopenharmony_ci uiContentImpl->DumpViewData(node, viewDataWrap, false, true); 168623b3eb3cSopenharmony_ci 168723b3eb3cSopenharmony_ci auto pipelineContext = AceType::DynamicCast<NG::PipelineContext>(pipelineContext_); 168823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext, false); 168923b3eb3cSopenharmony_ci auto callback = std::make_shared<SaveRequestCallback>(pipelineContext, onFinish); 169023b3eb3cSopenharmony_ci auto viewDataWrapOhos = AceType::DynamicCast<ViewDataWrapOhos>(viewDataWrap); 169123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(viewDataWrapOhos, false); 169223b3eb3cSopenharmony_ci auto viewData = viewDataWrapOhos->GetViewData(); 169323b3eb3cSopenharmony_ci if (!isNative) { 169423b3eb3cSopenharmony_ci OverwritePageNodeInfo(node, viewData); 169523b3eb3cSopenharmony_ci } 169623b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillRequest autoFillRequest; 169723b3eb3cSopenharmony_ci autoFillRequest.viewData = viewData; 169823b3eb3cSopenharmony_ci autoFillRequest.autoFillCommand = AbilityRuntime::AutoFill::AutoFillCommand::SAVE; 169923b3eb3cSopenharmony_ci autoFillRequest.autoFillType = ViewDataWrap::ViewDataToType(viewData); 170023b3eb3cSopenharmony_ci autoFillRequest.doAfterAsyncModalBinding = std::move(onUIExtNodeBindingCompleted); 170123b3eb3cSopenharmony_ci if (instanceId != -1) { 170223b3eb3cSopenharmony_ci auto uiWindow = GetUIWindow(instanceId); 170323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow, false); 170423b3eb3cSopenharmony_ci uiContent = uiWindow->GetUIContent(); 170523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiContent, false); 170623b3eb3cSopenharmony_ci } 170723b3eb3cSopenharmony_ci AbilityRuntime::AutoFill::AutoFillResult result; 170823b3eb3cSopenharmony_ci if (AbilityRuntime::AutoFillManager::GetInstance().RequestAutoSave( 170923b3eb3cSopenharmony_ci uiContent, autoFillRequest, callback, result) != 0) { 171023b3eb3cSopenharmony_ci return false; 171123b3eb3cSopenharmony_ci } 171223b3eb3cSopenharmony_ci return true; 171323b3eb3cSopenharmony_ci} 171423b3eb3cSopenharmony_ci 171523b3eb3cSopenharmony_cistd::shared_ptr<NavigationController> AceContainer::GetNavigationController( 171623b3eb3cSopenharmony_ci const std::string& navigationId) 171723b3eb3cSopenharmony_ci{ 171823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext_, nullptr); 171923b3eb3cSopenharmony_ci return pipelineContext_->GetNavigationController(navigationId); 172023b3eb3cSopenharmony_ci} 172123b3eb3cSopenharmony_ci 172223b3eb3cSopenharmony_civoid AceContainer::SetHapPath(const std::string& hapPath) 172323b3eb3cSopenharmony_ci{ 172423b3eb3cSopenharmony_ci if (hapPath.empty()) { 172523b3eb3cSopenharmony_ci LOGW("SetHapPath, Use .index to load resource"); 172623b3eb3cSopenharmony_ci return; 172723b3eb3cSopenharmony_ci } 172823b3eb3cSopenharmony_ci LOGI("SetHapPath, Use hap path to load resource"); 172923b3eb3cSopenharmony_ci webHapPath_ = hapPath; 173023b3eb3cSopenharmony_ci resourceInfo_.SetHapPath(hapPath); 173123b3eb3cSopenharmony_ci SystemProperties::SetUnZipHap(false); 173223b3eb3cSopenharmony_ci} 173323b3eb3cSopenharmony_ci 173423b3eb3cSopenharmony_civoid AceContainer::Dispatch( 173523b3eb3cSopenharmony_ci const std::string& group, std::vector<uint8_t>&& data, int32_t id, bool replyToComponent) const 173623b3eb3cSopenharmony_ci{ 173723b3eb3cSopenharmony_ci return; 173823b3eb3cSopenharmony_ci} 173923b3eb3cSopenharmony_ci 174023b3eb3cSopenharmony_civoid AceContainer::DispatchPluginError(int32_t callbackId, int32_t errorCode, std::string&& errorMessage) const 174123b3eb3cSopenharmony_ci{ 174223b3eb3cSopenharmony_ci auto front = GetFrontend(); 174323b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 174423b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 174523b3eb3cSopenharmony_ci taskExecutor_->PostTask( 174623b3eb3cSopenharmony_ci [front, callbackId, errorCode, errorMessage = std::move(errorMessage)]() mutable { 174723b3eb3cSopenharmony_ci front->TransferJsPluginGetError(callbackId, errorCode, std::move(errorMessage)); 174823b3eb3cSopenharmony_ci }, 174923b3eb3cSopenharmony_ci TaskExecutor::TaskType::BACKGROUND, "ArkUIDispatchPluginError"); 175023b3eb3cSopenharmony_ci} 175123b3eb3cSopenharmony_ci 175223b3eb3cSopenharmony_cibool AceContainer::Dump(const std::vector<std::string>& params, std::vector<std::string>& info) 175323b3eb3cSopenharmony_ci{ 175423b3eb3cSopenharmony_ci if (isDumping_.test_and_set()) { 175523b3eb3cSopenharmony_ci LOGW("another dump is still running"); 175623b3eb3cSopenharmony_ci return false; 175723b3eb3cSopenharmony_ci } 175823b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 175923b3eb3cSopenharmony_ci auto result = false; 176023b3eb3cSopenharmony_ci paramUie_.assign(params.begin(), params.end()); 176123b3eb3cSopenharmony_ci std::unique_ptr<std::ostream> ostream = std::make_unique<std::ostringstream>(); 176223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(ostream, false); 176323b3eb3cSopenharmony_ci DumpLog::GetInstance().SetDumpFile(std::move(ostream)); 176423b3eb3cSopenharmony_ci if (IsUIExtensionWindow()) { 176523b3eb3cSopenharmony_ci DumpLog::GetInstance().SetSeparator(";"); 176623b3eb3cSopenharmony_ci } 176723b3eb3cSopenharmony_ci auto context = runtimeContext_.lock(); 176823b3eb3cSopenharmony_ci DumpLog::GetInstance().Print("bundleName:" + context->GetHapModuleInfo()->bundleName); 176923b3eb3cSopenharmony_ci DumpLog::GetInstance().Print("moduleName:" + context->GetHapModuleInfo()->moduleName); 177023b3eb3cSopenharmony_ci result = DumpInfo(params); 177123b3eb3cSopenharmony_ci const auto& infoFile = DumpLog::GetInstance().GetDumpFile(); 177223b3eb3cSopenharmony_ci auto* ostringstream = static_cast<std::ostringstream*>(infoFile.get()); 177323b3eb3cSopenharmony_ci info.emplace_back(ostringstream->str()); 177423b3eb3cSopenharmony_ci DumpLog::GetInstance().Reset(); 177523b3eb3cSopenharmony_ci if (!result) { 177623b3eb3cSopenharmony_ci DumpLog::ShowDumpHelp(info); 177723b3eb3cSopenharmony_ci } 177823b3eb3cSopenharmony_ci isDumping_.clear(); 177923b3eb3cSopenharmony_ci return true; 178023b3eb3cSopenharmony_ci} 178123b3eb3cSopenharmony_ci 178223b3eb3cSopenharmony_cibool AceContainer::DumpInfo(const std::vector<std::string>& params) 178323b3eb3cSopenharmony_ci{ 178423b3eb3cSopenharmony_ci if (aceView_ && aceView_->Dump(params)) { 178523b3eb3cSopenharmony_ci return true; 178623b3eb3cSopenharmony_ci } 178723b3eb3cSopenharmony_ci 178823b3eb3cSopenharmony_ci if (OnDumpInfo(params)) { 178923b3eb3cSopenharmony_ci return true; 179023b3eb3cSopenharmony_ci } 179123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext_, false); 179223b3eb3cSopenharmony_ci return pipelineContext_->Dump(params); 179323b3eb3cSopenharmony_ci} 179423b3eb3cSopenharmony_ci 179523b3eb3cSopenharmony_cibool AceContainer::OnDumpInfo(const std::vector<std::string>& params) 179623b3eb3cSopenharmony_ci{ 179723b3eb3cSopenharmony_ci if (!params.empty() && params[0] == "-basicinfo") { 179823b3eb3cSopenharmony_ci DumpLog::GetInstance().Print("BasicInfo: "); 179923b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "InstanceId: " + std::to_string(instanceId_)); 180023b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, 180123b3eb3cSopenharmony_ci "FrontendType: " + std::to_string(static_cast<typename std::underlying_type<FrontendType>::type>(type_))); 180223b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "NewPipeline: " + std::string(IsUseNewPipeline() ? "true" : "false")); 180323b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "WindowName: " + windowName_); 180423b3eb3cSopenharmony_ci DumpLog::GetInstance().Print( 180523b3eb3cSopenharmony_ci 1, "WindowState: " + 180623b3eb3cSopenharmony_ci (!frontend_ ? "frontend is null" 180723b3eb3cSopenharmony_ci : std::to_string(static_cast<typename std::underlying_type<Frontend::State>::type>( 180823b3eb3cSopenharmony_ci frontend_->GetState())))); 180923b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "Language: " + AceApplicationInfo::GetInstance().GetLocaleTag()); 181023b3eb3cSopenharmony_ci DumpLog::GetInstance().Print( 181123b3eb3cSopenharmony_ci 1, "RTL: " + std::string(AceApplicationInfo::GetInstance().IsRightToLeft() ? "true" : "false")); 181223b3eb3cSopenharmony_ci DumpLog::GetInstance().Print( 181323b3eb3cSopenharmony_ci 1, "ColorMode: " + std::string(SystemProperties::GetColorMode() == ColorMode::DARK ? "Dark" : "Light")); 181423b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, 181523b3eb3cSopenharmony_ci "DeviceOrientation: " + std::string(SystemProperties::GetDeviceOrientation() == DeviceOrientation::LANDSCAPE 181623b3eb3cSopenharmony_ci ? "Landscape" 181723b3eb3cSopenharmony_ci : "Portrait")); 181823b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "Resolution: " + std::to_string(SystemProperties::GetDeviceWidth()) + "*" + 181923b3eb3cSopenharmony_ci std::to_string(SystemProperties::GetDeviceHeight())); 182023b3eb3cSopenharmony_ci if (pipelineContext_) { 182123b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "AppBgColor: " + pipelineContext_->GetAppBgColor().ColorToString()); 182223b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "Density: " + std::to_string(pipelineContext_->GetDensity())); 182323b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "ViewScale: " + std::to_string(pipelineContext_->GetViewScale())); 182423b3eb3cSopenharmony_ci DumpLog::GetInstance().Print( 182523b3eb3cSopenharmony_ci 1, "DisplayWindowRect: " + pipelineContext_->GetDisplayWindowRectInfo().ToString()); 182623b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "vsyncID: " + std::to_string(pipelineContext_->GetFrameCount())); 182723b3eb3cSopenharmony_ci } 182823b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "ApiVersion: " + SystemProperties::GetApiVersion()); 182923b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "ReleaseType: " + SystemProperties::GetReleaseType()); 183023b3eb3cSopenharmony_ci DumpLog::GetInstance().Print(1, "DeviceType: " + SystemProperties::GetParamDeviceType()); 183123b3eb3cSopenharmony_ci return true; 183223b3eb3cSopenharmony_ci } 183323b3eb3cSopenharmony_ci return false; 183423b3eb3cSopenharmony_ci} 183523b3eb3cSopenharmony_ci 183623b3eb3cSopenharmony_civoid AceContainer::TriggerGarbageCollection() 183723b3eb3cSopenharmony_ci{ 183823b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 183923b3eb3cSopenharmony_ci#if !defined(OHOS_PLATFORM) || !defined(ENABLE_NATIVE_VIEW) 184023b3eb3cSopenharmony_ci // GPU and IO thread is standalone while disable native view 184123b3eb3cSopenharmony_ci taskExecutor_->PostTask([] { PurgeMallocCache(); }, TaskExecutor::TaskType::GPU, "ArkUIPurgeMallocCache"); 184223b3eb3cSopenharmony_ci taskExecutor_->PostTask([] { PurgeMallocCache(); }, TaskExecutor::TaskType::IO, "ArkUIPurgeMallocCache"); 184323b3eb3cSopenharmony_ci#endif 184423b3eb3cSopenharmony_ci taskExecutor_->PostTask([] { PurgeMallocCache(); }, TaskExecutor::TaskType::UI, "ArkUIPurgeMallocCache"); 184523b3eb3cSopenharmony_ci taskExecutor_->PostTask( 184623b3eb3cSopenharmony_ci [frontend = WeakPtr<Frontend>(frontend_)] { 184723b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 184823b3eb3cSopenharmony_ci if (sp) { 184923b3eb3cSopenharmony_ci sp->TriggerGarbageCollection(); 185023b3eb3cSopenharmony_ci } 185123b3eb3cSopenharmony_ci PurgeMallocCache(); 185223b3eb3cSopenharmony_ci }, 185323b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUITriggerGarbageCollection"); 185423b3eb3cSopenharmony_ci} 185523b3eb3cSopenharmony_ci 185623b3eb3cSopenharmony_civoid AceContainer::DumpHeapSnapshot(bool isPrivate) 185723b3eb3cSopenharmony_ci{ 185823b3eb3cSopenharmony_ci taskExecutor_->PostTask( 185923b3eb3cSopenharmony_ci [isPrivate, frontend = WeakPtr<Frontend>(frontend_)] { 186023b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 186123b3eb3cSopenharmony_ci CHECK_NULL_VOID(sp); 186223b3eb3cSopenharmony_ci sp->DumpHeapSnapshot(isPrivate); 186323b3eb3cSopenharmony_ci }, 186423b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIDumpHeapSnapshot"); 186523b3eb3cSopenharmony_ci} 186623b3eb3cSopenharmony_ci 186723b3eb3cSopenharmony_civoid AceContainer::DestroyHeapProfiler() 186823b3eb3cSopenharmony_ci{ 186923b3eb3cSopenharmony_ci taskExecutor_->PostTask( 187023b3eb3cSopenharmony_ci [frontend = WeakPtr<Frontend>(frontend_)] { 187123b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 187223b3eb3cSopenharmony_ci CHECK_NULL_VOID(sp); 187323b3eb3cSopenharmony_ci sp->DestroyHeapProfiler(); 187423b3eb3cSopenharmony_ci }, 187523b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIDestroyHeapProfiler"); 187623b3eb3cSopenharmony_ci} 187723b3eb3cSopenharmony_ci 187823b3eb3cSopenharmony_civoid AceContainer::ForceFullGC() 187923b3eb3cSopenharmony_ci{ 188023b3eb3cSopenharmony_ci taskExecutor_->PostTask( 188123b3eb3cSopenharmony_ci [frontend = WeakPtr<Frontend>(frontend_)] { 188223b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 188323b3eb3cSopenharmony_ci CHECK_NULL_VOID(sp); 188423b3eb3cSopenharmony_ci sp->ForceFullGC(); 188523b3eb3cSopenharmony_ci }, 188623b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUIForceFullGC"); 188723b3eb3cSopenharmony_ci} 188823b3eb3cSopenharmony_ci 188923b3eb3cSopenharmony_civoid AceContainer::SetLocalStorage( 189023b3eb3cSopenharmony_ci NativeReference* storage, const std::shared_ptr<OHOS::AbilityRuntime::Context>& context) 189123b3eb3cSopenharmony_ci{ 189223b3eb3cSopenharmony_ci ContainerScope scope(instanceId_); 189323b3eb3cSopenharmony_ci taskExecutor_->PostSyncTask( 189423b3eb3cSopenharmony_ci [frontend = WeakPtr<Frontend>(frontend_), storage, 189523b3eb3cSopenharmony_ci contextWeak = std::weak_ptr<OHOS::AbilityRuntime::Context>(context), id = instanceId_, 189623b3eb3cSopenharmony_ci sharedRuntime = sharedRuntime_] { 189723b3eb3cSopenharmony_ci auto sp = frontend.Upgrade(); 189823b3eb3cSopenharmony_ci auto contextRef = contextWeak.lock(); 189923b3eb3cSopenharmony_ci if (!sp || !contextRef) { 190023b3eb3cSopenharmony_ci ReleaseStorageReference(sharedRuntime, storage); 190123b3eb3cSopenharmony_ci return; 190223b3eb3cSopenharmony_ci } 190323b3eb3cSopenharmony_ci#ifdef NG_BUILD 190423b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontendNG>(sp); 190523b3eb3cSopenharmony_ci#else 190623b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontend>(sp); 190723b3eb3cSopenharmony_ci#endif 190823b3eb3cSopenharmony_ci if (!declarativeFrontend) { 190923b3eb3cSopenharmony_ci ReleaseStorageReference(sharedRuntime, storage); 191023b3eb3cSopenharmony_ci return; 191123b3eb3cSopenharmony_ci } 191223b3eb3cSopenharmony_ci auto jsEngine = declarativeFrontend->GetJsEngine(); 191323b3eb3cSopenharmony_ci if (!jsEngine) { 191423b3eb3cSopenharmony_ci ReleaseStorageReference(sharedRuntime, storage); 191523b3eb3cSopenharmony_ci return; 191623b3eb3cSopenharmony_ci } 191723b3eb3cSopenharmony_ci if (contextRef->GetBindingObject() && contextRef->GetBindingObject()->Get<NativeReference>()) { 191823b3eb3cSopenharmony_ci jsEngine->SetContext(id, contextRef->GetBindingObject()->Get<NativeReference>()); 191923b3eb3cSopenharmony_ci } 192023b3eb3cSopenharmony_ci if (storage) { 192123b3eb3cSopenharmony_ci jsEngine->SetLocalStorage(id, storage); 192223b3eb3cSopenharmony_ci } 192323b3eb3cSopenharmony_ci }, 192423b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUISetLocalStorage"); 192523b3eb3cSopenharmony_ci} 192623b3eb3cSopenharmony_ci 192723b3eb3cSopenharmony_civoid AceContainer::AddAssetPath(int32_t instanceId, const std::string& packagePath, const std::string& hapPath, 192823b3eb3cSopenharmony_ci const std::vector<std::string>& paths) 192923b3eb3cSopenharmony_ci{ 193023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 193123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 193223b3eb3cSopenharmony_ci RefPtr<AssetManagerImpl> assetManagerImpl; 193323b3eb3cSopenharmony_ci if (container->assetManager_) { 193423b3eb3cSopenharmony_ci assetManagerImpl = AceType::DynamicCast<AssetManagerImpl>(container->assetManager_); 193523b3eb3cSopenharmony_ci } else { 193623b3eb3cSopenharmony_ci assetManagerImpl = Referenced::MakeRefPtr<AssetManagerImpl>(); 193723b3eb3cSopenharmony_ci container->assetManager_ = assetManagerImpl; 193823b3eb3cSopenharmony_ci if (container->type_ != FrontendType::DECLARATIVE_JS && container->type_ != FrontendType::DECLARATIVE_CJ) { 193923b3eb3cSopenharmony_ci container->frontend_->SetAssetManager(assetManagerImpl); 194023b3eb3cSopenharmony_ci } 194123b3eb3cSopenharmony_ci } 194223b3eb3cSopenharmony_ci CHECK_NULL_VOID(assetManagerImpl); 194323b3eb3cSopenharmony_ci if (!hapPath.empty()) { 194423b3eb3cSopenharmony_ci auto assetProvider = AceType::MakeRefPtr<HapAssetProviderImpl>(); 194523b3eb3cSopenharmony_ci if (assetProvider->Initialize(hapPath, paths)) { 194623b3eb3cSopenharmony_ci LOGI("Push AssetProvider to queue."); 194723b3eb3cSopenharmony_ci assetManagerImpl->PushBack(std::move(assetProvider)); 194823b3eb3cSopenharmony_ci } 194923b3eb3cSopenharmony_ci } 195023b3eb3cSopenharmony_ci if (!packagePath.empty()) { 195123b3eb3cSopenharmony_ci auto assetProvider = AceType::MakeRefPtr<FileAssetProviderImpl>(); 195223b3eb3cSopenharmony_ci if (assetProvider->Initialize(packagePath, paths)) { 195323b3eb3cSopenharmony_ci LOGI("Push AssetProvider to queue."); 195423b3eb3cSopenharmony_ci assetManagerImpl->PushBack(std::move(assetProvider)); 195523b3eb3cSopenharmony_ci } 195623b3eb3cSopenharmony_ci } 195723b3eb3cSopenharmony_ci} 195823b3eb3cSopenharmony_ci 195923b3eb3cSopenharmony_civoid AceContainer::AddLibPath(int32_t instanceId, const std::vector<std::string>& libPath) 196023b3eb3cSopenharmony_ci{ 196123b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 196223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 196323b3eb3cSopenharmony_ci RefPtr<AssetManager> assetManagerImpl; 196423b3eb3cSopenharmony_ci if (container->assetManager_) { 196523b3eb3cSopenharmony_ci assetManagerImpl = AceType::DynamicCast<AssetManagerImpl>(container->assetManager_); 196623b3eb3cSopenharmony_ci } else { 196723b3eb3cSopenharmony_ci assetManagerImpl = Referenced::MakeRefPtr<AssetManagerImpl>(); 196823b3eb3cSopenharmony_ci container->assetManager_ = assetManagerImpl; 196923b3eb3cSopenharmony_ci if (container->type_ != FrontendType::DECLARATIVE_JS && container->type_ != FrontendType::DECLARATIVE_CJ) { 197023b3eb3cSopenharmony_ci container->frontend_->SetAssetManager(assetManagerImpl); 197123b3eb3cSopenharmony_ci } 197223b3eb3cSopenharmony_ci } 197323b3eb3cSopenharmony_ci CHECK_NULL_VOID(assetManagerImpl); 197423b3eb3cSopenharmony_ci assetManagerImpl->SetLibPath("default", libPath); 197523b3eb3cSopenharmony_ci} 197623b3eb3cSopenharmony_ci 197723b3eb3cSopenharmony_civoid AceContainer::AttachView(std::shared_ptr<Window> window, const RefPtr<AceView>& view, double density, float width, 197823b3eb3cSopenharmony_ci float height, uint32_t windowId, UIEnvCallback callback) 197923b3eb3cSopenharmony_ci{ 198023b3eb3cSopenharmony_ci aceView_ = view; 198123b3eb3cSopenharmony_ci auto instanceId = aceView_->GetInstanceId(); 198223b3eb3cSopenharmony_ci auto taskExecutorImpl = AceType::DynamicCast<TaskExecutorImpl>(taskExecutor_); 198323b3eb3cSopenharmony_ci if (!isSubContainer_) { 198423b3eb3cSopenharmony_ci auto aceView = AceType::DynamicCast<AceViewOhos>(aceView_); 198523b3eb3cSopenharmony_ci ACE_DCHECK(aceView != nullptr); 198623b3eb3cSopenharmony_ci taskExecutorImpl->InitOtherThreads(aceView->GetThreadModelImpl()); 198723b3eb3cSopenharmony_ci } 198823b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 198923b3eb3cSopenharmony_ci if (type_ == FrontendType::DECLARATIVE_JS || type_ == FrontendType::DECLARATIVE_CJ) { 199023b3eb3cSopenharmony_ci // For DECLARATIVE_JS frontend display UI in JS thread temporarily. 199123b3eb3cSopenharmony_ci taskExecutorImpl->InitJsThread(false); 199223b3eb3cSopenharmony_ci InitializeFrontend(); 199323b3eb3cSopenharmony_ci auto front = GetFrontend(); 199423b3eb3cSopenharmony_ci if (front) { 199523b3eb3cSopenharmony_ci front->UpdateState(Frontend::State::ON_CREATE); 199623b3eb3cSopenharmony_ci front->SetJsMessageDispatcher(AceType::Claim(this)); 199723b3eb3cSopenharmony_ci front->SetAssetManager(assetManager_); 199823b3eb3cSopenharmony_ci } 199923b3eb3cSopenharmony_ci } else if (type_ != FrontendType::JS_CARD) { 200023b3eb3cSopenharmony_ci aceView_->SetCreateTime(createTime_); 200123b3eb3cSopenharmony_ci } 200223b3eb3cSopenharmony_ci resRegister_ = aceView_->GetPlatformResRegister(); 200323b3eb3cSopenharmony_ci#ifndef NG_BUILD 200423b3eb3cSopenharmony_ci if (useNewPipeline_) { 200523b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<NG::PipelineContext>( 200623b3eb3cSopenharmony_ci window, taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 200723b3eb3cSopenharmony_ci pipelineContext_->SetTextFieldManager(AceType::MakeRefPtr<NG::TextFieldManagerNG>()); 200823b3eb3cSopenharmony_ci } else { 200923b3eb3cSopenharmony_ci LOGI("Create old pipeline."); 201023b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<PipelineContext>( 201123b3eb3cSopenharmony_ci window, taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 201223b3eb3cSopenharmony_ci pipelineContext_->SetTextFieldManager(AceType::MakeRefPtr<TextFieldManager>()); 201323b3eb3cSopenharmony_ci } 201423b3eb3cSopenharmony_ci#else 201523b3eb3cSopenharmony_ci pipelineContext_ = AceType::MakeRefPtr<NG::PipelineContext>( 201623b3eb3cSopenharmony_ci window, taskExecutor_, assetManager_, resRegister_, frontend_, instanceId); 201723b3eb3cSopenharmony_ci pipelineContext_->SetTextFieldManager(AceType::MakeRefPtr<NG::TextFieldManagerNG>()); 201823b3eb3cSopenharmony_ci#endif 201923b3eb3cSopenharmony_ci 202023b3eb3cSopenharmony_ci#ifdef FORM_SUPPORTED 202123b3eb3cSopenharmony_ci if (isFormRender_) { 202223b3eb3cSopenharmony_ci pipelineContext_->SetIsFormRender(isFormRender_); 202323b3eb3cSopenharmony_ci pipelineContext_->SetIsDynamicRender(isDynamicRender_); 202423b3eb3cSopenharmony_ci auto cardFrontend = AceType::DynamicCast<FormFrontendDeclarative>(frontend_); 202523b3eb3cSopenharmony_ci if (cardFrontend) { 202623b3eb3cSopenharmony_ci cardFrontend->SetTaskExecutor(taskExecutor_); 202723b3eb3cSopenharmony_ci cardFrontend->SetLoadCardCallBack(WeakPtr<PipelineBase>(pipelineContext_)); 202823b3eb3cSopenharmony_ci } 202923b3eb3cSopenharmony_ci } 203023b3eb3cSopenharmony_ci#endif 203123b3eb3cSopenharmony_ci 203223b3eb3cSopenharmony_ci auto windowDensityCallback = [weak = WeakClaim(this)]() { 203323b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 203423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, 0.0); 203523b3eb3cSopenharmony_ci return container->GetWindowDensity(); 203623b3eb3cSopenharmony_ci }; 203723b3eb3cSopenharmony_ci pipelineContext_->RegisterWindowDensityCallback(std::move(windowDensityCallback)); 203823b3eb3cSopenharmony_ci 203923b3eb3cSopenharmony_ci pipelineContext_->SetRootSize(density, width, height); 204023b3eb3cSopenharmony_ci if (isFormRender_) { 204123b3eb3cSopenharmony_ci pipelineContext_->OnSurfaceDensityChanged(density); 204223b3eb3cSopenharmony_ci } 204323b3eb3cSopenharmony_ci pipelineContext_->SetIsRightToLeft(AceApplicationInfo::GetInstance().IsRightToLeft()); 204423b3eb3cSopenharmony_ci pipelineContext_->SetWindowId(windowId); 204523b3eb3cSopenharmony_ci pipelineContext_->SetWindowModal(windowModal_); 204623b3eb3cSopenharmony_ci if (uiWindow_) { 204723b3eb3cSopenharmony_ci auto windowType = uiWindow_->GetType(); 204823b3eb3cSopenharmony_ci pipelineContext_->SetIsAppWindow( 204923b3eb3cSopenharmony_ci windowType < Rosen::WindowType::SYSTEM_WINDOW_BASE && windowType >= Rosen::WindowType::APP_WINDOW_BASE); 205023b3eb3cSopenharmony_ci } 205123b3eb3cSopenharmony_ci if (installationFree_) { 205223b3eb3cSopenharmony_ci pipelineContext_->SetInstallationFree(installationFree_); 205323b3eb3cSopenharmony_ci pipelineContext_->SetSharePanelCallback(std::move(sharePanelCallback_)); 205423b3eb3cSopenharmony_ci std::shared_ptr<AppExecFwk::AbilityInfo> info = abilityInfo_.lock(); 205523b3eb3cSopenharmony_ci if (info != nullptr) { 205623b3eb3cSopenharmony_ci pipelineContext_->SetAppLabelId(info->labelId); 205723b3eb3cSopenharmony_ci } 205823b3eb3cSopenharmony_ci } 205923b3eb3cSopenharmony_ci if (isSubContainer_) { 206023b3eb3cSopenharmony_ci pipelineContext_->SetIsSubPipeline(true); 206123b3eb3cSopenharmony_ci } 206223b3eb3cSopenharmony_ci 206323b3eb3cSopenharmony_ci pipelineContext_->SetDrawDelegate(aceView_->GetDrawDelegate()); 206423b3eb3cSopenharmony_ci InitWindowCallback(); 206523b3eb3cSopenharmony_ci InitializeCallback(); 206623b3eb3cSopenharmony_ci 206723b3eb3cSopenharmony_ci auto&& finishEventHandler = [weak = WeakClaim(this), instanceId] { 206823b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 206923b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 207023b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 207123b3eb3cSopenharmony_ci auto context = container->GetPipelineContext(); 207223b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 207323b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 207423b3eb3cSopenharmony_ci [weak = WeakPtr<AceContainer>(container)] { 207523b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 207623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 207723b3eb3cSopenharmony_ci container->OnFinish(); 207823b3eb3cSopenharmony_ci }, 207923b3eb3cSopenharmony_ci TaskExecutor::TaskType::PLATFORM, "ArkUIHandleFinishEvent"); 208023b3eb3cSopenharmony_ci }; 208123b3eb3cSopenharmony_ci pipelineContext_->SetFinishEventHandler(finishEventHandler); 208223b3eb3cSopenharmony_ci 208323b3eb3cSopenharmony_ci auto&& startAbilityHandler = [weak = WeakClaim(this), instanceId](const std::string& address) { 208423b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 208523b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 208623b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 208723b3eb3cSopenharmony_ci auto context = container->GetPipelineContext(); 208823b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 208923b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 209023b3eb3cSopenharmony_ci [weak = WeakPtr<AceContainer>(container), address]() { 209123b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 209223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 209323b3eb3cSopenharmony_ci container->OnStartAbility(address); 209423b3eb3cSopenharmony_ci }, 209523b3eb3cSopenharmony_ci TaskExecutor::TaskType::PLATFORM, "ArkUIHandleStartAbility"); 209623b3eb3cSopenharmony_ci }; 209723b3eb3cSopenharmony_ci pipelineContext_->SetStartAbilityHandler(startAbilityHandler); 209823b3eb3cSopenharmony_ci 209923b3eb3cSopenharmony_ci auto&& setStatusBarEventHandler = [weak = WeakClaim(this), instanceId](const Color& color) { 210023b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 210123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 210223b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 210323b3eb3cSopenharmony_ci auto context = container->GetPipelineContext(); 210423b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 210523b3eb3cSopenharmony_ci context->GetTaskExecutor()->PostTask( 210623b3eb3cSopenharmony_ci [weak, color = color.GetValue()]() { 210723b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 210823b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 210923b3eb3cSopenharmony_ci if (container->platformEventCallback_) { 211023b3eb3cSopenharmony_ci container->platformEventCallback_->OnStatusBarBgColorChanged(color); 211123b3eb3cSopenharmony_ci } 211223b3eb3cSopenharmony_ci }, 211323b3eb3cSopenharmony_ci TaskExecutor::TaskType::PLATFORM, "ArkUIStatusBarColorChanged"); 211423b3eb3cSopenharmony_ci }; 211523b3eb3cSopenharmony_ci pipelineContext_->SetStatusBarEventHandler(setStatusBarEventHandler); 211623b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread) { 211723b3eb3cSopenharmony_ci FrameReport::GetInstance().Init(); 211823b3eb3cSopenharmony_ci } else { 211923b3eb3cSopenharmony_ci taskExecutor_->PostTask([] { FrameReport::GetInstance().Init(); }, 212023b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIFrameReportInit"); 212123b3eb3cSopenharmony_ci } 212223b3eb3cSopenharmony_ci 212323b3eb3cSopenharmony_ci // Load custom style at UI thread before frontend attach, for loading style before building tree. 212423b3eb3cSopenharmony_ci auto initThemeManagerTask = [pipelineContext = pipelineContext_, assetManager = assetManager_, 212523b3eb3cSopenharmony_ci colorScheme = colorScheme_, resourceInfo = resourceInfo_, 212623b3eb3cSopenharmony_ci context = runtimeContext_.lock(), abilityInfo = abilityInfo_.lock()]() { 212723b3eb3cSopenharmony_ci ACE_SCOPED_TRACE("OHOS::LoadThemes()"); 212823b3eb3cSopenharmony_ci 212923b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 213023b3eb3cSopenharmony_ci InitResourceAndThemeManager(pipelineContext, assetManager, colorScheme, resourceInfo, context, abilityInfo); 213123b3eb3cSopenharmony_ci } else { 213223b3eb3cSopenharmony_ci ThemeConstants::InitDeviceType(); 213323b3eb3cSopenharmony_ci auto themeManager = AceType::MakeRefPtr<ThemeManagerImpl>(); 213423b3eb3cSopenharmony_ci pipelineContext->SetThemeManager(themeManager); 213523b3eb3cSopenharmony_ci themeManager->InitResource(resourceInfo); 213623b3eb3cSopenharmony_ci themeManager->SetColorScheme(colorScheme); 213723b3eb3cSopenharmony_ci themeManager->LoadCustomTheme(assetManager); 213823b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 213923b3eb3cSopenharmony_ci } 214023b3eb3cSopenharmony_ci auto themeManager = pipelineContext->GetThemeManager(); 214123b3eb3cSopenharmony_ci if (themeManager) { 214223b3eb3cSopenharmony_ci pipelineContext->SetAppBgColor(themeManager->GetBackgroundColor()); 214323b3eb3cSopenharmony_ci } 214423b3eb3cSopenharmony_ci }; 214523b3eb3cSopenharmony_ci 214623b3eb3cSopenharmony_ci auto setupRootElementTask = [context = pipelineContext_, callback, isSubContainer = isSubContainer_]() { 214723b3eb3cSopenharmony_ci if (callback != nullptr) { 214823b3eb3cSopenharmony_ci callback(AceType::DynamicCast<PipelineContext>(context)); 214923b3eb3cSopenharmony_ci } 215023b3eb3cSopenharmony_ci if (!isSubContainer) { 215123b3eb3cSopenharmony_ci context->SetupRootElement(); 215223b3eb3cSopenharmony_ci } 215323b3eb3cSopenharmony_ci }; 215423b3eb3cSopenharmony_ci if (GetSettings().usePlatformAsUIThread) { 215523b3eb3cSopenharmony_ci initThemeManagerTask(); 215623b3eb3cSopenharmony_ci setupRootElementTask(); 215723b3eb3cSopenharmony_ci } else { 215823b3eb3cSopenharmony_ci taskExecutor_->PostTask(initThemeManagerTask, TaskExecutor::TaskType::UI, "ArkUIInitThemeManager"); 215923b3eb3cSopenharmony_ci taskExecutor_->PostTask(setupRootElementTask, TaskExecutor::TaskType::UI, "ArkUISetupRootElement"); 216023b3eb3cSopenharmony_ci } 216123b3eb3cSopenharmony_ci 216223b3eb3cSopenharmony_ci aceView_->Launch(); 216323b3eb3cSopenharmony_ci 216423b3eb3cSopenharmony_ci#ifdef NG_BUILD 216523b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontendNG>(frontend_); 216623b3eb3cSopenharmony_ci#else 216723b3eb3cSopenharmony_ci auto declarativeFrontend = AceType::DynamicCast<DeclarativeFrontend>(frontend_); 216823b3eb3cSopenharmony_ci#endif 216923b3eb3cSopenharmony_ci if (declarativeFrontend) { 217023b3eb3cSopenharmony_ci auto jsEngine = AceType::DynamicCast<Framework::JsiDeclarativeEngine>(declarativeFrontend->GetJsEngine()); 217123b3eb3cSopenharmony_ci if (jsEngine && !isFormRender_) { 217223b3eb3cSopenharmony_ci // register state profiler callback 217323b3eb3cSopenharmony_ci jsEngine->JsStateProfilerResgiter(); 217423b3eb3cSopenharmony_ci } 217523b3eb3cSopenharmony_ci } 217623b3eb3cSopenharmony_ci 217723b3eb3cSopenharmony_ci if (!isSubContainer_) { 217823b3eb3cSopenharmony_ci // Only MainWindow instance in FA model will be registered to watch dog. 217923b3eb3cSopenharmony_ci if (!GetSettings().usingSharedRuntime && !AceApplicationInfo::GetInstance().IsNeedDebugBreakPoint()) { 218023b3eb3cSopenharmony_ci AceEngine::Get().RegisterToWatchDog(instanceId, taskExecutor_, GetSettings().useUIAsJSThread); 218123b3eb3cSopenharmony_ci } 218223b3eb3cSopenharmony_ci frontend_->AttachPipelineContext(pipelineContext_); 218323b3eb3cSopenharmony_ci } else if (frontend_->GetType() == FrontendType::DECLARATIVE_JS) { 218423b3eb3cSopenharmony_ci if (declarativeFrontend) { 218523b3eb3cSopenharmony_ci declarativeFrontend->AttachSubPipelineContext(pipelineContext_); 218623b3eb3cSopenharmony_ci } 218723b3eb3cSopenharmony_ci return; 218823b3eb3cSopenharmony_ci } 218923b3eb3cSopenharmony_ci 219023b3eb3cSopenharmony_ci auto dataAbilityHelperImpl = [ability = GetAbilityInner(), runtimeContext = runtimeContext_, 219123b3eb3cSopenharmony_ci useStageModel = useStageModel_]() { 219223b3eb3cSopenharmony_ci return AceType::MakeRefPtr<DataAbilityHelperStandard>(ability.lock(), runtimeContext.lock(), useStageModel); 219323b3eb3cSopenharmony_ci }; 219423b3eb3cSopenharmony_ci auto dataProviderManager = MakeRefPtr<DataProviderManagerStandard>(dataAbilityHelperImpl); 219523b3eb3cSopenharmony_ci pipelineContext_->SetDataProviderManager(dataProviderManager); 219623b3eb3cSopenharmony_ci 219723b3eb3cSopenharmony_ci#if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED) 219823b3eb3cSopenharmony_ci pipelineContext_->SetPostRTTaskCallBack([](std::function<void()>&& task) { 219923b3eb3cSopenharmony_ci auto syncTask = std::make_shared<AceRosenSyncTask>(std::move(task)); 220023b3eb3cSopenharmony_ci Rosen::RSTransactionProxy::GetInstance()->ExecuteSynchronousTask(syncTask); 220123b3eb3cSopenharmony_ci }); 220223b3eb3cSopenharmony_ci#endif 220323b3eb3cSopenharmony_ci} 220423b3eb3cSopenharmony_ci 220523b3eb3cSopenharmony_civoid AceContainer::SetUIWindowInner(sptr<OHOS::Rosen::Window> uiWindow) 220623b3eb3cSopenharmony_ci{ 220723b3eb3cSopenharmony_ci uiWindow_ = uiWindow; 220823b3eb3cSopenharmony_ci} 220923b3eb3cSopenharmony_ci 221023b3eb3cSopenharmony_cisptr<OHOS::Rosen::Window> AceContainer::GetUIWindowInner() const 221123b3eb3cSopenharmony_ci{ 221223b3eb3cSopenharmony_ci return uiWindow_; 221323b3eb3cSopenharmony_ci} 221423b3eb3cSopenharmony_ci 221523b3eb3cSopenharmony_cistd::weak_ptr<OHOS::AppExecFwk::Ability> AceContainer::GetAbilityInner() const 221623b3eb3cSopenharmony_ci{ 221723b3eb3cSopenharmony_ci return aceAbility_; 221823b3eb3cSopenharmony_ci} 221923b3eb3cSopenharmony_ci 222023b3eb3cSopenharmony_cistd::weak_ptr<OHOS::AbilityRuntime::Context> AceContainer::GetRuntimeContextInner() const 222123b3eb3cSopenharmony_ci{ 222223b3eb3cSopenharmony_ci return runtimeContext_; 222323b3eb3cSopenharmony_ci} 222423b3eb3cSopenharmony_ci 222523b3eb3cSopenharmony_cibool AceContainer::IsLauncherContainer() 222623b3eb3cSopenharmony_ci{ 222723b3eb3cSopenharmony_ci auto runtime = runtimeContext_.lock(); 222823b3eb3cSopenharmony_ci if (!runtime) { 222923b3eb3cSopenharmony_ci return false; 223023b3eb3cSopenharmony_ci } 223123b3eb3cSopenharmony_ci auto info = runtime->GetApplicationInfo(); 223223b3eb3cSopenharmony_ci return info ? info->isLauncherApp : false; 223323b3eb3cSopenharmony_ci} 223423b3eb3cSopenharmony_ci 223523b3eb3cSopenharmony_cibool AceContainer::IsTransparentBg() const 223623b3eb3cSopenharmony_ci{ 223723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipelineContext_, true); 223823b3eb3cSopenharmony_ci Color bgColor = pipelineContext_->GetAppBgColor(); 223923b3eb3cSopenharmony_ci std::string bgOpacity = bgColor.ColorToString().substr(0, 3); 224023b3eb3cSopenharmony_ci std::string transparentOpacity = "#00"; 224123b3eb3cSopenharmony_ci return bgColor == Color::TRANSPARENT || bgOpacity == transparentOpacity; 224223b3eb3cSopenharmony_ci} 224323b3eb3cSopenharmony_ci 224423b3eb3cSopenharmony_civoid AceContainer::SetWindowStyle(int32_t instanceId, WindowModal windowModal, ColorScheme colorScheme) 224523b3eb3cSopenharmony_ci{ 224623b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 224723b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 224823b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 224923b3eb3cSopenharmony_ci container->SetWindowModal(windowModal); 225023b3eb3cSopenharmony_ci container->SetColorScheme(colorScheme); 225123b3eb3cSopenharmony_ci} 225223b3eb3cSopenharmony_ci 225323b3eb3cSopenharmony_civoid AceContainer::SetDialogCallback(int32_t instanceId, FrontendDialogCallback callback) 225423b3eb3cSopenharmony_ci{ 225523b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 225623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 225723b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 225823b3eb3cSopenharmony_ci if (front && front->GetType() == FrontendType::JS) { 225923b3eb3cSopenharmony_ci front->SetDialogCallback(callback); 226023b3eb3cSopenharmony_ci } 226123b3eb3cSopenharmony_ci} 226223b3eb3cSopenharmony_ci 226323b3eb3cSopenharmony_cistd::pair<RouterRecoverRecord, UIContentErrorCode> AceContainer::RestoreRouterStack( 226423b3eb3cSopenharmony_ci int32_t instanceId, const std::string& contentInfo, ContentInfoType type) 226523b3eb3cSopenharmony_ci{ 226623b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 226723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, std::make_pair(RouterRecoverRecord(), UIContentErrorCode::NULL_POINTER)); 226823b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 226923b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 227023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, std::make_pair(RouterRecoverRecord(), UIContentErrorCode::NULL_POINTER)); 227123b3eb3cSopenharmony_ci return front->RestoreRouterStack(contentInfo, type); 227223b3eb3cSopenharmony_ci} 227323b3eb3cSopenharmony_ci 227423b3eb3cSopenharmony_cistd::string AceContainer::GetContentInfo(int32_t instanceId, ContentInfoType type) 227523b3eb3cSopenharmony_ci{ 227623b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId); 227723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, ""); 227823b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 227923b3eb3cSopenharmony_ci auto front = container->GetFrontend(); 228023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(front, ""); 228123b3eb3cSopenharmony_ci return front->GetContentInfo(type); 228223b3eb3cSopenharmony_ci} 228323b3eb3cSopenharmony_ci 228423b3eb3cSopenharmony_civoid AceContainer::SetWindowPos(int32_t left, int32_t top) 228523b3eb3cSopenharmony_ci{ 228623b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend_); 228723b3eb3cSopenharmony_ci auto accessibilityManager = frontend_->GetAccessibilityManager(); 228823b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 228923b3eb3cSopenharmony_ci accessibilityManager->SetWindowPos(left, top, windowId_); 229023b3eb3cSopenharmony_ci} 229123b3eb3cSopenharmony_ci 229223b3eb3cSopenharmony_civoid AceContainer::InitializeSubContainer(int32_t parentContainerId) 229323b3eb3cSopenharmony_ci{ 229423b3eb3cSopenharmony_ci auto parentContainer = AceEngine::Get().GetContainer(parentContainerId); 229523b3eb3cSopenharmony_ci CHECK_NULL_VOID(parentContainer); 229623b3eb3cSopenharmony_ci auto taskExec = parentContainer->GetTaskExecutor(); 229723b3eb3cSopenharmony_ci taskExecutor_ = AceType::DynamicCast<TaskExecutorImpl>(std::move(taskExec)); 229823b3eb3cSopenharmony_ci auto parentSettings = parentContainer->GetSettings(); 229923b3eb3cSopenharmony_ci GetSettings().useUIAsJSThread = parentSettings.useUIAsJSThread; 230023b3eb3cSopenharmony_ci GetSettings().usePlatformAsUIThread = parentSettings.usePlatformAsUIThread; 230123b3eb3cSopenharmony_ci GetSettings().usingSharedRuntime = parentSettings.usingSharedRuntime; 230223b3eb3cSopenharmony_ci} 230323b3eb3cSopenharmony_ci 230423b3eb3cSopenharmony_civoid AceContainer::InitWindowCallback() 230523b3eb3cSopenharmony_ci{ 230623b3eb3cSopenharmony_ci if (!pipelineContext_ || !uiWindow_) { 230723b3eb3cSopenharmony_ci return; 230823b3eb3cSopenharmony_ci } 230923b3eb3cSopenharmony_ci auto& windowManager = pipelineContext_->GetWindowManager(); 231023b3eb3cSopenharmony_ci std::shared_ptr<AppExecFwk::AbilityInfo> info = abilityInfo_.lock(); 231123b3eb3cSopenharmony_ci if (info != nullptr) { 231223b3eb3cSopenharmony_ci windowManager->SetAppLabelId(info->labelId); 231323b3eb3cSopenharmony_ci windowManager->SetAppIconId(info->iconId); 231423b3eb3cSopenharmony_ci } 231523b3eb3cSopenharmony_ci windowManager->SetWindowMinimizeCallBack([window = uiWindow_]() { window->Minimize(); }); 231623b3eb3cSopenharmony_ci windowManager->SetWindowMaximizeCallBack([window = uiWindow_]() { window->Maximize(); }); 231723b3eb3cSopenharmony_ci windowManager->SetWindowMaximizeFloatingCallBack([window = uiWindow_]() { window->MaximizeFloating(); }); 231823b3eb3cSopenharmony_ci windowManager->SetWindowRecoverCallBack([window = uiWindow_]() { window->Recover(); }); 231923b3eb3cSopenharmony_ci windowManager->SetWindowCloseCallBack([window = uiWindow_]() { window->Close(); }); 232023b3eb3cSopenharmony_ci windowManager->SetWindowStartMoveCallBack([window = uiWindow_]() { window->StartMove(); }); 232123b3eb3cSopenharmony_ci windowManager->SetGetWindowStartMoveFlagCallBack( 232223b3eb3cSopenharmony_ci [window = uiWindow_]() -> uint32_t { return static_cast<uint32_t>(window->GetStartMoveFlag()); }); 232323b3eb3cSopenharmony_ci windowManager->SetWindowSplitPrimaryCallBack( 232423b3eb3cSopenharmony_ci [window = uiWindow_]() { window->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY); }); 232523b3eb3cSopenharmony_ci windowManager->SetWindowSplitSecondaryCallBack( 232623b3eb3cSopenharmony_ci [window = uiWindow_]() { window->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_SPLIT_SECONDARY); }); 232723b3eb3cSopenharmony_ci windowManager->SetWindowGetModeCallBack( 232823b3eb3cSopenharmony_ci [window = uiWindow_]() -> WindowMode { return static_cast<WindowMode>(window->GetMode()); }); 232923b3eb3cSopenharmony_ci windowManager->SetWindowGetTypeCallBack( 233023b3eb3cSopenharmony_ci [window = uiWindow_]() -> WindowType { return static_cast<WindowType>(window->GetType()); }); 233123b3eb3cSopenharmony_ci windowManager->SetWindowSetMaximizeModeCallBack( 233223b3eb3cSopenharmony_ci [window = uiWindow_](MaximizeMode mode) { 233323b3eb3cSopenharmony_ci window->SetGlobalMaximizeMode(static_cast<Rosen::MaximizeMode>(mode)); 233423b3eb3cSopenharmony_ci }); 233523b3eb3cSopenharmony_ci windowManager->SetWindowGetMaximizeModeCallBack( 233623b3eb3cSopenharmony_ci [window = uiWindow_]() -> MaximizeMode { 233723b3eb3cSopenharmony_ci return static_cast<MaximizeMode>(window->GetGlobalMaximizeMode()); 233823b3eb3cSopenharmony_ci }); 233923b3eb3cSopenharmony_ci windowManager->SetGetSystemBarStyleCallBack( 234023b3eb3cSopenharmony_ci [window = uiWindow_]() -> RefPtr<SystemBarStyle> { 234123b3eb3cSopenharmony_ci return SystemBarStyleOhos::GetCurrentSystemBarStyle(window); 234223b3eb3cSopenharmony_ci }); 234323b3eb3cSopenharmony_ci windowManager->SetSetSystemBarStyleCallBack( 234423b3eb3cSopenharmony_ci [window = uiWindow_](const RefPtr<SystemBarStyle>& style) { 234523b3eb3cSopenharmony_ci SystemBarStyleOhos::SetSystemBarStyle(window, style); 234623b3eb3cSopenharmony_ci }); 234723b3eb3cSopenharmony_ci windowManager->SetGetFreeMultiWindowModeEnabledStateCallback( 234823b3eb3cSopenharmony_ci [window = uiWindow_]() -> bool { 234923b3eb3cSopenharmony_ci return window->GetFreeMultiWindowModeEnabledState(); 235023b3eb3cSopenharmony_ci }); 235123b3eb3cSopenharmony_ci 235223b3eb3cSopenharmony_ci pipelineContext_->SetGetWindowRectImpl([window = uiWindow_]() -> Rect { 235323b3eb3cSopenharmony_ci Rect rect; 235423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window, rect); 235523b3eb3cSopenharmony_ci auto windowRect = window->GetRect(); 235623b3eb3cSopenharmony_ci rect.SetRect(windowRect.posX_, windowRect.posY_, windowRect.width_, windowRect.height_); 235723b3eb3cSopenharmony_ci return rect; 235823b3eb3cSopenharmony_ci }); 235923b3eb3cSopenharmony_ci} 236023b3eb3cSopenharmony_ci 236123b3eb3cSopenharmony_ciNG::SafeAreaInsets AceContainer::GetViewSafeAreaByType(OHOS::Rosen::AvoidAreaType type) 236223b3eb3cSopenharmony_ci{ 236323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, {}); 236423b3eb3cSopenharmony_ci Rosen::AvoidArea avoidArea; 236523b3eb3cSopenharmony_ci Rosen::WMError ret = uiWindow_->GetAvoidAreaByType(type, avoidArea); 236623b3eb3cSopenharmony_ci if (ret == Rosen::WMError::WM_OK) { 236723b3eb3cSopenharmony_ci auto safeAreaInsets = ConvertAvoidArea(avoidArea); 236823b3eb3cSopenharmony_ci TAG_LOGI(ACE_LAYOUT, "SafeArea get success, area type is:%{public}d insets area is:%{public}s", 236923b3eb3cSopenharmony_ci static_cast<int32_t>(type), safeAreaInsets.ToString().c_str()); 237023b3eb3cSopenharmony_ci return safeAreaInsets; 237123b3eb3cSopenharmony_ci } 237223b3eb3cSopenharmony_ci return {}; 237323b3eb3cSopenharmony_ci} 237423b3eb3cSopenharmony_ci 237523b3eb3cSopenharmony_ciRect AceContainer::GetSessionAvoidAreaByType(uint32_t safeAreaType) 237623b3eb3cSopenharmony_ci{ 237723b3eb3cSopenharmony_ci Rosen::WSRect avoidArea; 237823b3eb3cSopenharmony_ci Rect sessionAvoidArea; 237923b3eb3cSopenharmony_ci if (safeAreaType == NG::SAFE_AREA_TYPE_SYSTEM) { 238023b3eb3cSopenharmony_ci auto ret = 238123b3eb3cSopenharmony_ci Rosen::RootScene::staticRootScene_->GetSessionRectByType(Rosen::AvoidAreaType::TYPE_SYSTEM, avoidArea); 238223b3eb3cSopenharmony_ci if (ret == Rosen::WMError::WM_OK) { 238323b3eb3cSopenharmony_ci sessionAvoidArea.SetRect(avoidArea.posX_, avoidArea.posY_, avoidArea.width_, avoidArea.height_); 238423b3eb3cSopenharmony_ci } 238523b3eb3cSopenharmony_ci } else if (safeAreaType == NG::SAFE_AREA_TYPE_KEYBOARD) { 238623b3eb3cSopenharmony_ci auto ret = 238723b3eb3cSopenharmony_ci Rosen::RootScene::staticRootScene_->GetSessionRectByType(Rosen::AvoidAreaType::TYPE_KEYBOARD, avoidArea); 238823b3eb3cSopenharmony_ci if (ret == Rosen::WMError::WM_OK) { 238923b3eb3cSopenharmony_ci sessionAvoidArea.SetRect(avoidArea.posX_, avoidArea.posY_, avoidArea.width_, avoidArea.height_); 239023b3eb3cSopenharmony_ci } 239123b3eb3cSopenharmony_ci } 239223b3eb3cSopenharmony_ci LOGI("GetSessionAvoidAreaByType safeAreaType: %{public}u, sessionAvoidArea; %{public}s", safeAreaType, 239323b3eb3cSopenharmony_ci sessionAvoidArea.ToString().c_str()); 239423b3eb3cSopenharmony_ci return sessionAvoidArea; 239523b3eb3cSopenharmony_ci} 239623b3eb3cSopenharmony_ci 239723b3eb3cSopenharmony_ciNG::SafeAreaInsets AceContainer::GetKeyboardSafeArea() 239823b3eb3cSopenharmony_ci{ 239923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, {}); 240023b3eb3cSopenharmony_ci Rosen::AvoidArea avoidArea; 240123b3eb3cSopenharmony_ci Rosen::WMError ret = uiWindow_->GetAvoidAreaByType(Rosen::AvoidAreaType::TYPE_KEYBOARD, avoidArea); 240223b3eb3cSopenharmony_ci if (ret == Rosen::WMError::WM_OK) { 240323b3eb3cSopenharmony_ci return ConvertAvoidArea(avoidArea); 240423b3eb3cSopenharmony_ci } 240523b3eb3cSopenharmony_ci return {}; 240623b3eb3cSopenharmony_ci} 240723b3eb3cSopenharmony_ci 240823b3eb3cSopenharmony_ciRosen::AvoidArea AceContainer::GetAvoidAreaByType(Rosen::AvoidAreaType type) 240923b3eb3cSopenharmony_ci{ 241023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, {}); 241123b3eb3cSopenharmony_ci Rosen::AvoidArea avoidArea; 241223b3eb3cSopenharmony_ci Rosen::WMError ret = uiWindow_->GetAvoidAreaByType(type, avoidArea); 241323b3eb3cSopenharmony_ci if (ret == Rosen::WMError::WM_OK) { 241423b3eb3cSopenharmony_ci return avoidArea; 241523b3eb3cSopenharmony_ci } 241623b3eb3cSopenharmony_ci return {}; 241723b3eb3cSopenharmony_ci} 241823b3eb3cSopenharmony_ci 241923b3eb3cSopenharmony_cistd::shared_ptr<OHOS::AbilityRuntime::Context> AceContainer::GetAbilityContextByModule( 242023b3eb3cSopenharmony_ci const std::string& bundle, const std::string& module) 242123b3eb3cSopenharmony_ci{ 242223b3eb3cSopenharmony_ci auto context = runtimeContext_.lock(); 242323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 242423b3eb3cSopenharmony_ci if (!isFormRender_ && !bundle.empty() && !module.empty()) { 242523b3eb3cSopenharmony_ci std::string encode = EncodeBundleAndModule(bundle, module); 242623b3eb3cSopenharmony_ci if (taskExecutor_->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { 242723b3eb3cSopenharmony_ci RecordResAdapter(encode); 242823b3eb3cSopenharmony_ci } else { 242923b3eb3cSopenharmony_ci taskExecutor_->PostTask( 243023b3eb3cSopenharmony_ci [encode, instanceId = instanceId_]() -> void { 243123b3eb3cSopenharmony_ci auto container = AceContainer::GetContainer(instanceId); 243223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 243323b3eb3cSopenharmony_ci container->RecordResAdapter(encode); 243423b3eb3cSopenharmony_ci }, 243523b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIRecordResAdapter"); 243623b3eb3cSopenharmony_ci } 243723b3eb3cSopenharmony_ci } 243823b3eb3cSopenharmony_ci return isFormRender_ ? nullptr : context->CreateModuleContext(bundle, module); 243923b3eb3cSopenharmony_ci} 244023b3eb3cSopenharmony_ci 244123b3eb3cSopenharmony_civoid AceContainer::CheckAndSetFontFamily() 244223b3eb3cSopenharmony_ci{ 244323b3eb3cSopenharmony_ci auto fontManager = pipelineContext_->GetFontManager(); 244423b3eb3cSopenharmony_ci CHECK_NULL_VOID(fontManager); 244523b3eb3cSopenharmony_ci if (fontManager->IsUseAppCustomFont()) { 244623b3eb3cSopenharmony_ci return; 244723b3eb3cSopenharmony_ci } 244823b3eb3cSopenharmony_ci std::string familyName = ""; 244923b3eb3cSopenharmony_ci std::string path = "/data/themes/a/app"; 245023b3eb3cSopenharmony_ci if (!IsFontFileExistInPath(path)) { 245123b3eb3cSopenharmony_ci path = "/data/themes/b/app"; 245223b3eb3cSopenharmony_ci if (!IsFontFileExistInPath(path)) { 245323b3eb3cSopenharmony_ci return; 245423b3eb3cSopenharmony_ci } 245523b3eb3cSopenharmony_ci } 245623b3eb3cSopenharmony_ci path = path.append("/fonts/"); 245723b3eb3cSopenharmony_ci familyName = GetFontFamilyName(path); 245823b3eb3cSopenharmony_ci if (familyName.empty()) { 245923b3eb3cSopenharmony_ci return; 246023b3eb3cSopenharmony_ci } 246123b3eb3cSopenharmony_ci path = path.append(familyName); 246223b3eb3cSopenharmony_ci if (isFormRender_) { 246323b3eb3cSopenharmony_ci // Resolve garbled characters caused by FRS multi-thread async 246423b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(g_mutexFormRenderFontFamily); 246523b3eb3cSopenharmony_ci fontManager->SetFontFamily(familyName.c_str(), path.c_str()); 246623b3eb3cSopenharmony_ci } else { 246723b3eb3cSopenharmony_ci fontManager->SetFontFamily(familyName.c_str(), path.c_str()); 246823b3eb3cSopenharmony_ci } 246923b3eb3cSopenharmony_ci} 247023b3eb3cSopenharmony_ci 247123b3eb3cSopenharmony_civoid AceContainer::SetFontScaleAndWeightScale( 247223b3eb3cSopenharmony_ci const ParsedConfig& parsedConfig, ConfigurationChange& configurationChange) 247323b3eb3cSopenharmony_ci{ 247423b3eb3cSopenharmony_ci if (!parsedConfig.fontScale.empty()) { 247523b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_AUTO_FILL, "parsedConfig fontScale: %{public}s", parsedConfig.fontScale.c_str()); 247623b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 247723b3eb3cSopenharmony_ci float fontSizeScale = StringUtils::StringToFloat(parsedConfig.fontScale); 247823b3eb3cSopenharmony_ci if (fontSizeScale != pipelineContext_->GetFontScale()) { 247923b3eb3cSopenharmony_ci SetFontScale(instanceId_, fontSizeScale); 248023b3eb3cSopenharmony_ci configurationChange.fontScaleUpdate = true; 248123b3eb3cSopenharmony_ci } 248223b3eb3cSopenharmony_ci } 248323b3eb3cSopenharmony_ci if (!parsedConfig.fontWeightScale.empty()) { 248423b3eb3cSopenharmony_ci TAG_LOGD(AceLogTag::ACE_AUTO_FILL, "parsedConfig fontWeightScale: %{public}s", 248523b3eb3cSopenharmony_ci parsedConfig.fontWeightScale.c_str()); 248623b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 248723b3eb3cSopenharmony_ci float fontWeightScale = StringUtils::StringToFloat(parsedConfig.fontWeightScale); 248823b3eb3cSopenharmony_ci if (fontWeightScale != pipelineContext_->GetFontWeightScale()) { 248923b3eb3cSopenharmony_ci SetFontWeightScale(instanceId_, fontWeightScale); 249023b3eb3cSopenharmony_ci configurationChange.fontWeightScaleUpdate = true; 249123b3eb3cSopenharmony_ci } 249223b3eb3cSopenharmony_ci } 249323b3eb3cSopenharmony_ci} 249423b3eb3cSopenharmony_ci 249523b3eb3cSopenharmony_civoid AceContainer::ReleaseResourceAdapter() 249623b3eb3cSopenharmony_ci{ 249723b3eb3cSopenharmony_ci for (auto &encode : resAdapterRecord_) { 249823b3eb3cSopenharmony_ci std::string bundleName; 249923b3eb3cSopenharmony_ci std::string moduleName; 250023b3eb3cSopenharmony_ci DecodeBundleAndModule(encode, bundleName, moduleName); 250123b3eb3cSopenharmony_ci ResourceManager::GetInstance().RemoveResourceAdapter(bundleName, moduleName); 250223b3eb3cSopenharmony_ci } 250323b3eb3cSopenharmony_ci resAdapterRecord_.clear(); 250423b3eb3cSopenharmony_ci 250523b3eb3cSopenharmony_ci if (isFormRender_) { 250623b3eb3cSopenharmony_ci auto runtimeContext = runtimeContext_.lock(); 250723b3eb3cSopenharmony_ci if (runtimeContext) { 250823b3eb3cSopenharmony_ci auto defaultBundleName = ""; 250923b3eb3cSopenharmony_ci auto defaultModuleName = ""; 251023b3eb3cSopenharmony_ci ResourceManager::GetInstance().RemoveResourceAdapter(defaultBundleName, defaultModuleName); 251123b3eb3cSopenharmony_ci 251223b3eb3cSopenharmony_ci auto bundleName = runtimeContext->GetBundleName(); 251323b3eb3cSopenharmony_ci auto moduleName = runtimeContext->GetHapModuleInfo()->name; 251423b3eb3cSopenharmony_ci ResourceManager::GetInstance().RemoveResourceAdapter(bundleName, moduleName); 251523b3eb3cSopenharmony_ci } 251623b3eb3cSopenharmony_ci } 251723b3eb3cSopenharmony_ci} 251823b3eb3cSopenharmony_ci 251923b3eb3cSopenharmony_ciDeviceOrientation AceContainer::ProcessDirectionUpdate( 252023b3eb3cSopenharmony_ci const ParsedConfig& parsedConfig, ConfigurationChange& configurationChange) 252123b3eb3cSopenharmony_ci{ 252223b3eb3cSopenharmony_ci if (!parsedConfig.direction.empty()) { 252323b3eb3cSopenharmony_ci auto resDirection = DeviceOrientation::ORIENTATION_UNDEFINED; 252423b3eb3cSopenharmony_ci if (parsedConfig.direction == "horizontal") { 252523b3eb3cSopenharmony_ci resDirection = DeviceOrientation::LANDSCAPE; 252623b3eb3cSopenharmony_ci } else if (parsedConfig.direction == "vertical") { 252723b3eb3cSopenharmony_ci resDirection = DeviceOrientation::PORTRAIT; 252823b3eb3cSopenharmony_ci } 252923b3eb3cSopenharmony_ci configurationChange.directionUpdate = true; 253023b3eb3cSopenharmony_ci return resDirection; 253123b3eb3cSopenharmony_ci } 253223b3eb3cSopenharmony_ci return DeviceOrientation::ORIENTATION_UNDEFINED; 253323b3eb3cSopenharmony_ci} 253423b3eb3cSopenharmony_ci 253523b3eb3cSopenharmony_civoid AceContainer::ProcessThemeUpdate(const ParsedConfig& parsedConfig, ConfigurationChange& configurationChange) 253623b3eb3cSopenharmony_ci{ 253723b3eb3cSopenharmony_ci if (!parsedConfig.themeTag.empty()) { 253823b3eb3cSopenharmony_ci std::unique_ptr<JsonValue> json = JsonUtil::ParseJsonString(parsedConfig.themeTag); 253923b3eb3cSopenharmony_ci int fontUpdate = json->GetInt("fonts"); 254023b3eb3cSopenharmony_ci configurationChange.fontUpdate = configurationChange.fontUpdate || fontUpdate; 254123b3eb3cSopenharmony_ci int iconUpdate = json->GetInt("icons"); 254223b3eb3cSopenharmony_ci configurationChange.iconUpdate = iconUpdate; 254323b3eb3cSopenharmony_ci int skinUpdate = json->GetInt("skin"); 254423b3eb3cSopenharmony_ci configurationChange.skinUpdate = skinUpdate; 254523b3eb3cSopenharmony_ci if (fontUpdate) { 254623b3eb3cSopenharmony_ci CheckAndSetFontFamily(); 254723b3eb3cSopenharmony_ci } 254823b3eb3cSopenharmony_ci } 254923b3eb3cSopenharmony_ci} 255023b3eb3cSopenharmony_ci 255123b3eb3cSopenharmony_civoid AceContainer::UpdateConfiguration(const ParsedConfig& parsedConfig, const std::string& configuration) 255223b3eb3cSopenharmony_ci{ 255323b3eb3cSopenharmony_ci if (!parsedConfig.IsValid()) { 255423b3eb3cSopenharmony_ci LOGW("AceContainer::OnConfigurationUpdated param is empty"); 255523b3eb3cSopenharmony_ci return; 255623b3eb3cSopenharmony_ci } 255723b3eb3cSopenharmony_ci ConfigurationChange configurationChange; 255823b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 255923b3eb3cSopenharmony_ci auto themeManager = pipelineContext_->GetThemeManager(); 256023b3eb3cSopenharmony_ci CHECK_NULL_VOID(themeManager); 256123b3eb3cSopenharmony_ci auto resConfig = GetResourceConfiguration(); 256223b3eb3cSopenharmony_ci if (!parsedConfig.colorMode.empty()) { 256323b3eb3cSopenharmony_ci configurationChange.colorModeUpdate = true; 256423b3eb3cSopenharmony_ci if (parsedConfig.colorMode == "dark") { 256523b3eb3cSopenharmony_ci SystemProperties::SetColorMode(ColorMode::DARK); 256623b3eb3cSopenharmony_ci SetColorScheme(ColorScheme::SCHEME_DARK); 256723b3eb3cSopenharmony_ci resConfig.SetColorMode(ColorMode::DARK); 256823b3eb3cSopenharmony_ci } else { 256923b3eb3cSopenharmony_ci SystemProperties::SetColorMode(ColorMode::LIGHT); 257023b3eb3cSopenharmony_ci SetColorScheme(ColorScheme::SCHEME_LIGHT); 257123b3eb3cSopenharmony_ci resConfig.SetColorMode(ColorMode::LIGHT); 257223b3eb3cSopenharmony_ci } 257323b3eb3cSopenharmony_ci } 257423b3eb3cSopenharmony_ci if (!parsedConfig.deviceAccess.empty()) { 257523b3eb3cSopenharmony_ci // Event of accessing mouse or keyboard 257623b3eb3cSopenharmony_ci SystemProperties::SetDeviceAccess(parsedConfig.deviceAccess == "true"); 257723b3eb3cSopenharmony_ci resConfig.SetDeviceAccess(parsedConfig.deviceAccess == "true"); 257823b3eb3cSopenharmony_ci } 257923b3eb3cSopenharmony_ci if (!parsedConfig.languageTag.empty()) { 258023b3eb3cSopenharmony_ci std::string language; 258123b3eb3cSopenharmony_ci std::string script; 258223b3eb3cSopenharmony_ci std::string region; 258323b3eb3cSopenharmony_ci Localization::ParseLocaleTag(parsedConfig.languageTag, language, script, region, false); 258423b3eb3cSopenharmony_ci if (!language.empty() || !script.empty() || !region.empty()) { 258523b3eb3cSopenharmony_ci configurationChange.languageUpdate = true; 258623b3eb3cSopenharmony_ci AceApplicationInfo::GetInstance().SetLocale(language, region, script, ""); 258723b3eb3cSopenharmony_ci } 258823b3eb3cSopenharmony_ci } 258923b3eb3cSopenharmony_ci if (!parsedConfig.fontFamily.empty()) { 259023b3eb3cSopenharmony_ci auto fontManager = pipelineContext_->GetFontManager(); 259123b3eb3cSopenharmony_ci CHECK_NULL_VOID(fontManager); 259223b3eb3cSopenharmony_ci configurationChange.fontUpdate = true; 259323b3eb3cSopenharmony_ci fontManager->SetAppCustomFont(parsedConfig.fontFamily); 259423b3eb3cSopenharmony_ci } 259523b3eb3cSopenharmony_ci if (!parsedConfig.direction.empty()) { 259623b3eb3cSopenharmony_ci resConfig.SetOrientation(ProcessDirectionUpdate(parsedConfig, configurationChange)); 259723b3eb3cSopenharmony_ci } 259823b3eb3cSopenharmony_ci if (!parsedConfig.densitydpi.empty()) { 259923b3eb3cSopenharmony_ci configurationChange.dpiUpdate = true; 260023b3eb3cSopenharmony_ci } 260123b3eb3cSopenharmony_ci ProcessThemeUpdate(parsedConfig, configurationChange); 260223b3eb3cSopenharmony_ci if (!parsedConfig.colorModeIsSetByApp.empty()) { 260323b3eb3cSopenharmony_ci resConfig.SetColorModeIsSetByApp(true); 260423b3eb3cSopenharmony_ci } 260523b3eb3cSopenharmony_ci if (!parsedConfig.mcc.empty()) { 260623b3eb3cSopenharmony_ci resConfig.SetMcc(StringUtils::StringToUint(parsedConfig.mcc)); 260723b3eb3cSopenharmony_ci } 260823b3eb3cSopenharmony_ci if (!parsedConfig.mnc.empty()) { 260923b3eb3cSopenharmony_ci resConfig.SetMnc(StringUtils::StringToUint(parsedConfig.mnc)); 261023b3eb3cSopenharmony_ci } 261123b3eb3cSopenharmony_ci if (!parsedConfig.preferredLanguage.empty()) { 261223b3eb3cSopenharmony_ci resConfig.SetPreferredLanguage(parsedConfig.preferredLanguage); 261323b3eb3cSopenharmony_ci configurationChange.languageUpdate = true; 261423b3eb3cSopenharmony_ci } 261523b3eb3cSopenharmony_ci SetFontScaleAndWeightScale(parsedConfig, configurationChange); 261623b3eb3cSopenharmony_ci SetResourceConfiguration(resConfig); 261723b3eb3cSopenharmony_ci themeManager->UpdateConfig(resConfig); 261823b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 261923b3eb3cSopenharmony_ci ResourceManager::GetInstance().UpdateResourceConfig(resConfig, !parsedConfig.themeTag.empty()); 262023b3eb3cSopenharmony_ci } 262123b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 262223b3eb3cSopenharmony_ci auto front = GetFrontend(); 262323b3eb3cSopenharmony_ci CHECK_NULL_VOID(front); 262423b3eb3cSopenharmony_ci if (!configurationChange.directionUpdate && !configurationChange.dpiUpdate) { 262523b3eb3cSopenharmony_ci front->OnConfigurationUpdated(configuration); 262623b3eb3cSopenharmony_ci } 262723b3eb3cSopenharmony_ci#ifdef PLUGIN_COMPONENT_SUPPORTED 262823b3eb3cSopenharmony_ci OHOS::Ace::PluginManager::GetInstance().UpdateConfigurationInPlugin(resConfig, taskExecutor_); 262923b3eb3cSopenharmony_ci#endif 263023b3eb3cSopenharmony_ci NotifyConfigurationChange(!parsedConfig.deviceAccess.empty(), configurationChange); 263123b3eb3cSopenharmony_ci NotifyConfigToSubContainers(parsedConfig, configuration); 263223b3eb3cSopenharmony_ci // change color mode and theme to clear image cache 263323b3eb3cSopenharmony_ci pipelineContext_->ClearImageCache(); 263423b3eb3cSopenharmony_ci} 263523b3eb3cSopenharmony_ci 263623b3eb3cSopenharmony_civoid AceContainer::NotifyConfigToSubContainers(const ParsedConfig& parsedConfig, const std::string& configuration) 263723b3eb3cSopenharmony_ci{ 263823b3eb3cSopenharmony_ci for (auto& item : configurationChangedCallbacks_) { 263923b3eb3cSopenharmony_ci if (item.second) { 264023b3eb3cSopenharmony_ci item.second(parsedConfig, configuration); 264123b3eb3cSopenharmony_ci } 264223b3eb3cSopenharmony_ci } 264323b3eb3cSopenharmony_ci} 264423b3eb3cSopenharmony_ci 264523b3eb3cSopenharmony_civoid AceContainer::NotifyConfigurationChange( 264623b3eb3cSopenharmony_ci bool needReloadTransition, const ConfigurationChange& configurationChange) 264723b3eb3cSopenharmony_ci{ 264823b3eb3cSopenharmony_ci auto taskExecutor = GetTaskExecutor(); 264923b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 265023b3eb3cSopenharmony_ci taskExecutor->PostTask( 265123b3eb3cSopenharmony_ci [instanceId = instanceId_, weak = WeakClaim(this), needReloadTransition, configurationChange]() { 265223b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 265323b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 265423b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 265523b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 265623b3eb3cSopenharmony_ci if (frontend) { 265723b3eb3cSopenharmony_ci LOGI("AceContainer UpdateConfiguration frontend MarkNeedUpdate"); 265823b3eb3cSopenharmony_ci frontend->FlushReload(); 265923b3eb3cSopenharmony_ci } 266023b3eb3cSopenharmony_ci auto taskExecutor = container->GetTaskExecutor(); 266123b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 266223b3eb3cSopenharmony_ci taskExecutor->PostTask( 266323b3eb3cSopenharmony_ci [instanceId, weak, needReloadTransition, configurationChange]() { 266423b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 266523b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 266623b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 266723b3eb3cSopenharmony_ci auto pipeline = container->GetPipelineContext(); 266823b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipeline); 266923b3eb3cSopenharmony_ci auto themeManager = pipeline->GetThemeManager(); 267023b3eb3cSopenharmony_ci CHECK_NULL_VOID(themeManager); 267123b3eb3cSopenharmony_ci if (configurationChange.directionUpdate && 267223b3eb3cSopenharmony_ci (themeManager->GetResourceLimitKeys() & DIRECTION_KEY) == 0) { 267323b3eb3cSopenharmony_ci return; 267423b3eb3cSopenharmony_ci } 267523b3eb3cSopenharmony_ci if (configurationChange.colorModeUpdate && !container->IsUseCustomBg() && 267623b3eb3cSopenharmony_ci !container->IsTransparentBg()) { 267723b3eb3cSopenharmony_ci pipeline->SetAppBgColor(themeManager->GetBackgroundColor()); 267823b3eb3cSopenharmony_ci } 267923b3eb3cSopenharmony_ci pipeline->NotifyConfigurationChange(); 268023b3eb3cSopenharmony_ci if (configurationChange.IsNeedUpdate()) { 268123b3eb3cSopenharmony_ci pipeline->FlushReload(configurationChange); 268223b3eb3cSopenharmony_ci } 268323b3eb3cSopenharmony_ci if (needReloadTransition) { 268423b3eb3cSopenharmony_ci // reload transition animation 268523b3eb3cSopenharmony_ci pipeline->FlushReloadTransition(); 268623b3eb3cSopenharmony_ci } 268723b3eb3cSopenharmony_ci pipeline->ChangeDarkModeBrightness(); 268823b3eb3cSopenharmony_ci }, 268923b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIFlushReloadTransition"); 269023b3eb3cSopenharmony_ci }, 269123b3eb3cSopenharmony_ci TaskExecutor::TaskType::JS, "ArkUINotifyConfigurationChange"); 269223b3eb3cSopenharmony_ci} 269323b3eb3cSopenharmony_ci 269423b3eb3cSopenharmony_civoid AceContainer::HotReload() 269523b3eb3cSopenharmony_ci{ 269623b3eb3cSopenharmony_ci auto taskExecutor = GetTaskExecutor(); 269723b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor); 269823b3eb3cSopenharmony_ci taskExecutor->PostTask( 269923b3eb3cSopenharmony_ci [instanceId = instanceId_, weak = WeakClaim(this)]() { 270023b3eb3cSopenharmony_ci ContainerScope scope(instanceId); 270123b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 270223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 270323b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 270423b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 270523b3eb3cSopenharmony_ci LOGI("AceContainer Flush Frontend for HotReload"); 270623b3eb3cSopenharmony_ci frontend->HotReload(); 270723b3eb3cSopenharmony_ci 270823b3eb3cSopenharmony_ci auto pipeline = container->GetPipelineContext(); 270923b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipeline); 271023b3eb3cSopenharmony_ci pipeline->FlushReload(ConfigurationChange()); 271123b3eb3cSopenharmony_ci }, 271223b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIHotReload"); 271323b3eb3cSopenharmony_ci} 271423b3eb3cSopenharmony_ci 271523b3eb3cSopenharmony_civoid AceContainer::SetToken(sptr<IRemoteObject>& token) 271623b3eb3cSopenharmony_ci{ 271723b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(cardTokensMutex_); 271823b3eb3cSopenharmony_ci if (token) { 271923b3eb3cSopenharmony_ci token_ = token; 272023b3eb3cSopenharmony_ci } 272123b3eb3cSopenharmony_ci} 272223b3eb3cSopenharmony_ci 272323b3eb3cSopenharmony_cisptr<IRemoteObject> AceContainer::GetToken() 272423b3eb3cSopenharmony_ci{ 272523b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(cardTokensMutex_); 272623b3eb3cSopenharmony_ci if (token_) { 272723b3eb3cSopenharmony_ci return token_; 272823b3eb3cSopenharmony_ci } 272923b3eb3cSopenharmony_ci LOGE("fail to get Token"); 273023b3eb3cSopenharmony_ci return nullptr; 273123b3eb3cSopenharmony_ci} 273223b3eb3cSopenharmony_ci 273323b3eb3cSopenharmony_civoid AceContainer::SetParentToken(sptr<IRemoteObject>& token) 273423b3eb3cSopenharmony_ci{ 273523b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(cardTokensMutex_); 273623b3eb3cSopenharmony_ci if (token) { 273723b3eb3cSopenharmony_ci parentToken_ = token; 273823b3eb3cSopenharmony_ci } 273923b3eb3cSopenharmony_ci} 274023b3eb3cSopenharmony_ci 274123b3eb3cSopenharmony_cisptr<IRemoteObject> AceContainer::GetParentToken() 274223b3eb3cSopenharmony_ci{ 274323b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(cardTokensMutex_); 274423b3eb3cSopenharmony_ci return parentToken_; 274523b3eb3cSopenharmony_ci} 274623b3eb3cSopenharmony_ci 274723b3eb3cSopenharmony_ci// ArkTsCard start 274823b3eb3cSopenharmony_cistd::shared_ptr<Rosen::RSSurfaceNode> AceContainer::GetFormSurfaceNode(int32_t instanceId) 274923b3eb3cSopenharmony_ci{ 275023b3eb3cSopenharmony_ci auto container = AceType::DynamicCast<AceContainer>(AceEngine::Get().GetContainer(instanceId)); 275123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(container, nullptr); 275223b3eb3cSopenharmony_ci auto context = AceType::DynamicCast<NG::PipelineContext>(container->GetPipelineContext()); 275323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(context, nullptr); 275423b3eb3cSopenharmony_ci auto window = static_cast<FormRenderWindow*>(context->GetWindow()); 275523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(window, nullptr); 275623b3eb3cSopenharmony_ci return window->GetRSSurfaceNode(); 275723b3eb3cSopenharmony_ci} 275823b3eb3cSopenharmony_ci 275923b3eb3cSopenharmony_civoid AceContainer::UpdateFormData(const std::string& data) 276023b3eb3cSopenharmony_ci{ 276123b3eb3cSopenharmony_ci#ifdef FORM_SUPPORTED 276223b3eb3cSopenharmony_ci auto frontend = AceType::DynamicCast<FormFrontendDeclarative>(frontend_); 276323b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 276423b3eb3cSopenharmony_ci frontend->UpdateData(data); 276523b3eb3cSopenharmony_ci#endif 276623b3eb3cSopenharmony_ci} 276723b3eb3cSopenharmony_ci 276823b3eb3cSopenharmony_civoid AceContainer::UpdateFormSharedImage(const std::map<std::string, sptr<AppExecFwk::FormAshmem>>& imageDataMap) 276923b3eb3cSopenharmony_ci{ 277023b3eb3cSopenharmony_ci std::vector<std::string> picNameArray; 277123b3eb3cSopenharmony_ci std::vector<int> fileDescriptorArray; 277223b3eb3cSopenharmony_ci std::vector<int> byteLenArray; 277323b3eb3cSopenharmony_ci if (!imageDataMap.empty()) { 277423b3eb3cSopenharmony_ci for (auto& imageData : imageDataMap) { 277523b3eb3cSopenharmony_ci picNameArray.push_back(imageData.first); 277623b3eb3cSopenharmony_ci fileDescriptorArray.push_back(imageData.second->GetAshmemFd()); 277723b3eb3cSopenharmony_ci byteLenArray.push_back(imageData.second->GetAshmemSize()); 277823b3eb3cSopenharmony_ci } 277923b3eb3cSopenharmony_ci GetNamesOfSharedImage(picNameArray); 278023b3eb3cSopenharmony_ci UpdateSharedImage(picNameArray, byteLenArray, fileDescriptorArray); 278123b3eb3cSopenharmony_ci } 278223b3eb3cSopenharmony_ci} 278323b3eb3cSopenharmony_ci 278423b3eb3cSopenharmony_civoid AceContainer::UpdateResource() 278523b3eb3cSopenharmony_ci{ 278623b3eb3cSopenharmony_ci // Reload theme and resource 278723b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipelineContext_); 278823b3eb3cSopenharmony_ci 278923b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 279023b3eb3cSopenharmony_ci auto context = runtimeContext_.lock(); 279123b3eb3cSopenharmony_ci auto abilityInfo = abilityInfo_.lock(); 279223b3eb3cSopenharmony_ci if (pipelineContext_->IsFormRender()) { 279323b3eb3cSopenharmony_ci ReleaseResourceAdapter(); 279423b3eb3cSopenharmony_ci } 279523b3eb3cSopenharmony_ci InitResourceAndThemeManager( 279623b3eb3cSopenharmony_ci pipelineContext_, assetManager_, colorScheme_, resourceInfo_, context, abilityInfo, true); 279723b3eb3cSopenharmony_ci } else { 279823b3eb3cSopenharmony_ci ThemeConstants::InitDeviceType(); 279923b3eb3cSopenharmony_ci auto themeManager = AceType::MakeRefPtr<ThemeManagerImpl>(); 280023b3eb3cSopenharmony_ci pipelineContext_->SetThemeManager(themeManager); 280123b3eb3cSopenharmony_ci themeManager->InitResource(resourceInfo_); 280223b3eb3cSopenharmony_ci themeManager->SetColorScheme(colorScheme_); 280323b3eb3cSopenharmony_ci themeManager->LoadCustomTheme(assetManager_); 280423b3eb3cSopenharmony_ci themeManager->LoadResourceThemes(); 280523b3eb3cSopenharmony_ci } 280623b3eb3cSopenharmony_ci 280723b3eb3cSopenharmony_ci auto cache = pipelineContext_->GetImageCache(); 280823b3eb3cSopenharmony_ci if (cache) { 280923b3eb3cSopenharmony_ci cache->Clear(); 281023b3eb3cSopenharmony_ci } 281123b3eb3cSopenharmony_ci} 281223b3eb3cSopenharmony_ci 281323b3eb3cSopenharmony_civoid AceContainer::GetNamesOfSharedImage(std::vector<std::string>& picNameArray) 281423b3eb3cSopenharmony_ci{ 281523b3eb3cSopenharmony_ci if (picNameArray.empty()) { 281623b3eb3cSopenharmony_ci LOGE("picNameArray is null!"); 281723b3eb3cSopenharmony_ci return; 281823b3eb3cSopenharmony_ci } 281923b3eb3cSopenharmony_ci auto context = AceType::DynamicCast<NG::PipelineContext>(GetPipelineContext()); 282023b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 282123b3eb3cSopenharmony_ci auto sharedImageManager = context->GetOrCreateSharedImageManager(); 282223b3eb3cSopenharmony_ci auto nameSize = picNameArray.size(); 282323b3eb3cSopenharmony_ci for (uint32_t i = 0; i < nameSize; i++) { 282423b3eb3cSopenharmony_ci // get name of picture 282523b3eb3cSopenharmony_ci auto name = picNameArray[i]; 282623b3eb3cSopenharmony_ci sharedImageManager->AddPictureNamesToReloadMap(std::move(name)); 282723b3eb3cSopenharmony_ci } 282823b3eb3cSopenharmony_ci} 282923b3eb3cSopenharmony_ci 283023b3eb3cSopenharmony_civoid AceContainer::UpdateSharedImage( 283123b3eb3cSopenharmony_ci std::vector<std::string>& picNameArray, std::vector<int32_t>& byteLenArray, std::vector<int>& fileDescriptorArray) 283223b3eb3cSopenharmony_ci{ 283323b3eb3cSopenharmony_ci auto context = GetPipelineContext(); 283423b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 283523b3eb3cSopenharmony_ci if (picNameArray.empty() || byteLenArray.empty() || fileDescriptorArray.empty()) { 283623b3eb3cSopenharmony_ci LOGE("array is null! when try UpdateSharedImage"); 283723b3eb3cSopenharmony_ci return; 283823b3eb3cSopenharmony_ci } 283923b3eb3cSopenharmony_ci auto nameArraySize = picNameArray.size(); 284023b3eb3cSopenharmony_ci if (nameArraySize != byteLenArray.size()) { 284123b3eb3cSopenharmony_ci LOGE("nameArraySize does not equal to fileDescriptorArraySize, please check!"); 284223b3eb3cSopenharmony_ci return; 284323b3eb3cSopenharmony_ci } 284423b3eb3cSopenharmony_ci if (nameArraySize != fileDescriptorArray.size()) { 284523b3eb3cSopenharmony_ci LOGE("nameArraySize does not equal to fileDescriptorArraySize, please check!"); 284623b3eb3cSopenharmony_ci return; 284723b3eb3cSopenharmony_ci } 284823b3eb3cSopenharmony_ci // now it can be assured that all three arrays are of the same size 284923b3eb3cSopenharmony_ci 285023b3eb3cSopenharmony_ci std::string picNameCopy; 285123b3eb3cSopenharmony_ci for (uint32_t i = 0; i < nameArraySize; i++) { 285223b3eb3cSopenharmony_ci // get name of picture 285323b3eb3cSopenharmony_ci auto picName = picNameArray[i]; 285423b3eb3cSopenharmony_ci // save a copy of picName and ReleaseStringUTFChars immediately to avoid memory leak 285523b3eb3cSopenharmony_ci picNameCopy = picName; 285623b3eb3cSopenharmony_ci 285723b3eb3cSopenharmony_ci // get fd ID 285823b3eb3cSopenharmony_ci auto fd = fileDescriptorArray[i]; 285923b3eb3cSopenharmony_ci 286023b3eb3cSopenharmony_ci auto newFd = dup(fd); 286123b3eb3cSopenharmony_ci if (newFd < 0) { 286223b3eb3cSopenharmony_ci LOGE("dup fd fail, fail reason: %{public}s, fd: %{public}d, picName: %{private}s, length: %{public}d", 286323b3eb3cSopenharmony_ci strerror(errno), fd, picNameCopy.c_str(), byteLenArray[i]); 286423b3eb3cSopenharmony_ci continue; 286523b3eb3cSopenharmony_ci } 286623b3eb3cSopenharmony_ci 286723b3eb3cSopenharmony_ci auto ashmem = Ashmem(newFd, byteLenArray[i]); 286823b3eb3cSopenharmony_ci GetImageDataFromAshmem(picNameCopy, ashmem, context, byteLenArray[i]); 286923b3eb3cSopenharmony_ci ashmem.UnmapAshmem(); 287023b3eb3cSopenharmony_ci ashmem.CloseAshmem(); 287123b3eb3cSopenharmony_ci } 287223b3eb3cSopenharmony_ci} 287323b3eb3cSopenharmony_ci 287423b3eb3cSopenharmony_civoid AceContainer::GetImageDataFromAshmem( 287523b3eb3cSopenharmony_ci const std::string& picName, Ashmem& ashmem, const RefPtr<PipelineBase>& pipelineContext, int len) 287623b3eb3cSopenharmony_ci{ 287723b3eb3cSopenharmony_ci bool ret = ashmem.MapReadOnlyAshmem(); 287823b3eb3cSopenharmony_ci // if any exception causes a [return] before [AddSharedImage], the memory image will not show because [RenderImage] 287923b3eb3cSopenharmony_ci // will never be notified to start loading. 288023b3eb3cSopenharmony_ci if (!ret) { 288123b3eb3cSopenharmony_ci LOGE("MapReadOnlyAshmem fail, fail reason: %{public}s, picName: %{private}s, length: %{public}d, " 288223b3eb3cSopenharmony_ci "fd: %{public}d", 288323b3eb3cSopenharmony_ci strerror(errno), picName.c_str(), len, ashmem.GetAshmemFd()); 288423b3eb3cSopenharmony_ci return; 288523b3eb3cSopenharmony_ci } 288623b3eb3cSopenharmony_ci const uint8_t* imageData = reinterpret_cast<const uint8_t*>(ashmem.ReadFromAshmem(len, 0)); 288723b3eb3cSopenharmony_ci if (imageData == nullptr) { 288823b3eb3cSopenharmony_ci LOGE("imageData is nullptr, errno is: %{public}s, picName: %{private}s, length: %{public}d, fd: %{public}d", 288923b3eb3cSopenharmony_ci strerror(errno), picName.c_str(), len, ashmem.GetAshmemFd()); 289023b3eb3cSopenharmony_ci return; 289123b3eb3cSopenharmony_ci } 289223b3eb3cSopenharmony_ci auto context = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 289323b3eb3cSopenharmony_ci CHECK_NULL_VOID(context); 289423b3eb3cSopenharmony_ci RefPtr<SharedImageManager> sharedImageManager = context->GetOrCreateSharedImageManager(); 289523b3eb3cSopenharmony_ci if (sharedImageManager) { 289623b3eb3cSopenharmony_ci // read image data from shared memory and save a copy to sharedImageManager 289723b3eb3cSopenharmony_ci sharedImageManager->AddSharedImage(picName, std::vector<uint8_t>(imageData, imageData + len)); 289823b3eb3cSopenharmony_ci } 289923b3eb3cSopenharmony_ci} 290023b3eb3cSopenharmony_ci 290123b3eb3cSopenharmony_cibool AceContainer::IsScenceBoardWindow() 290223b3eb3cSopenharmony_ci{ 290323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 290423b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_SCENE_BOARD; 290523b3eb3cSopenharmony_ci} 290623b3eb3cSopenharmony_ci 290723b3eb3cSopenharmony_cibool AceContainer::IsUIExtensionWindow() 290823b3eb3cSopenharmony_ci{ 290923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 291023b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION; 291123b3eb3cSopenharmony_ci} 291223b3eb3cSopenharmony_ci 291323b3eb3cSopenharmony_cibool AceContainer::IsSceneBoardEnabled() 291423b3eb3cSopenharmony_ci{ 291523b3eb3cSopenharmony_ci return Rosen::SceneBoardJudgement::IsSceneBoardEnabled(); 291623b3eb3cSopenharmony_ci} 291723b3eb3cSopenharmony_ci// ArkTsCard end 291823b3eb3cSopenharmony_ci 291923b3eb3cSopenharmony_cibool AceContainer::IsMainWindow() const 292023b3eb3cSopenharmony_ci{ 292123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 292223b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; 292323b3eb3cSopenharmony_ci} 292423b3eb3cSopenharmony_ci 292523b3eb3cSopenharmony_cibool AceContainer::IsSubWindow() const 292623b3eb3cSopenharmony_ci{ 292723b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 292823b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW; 292923b3eb3cSopenharmony_ci} 293023b3eb3cSopenharmony_ci 293123b3eb3cSopenharmony_cibool AceContainer::IsDialogWindow() const 293223b3eb3cSopenharmony_ci{ 293323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 293423b3eb3cSopenharmony_ci return uiWindow_->GetType() == Rosen::WindowType::WINDOW_TYPE_DIALOG; 293523b3eb3cSopenharmony_ci} 293623b3eb3cSopenharmony_ci 293723b3eb3cSopenharmony_cibool AceContainer::IsSystemWindow() const 293823b3eb3cSopenharmony_ci{ 293923b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 294023b3eb3cSopenharmony_ci return uiWindow_->GetType() >= Rosen::WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && 294123b3eb3cSopenharmony_ci uiWindow_->GetType() <= Rosen::WindowType::ABOVE_APP_SYSTEM_WINDOW_END; 294223b3eb3cSopenharmony_ci} 294323b3eb3cSopenharmony_ci 294423b3eb3cSopenharmony_ciuint32_t AceContainer::GetParentWindowType() const 294523b3eb3cSopenharmony_ci{ 294623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, DEFAULT_WINDOW_TYPE); 294723b3eb3cSopenharmony_ci return static_cast<uint32_t>(uiWindow_->GetParentWindowType()); 294823b3eb3cSopenharmony_ci} 294923b3eb3cSopenharmony_ci 295023b3eb3cSopenharmony_ciuint32_t AceContainer::GetWindowType() const 295123b3eb3cSopenharmony_ci{ 295223b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, DEFAULT_WINDOW_TYPE); 295323b3eb3cSopenharmony_ci return static_cast<uint32_t>(uiWindow_->GetType()); 295423b3eb3cSopenharmony_ci} 295523b3eb3cSopenharmony_ci 295623b3eb3cSopenharmony_cibool AceContainer::IsHostMainWindow() const 295723b3eb3cSopenharmony_ci{ 295823b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 295923b3eb3cSopenharmony_ci return uiWindow_->GetParentWindowType() == Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW; 296023b3eb3cSopenharmony_ci} 296123b3eb3cSopenharmony_ci 296223b3eb3cSopenharmony_cibool AceContainer::IsHostSubWindow() const 296323b3eb3cSopenharmony_ci{ 296423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 296523b3eb3cSopenharmony_ci return uiWindow_->GetParentWindowType() == Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW; 296623b3eb3cSopenharmony_ci} 296723b3eb3cSopenharmony_ci 296823b3eb3cSopenharmony_cibool AceContainer::IsHostDialogWindow() const 296923b3eb3cSopenharmony_ci{ 297023b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 297123b3eb3cSopenharmony_ci return uiWindow_->GetParentWindowType() == Rosen::WindowType::WINDOW_TYPE_DIALOG; 297223b3eb3cSopenharmony_ci} 297323b3eb3cSopenharmony_ci 297423b3eb3cSopenharmony_cibool AceContainer::IsHostSystemWindow() const 297523b3eb3cSopenharmony_ci{ 297623b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 297723b3eb3cSopenharmony_ci return uiWindow_->GetParentWindowType() >= Rosen::WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && 297823b3eb3cSopenharmony_ci uiWindow_->GetParentWindowType() <= Rosen::WindowType::ABOVE_APP_SYSTEM_WINDOW_END; 297923b3eb3cSopenharmony_ci} 298023b3eb3cSopenharmony_ci 298123b3eb3cSopenharmony_cibool AceContainer::IsHostSceneBoardWindow() const 298223b3eb3cSopenharmony_ci{ 298323b3eb3cSopenharmony_ci CHECK_NULL_RETURN(uiWindow_, false); 298423b3eb3cSopenharmony_ci return uiWindow_->GetParentWindowType() == Rosen::WindowType::WINDOW_TYPE_SCENE_BOARD; 298523b3eb3cSopenharmony_ci} 298623b3eb3cSopenharmony_ci 298723b3eb3cSopenharmony_ciuint32_t AceContainer::GetParentMainWindowId(uint32_t currentWindowId) const 298823b3eb3cSopenharmony_ci{ 298923b3eb3cSopenharmony_ci uint32_t parentMainWindowId = 0; 299023b3eb3cSopenharmony_ci if (uiWindow_) { 299123b3eb3cSopenharmony_ci parentMainWindowId = uiWindow_->GetParentMainWindowId(currentWindowId); 299223b3eb3cSopenharmony_ci if (parentMainWindowId == 0) { 299323b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, 299423b3eb3cSopenharmony_ci "GetParentMainWindowId, current windowId: %{public}d, main windowId: %{public}d", 299523b3eb3cSopenharmony_ci currentWindowId, parentMainWindowId); 299623b3eb3cSopenharmony_ci } 299723b3eb3cSopenharmony_ci } else { 299823b3eb3cSopenharmony_ci TAG_LOGE(AceLogTag::ACE_SUB_WINDOW, "Window in container is nullptr when getting main windowId"); 299923b3eb3cSopenharmony_ci } 300023b3eb3cSopenharmony_ci return parentMainWindowId; 300123b3eb3cSopenharmony_ci} 300223b3eb3cSopenharmony_ci 300323b3eb3cSopenharmony_civoid AceContainer::SetCurPointerEvent(const std::shared_ptr<MMI::PointerEvent>& currentEvent) 300423b3eb3cSopenharmony_ci{ 300523b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(pointerEventMutex_); 300623b3eb3cSopenharmony_ci CHECK_NULL_VOID(currentEvent); 300723b3eb3cSopenharmony_ci currentPointerEvent_ = currentEvent; 300823b3eb3cSopenharmony_ci auto pointerAction = currentEvent->GetPointerAction(); 300923b3eb3cSopenharmony_ci if (pointerAction == MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW || 301023b3eb3cSopenharmony_ci pointerAction == MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW) { 301123b3eb3cSopenharmony_ci return; 301223b3eb3cSopenharmony_ci } 301323b3eb3cSopenharmony_ci MMI::PointerEvent::PointerItem pointerItem; 301423b3eb3cSopenharmony_ci currentEvent->GetPointerItem(currentEvent->GetPointerId(), pointerItem); 301523b3eb3cSopenharmony_ci int32_t originId = pointerItem.GetOriginPointerId(); 301623b3eb3cSopenharmony_ci currentEvents_[originId] = currentEvent; 301723b3eb3cSopenharmony_ci auto callbacksIter = stopDragCallbackMap_.begin(); 301823b3eb3cSopenharmony_ci while (callbacksIter != stopDragCallbackMap_.end()) { 301923b3eb3cSopenharmony_ci auto pointerId = callbacksIter->first; 302023b3eb3cSopenharmony_ci MMI::PointerEvent::PointerItem pointerItem; 302123b3eb3cSopenharmony_ci if (!currentEvent->GetPointerItem(pointerId, pointerItem)) { 302223b3eb3cSopenharmony_ci for (const auto& callback : callbacksIter->second) { 302323b3eb3cSopenharmony_ci if (callback) { 302423b3eb3cSopenharmony_ci callback(); 302523b3eb3cSopenharmony_ci } 302623b3eb3cSopenharmony_ci } 302723b3eb3cSopenharmony_ci callbacksIter = stopDragCallbackMap_.erase(callbacksIter); 302823b3eb3cSopenharmony_ci } else { 302923b3eb3cSopenharmony_ci if (!pointerItem.IsPressed()) { 303023b3eb3cSopenharmony_ci for (const auto& callback : callbacksIter->second) { 303123b3eb3cSopenharmony_ci if (callback) { 303223b3eb3cSopenharmony_ci callback(); 303323b3eb3cSopenharmony_ci } 303423b3eb3cSopenharmony_ci } 303523b3eb3cSopenharmony_ci callbacksIter = stopDragCallbackMap_.erase(callbacksIter); 303623b3eb3cSopenharmony_ci } else { 303723b3eb3cSopenharmony_ci ++callbacksIter; 303823b3eb3cSopenharmony_ci } 303923b3eb3cSopenharmony_ci } 304023b3eb3cSopenharmony_ci } 304123b3eb3cSopenharmony_ci} 304223b3eb3cSopenharmony_ci 304323b3eb3cSopenharmony_cibool AceContainer::GetCurPointerEventInfo( 304423b3eb3cSopenharmony_ci int32_t& pointerId, int32_t& globalX, int32_t& globalY, int32_t& sourceType, 304523b3eb3cSopenharmony_ci int32_t& sourceTool, StopDragCallback&& stopDragCallback) 304623b3eb3cSopenharmony_ci{ 304723b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(pointerEventMutex_); 304823b3eb3cSopenharmony_ci MMI::PointerEvent::PointerItem pointerItem; 304923b3eb3cSopenharmony_ci auto iter = currentEvents_.find(pointerId); 305023b3eb3cSopenharmony_ci if (iter == currentEvents_.end()) { 305123b3eb3cSopenharmony_ci return false; 305223b3eb3cSopenharmony_ci } 305323b3eb3cSopenharmony_ci 305423b3eb3cSopenharmony_ci auto currentPointerEvent = iter->second; 305523b3eb3cSopenharmony_ci CHECK_NULL_RETURN(currentPointerEvent, false); 305623b3eb3cSopenharmony_ci pointerId = currentPointerEvent->GetPointerId(); 305723b3eb3cSopenharmony_ci if (!currentPointerEvent->GetPointerItem(pointerId, pointerItem) || !pointerItem.IsPressed()) { 305823b3eb3cSopenharmony_ci return false; 305923b3eb3cSopenharmony_ci } 306023b3eb3cSopenharmony_ci sourceType = currentPointerEvent->GetSourceType(); 306123b3eb3cSopenharmony_ci globalX = pointerItem.GetDisplayX(); 306223b3eb3cSopenharmony_ci globalY = pointerItem.GetDisplayY(); 306323b3eb3cSopenharmony_ci sourceTool = pointerItem.GetToolType(); 306423b3eb3cSopenharmony_ci RegisterStopDragCallback(pointerId, std::move(stopDragCallback)); 306523b3eb3cSopenharmony_ci return true; 306623b3eb3cSopenharmony_ci} 306723b3eb3cSopenharmony_ci 306823b3eb3cSopenharmony_cibool AceContainer::GetCurPointerEventSourceType(int32_t& sourceType) 306923b3eb3cSopenharmony_ci{ 307023b3eb3cSopenharmony_ci std::lock_guard<std::mutex> lock(pointerEventMutex_); 307123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(currentPointerEvent_, false); 307223b3eb3cSopenharmony_ci MMI::PointerEvent::PointerItem pointerItem; 307323b3eb3cSopenharmony_ci sourceType = currentPointerEvent_->GetSourceType(); 307423b3eb3cSopenharmony_ci return true; 307523b3eb3cSopenharmony_ci} 307623b3eb3cSopenharmony_ci 307723b3eb3cSopenharmony_civoid AceContainer::RegisterStopDragCallback(int32_t pointerId, StopDragCallback&& stopDragCallback) 307823b3eb3cSopenharmony_ci{ 307923b3eb3cSopenharmony_ci auto iter = stopDragCallbackMap_.find(pointerId); 308023b3eb3cSopenharmony_ci if (iter != stopDragCallbackMap_.end()) { 308123b3eb3cSopenharmony_ci iter->second.emplace_back(std::move(stopDragCallback)); 308223b3eb3cSopenharmony_ci } else { 308323b3eb3cSopenharmony_ci std::list<StopDragCallback> list; 308423b3eb3cSopenharmony_ci list.emplace_back(std::move(stopDragCallback)); 308523b3eb3cSopenharmony_ci stopDragCallbackMap_.emplace(pointerId, list); 308623b3eb3cSopenharmony_ci } 308723b3eb3cSopenharmony_ci} 308823b3eb3cSopenharmony_ci 308923b3eb3cSopenharmony_civoid AceContainer::SearchElementInfoByAccessibilityIdNG( 309023b3eb3cSopenharmony_ci int64_t elementId, int32_t mode, int64_t baseParent, 309123b3eb3cSopenharmony_ci std::list<Accessibility::AccessibilityElementInfo>& output) 309223b3eb3cSopenharmony_ci{ 309323b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor_); 309423b3eb3cSopenharmony_ci taskExecutor_->PostSyncTaskTimeout( 309523b3eb3cSopenharmony_ci [weak = WeakClaim(this), elementId, mode, baseParent, &output]() { 309623b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 309723b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 309823b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 309923b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 310023b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 310123b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 310223b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 310323b3eb3cSopenharmony_ci auto accessibilityManager = frontend->GetAccessibilityManager(); 310423b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 310523b3eb3cSopenharmony_ci accessibilityManager->SearchElementInfoByAccessibilityIdNG( 310623b3eb3cSopenharmony_ci elementId, mode, output, ngPipeline, baseParent); 310723b3eb3cSopenharmony_ci }, 310823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, SEARCH_ELEMENT_TIMEOUT_TIME, "ArkUISearchElementInfoById"); 310923b3eb3cSopenharmony_ci} 311023b3eb3cSopenharmony_ci 311123b3eb3cSopenharmony_civoid AceContainer::SearchElementInfosByTextNG( 311223b3eb3cSopenharmony_ci int64_t elementId, const std::string& text, int64_t baseParent, 311323b3eb3cSopenharmony_ci std::list<Accessibility::AccessibilityElementInfo>& output) 311423b3eb3cSopenharmony_ci{ 311523b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor_); 311623b3eb3cSopenharmony_ci taskExecutor_->PostSyncTaskTimeout( 311723b3eb3cSopenharmony_ci [weak = WeakClaim(this), elementId, &text, baseParent, &output]() { 311823b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 311923b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 312023b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 312123b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 312223b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 312323b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 312423b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 312523b3eb3cSopenharmony_ci auto accessibilityManager = frontend->GetAccessibilityManager(); 312623b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 312723b3eb3cSopenharmony_ci accessibilityManager->SearchElementInfosByTextNG( 312823b3eb3cSopenharmony_ci elementId, text, output, ngPipeline, baseParent); 312923b3eb3cSopenharmony_ci }, 313023b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, SEARCH_ELEMENT_TIMEOUT_TIME, "ArkUISearchElementInfoByText"); 313123b3eb3cSopenharmony_ci} 313223b3eb3cSopenharmony_ci 313323b3eb3cSopenharmony_civoid AceContainer::FindFocusedElementInfoNG( 313423b3eb3cSopenharmony_ci int64_t elementId, int32_t focusType, int64_t baseParent, 313523b3eb3cSopenharmony_ci Accessibility::AccessibilityElementInfo& output) 313623b3eb3cSopenharmony_ci{ 313723b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor_); 313823b3eb3cSopenharmony_ci taskExecutor_->PostSyncTaskTimeout( 313923b3eb3cSopenharmony_ci [weak = WeakClaim(this), elementId, focusType, baseParent, &output]() { 314023b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 314123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 314223b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 314323b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 314423b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 314523b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 314623b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 314723b3eb3cSopenharmony_ci auto accessibilityManager = frontend->GetAccessibilityManager(); 314823b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 314923b3eb3cSopenharmony_ci accessibilityManager->FindFocusedElementInfoNG( 315023b3eb3cSopenharmony_ci elementId, focusType, output, ngPipeline, baseParent); 315123b3eb3cSopenharmony_ci }, 315223b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, SEARCH_ELEMENT_TIMEOUT_TIME, "ArkUIFindFocusedElementInfo"); 315323b3eb3cSopenharmony_ci} 315423b3eb3cSopenharmony_ci 315523b3eb3cSopenharmony_civoid AceContainer::FocusMoveSearchNG( 315623b3eb3cSopenharmony_ci int64_t elementId, int32_t direction, int64_t baseParent, 315723b3eb3cSopenharmony_ci Accessibility::AccessibilityElementInfo& output) 315823b3eb3cSopenharmony_ci{ 315923b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor_); 316023b3eb3cSopenharmony_ci taskExecutor_->PostSyncTaskTimeout( 316123b3eb3cSopenharmony_ci [weak = WeakClaim(this), elementId, direction, baseParent, &output]() { 316223b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 316323b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 316423b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 316523b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 316623b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 316723b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 316823b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 316923b3eb3cSopenharmony_ci auto accessibilityManager = frontend->GetAccessibilityManager(); 317023b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 317123b3eb3cSopenharmony_ci accessibilityManager->FocusMoveSearchNG(elementId, direction, output, ngPipeline, baseParent); 317223b3eb3cSopenharmony_ci }, 317323b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, SEARCH_ELEMENT_TIMEOUT_TIME, "ArkUIFocusMoveSearch"); 317423b3eb3cSopenharmony_ci} 317523b3eb3cSopenharmony_ci 317623b3eb3cSopenharmony_cibool AceContainer::NotifyExecuteAction( 317723b3eb3cSopenharmony_ci int64_t elementId, const std::map<std::string, std::string>& actionArguments, 317823b3eb3cSopenharmony_ci int32_t action, int64_t offset) 317923b3eb3cSopenharmony_ci{ 318023b3eb3cSopenharmony_ci bool IsExecuted = false; 318123b3eb3cSopenharmony_ci CHECK_NULL_RETURN(taskExecutor_, IsExecuted); 318223b3eb3cSopenharmony_ci taskExecutor_->PostSyncTaskTimeout( 318323b3eb3cSopenharmony_ci [weak = WeakClaim(this), elementId, &actionArguments, action, offset, &IsExecuted]() { 318423b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 318523b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 318623b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 318723b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 318823b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 318923b3eb3cSopenharmony_ci auto frontend = container->GetFrontend(); 319023b3eb3cSopenharmony_ci CHECK_NULL_VOID(frontend); 319123b3eb3cSopenharmony_ci auto accessibilityManager = frontend->GetAccessibilityManager(); 319223b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManager); 319323b3eb3cSopenharmony_ci IsExecuted = accessibilityManager->ExecuteExtensionActionNG( 319423b3eb3cSopenharmony_ci elementId, actionArguments, action, ngPipeline, offset); 319523b3eb3cSopenharmony_ci }, 319623b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, SEARCH_ELEMENT_TIMEOUT_TIME, "ArkUIExecuteExtensionAction"); 319723b3eb3cSopenharmony_ci return IsExecuted; 319823b3eb3cSopenharmony_ci} 319923b3eb3cSopenharmony_ci 320023b3eb3cSopenharmony_civoid AceContainer::HandleAccessibilityHoverEvent(float pointX, float pointY, int32_t sourceType, 320123b3eb3cSopenharmony_ci int32_t eventType, int64_t timeMs) 320223b3eb3cSopenharmony_ci{ 320323b3eb3cSopenharmony_ci CHECK_NULL_VOID(taskExecutor_); 320423b3eb3cSopenharmony_ci taskExecutor_->PostTask( 320523b3eb3cSopenharmony_ci [weak = WeakClaim(this), pointX, pointY, sourceType, eventType, timeMs] { 320623b3eb3cSopenharmony_ci auto container = weak.Upgrade(); 320723b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 320823b3eb3cSopenharmony_ci ContainerScope scope(container->GetInstanceId()); 320923b3eb3cSopenharmony_ci auto pipelineContext = container->GetPipelineContext(); 321023b3eb3cSopenharmony_ci auto ngPipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext); 321123b3eb3cSopenharmony_ci CHECK_NULL_VOID(ngPipeline); 321223b3eb3cSopenharmony_ci auto root = ngPipeline->GetRootElement(); 321323b3eb3cSopenharmony_ci CHECK_NULL_VOID(root); 321423b3eb3cSopenharmony_ci auto accessibilityManagerNG = ngPipeline->GetAccessibilityManagerNG(); 321523b3eb3cSopenharmony_ci CHECK_NULL_VOID(accessibilityManagerNG); 321623b3eb3cSopenharmony_ci accessibilityManagerNG->HandleAccessibilityHoverEvent(root, pointX, pointY, sourceType, eventType, timeMs); 321723b3eb3cSopenharmony_ci }, 321823b3eb3cSopenharmony_ci TaskExecutor::TaskType::UI, "ArkUIHandleAccessibilityHoverEvent"); 321923b3eb3cSopenharmony_ci} 322023b3eb3cSopenharmony_ci 322123b3eb3cSopenharmony_cistd::vector<Ace::RectF> AceContainer::GetOverlayNodePositions() 322223b3eb3cSopenharmony_ci{ 322323b3eb3cSopenharmony_ci auto pipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext_); 322423b3eb3cSopenharmony_ci CHECK_NULL_RETURN(pipeline, {}); 322523b3eb3cSopenharmony_ci return pipeline->GetOverlayNodePositions(); 322623b3eb3cSopenharmony_ci} 322723b3eb3cSopenharmony_ci 322823b3eb3cSopenharmony_civoid AceContainer::RegisterOverlayNodePositionsUpdateCallback( 322923b3eb3cSopenharmony_ci const std::function<void(std::vector<Ace::RectF>)>&& callback) 323023b3eb3cSopenharmony_ci{ 323123b3eb3cSopenharmony_ci auto pipeline = AceType::DynamicCast<NG::PipelineContext>(pipelineContext_); 323223b3eb3cSopenharmony_ci CHECK_NULL_VOID(pipeline); 323323b3eb3cSopenharmony_ci pipeline->RegisterOverlayNodePositionsUpdateCallback(std::move(callback)); 323423b3eb3cSopenharmony_ci} 323523b3eb3cSopenharmony_ci 323623b3eb3cSopenharmony_civoid AceContainer::TerminateUIExtension() 323723b3eb3cSopenharmony_ci{ 323823b3eb3cSopenharmony_ci if (!IsUIExtensionWindow()) { 323923b3eb3cSopenharmony_ci return; 324023b3eb3cSopenharmony_ci } 324123b3eb3cSopenharmony_ci auto sharedContext = runtimeContext_.lock(); 324223b3eb3cSopenharmony_ci auto uiExtensionContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::UIExtensionContext>(sharedContext); 324323b3eb3cSopenharmony_ci CHECK_NULL_VOID(uiExtensionContext); 324423b3eb3cSopenharmony_ci uiExtensionContext->TerminateSelf(); 324523b3eb3cSopenharmony_ci} 324623b3eb3cSopenharmony_ci 324723b3eb3cSopenharmony_ciRosen::WMError AceContainer::RegisterAvoidAreaChangeListener(sptr<Rosen::IAvoidAreaChangedListener>& listener) 324823b3eb3cSopenharmony_ci{ 324923b3eb3cSopenharmony_ci if (!uiWindow_) { 325023b3eb3cSopenharmony_ci return Rosen::WMError::WM_DO_NOTHING; 325123b3eb3cSopenharmony_ci } 325223b3eb3cSopenharmony_ci return uiWindow_->RegisterAvoidAreaChangeListener(listener); 325323b3eb3cSopenharmony_ci} 325423b3eb3cSopenharmony_ci 325523b3eb3cSopenharmony_ciRosen::WMError AceContainer::UnregisterAvoidAreaChangeListener(sptr<Rosen::IAvoidAreaChangedListener>& listener) 325623b3eb3cSopenharmony_ci{ 325723b3eb3cSopenharmony_ci if (!uiWindow_) { 325823b3eb3cSopenharmony_ci return Rosen::WMError::WM_DO_NOTHING; 325923b3eb3cSopenharmony_ci } 326023b3eb3cSopenharmony_ci return uiWindow_->UnregisterAvoidAreaChangeListener(listener); 326123b3eb3cSopenharmony_ci} 326223b3eb3cSopenharmony_ci 326323b3eb3cSopenharmony_ciextern "C" ACE_FORCE_EXPORT void OHOS_ACE_HotReloadPage() 326423b3eb3cSopenharmony_ci{ 326523b3eb3cSopenharmony_ci AceEngine::Get().NotifyContainers([](const RefPtr<Container>& container) { 326623b3eb3cSopenharmony_ci LOGI("starting hotReload"); 326723b3eb3cSopenharmony_ci#ifndef NG_BUILD 326823b3eb3cSopenharmony_ci if (Container::IsCurrentUseNewPipeline()) { 326923b3eb3cSopenharmony_ci container->HotReload(); 327023b3eb3cSopenharmony_ci } else { 327123b3eb3cSopenharmony_ci container->NotifyConfigurationChange(true); 327223b3eb3cSopenharmony_ci } 327323b3eb3cSopenharmony_ci#else 327423b3eb3cSopenharmony_ci container->HotReload(); 327523b3eb3cSopenharmony_ci#endif 327623b3eb3cSopenharmony_ci }); 327723b3eb3cSopenharmony_ci} 327823b3eb3cSopenharmony_ci 327923b3eb3cSopenharmony_cibool AceContainer::NeedFullUpdate(uint32_t limitKey) 328023b3eb3cSopenharmony_ci{ 328123b3eb3cSopenharmony_ci auto themeManager = pipelineContext_->GetThemeManager(); 328223b3eb3cSopenharmony_ci if (!themeManager || (themeManager->GetResourceLimitKeys() & limitKey) == 0) { 328323b3eb3cSopenharmony_ci return false; 328423b3eb3cSopenharmony_ci } 328523b3eb3cSopenharmony_ci return true; 328623b3eb3cSopenharmony_ci} 328723b3eb3cSopenharmony_ci 328823b3eb3cSopenharmony_civoid AceContainer::NotifyDensityUpdate() 328923b3eb3cSopenharmony_ci{ 329023b3eb3cSopenharmony_ci bool fullUpdate = NeedFullUpdate(DENSITY_KEY); 329123b3eb3cSopenharmony_ci auto frontend = GetFrontend(); 329223b3eb3cSopenharmony_ci if (frontend) { 329323b3eb3cSopenharmony_ci frontend->FlushReload(); 329423b3eb3cSopenharmony_ci } 329523b3eb3cSopenharmony_ci ConfigurationChange configurationChange { .dpiUpdate = true }; 329623b3eb3cSopenharmony_ci pipelineContext_->FlushReload(configurationChange, fullUpdate); 329723b3eb3cSopenharmony_ci} 329823b3eb3cSopenharmony_ci 329923b3eb3cSopenharmony_civoid AceContainer::NotifyDirectionUpdate() 330023b3eb3cSopenharmony_ci{ 330123b3eb3cSopenharmony_ci bool fullUpdate = NeedFullUpdate(DIRECTION_KEY); 330223b3eb3cSopenharmony_ci if (fullUpdate) { 330323b3eb3cSopenharmony_ci ConfigurationChange configurationChange { .directionUpdate = true }; 330423b3eb3cSopenharmony_ci pipelineContext_->FlushReload(configurationChange, fullUpdate); 330523b3eb3cSopenharmony_ci } 330623b3eb3cSopenharmony_ci} 330723b3eb3cSopenharmony_ci 330823b3eb3cSopenharmony_civoid AceContainer::RenderLayoutBoundary(bool isDebugBoundary) 330923b3eb3cSopenharmony_ci{ 331023b3eb3cSopenharmony_ci auto container = AceEngine::Get().GetContainer(instanceId_); 331123b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 331223b3eb3cSopenharmony_ci CHECK_NULL_VOID(renderBoundaryManager_); 331323b3eb3cSopenharmony_ci renderBoundaryManager_->PostTaskRenderBoundary(isDebugBoundary, container); 331423b3eb3cSopenharmony_ci} 331523b3eb3cSopenharmony_ci 331623b3eb3cSopenharmony_civoid AceContainer::AddWatchSystemParameter() 331723b3eb3cSopenharmony_ci{ 331823b3eb3cSopenharmony_ci auto task = [weak = WeakClaim(this)] { 331923b3eb3cSopenharmony_ci auto weakPtr = weak.Upgrade(); 332023b3eb3cSopenharmony_ci CHECK_NULL_VOID(weakPtr); 332123b3eb3cSopenharmony_ci auto container = static_cast<void*>(weakPtr.GetRawPtr()); 332223b3eb3cSopenharmony_ci CHECK_NULL_VOID(container); 332323b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter( 332423b3eb3cSopenharmony_ci ENABLE_TRACE_LAYOUT_KEY, container, SystemProperties::EnableSystemParameterTraceLayoutCallback); 332523b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter( 332623b3eb3cSopenharmony_ci ENABLE_TRACE_INPUTEVENT_KEY, container, SystemProperties::EnableSystemParameterTraceInputEventCallback); 332723b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter(ENABLE_SECURITY_DEVELOPERMODE_KEY, container, 332823b3eb3cSopenharmony_ci SystemProperties::EnableSystemParameterSecurityDevelopermodeCallback); 332923b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter( 333023b3eb3cSopenharmony_ci ENABLE_DEBUG_STATEMGR_KEY, container, SystemProperties::EnableSystemParameterDebugStatemgrCallback); 333123b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter( 333223b3eb3cSopenharmony_ci ENABLE_DEBUG_BOUNDARY_KEY, container, SystemProperties::EnableSystemParameterDebugBoundaryCallback); 333323b3eb3cSopenharmony_ci SystemProperties::AddWatchSystemParameter( 333423b3eb3cSopenharmony_ci ENABLE_PERFORMANCE_MONITOR_KEY, container, 333523b3eb3cSopenharmony_ci SystemProperties::EnableSystemParameterPerformanceMonitorCallback); 333623b3eb3cSopenharmony_ci }; 333723b3eb3cSopenharmony_ci BackgroundTaskExecutor::GetInstance().PostTask(task); 333823b3eb3cSopenharmony_ci} 333923b3eb3cSopenharmony_ci 334023b3eb3cSopenharmony_civoid AceContainer::RemoveWatchSystemParameter() 334123b3eb3cSopenharmony_ci{ 334223b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 334323b3eb3cSopenharmony_ci ENABLE_TRACE_LAYOUT_KEY, this, SystemProperties::EnableSystemParameterTraceLayoutCallback); 334423b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 334523b3eb3cSopenharmony_ci ENABLE_TRACE_INPUTEVENT_KEY, this, SystemProperties::EnableSystemParameterTraceInputEventCallback); 334623b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 334723b3eb3cSopenharmony_ci ENABLE_SECURITY_DEVELOPERMODE_KEY, this, SystemProperties::EnableSystemParameterSecurityDevelopermodeCallback); 334823b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 334923b3eb3cSopenharmony_ci ENABLE_DEBUG_STATEMGR_KEY, this, SystemProperties::EnableSystemParameterDebugStatemgrCallback); 335023b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 335123b3eb3cSopenharmony_ci ENABLE_DEBUG_BOUNDARY_KEY, this, SystemProperties::EnableSystemParameterDebugBoundaryCallback); 335223b3eb3cSopenharmony_ci SystemProperties::RemoveWatchSystemParameter( 335323b3eb3cSopenharmony_ci ENABLE_PERFORMANCE_MONITOR_KEY, this, SystemProperties::EnableSystemParameterPerformanceMonitorCallback); 335423b3eb3cSopenharmony_ci} 335523b3eb3cSopenharmony_ci 335623b3eb3cSopenharmony_civoid AceContainer::UpdateResourceOrientation(int32_t orientation) 335723b3eb3cSopenharmony_ci{ 335823b3eb3cSopenharmony_ci DeviceOrientation newOrientation = WindowUtils::GetDeviceOrientation(orientation); 335923b3eb3cSopenharmony_ci auto resConfig = GetResourceConfiguration(); 336023b3eb3cSopenharmony_ci resConfig.SetOrientation(newOrientation); 336123b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 336223b3eb3cSopenharmony_ci ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false); 336323b3eb3cSopenharmony_ci } 336423b3eb3cSopenharmony_ci SetResourceConfiguration(resConfig); 336523b3eb3cSopenharmony_ci} 336623b3eb3cSopenharmony_ci 336723b3eb3cSopenharmony_civoid AceContainer::UpdateResourceDensity(double density) 336823b3eb3cSopenharmony_ci{ 336923b3eb3cSopenharmony_ci auto resConfig = GetResourceConfiguration(); 337023b3eb3cSopenharmony_ci resConfig.SetDensity(density); 337123b3eb3cSopenharmony_ci if (SystemProperties::GetResourceDecoupling()) { 337223b3eb3cSopenharmony_ci ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false); 337323b3eb3cSopenharmony_ci } 337423b3eb3cSopenharmony_ci SetResourceConfiguration(resConfig); 337523b3eb3cSopenharmony_ci} 337623b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform 3377