123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2021-2023 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/preview/entrance/ace_ability.h"
1723b3eb3cSopenharmony_ci#include "adapter/preview/entrance/ace_view_preview.h"
1823b3eb3cSopenharmony_ci
1923b3eb3cSopenharmony_ci#ifdef INIT_ICU_DATA_PATH
2023b3eb3cSopenharmony_ci#include "unicode/putil.h"
2123b3eb3cSopenharmony_ci#endif
2223b3eb3cSopenharmony_ci
2323b3eb3cSopenharmony_ci#include <ui/rs_surface_node.h>
2423b3eb3cSopenharmony_ci#include <ui/rs_ui_director.h>
2523b3eb3cSopenharmony_ci
2623b3eb3cSopenharmony_ci#include "include/core/SkFontMgr.h"
2723b3eb3cSopenharmony_ci#include "previewer/include/window.h"
2823b3eb3cSopenharmony_ci
2923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_new_pipe_judgement.h"
3023b3eb3cSopenharmony_ci#include "adapter/preview/entrance/ace_application_info.h"
3123b3eb3cSopenharmony_ci#include "adapter/preview/entrance/ace_container.h"
3223b3eb3cSopenharmony_ci#include "adapter/preview/entrance/event_dispatcher.h"
3323b3eb3cSopenharmony_ci#include "adapter/preview/entrance/rs_dir_asset_provider.h"
3423b3eb3cSopenharmony_ci#include "adapter/preview/external/ability/stage/stage_context.h"
3523b3eb3cSopenharmony_ci#include "adapter/preview/inspector/inspector_client.h"
3623b3eb3cSopenharmony_ci#include "core/common/resource/resource_configuration.h"
3723b3eb3cSopenharmony_ci#include "frameworks/base/utils/utils.h"
3823b3eb3cSopenharmony_ci#include "frameworks/bridge/common/utils/utils.h"
3923b3eb3cSopenharmony_ci#include "frameworks/bridge/js_frontend/js_frontend.h"
4023b3eb3cSopenharmony_ci#include "frameworks/core/common/ace_engine.h"
4123b3eb3cSopenharmony_ci#ifdef COMPONENT_TEST_ENABLED
4223b3eb3cSopenharmony_ci#include "frameworks/component_test/test_config.h"
4323b3eb3cSopenharmony_ci#endif // COMPONENT_TEST_ENABLED
4423b3eb3cSopenharmony_ci
4523b3eb3cSopenharmony_cinamespace OHOS::Ace::Platform {
4623b3eb3cSopenharmony_cinamespace {
4723b3eb3cSopenharmony_ci
4823b3eb3cSopenharmony_ciconstexpr char ASSET_PATH_SHARE[] = "share";
4923b3eb3cSopenharmony_ci#ifdef WINDOWS_PLATFORM
5023b3eb3cSopenharmony_ciconstexpr char DELIMITER[] = "\\";
5123b3eb3cSopenharmony_ciconstexpr char ASSET_PATH_SHARE_STAGE[] = "resources\\base\\profile";
5223b3eb3cSopenharmony_ci#else
5323b3eb3cSopenharmony_ciconstexpr char DELIMITER[] = "/";
5423b3eb3cSopenharmony_ciconstexpr char ASSET_PATH_SHARE_STAGE[] = "resources/base/profile";
5523b3eb3cSopenharmony_ci#endif
5623b3eb3cSopenharmony_ci
5723b3eb3cSopenharmony_civoid SetFontMgrConfig(const std::string& containerSdkPath)
5823b3eb3cSopenharmony_ci{
5923b3eb3cSopenharmony_ci    // To check if use ohos or container fonts.
6023b3eb3cSopenharmony_ci    std::string runtimeOS = "OHOS_Container";
6123b3eb3cSopenharmony_ci    std::string containerFontBasePath = containerSdkPath + DELIMITER + "resources" + DELIMITER + "fonts" + DELIMITER;
6223b3eb3cSopenharmony_ci    RSDirAssetProvider dirAsset(containerFontBasePath);
6323b3eb3cSopenharmony_ci    std::vector<std::string> fileList;
6423b3eb3cSopenharmony_ci    dirAsset.GetAssetList("", fileList);
6523b3eb3cSopenharmony_ci    if (containerSdkPath.empty() || fileList.empty()) {
6623b3eb3cSopenharmony_ci        runtimeOS = "OHOS";
6723b3eb3cSopenharmony_ci        containerFontBasePath = "";
6823b3eb3cSopenharmony_ci    }
6923b3eb3cSopenharmony_ci    SkFontMgr::SetFontMgrConfig(runtimeOS, containerFontBasePath);
7023b3eb3cSopenharmony_ci}
7123b3eb3cSopenharmony_ci
7223b3eb3cSopenharmony_cistd::string GetCustomAssetPath(std::string assetPath)
7323b3eb3cSopenharmony_ci{
7423b3eb3cSopenharmony_ci    if (assetPath.empty()) {
7523b3eb3cSopenharmony_ci        LOGW("AssetPath is null.");
7623b3eb3cSopenharmony_ci        return std::string();
7723b3eb3cSopenharmony_ci    }
7823b3eb3cSopenharmony_ci    std::string customAssetPath;
7923b3eb3cSopenharmony_ci    if (OHOS::Ace::Framework::EndWith(assetPath, DELIMITER)) {
8023b3eb3cSopenharmony_ci        assetPath = assetPath.substr(0, assetPath.size() - 1);
8123b3eb3cSopenharmony_ci    }
8223b3eb3cSopenharmony_ci    customAssetPath = assetPath.substr(0, assetPath.find_last_of(DELIMITER) + 1);
8323b3eb3cSopenharmony_ci    return customAssetPath;
8423b3eb3cSopenharmony_ci}
8523b3eb3cSopenharmony_ci
8623b3eb3cSopenharmony_ciinline void DumpAceRunArgs(const AceRunArgs& runArgs)
8723b3eb3cSopenharmony_ci{
8823b3eb3cSopenharmony_ci#ifdef ACE_DEBUG
8923b3eb3cSopenharmony_ci    LOGI("runArgs.pageProfile: %{private}s", runArgs.pageProfile.c_str());
9023b3eb3cSopenharmony_ci    LOGI("runArgs.asset: %{private}s", runArgs.assetPath.c_str());
9123b3eb3cSopenharmony_ci    LOGI("runArgs.systemResources: %{private}s", runArgs.systemResourcesPath.c_str());
9223b3eb3cSopenharmony_ci    LOGI("runArgs.appResources: %{private}s", runArgs.appResourcesPath.c_str());
9323b3eb3cSopenharmony_ci    LOGI("runArgs.themeId: %{private}u", runArgs.themeId);
9423b3eb3cSopenharmony_ci    LOGI("runArgs.deviceConfig.orientation: %{private}d", static_cast<int>(runArgs.deviceConfig.orientation));
9523b3eb3cSopenharmony_ci    LOGI("runArgs.deviceConfig.density: %{private}lf", runArgs.deviceConfig.density);
9623b3eb3cSopenharmony_ci    LOGI("runArgs.deviceConfig.deviceType: %{private}d", static_cast<int>(runArgs.deviceConfig.deviceType));
9723b3eb3cSopenharmony_ci    LOGI("runArgs.deviceConfig.fontRatio: %{private}lf", runArgs.deviceConfig.fontRatio);
9823b3eb3cSopenharmony_ci    LOGI("runArgs.deviceConfig.colorMode: %{private}d", static_cast<int>(runArgs.deviceConfig.colorMode));
9923b3eb3cSopenharmony_ci    LOGI("runArgs.url: %{private}s", runArgs.url.c_str());
10023b3eb3cSopenharmony_ci    LOGI("runArgs.windowTitle: %{private}s", runArgs.windowTitle.c_str());
10123b3eb3cSopenharmony_ci    LOGI("runArgs.isRound: %{private}s", runArgs.isRound ? "true" : "false");
10223b3eb3cSopenharmony_ci    LOGI("runArgs.viewWidth: %{private}d", runArgs.viewWidth);
10323b3eb3cSopenharmony_ci    LOGI("runArgs.viewHeight: %{private}d", runArgs.viewHeight);
10423b3eb3cSopenharmony_ci    LOGI("runArgs.deviceWidth: %{private}d", runArgs.deviceWidth);
10523b3eb3cSopenharmony_ci    LOGI("runArgs.deviceHeight: %{private}d", runArgs.deviceHeight);
10623b3eb3cSopenharmony_ci#endif
10723b3eb3cSopenharmony_ci}
10823b3eb3cSopenharmony_ci
10923b3eb3cSopenharmony_ci} // namespace
11023b3eb3cSopenharmony_ci
11123b3eb3cSopenharmony_ciNG::SafeAreaInsets ConvertAvoidArea(const OHOS::Rosen::AvoidArea& avoidArea)
11223b3eb3cSopenharmony_ci{
11323b3eb3cSopenharmony_ci    return NG::SafeAreaInsets({ avoidArea.leftRect_.posX_, avoidArea.leftRect_.posX_ + avoidArea.leftRect_.width_ },
11423b3eb3cSopenharmony_ci        { avoidArea.topRect_.posY_, avoidArea.topRect_.posY_ + avoidArea.topRect_.height_ },
11523b3eb3cSopenharmony_ci        { avoidArea.rightRect_.posX_, avoidArea.rightRect_.posX_ + avoidArea.rightRect_.width_ },
11623b3eb3cSopenharmony_ci        { avoidArea.bottomRect_.posY_, avoidArea.bottomRect_.posY_ + avoidArea.bottomRect_.height_ });
11723b3eb3cSopenharmony_ci}
11823b3eb3cSopenharmony_ci
11923b3eb3cSopenharmony_ciNG::SafeAreaInsets GetViewSafeAreaByType(OHOS::Rosen::AvoidAreaType type, sptr<OHOS::Rosen::Window> rsWindow)
12023b3eb3cSopenharmony_ci{
12123b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(rsWindow, {});
12223b3eb3cSopenharmony_ci    Rosen::AvoidArea avoidArea;
12323b3eb3cSopenharmony_ci    Rosen::WMError ret = rsWindow->GetAvoidAreaByType(type, avoidArea);
12423b3eb3cSopenharmony_ci    if (ret == Rosen::WMError::WM_OK) {
12523b3eb3cSopenharmony_ci        auto safeAreaInsets = ConvertAvoidArea(avoidArea);
12623b3eb3cSopenharmony_ci        LOGI("SafeArea get success, area type is:%{public}d insets area is:%{public}s", static_cast<int32_t>(type),
12723b3eb3cSopenharmony_ci            safeAreaInsets.ToString().c_str());
12823b3eb3cSopenharmony_ci        return safeAreaInsets;
12923b3eb3cSopenharmony_ci    }
13023b3eb3cSopenharmony_ci    return {};
13123b3eb3cSopenharmony_ci}
13223b3eb3cSopenharmony_ci
13323b3eb3cSopenharmony_ciclass IIgnoreViewSafeAreaListenerPreview  : public OHOS::Rosen::IIgnoreViewSafeAreaListener {
13423b3eb3cSopenharmony_cipublic:
13523b3eb3cSopenharmony_ci    explicit IIgnoreViewSafeAreaListenerPreview(int32_t instanceId) : instanceId_(instanceId) {}
13623b3eb3cSopenharmony_ci    ~IIgnoreViewSafeAreaListenerPreview() = default;
13723b3eb3cSopenharmony_ci
13823b3eb3cSopenharmony_ci    void SetIgnoreViewSafeArea(bool ignoreViewSafeArea)
13923b3eb3cSopenharmony_ci    {
14023b3eb3cSopenharmony_ci        LOGD("[instanceId_:%{public}d]: SetIgnoreViewSafeArea:%{public}u", instanceId_, ignoreViewSafeArea);
14123b3eb3cSopenharmony_ci        auto container = AceEngine::Get().GetContainer(instanceId_);
14223b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
14323b3eb3cSopenharmony_ci        auto pipelineContext = container->GetPipelineContext();
14423b3eb3cSopenharmony_ci        auto taskExecutor = container->GetTaskExecutor();
14523b3eb3cSopenharmony_ci        CHECK_NULL_VOID(taskExecutor);
14623b3eb3cSopenharmony_ci        taskExecutor->PostSyncTask(
14723b3eb3cSopenharmony_ci            [&pipelineContext, container, ignoreSafeArea = ignoreViewSafeArea]() {
14823b3eb3cSopenharmony_ci                pipelineContext->SetIgnoreViewSafeArea(ignoreSafeArea);
14923b3eb3cSopenharmony_ci            },
15023b3eb3cSopenharmony_ci            TaskExecutor::TaskType::UI, "ArkUISetIgnoreViewSafeArea");
15123b3eb3cSopenharmony_ci    }
15223b3eb3cSopenharmony_ci
15323b3eb3cSopenharmony_ciprivate:
15423b3eb3cSopenharmony_ci    int32_t instanceId_ = -1;
15523b3eb3cSopenharmony_ci};
15623b3eb3cSopenharmony_ci
15723b3eb3cSopenharmony_ciclass AvoidAreaChangedListenerPreview : public OHOS::Rosen::IAvoidAreaChangedListener {
15823b3eb3cSopenharmony_cipublic:
15923b3eb3cSopenharmony_ci    explicit AvoidAreaChangedListenerPreview(int32_t instanceId) : instanceId_(instanceId) {}
16023b3eb3cSopenharmony_ci    ~AvoidAreaChangedListenerPreview() = default;
16123b3eb3cSopenharmony_ci
16223b3eb3cSopenharmony_ci    void OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type)
16323b3eb3cSopenharmony_ci    {
16423b3eb3cSopenharmony_ci        LOGD("Avoid area changed, type:%{public}d, topRect: avoidArea:x:%{public}d, y:%{public}d, "
16523b3eb3cSopenharmony_ci             "width:%{public}d, height:%{public}d; bottomRect: avoidArea:x:%{public}d, y:%{public}d, "
16623b3eb3cSopenharmony_ci             "width:%{public}d, height:%{public}d",
16723b3eb3cSopenharmony_ci            type, avoidArea.topRect_.posX_, avoidArea.topRect_.posY_, (int32_t)avoidArea.topRect_.width_,
16823b3eb3cSopenharmony_ci            (int32_t)avoidArea.topRect_.height_, avoidArea.bottomRect_.posX_, avoidArea.bottomRect_.posY_,
16923b3eb3cSopenharmony_ci            (int32_t)avoidArea.bottomRect_.width_, (int32_t)avoidArea.bottomRect_.height_);
17023b3eb3cSopenharmony_ci        auto container = Platform::AceContainer::GetContainerInstance(instanceId_);
17123b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
17223b3eb3cSopenharmony_ci        auto pipeline = container->GetPipelineContext();
17323b3eb3cSopenharmony_ci        CHECK_NULL_VOID(pipeline);
17423b3eb3cSopenharmony_ci        auto taskExecutor = container->GetTaskExecutor();
17523b3eb3cSopenharmony_ci        CHECK_NULL_VOID(taskExecutor);
17623b3eb3cSopenharmony_ci        if (type == Rosen::AvoidAreaType::TYPE_SYSTEM) {
17723b3eb3cSopenharmony_ci            systemSafeArea_ = ConvertAvoidArea(avoidArea);
17823b3eb3cSopenharmony_ci        } else if (type == Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
17923b3eb3cSopenharmony_ci            navigationBar_ = ConvertAvoidArea(avoidArea);
18023b3eb3cSopenharmony_ci        } else if (type == Rosen::AvoidAreaType::TYPE_CUTOUT) {
18123b3eb3cSopenharmony_ci            cutoutSafeArea_ = ConvertAvoidArea(avoidArea);
18223b3eb3cSopenharmony_ci        }
18323b3eb3cSopenharmony_ci        auto safeArea = systemSafeArea_;
18423b3eb3cSopenharmony_ci        auto navSafeArea = navigationBar_;
18523b3eb3cSopenharmony_ci        auto cutoutSafeArea = cutoutSafeArea_;
18623b3eb3cSopenharmony_ci        taskExecutor->PostTask(
18723b3eb3cSopenharmony_ci            [pipeline, safeArea, navSafeArea, cutoutSafeArea, type, avoidArea] {
18823b3eb3cSopenharmony_ci                if (type == Rosen::AvoidAreaType::TYPE_SYSTEM) {
18923b3eb3cSopenharmony_ci                    pipeline->UpdateSystemSafeArea(safeArea);
19023b3eb3cSopenharmony_ci                } else if (type == Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR) {
19123b3eb3cSopenharmony_ci                    pipeline->UpdateNavSafeArea(navSafeArea);
19223b3eb3cSopenharmony_ci                } else if (type == Rosen::AvoidAreaType::TYPE_CUTOUT && pipeline->GetUseCutout()) {
19323b3eb3cSopenharmony_ci                    pipeline->UpdateCutoutSafeArea(cutoutSafeArea);
19423b3eb3cSopenharmony_ci                }
19523b3eb3cSopenharmony_ci                // for ui extension component
19623b3eb3cSopenharmony_ci                pipeline->UpdateOriginAvoidArea(avoidArea, static_cast<uint32_t>(type));
19723b3eb3cSopenharmony_ci            },
19823b3eb3cSopenharmony_ci            TaskExecutor::TaskType::UI, "ArkUIUpdateOriginAvoidArea");
19923b3eb3cSopenharmony_ci    }
20023b3eb3cSopenharmony_ci
20123b3eb3cSopenharmony_ciprivate:
20223b3eb3cSopenharmony_ci    NG::SafeAreaInsets systemSafeArea_;
20323b3eb3cSopenharmony_ci    NG::SafeAreaInsets navigationBar_;
20423b3eb3cSopenharmony_ci    NG::SafeAreaInsets cutoutSafeArea_;
20523b3eb3cSopenharmony_ci    int32_t instanceId_ = -1;
20623b3eb3cSopenharmony_ci};
20723b3eb3cSopenharmony_ci
20823b3eb3cSopenharmony_ciAceAbility::AceAbility(const AceRunArgs& runArgs) : runArgs_(runArgs)
20923b3eb3cSopenharmony_ci{
21023b3eb3cSopenharmony_ci    static std::once_flag onceFlag;
21123b3eb3cSopenharmony_ci    std::call_once(onceFlag, []() {
21223b3eb3cSopenharmony_ci        Container::UpdateCurrent(ACE_INSTANCE_ID);
21323b3eb3cSopenharmony_ci    });
21423b3eb3cSopenharmony_ci    SystemProperties::SetExtSurfaceEnabled(!runArgs.containerSdkPath.empty());
21523b3eb3cSopenharmony_ci    SystemProperties::InitDeviceInfo(runArgs.deviceWidth, runArgs.deviceHeight,
21623b3eb3cSopenharmony_ci        runArgs.deviceConfig.orientation == DeviceOrientation::PORTRAIT ? 0 : 1, runArgs.deviceConfig.density,
21723b3eb3cSopenharmony_ci        runArgs.isRound);
21823b3eb3cSopenharmony_ci    SystemProperties::InitDeviceType(runArgs.deviceConfig.deviceType);
21923b3eb3cSopenharmony_ci    SystemProperties::SetColorMode(runArgs.deviceConfig.colorMode);
22023b3eb3cSopenharmony_ci    InitializeAppInfo();
22123b3eb3cSopenharmony_ci    if (runArgs_.aceVersion == AceVersion::ACE_1_0) {
22223b3eb3cSopenharmony_ci        if (runArgs_.formsEnabled) {
22323b3eb3cSopenharmony_ci            LOGI("CreateContainer with JS_CARD frontend");
22423b3eb3cSopenharmony_ci            AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS_CARD, false);
22523b3eb3cSopenharmony_ci        } else {
22623b3eb3cSopenharmony_ci            LOGI("CreateContainer with JS frontend");
22723b3eb3cSopenharmony_ci            AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::JS, false);
22823b3eb3cSopenharmony_ci        }
22923b3eb3cSopenharmony_ci    } else if (runArgs_.aceVersion == AceVersion::ACE_2_0) {
23023b3eb3cSopenharmony_ci        if (runArgs_.formsEnabled) {
23123b3eb3cSopenharmony_ci            LOGI("CreateContainer with ETS_CARD frontend");
23223b3eb3cSopenharmony_ci            AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::ETS_CARD, useNewPipeline_);
23323b3eb3cSopenharmony_ci        } else {
23423b3eb3cSopenharmony_ci            LOGI("CreateContainer with JSDECLARATIVE frontend");
23523b3eb3cSopenharmony_ci            AceContainer::CreateContainer(ACE_INSTANCE_ID, FrontendType::DECLARATIVE_JS, useNewPipeline_);
23623b3eb3cSopenharmony_ci        }
23723b3eb3cSopenharmony_ci    } else {
23823b3eb3cSopenharmony_ci        LOGW("UnKnown frontend type");
23923b3eb3cSopenharmony_ci    }
24023b3eb3cSopenharmony_ci    AceContainer::SetComponentModeFlag(runArgs.isComponentMode);
24123b3eb3cSopenharmony_ci    SetConfigChanges(runArgs.configChanges);
24223b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
24323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
24423b3eb3cSopenharmony_ci    container->SetContainerSdkPath(runArgs.containerSdkPath);
24523b3eb3cSopenharmony_ci    container->SetInstallationFree(installationFree_);
24623b3eb3cSopenharmony_ci    container->SetLabelId(labelId_);
24723b3eb3cSopenharmony_ci    auto config = container->GetResourceConfiguration();
24823b3eb3cSopenharmony_ci    config.SetDeviceType(SystemProperties::GetDeviceType());
24923b3eb3cSopenharmony_ci    config.SetOrientation(SystemProperties::GetDeviceOrientation());
25023b3eb3cSopenharmony_ci    config.SetDensity(SystemProperties::GetResolution());
25123b3eb3cSopenharmony_ci    config.SetColorMode(SystemProperties::GetColorMode());
25223b3eb3cSopenharmony_ci    config.SetFontRatio(runArgs.deviceConfig.fontRatio);
25323b3eb3cSopenharmony_ci    container->SetResourceConfiguration(config);
25423b3eb3cSopenharmony_ci    container->SetBundleName(bundleName_);
25523b3eb3cSopenharmony_ci    container->SetModuleName(moduleName_);
25623b3eb3cSopenharmony_ci    container->SetApiTargetVersion(AceApplicationInfo::GetInstance().GetApiTargetVersion());
25723b3eb3cSopenharmony_ci    InitializeClipboard();
25823b3eb3cSopenharmony_ci}
25923b3eb3cSopenharmony_ci
26023b3eb3cSopenharmony_ciAceAbility::~AceAbility()
26123b3eb3cSopenharmony_ci{
26223b3eb3cSopenharmony_ci    AceContainer::DestroyContainer(ACE_INSTANCE_ID);
26323b3eb3cSopenharmony_ci}
26423b3eb3cSopenharmony_ci
26523b3eb3cSopenharmony_civoid AceAbility::SetMockModuleList(const std::map<std::string, std::string>& mockJsonInfo)
26623b3eb3cSopenharmony_ci{
26723b3eb3cSopenharmony_ci    // only support the stage model
26823b3eb3cSopenharmony_ci    if (runArgs_.projectModel == ProjectModel::STAGE) {
26923b3eb3cSopenharmony_ci        auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
27023b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
27123b3eb3cSopenharmony_ci        container->SetMockModuleList(mockJsonInfo);
27223b3eb3cSopenharmony_ci    }
27323b3eb3cSopenharmony_ci}
27423b3eb3cSopenharmony_ci
27523b3eb3cSopenharmony_cistd::unique_ptr<AceAbility> AceAbility::CreateInstance(AceRunArgs& runArgs)
27623b3eb3cSopenharmony_ci{
27723b3eb3cSopenharmony_ci    DumpAceRunArgs(runArgs);
27823b3eb3cSopenharmony_ci    LOGI("Start create AceAbility instance");
27923b3eb3cSopenharmony_ci#ifdef INIT_ICU_DATA_PATH
28023b3eb3cSopenharmony_ci    std::string icuPath = ".";
28123b3eb3cSopenharmony_ci    u_setDataDirectory(icuPath.c_str());
28223b3eb3cSopenharmony_ci#endif
28323b3eb3cSopenharmony_ci    AceApplicationInfo::GetInstance().SetLocale(runArgs.language, runArgs.region, runArgs.script, "");
28423b3eb3cSopenharmony_ci    SetFontMgrConfig(runArgs.containerSdkPath);
28523b3eb3cSopenharmony_ci    EventDispatcher::GetInstance().Initialize();
28623b3eb3cSopenharmony_ci    auto aceAbility = std::make_unique<AceAbility>(runArgs);
28723b3eb3cSopenharmony_ci    return aceAbility;
28823b3eb3cSopenharmony_ci}
28923b3eb3cSopenharmony_ci
29023b3eb3cSopenharmony_civoid AceAbility::InitEnv()
29123b3eb3cSopenharmony_ci{
29223b3eb3cSopenharmony_ci    std::vector<std::string> paths;
29323b3eb3cSopenharmony_ci    paths.push_back(runArgs_.assetPath);
29423b3eb3cSopenharmony_ci    std::string appResourcesPath(runArgs_.appResourcesPath);
29523b3eb3cSopenharmony_ci    if (!OHOS::Ace::Framework::EndWith(appResourcesPath, DELIMITER)) {
29623b3eb3cSopenharmony_ci        appResourcesPath.append(DELIMITER);
29723b3eb3cSopenharmony_ci    }
29823b3eb3cSopenharmony_ci    if (runArgs_.projectModel == ProjectModel::STAGE) {
29923b3eb3cSopenharmony_ci        // eTS Card
30023b3eb3cSopenharmony_ci        if (runArgs_.aceVersion == AceVersion::ACE_2_0 && runArgs_.formsEnabled) {
30123b3eb3cSopenharmony_ci            paths.push_back(runArgs_.assetPath + DELIMITER + "ets");
30223b3eb3cSopenharmony_ci        }
30323b3eb3cSopenharmony_ci        paths.push_back(appResourcesPath);
30423b3eb3cSopenharmony_ci        paths.push_back(appResourcesPath + ASSET_PATH_SHARE_STAGE);
30523b3eb3cSopenharmony_ci    } else {
30623b3eb3cSopenharmony_ci        paths.push_back(GetCustomAssetPath(runArgs_.assetPath) + ASSET_PATH_SHARE);
30723b3eb3cSopenharmony_ci    }
30823b3eb3cSopenharmony_ci    if (!runArgs_.containerSdkPath.empty()) {
30923b3eb3cSopenharmony_ci        paths.push_back(runArgs_.containerSdkPath);
31023b3eb3cSopenharmony_ci    }
31123b3eb3cSopenharmony_ci    AceContainer::AddAssetPath(ACE_INSTANCE_ID, "", paths);
31223b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
31323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
31423b3eb3cSopenharmony_ci    if (runArgs_.projectModel == ProjectModel::STAGE) {
31523b3eb3cSopenharmony_ci        auto pkgcontextinfo = Referenced::MakeRefPtr<StagePkgContextInfo>();
31623b3eb3cSopenharmony_ci        pkgcontextinfo->SetPkgNameList(runArgs_.packageNameList);
31723b3eb3cSopenharmony_ci        pkgcontextinfo->SetPkgContextInfoAndAliasMap(runArgs_.pkgContextInfoJsonStringMap);
31823b3eb3cSopenharmony_ci        container->SetPkgContextInfo(pkgcontextinfo);
31923b3eb3cSopenharmony_ci        if (runArgs_.formsEnabled) {
32023b3eb3cSopenharmony_ci            container->SetStageCardConfig(runArgs_.pageProfile, runArgs_.url);
32123b3eb3cSopenharmony_ci        } else {
32223b3eb3cSopenharmony_ci            container->SetPageProfile((runArgs_.pageProfile.empty() ? "" : runArgs_.pageProfile + ".json"));
32323b3eb3cSopenharmony_ci        }
32423b3eb3cSopenharmony_ci    }
32523b3eb3cSopenharmony_ci    AceContainer::SetResourcesPathAndThemeStyle(ACE_INSTANCE_ID, runArgs_.systemResourcesPath,
32623b3eb3cSopenharmony_ci        runArgs_.containerSdkPath, runArgs_.appResourcesPath, runArgs_.themeId, runArgs_.deviceConfig.colorMode);
32723b3eb3cSopenharmony_ci
32823b3eb3cSopenharmony_ci    auto view = AceViewPreview::CreateView(ACE_INSTANCE_ID);
32923b3eb3cSopenharmony_ci    auto window = GetWindow();
33023b3eb3cSopenharmony_ci    avoidAreaChangedListener_ = new AvoidAreaChangedListenerPreview(ACE_INSTANCE_ID);
33123b3eb3cSopenharmony_ci    window->RegisterAvoidAreaChangeListener(avoidAreaChangedListener_);
33223b3eb3cSopenharmony_ci    ignoreViewSafeAreaListener_ = new IIgnoreViewSafeAreaListenerPreview(ACE_INSTANCE_ID);
33323b3eb3cSopenharmony_ci    window->RegisterIgnoreViewSafeAreaListener(ignoreViewSafeAreaListener_);
33423b3eb3cSopenharmony_ci    UIEnvCallback callback = [window, id = ACE_INSTANCE_ID](const OHOS::Ace::RefPtr<PipelineContext>& context) mutable {
33523b3eb3cSopenharmony_ci        CHECK_NULL_VOID(context);
33623b3eb3cSopenharmony_ci        CHECK_NULL_VOID(window);
33723b3eb3cSopenharmony_ci        auto director = OHOS::Rosen::RSUIDirector::Create();
33823b3eb3cSopenharmony_ci        CHECK_NULL_VOID(director);
33923b3eb3cSopenharmony_ci        director->SetRSSurfaceNode(window->GetSurfaceNode());
34023b3eb3cSopenharmony_ci        auto container = AceContainer::GetContainerInstance(id);
34123b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
34223b3eb3cSopenharmony_ci        auto func = [taskExecutor = container->GetTaskExecutor(), id](
34323b3eb3cSopenharmony_ci            const std::function<void()>& task, uint32_t delay) {
34423b3eb3cSopenharmony_ci            CHECK_NULL_VOID(taskExecutor);
34523b3eb3cSopenharmony_ci            ContainerScope scope(id);
34623b3eb3cSopenharmony_ci            taskExecutor->PostDelayedTask(
34723b3eb3cSopenharmony_ci                task, TaskExecutor::TaskType::UI, delay, "ArkUIRenderServiceTask", PriorityType::HIGH);
34823b3eb3cSopenharmony_ci        };
34923b3eb3cSopenharmony_ci        director->SetUITaskRunner(func, id);
35023b3eb3cSopenharmony_ci        director->Init();
35123b3eb3cSopenharmony_ci        context->SetRSUIDirector(director);
35223b3eb3cSopenharmony_ci    };
35323b3eb3cSopenharmony_ci
35423b3eb3cSopenharmony_ci    if (runArgs_.aceVersion == AceVersion::ACE_2_0) {
35523b3eb3cSopenharmony_ci        AceContainer::SetView(
35623b3eb3cSopenharmony_ci            view, window, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight, callback);
35723b3eb3cSopenharmony_ci        AceContainer::RunPage(ACE_INSTANCE_ID, runArgs_.url, "");
35823b3eb3cSopenharmony_ci    } else {
35923b3eb3cSopenharmony_ci        AceContainer::RunPage(ACE_INSTANCE_ID, runArgs_.url, "");
36023b3eb3cSopenharmony_ci        AceContainer::SetView(
36123b3eb3cSopenharmony_ci            view, window, runArgs_.deviceConfig.density, runArgs_.deviceWidth, runArgs_.deviceHeight, callback);
36223b3eb3cSopenharmony_ci    }
36323b3eb3cSopenharmony_ci    // Drive the native engine with the platform thread.
36423b3eb3cSopenharmony_ci    container->RunNativeEngineLoop();
36523b3eb3cSopenharmony_ci    auto pipelineContext = container->GetPipelineContext();
36623b3eb3cSopenharmony_ci    if (pipelineContext) {
36723b3eb3cSopenharmony_ci        LOGI("Set MinPlatformVersion to %{public}d", compatibleVersion_);
36823b3eb3cSopenharmony_ci        pipelineContext->SetMinPlatformVersion(compatibleVersion_);
36923b3eb3cSopenharmony_ci        pipelineContext->SetDisplayWindowRectInfo(
37023b3eb3cSopenharmony_ci            Rect(Offset(0.0f, 0.0f), Size(runArgs_.deviceWidth, runArgs_.deviceHeight)));
37123b3eb3cSopenharmony_ci    }
37223b3eb3cSopenharmony_ci    container->InitializeAppConfig(runArgs_.assetPath, bundleName_, moduleName_, compileMode_);
37323b3eb3cSopenharmony_ci    pipelineContext->UpdateSystemSafeArea(GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_SYSTEM, window));
37423b3eb3cSopenharmony_ci    if (pipelineContext->GetUseCutout()) {
37523b3eb3cSopenharmony_ci        pipelineContext->UpdateCutoutSafeArea(GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT, window));
37623b3eb3cSopenharmony_ci    }
37723b3eb3cSopenharmony_ci    pipelineContext->UpdateNavSafeArea(GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_NAVIGATION_INDICATOR, window));
37823b3eb3cSopenharmony_ci    AceContainer::AddRouterChangeCallback(ACE_INSTANCE_ID, runArgs_.onRouterChange);
37923b3eb3cSopenharmony_ci    OHOS::Ace::Framework::InspectorClient::GetInstance().RegisterFastPreviewErrorCallback(runArgs_.onError);
38023b3eb3cSopenharmony_ci    // Should make it possible to update surface changes by using viewWidth and viewHeight.
38123b3eb3cSopenharmony_ci    view->NotifySurfaceChanged(runArgs_.deviceWidth, runArgs_.deviceHeight);
38223b3eb3cSopenharmony_ci    view->NotifyDensityChanged(runArgs_.deviceConfig.density);
38323b3eb3cSopenharmony_ci}
38423b3eb3cSopenharmony_ci
38523b3eb3cSopenharmony_civoid AceAbility::InitializeClipboard() const
38623b3eb3cSopenharmony_ci{
38723b3eb3cSopenharmony_ci    ClipboardProxy::GetInstance()->SetDelegate(std::make_unique<Platform::ClipboardProxyImpl>());
38823b3eb3cSopenharmony_ci}
38923b3eb3cSopenharmony_ci
39023b3eb3cSopenharmony_civoid AceAbility::OnBackPressed() const
39123b3eb3cSopenharmony_ci{
39223b3eb3cSopenharmony_ci    LOGI("Process Back Pressed Event");
39323b3eb3cSopenharmony_ci    EventDispatcher::GetInstance().DispatchBackPressedEvent();
39423b3eb3cSopenharmony_ci}
39523b3eb3cSopenharmony_ci
39623b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const
39723b3eb3cSopenharmony_ci{
39823b3eb3cSopenharmony_ci    return EventDispatcher::GetInstance().DispatchTouchEvent(pointerEvent);
39923b3eb3cSopenharmony_ci}
40023b3eb3cSopenharmony_ci
40123b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const
40223b3eb3cSopenharmony_ci{
40323b3eb3cSopenharmony_ci    return EventDispatcher::GetInstance().DispatchKeyEvent(keyEvent);
40423b3eb3cSopenharmony_ci}
40523b3eb3cSopenharmony_ci
40623b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const
40723b3eb3cSopenharmony_ci{
40823b3eb3cSopenharmony_ci    return false;
40923b3eb3cSopenharmony_ci}
41023b3eb3cSopenharmony_ci
41123b3eb3cSopenharmony_cibool AceAbility::OnInputMethodEvent(const unsigned int codePoint) const
41223b3eb3cSopenharmony_ci{
41323b3eb3cSopenharmony_ci    return EventDispatcher::GetInstance().DispatchInputMethodEvent(codePoint);
41423b3eb3cSopenharmony_ci}
41523b3eb3cSopenharmony_ci
41623b3eb3cSopenharmony_civoid AceAbility::InitializeAppInfo()
41723b3eb3cSopenharmony_ci{
41823b3eb3cSopenharmony_ci    RefPtr<Context> context =
41923b3eb3cSopenharmony_ci        Context::CreateContext(runArgs_.projectModel == ProjectModel::STAGE, runArgs_.appResourcesPath);
42023b3eb3cSopenharmony_ci    if (runArgs_.projectModel == ProjectModel::STAGE) {
42123b3eb3cSopenharmony_ci        auto stageContext = AceType::DynamicCast<StageContext>(context);
42223b3eb3cSopenharmony_ci        CHECK_NULL_VOID(stageContext);
42323b3eb3cSopenharmony_ci        auto appInfo = stageContext->GetAppInfo();
42423b3eb3cSopenharmony_ci        CHECK_NULL_VOID(appInfo);
42523b3eb3cSopenharmony_ci        auto hapModuleInfo = stageContext->GetHapModuleInfo();
42623b3eb3cSopenharmony_ci        CHECK_NULL_VOID(hapModuleInfo);
42723b3eb3cSopenharmony_ci        bundleName_ = appInfo->GetBundleName();
42823b3eb3cSopenharmony_ci        moduleName_ = hapModuleInfo->GetModuleName();
42923b3eb3cSopenharmony_ci        compileMode_ = hapModuleInfo->GetCompileMode();
43023b3eb3cSopenharmony_ci        compatibleVersion_ = appInfo->GetMinAPIVersion();
43123b3eb3cSopenharmony_ci        auto targetVersion = appInfo->GetTargetAPIVersion();
43223b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(targetVersion));
43323b3eb3cSopenharmony_ci        auto releaseType = appInfo->GetApiReleaseType();
43423b3eb3cSopenharmony_ci        bool enablePartialUpdate = hapModuleInfo->GetPartialUpdateFlag();
43523b3eb3cSopenharmony_ci        // only app should have menubar, card don't need
43623b3eb3cSopenharmony_ci        if (!runArgs_.formsEnabled) {
43723b3eb3cSopenharmony_ci            installationFree_ = appInfo->IsInstallationFree();
43823b3eb3cSopenharmony_ci            labelId_ = hapModuleInfo->GetLabelId();
43923b3eb3cSopenharmony_ci        }
44023b3eb3cSopenharmony_ci        useNewPipeline_ = AceNewPipeJudgement::QueryAceNewPipeEnabledStage(
44123b3eb3cSopenharmony_ci            "", compatibleVersion_, targetVersion, releaseType, !enablePartialUpdate);
44223b3eb3cSopenharmony_ci    } else {
44323b3eb3cSopenharmony_ci        auto faContext = AceType::DynamicCast<FaContext>(context);
44423b3eb3cSopenharmony_ci        CHECK_NULL_VOID(faContext);
44523b3eb3cSopenharmony_ci        auto appInfo = faContext->GetAppInfo();
44623b3eb3cSopenharmony_ci        CHECK_NULL_VOID(appInfo);
44723b3eb3cSopenharmony_ci        auto hapModuleInfo = faContext->GetHapModuleInfo();
44823b3eb3cSopenharmony_ci        CHECK_NULL_VOID(hapModuleInfo);
44923b3eb3cSopenharmony_ci        bundleName_ = appInfo->GetBundleName();
45023b3eb3cSopenharmony_ci        compatibleVersion_ = appInfo->GetMinAPIVersion();
45123b3eb3cSopenharmony_ci        auto targetVersion = appInfo->GetTargetAPIVersion();
45223b3eb3cSopenharmony_ci        auto releaseType = appInfo->GetApiReleaseType();
45323b3eb3cSopenharmony_ci        useNewPipeline_ =
45423b3eb3cSopenharmony_ci            AceNewPipeJudgement::QueryAceNewPipeEnabledFA("", compatibleVersion_, targetVersion, releaseType);
45523b3eb3cSopenharmony_ci    }
45623b3eb3cSopenharmony_ci#ifdef COMPONENT_TEST_ENABLED
45723b3eb3cSopenharmony_ci    if (runArgs_.isComponentTestMode && runArgs_.componentTestConfig != "") {
45823b3eb3cSopenharmony_ci        ComponentTest::ParseComponentTestConfig(runArgs_.componentTestConfig);
45923b3eb3cSopenharmony_ci    }
46023b3eb3cSopenharmony_ci#endif // COMPONENT_TEST_ENABLED
46123b3eb3cSopenharmony_ci}
46223b3eb3cSopenharmony_ci
46323b3eb3cSopenharmony_civoid AceAbility::SetConfigChanges(const std::string& configChanges)
46423b3eb3cSopenharmony_ci{
46523b3eb3cSopenharmony_ci    if (configChanges == "") {
46623b3eb3cSopenharmony_ci        return;
46723b3eb3cSopenharmony_ci    }
46823b3eb3cSopenharmony_ci    std::vector<std::string> configChangesSplitter;
46923b3eb3cSopenharmony_ci    OHOS::Ace::StringUtils::StringSplitter(configChanges, ',', configChangesSplitter);
47023b3eb3cSopenharmony_ci    for (const auto& singleConfig : configChangesSplitter) {
47123b3eb3cSopenharmony_ci        if (singleConfig == "locale") {
47223b3eb3cSopenharmony_ci            configChanges_.watchLocale = true;
47323b3eb3cSopenharmony_ci            continue;
47423b3eb3cSopenharmony_ci        } else if (singleConfig == "layout") {
47523b3eb3cSopenharmony_ci            configChanges_.watchLayout = true;
47623b3eb3cSopenharmony_ci            continue;
47723b3eb3cSopenharmony_ci        } else if (singleConfig == "fontSize") {
47823b3eb3cSopenharmony_ci            configChanges_.watchFontSize = true;
47923b3eb3cSopenharmony_ci            continue;
48023b3eb3cSopenharmony_ci        } else if (singleConfig == "orientation") {
48123b3eb3cSopenharmony_ci            configChanges_.watchOrientation = true;
48223b3eb3cSopenharmony_ci            continue;
48323b3eb3cSopenharmony_ci        } else if (singleConfig == "density") {
48423b3eb3cSopenharmony_ci            configChanges_.watchDensity = true;
48523b3eb3cSopenharmony_ci            continue;
48623b3eb3cSopenharmony_ci        } else {
48723b3eb3cSopenharmony_ci            LOGW("unsupported config %{public}s", singleConfig.c_str());
48823b3eb3cSopenharmony_ci        }
48923b3eb3cSopenharmony_ci    }
49023b3eb3cSopenharmony_ci}
49123b3eb3cSopenharmony_ci
49223b3eb3cSopenharmony_civoid AceAbility::OnConfigurationChanged(const DeviceConfig& newConfig)
49323b3eb3cSopenharmony_ci{
49423b3eb3cSopenharmony_ci    if (newConfig.colorMode == runArgs_.deviceConfig.colorMode) {
49523b3eb3cSopenharmony_ci        return;
49623b3eb3cSopenharmony_ci    }
49723b3eb3cSopenharmony_ci    int32_t width = runArgs_.deviceWidth;
49823b3eb3cSopenharmony_ci    int32_t height = runArgs_.deviceHeight;
49923b3eb3cSopenharmony_ci    SurfaceChanged(runArgs_.deviceConfig.orientation, runArgs_.deviceConfig.density, width, height);
50023b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
50123b3eb3cSopenharmony_ci    if (!container) {
50223b3eb3cSopenharmony_ci        LOGW("container is null, change configuration failed.");
50323b3eb3cSopenharmony_ci        return;
50423b3eb3cSopenharmony_ci    }
50523b3eb3cSopenharmony_ci    container->UpdateDeviceConfig(newConfig);
50623b3eb3cSopenharmony_ci    runArgs_.deviceConfig.colorMode = newConfig.colorMode;
50723b3eb3cSopenharmony_ci    if (container->GetType() == FrontendType::DECLARATIVE_JS) {
50823b3eb3cSopenharmony_ci        container->NativeOnConfigurationUpdated(ACE_INSTANCE_ID);
50923b3eb3cSopenharmony_ci    }
51023b3eb3cSopenharmony_ci}
51123b3eb3cSopenharmony_ci
51223b3eb3cSopenharmony_civoid AceAbility::SurfaceChanged(
51323b3eb3cSopenharmony_ci    const DeviceOrientation& orientation, const double& resolution, int32_t& width, int32_t& height,
51423b3eb3cSopenharmony_ci    WindowSizeChangeReason type)
51523b3eb3cSopenharmony_ci{
51623b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
51723b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
51823b3eb3cSopenharmony_ci    auto viewPtr = AceType::DynamicCast<AceViewPreview>(container->GetAceView());
51923b3eb3cSopenharmony_ci    CHECK_NULL_VOID(viewPtr);
52023b3eb3cSopenharmony_ci    // Need to change the window resolution and then change the rendering resolution. Otherwise, the image may not adapt
52123b3eb3cSopenharmony_ci    // to the new window after the window is modified.
52223b3eb3cSopenharmony_ci    auto context = container->GetPipelineContext();
52323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(context);
52423b3eb3cSopenharmony_ci    context->SetDisplayWindowRectInfo(Rect(Offset(0, 0), Size(width, height)));
52523b3eb3cSopenharmony_ci    SystemProperties::InitDeviceInfo(
52623b3eb3cSopenharmony_ci        width, height, orientation == DeviceOrientation::PORTRAIT ? 0 : 1, resolution, runArgs_.isRound);
52723b3eb3cSopenharmony_ci    DeviceConfig deviceConfig = runArgs_.deviceConfig;
52823b3eb3cSopenharmony_ci    deviceConfig.orientation = orientation;
52923b3eb3cSopenharmony_ci    deviceConfig.density = resolution;
53023b3eb3cSopenharmony_ci    container->UpdateDeviceConfig(deviceConfig);
53123b3eb3cSopenharmony_ci    viewPtr->NotifyDensityChanged(resolution);
53223b3eb3cSopenharmony_ci    viewPtr->NotifySurfaceChanged(width, height, type);
53323b3eb3cSopenharmony_ci    if ((orientation != runArgs_.deviceConfig.orientation && configChanges_.watchOrientation) ||
53423b3eb3cSopenharmony_ci        (resolution != runArgs_.deviceConfig.density && configChanges_.watchDensity) ||
53523b3eb3cSopenharmony_ci        ((width != runArgs_.deviceWidth || height != runArgs_.deviceHeight) && configChanges_.watchLayout)) {
53623b3eb3cSopenharmony_ci        container->NativeOnConfigurationUpdated(ACE_INSTANCE_ID);
53723b3eb3cSopenharmony_ci    }
53823b3eb3cSopenharmony_ci    if (orientation != runArgs_.deviceConfig.orientation || resolution != runArgs_.deviceConfig.density) {
53923b3eb3cSopenharmony_ci        container->NotifyConfigurationChange(false, ConfigurationChange({ false, false, true }));
54023b3eb3cSopenharmony_ci    }
54123b3eb3cSopenharmony_ci    runArgs_.deviceConfig.orientation = orientation;
54223b3eb3cSopenharmony_ci    runArgs_.deviceConfig.density = resolution;
54323b3eb3cSopenharmony_ci    runArgs_.deviceWidth = width;
54423b3eb3cSopenharmony_ci    runArgs_.deviceHeight = height;
54523b3eb3cSopenharmony_ci}
54623b3eb3cSopenharmony_ci
54723b3eb3cSopenharmony_civoid AceAbility::ReplacePage(const std::string& url, const std::string& params)
54823b3eb3cSopenharmony_ci{
54923b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
55023b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
55123b3eb3cSopenharmony_ci    container->GetFrontend()->ReplacePage(url, params);
55223b3eb3cSopenharmony_ci}
55323b3eb3cSopenharmony_ci
55423b3eb3cSopenharmony_civoid AceAbility::LoadDocument(const std::string& url, const std::string& componentName, SystemParams& systemParams)
55523b3eb3cSopenharmony_ci{
55623b3eb3cSopenharmony_ci    LOGI("Component Preview start:%{public}s, ", componentName.c_str());
55723b3eb3cSopenharmony_ci    AceApplicationInfo::GetInstance().ChangeLocale(systemParams.language, systemParams.region);
55823b3eb3cSopenharmony_ci    runArgs_.isRound = systemParams.isRound;
55923b3eb3cSopenharmony_ci    SurfaceChanged(systemParams.orientation, systemParams.density, systemParams.deviceWidth, systemParams.deviceHeight);
56023b3eb3cSopenharmony_ci    DeviceConfig deviceConfig = {
56123b3eb3cSopenharmony_ci        .orientation = systemParams.orientation,
56223b3eb3cSopenharmony_ci        .density = systemParams.density,
56323b3eb3cSopenharmony_ci        .deviceType = systemParams.deviceType,
56423b3eb3cSopenharmony_ci        .colorMode = systemParams.colorMode,
56523b3eb3cSopenharmony_ci    };
56623b3eb3cSopenharmony_ci    OnConfigurationChanged(deviceConfig);
56723b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
56823b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
56923b3eb3cSopenharmony_ci    container->LoadDocument(url, componentName);
57023b3eb3cSopenharmony_ci    LOGI("Component Preview end");
57123b3eb3cSopenharmony_ci}
57223b3eb3cSopenharmony_ci
57323b3eb3cSopenharmony_cistd::string AceAbility::GetJSONTree()
57423b3eb3cSopenharmony_ci{
57523b3eb3cSopenharmony_ci    LOGI("Inspector start");
57623b3eb3cSopenharmony_ci    std::string jsonTreeStr;
57723b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
57823b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(container, "");
57923b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
58023b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(taskExecutor, "");
58123b3eb3cSopenharmony_ci    taskExecutor->PostSyncTask(
58223b3eb3cSopenharmony_ci        [&jsonTreeStr] { OHOS::Ace::Framework::InspectorClient::GetInstance().AssembleJSONTreeStr(jsonTreeStr); },
58323b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIGetJsonTreeStr");
58423b3eb3cSopenharmony_ci    LOGI("Inspector end");
58523b3eb3cSopenharmony_ci    return jsonTreeStr;
58623b3eb3cSopenharmony_ci}
58723b3eb3cSopenharmony_ci
58823b3eb3cSopenharmony_cistd::string AceAbility::GetDefaultJSONTree()
58923b3eb3cSopenharmony_ci{
59023b3eb3cSopenharmony_ci    std::string defaultJsonTreeStr;
59123b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
59223b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(container, "");
59323b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
59423b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(taskExecutor, "");
59523b3eb3cSopenharmony_ci    taskExecutor->PostSyncTask(
59623b3eb3cSopenharmony_ci        [&defaultJsonTreeStr] {
59723b3eb3cSopenharmony_ci            OHOS::Ace::Framework::InspectorClient::GetInstance().AssembleDefaultJSONTreeStr(defaultJsonTreeStr);
59823b3eb3cSopenharmony_ci        },
59923b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIGetDefaultJsonTreeStr");
60023b3eb3cSopenharmony_ci    return defaultJsonTreeStr;
60123b3eb3cSopenharmony_ci}
60223b3eb3cSopenharmony_ci
60323b3eb3cSopenharmony_cibool AceAbility::OperateComponent(const std::string& attrsJson)
60423b3eb3cSopenharmony_ci{
60523b3eb3cSopenharmony_ci    LOGI("Fast Preview start");
60623b3eb3cSopenharmony_ci    auto root = JsonUtil::ParseJsonString(attrsJson);
60723b3eb3cSopenharmony_ci    if (!root || !root->IsValid()) {
60823b3eb3cSopenharmony_ci        LOGE("Fast Preview failed: the attrsJson is illegal json format");
60923b3eb3cSopenharmony_ci        return false;
61023b3eb3cSopenharmony_ci    }
61123b3eb3cSopenharmony_ci
61223b3eb3cSopenharmony_ci    auto container = AceContainer::GetContainerInstance(ACE_INSTANCE_ID);
61323b3eb3cSopenharmony_ci    if (!container) {
61423b3eb3cSopenharmony_ci        LOGE("Fast Preview failed: container is null");
61523b3eb3cSopenharmony_ci        return false;
61623b3eb3cSopenharmony_ci    }
61723b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
61823b3eb3cSopenharmony_ci    if (!taskExecutor) {
61923b3eb3cSopenharmony_ci        LOGE("Fast Preview failed: taskExecutor is null");
62023b3eb3cSopenharmony_ci        return false;
62123b3eb3cSopenharmony_ci    }
62223b3eb3cSopenharmony_ci    taskExecutor->PostTask(
62323b3eb3cSopenharmony_ci        [attrsJson, instanceId = ACE_INSTANCE_ID] {
62423b3eb3cSopenharmony_ci            ContainerScope scope(instanceId);
62523b3eb3cSopenharmony_ci            bool result = OHOS::Ace::Framework::InspectorClient::GetInstance().OperateComponent(attrsJson);
62623b3eb3cSopenharmony_ci            if (!result) {
62723b3eb3cSopenharmony_ci                OHOS::Ace::Framework::InspectorClient::GetInstance().CallFastPreviewErrorCallback(attrsJson);
62823b3eb3cSopenharmony_ci            }
62923b3eb3cSopenharmony_ci        },
63023b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIOperateComponent");
63123b3eb3cSopenharmony_ci    LOGI("Fast Preview end");
63223b3eb3cSopenharmony_ci    return true;
63323b3eb3cSopenharmony_ci}
63423b3eb3cSopenharmony_ci
63523b3eb3cSopenharmony_civoid AceAbility::SetWindow(sptr<OHOS::Rosen::Window> rsWindow)
63623b3eb3cSopenharmony_ci{
63723b3eb3cSopenharmony_ci    rsWindow_ = rsWindow;
63823b3eb3cSopenharmony_ci}
63923b3eb3cSopenharmony_ci
64023b3eb3cSopenharmony_cisptr<OHOS::Rosen::Window> AceAbility::GetWindow()
64123b3eb3cSopenharmony_ci{
64223b3eb3cSopenharmony_ci    return rsWindow_;
64323b3eb3cSopenharmony_ci}
64423b3eb3cSopenharmony_ci
64523b3eb3cSopenharmony_ci} // namespace OHOS::Ace::Platform
646