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/ohos/entrance/ace_ability.h"
1723b3eb3cSopenharmony_ci
1823b3eb3cSopenharmony_ci#include <ui/rs_surface_node.h>
1923b3eb3cSopenharmony_ci
2023b3eb3cSopenharmony_ci#include "ability_process.h"
2123b3eb3cSopenharmony_ci#include "dm/display_manager.h"
2223b3eb3cSopenharmony_ci#include "form_utils_impl.h"
2323b3eb3cSopenharmony_ci#include "ohos/init_data.h"
2423b3eb3cSopenharmony_ci#include "ipc_skeleton.h"
2523b3eb3cSopenharmony_ci#include "res_config.h"
2623b3eb3cSopenharmony_ci#include "resource_manager.h"
2723b3eb3cSopenharmony_ci#include "session_info.h"
2823b3eb3cSopenharmony_ci#include "string_wrapper.h"
2923b3eb3cSopenharmony_ci
3023b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND
3123b3eb3cSopenharmony_ci#include "render_service_client/core/ui/rs_ui_director.h"
3223b3eb3cSopenharmony_ci#endif
3323b3eb3cSopenharmony_ci
3423b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_application_info.h"
3523b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_container.h"
3623b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_new_pipe_judgement.h"
3723b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/ace_view_ohos.h"
3823b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/capability_registry.h"
3923b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/plugin_utils_impl.h"
4023b3eb3cSopenharmony_ci#include "adapter/ohos/entrance/utils.h"
4123b3eb3cSopenharmony_ci#include "base/geometry/rect.h"
4223b3eb3cSopenharmony_ci#include "base/subwindow/subwindow_manager.h"
4323b3eb3cSopenharmony_ci#include "base/utils/system_properties.h"
4423b3eb3cSopenharmony_ci#include "base/utils/utils.h"
4523b3eb3cSopenharmony_ci#include "core/common/ace_engine.h"
4623b3eb3cSopenharmony_ci#include "core/common/container_scope.h"
4723b3eb3cSopenharmony_ci#include "core/common/form_manager.h"
4823b3eb3cSopenharmony_ci#include "core/common/frontend.h"
4923b3eb3cSopenharmony_ci#include "core/common/layout_inspector.h"
5023b3eb3cSopenharmony_ci#include "core/common/plugin_manager.h"
5123b3eb3cSopenharmony_ci#include "core/common/plugin_utils.h"
5223b3eb3cSopenharmony_ci#include "core/image/image_file_cache.h"
5323b3eb3cSopenharmony_cinamespace OHOS {
5423b3eb3cSopenharmony_cinamespace Ace {
5523b3eb3cSopenharmony_cinamespace {
5623b3eb3cSopenharmony_ci
5723b3eb3cSopenharmony_ciconst std::string ABS_BUNDLE_CODE_PATH = "/data/app/el1/bundle/public/";
5823b3eb3cSopenharmony_ciconst std::string LOCAL_BUNDLE_CODE_PATH = "/data/storage/el1/bundle/";
5923b3eb3cSopenharmony_ciconst std::string FILE_SEPARATOR = "/";
6023b3eb3cSopenharmony_ciconst std::string ACTION_VIEWDATA = "ohos.want.action.viewData";
6123b3eb3cSopenharmony_ciconstexpr int32_t PLATFORM_VERSION_TEN = 10;
6223b3eb3cSopenharmony_ci
6323b3eb3cSopenharmony_ciFrontendType GetFrontendType(const std::string& frontendType)
6423b3eb3cSopenharmony_ci{
6523b3eb3cSopenharmony_ci    if (frontendType == "normal") {
6623b3eb3cSopenharmony_ci        return FrontendType::JS;
6723b3eb3cSopenharmony_ci    } else if (frontendType == "form") {
6823b3eb3cSopenharmony_ci        return FrontendType::JS_CARD;
6923b3eb3cSopenharmony_ci    } else if (frontendType == "declarative") {
7023b3eb3cSopenharmony_ci        return FrontendType::DECLARATIVE_JS;
7123b3eb3cSopenharmony_ci    } else {
7223b3eb3cSopenharmony_ci        return FrontendType::JS;
7323b3eb3cSopenharmony_ci    }
7423b3eb3cSopenharmony_ci}
7523b3eb3cSopenharmony_ci
7623b3eb3cSopenharmony_ciFrontendType GetFrontendTypeFromManifest(const std::string& packagePath, const std::string& srcPath, bool isHap)
7723b3eb3cSopenharmony_ci{
7823b3eb3cSopenharmony_ci    std::string manifest = std::string("assets/js/default/manifest.json");
7923b3eb3cSopenharmony_ci    if (!srcPath.empty()) {
8023b3eb3cSopenharmony_ci        manifest = "assets/js/" + srcPath + "/manifest.json";
8123b3eb3cSopenharmony_ci    }
8223b3eb3cSopenharmony_ci    std::string jsonStr = isHap ? GetStringFromHap(packagePath, manifest) : GetStringFromFile(packagePath, manifest);
8323b3eb3cSopenharmony_ci    if (jsonStr.empty()) {
8423b3eb3cSopenharmony_ci        return FrontendType::JS;
8523b3eb3cSopenharmony_ci    }
8623b3eb3cSopenharmony_ci    auto rootJson = JsonUtil::ParseJsonString(jsonStr);
8723b3eb3cSopenharmony_ci    if (rootJson == nullptr) {
8823b3eb3cSopenharmony_ci        return FrontendType::JS;
8923b3eb3cSopenharmony_ci    }
9023b3eb3cSopenharmony_ci    auto mode = rootJson->GetObject("mode");
9123b3eb3cSopenharmony_ci    if (mode != nullptr) {
9223b3eb3cSopenharmony_ci        if (mode->GetString("syntax") == "ets" || mode->GetString("type") == "pageAbility") {
9323b3eb3cSopenharmony_ci            return FrontendType::DECLARATIVE_JS;
9423b3eb3cSopenharmony_ci        }
9523b3eb3cSopenharmony_ci    }
9623b3eb3cSopenharmony_ci    return GetFrontendType(rootJson->GetString("type"));
9723b3eb3cSopenharmony_ci}
9823b3eb3cSopenharmony_ci
9923b3eb3cSopenharmony_ci} // namespace
10023b3eb3cSopenharmony_ci
10123b3eb3cSopenharmony_ciusing namespace OHOS::AAFwk;
10223b3eb3cSopenharmony_ciusing namespace OHOS::AppExecFwk;
10323b3eb3cSopenharmony_ci
10423b3eb3cSopenharmony_ciusing AcePlatformFinish = std::function<void()>;
10523b3eb3cSopenharmony_ciusing AcePlatformStartAbility = std::function<void(const std::string& address)>;
10623b3eb3cSopenharmony_ciclass AcePlatformEventCallback final : public Platform::PlatformEventCallback {
10723b3eb3cSopenharmony_cipublic:
10823b3eb3cSopenharmony_ci    explicit AcePlatformEventCallback(AcePlatformFinish onFinish) : onFinish_(onFinish) {}
10923b3eb3cSopenharmony_ci    AcePlatformEventCallback(AcePlatformFinish onFinish, AcePlatformStartAbility onStartAbility)
11023b3eb3cSopenharmony_ci        : onFinish_(onFinish), onStartAbility_(onStartAbility)
11123b3eb3cSopenharmony_ci    {}
11223b3eb3cSopenharmony_ci
11323b3eb3cSopenharmony_ci    ~AcePlatformEventCallback() override = default;
11423b3eb3cSopenharmony_ci
11523b3eb3cSopenharmony_ci    void OnFinish() const override
11623b3eb3cSopenharmony_ci    {
11723b3eb3cSopenharmony_ci        LOGI("AcePlatformEventCallback OnFinish");
11823b3eb3cSopenharmony_ci        CHECK_NULL_VOID(onFinish_);
11923b3eb3cSopenharmony_ci        onFinish_();
12023b3eb3cSopenharmony_ci    }
12123b3eb3cSopenharmony_ci
12223b3eb3cSopenharmony_ci    void OnStartAbility(const std::string& address) override
12323b3eb3cSopenharmony_ci    {
12423b3eb3cSopenharmony_ci        LOGI("AcePlatformEventCallback OnStartAbility");
12523b3eb3cSopenharmony_ci        CHECK_NULL_VOID(onStartAbility_);
12623b3eb3cSopenharmony_ci        onStartAbility_(address);
12723b3eb3cSopenharmony_ci    }
12823b3eb3cSopenharmony_ci
12923b3eb3cSopenharmony_ci    void OnStatusBarBgColorChanged(uint32_t color) override
13023b3eb3cSopenharmony_ci    {
13123b3eb3cSopenharmony_ci        LOGI("AcePlatformEventCallback OnStatusBarBgColorChanged");
13223b3eb3cSopenharmony_ci    }
13323b3eb3cSopenharmony_ci
13423b3eb3cSopenharmony_ciprivate:
13523b3eb3cSopenharmony_ci    AcePlatformFinish onFinish_;
13623b3eb3cSopenharmony_ci    AcePlatformStartAbility onStartAbility_;
13723b3eb3cSopenharmony_ci};
13823b3eb3cSopenharmony_ci
13923b3eb3cSopenharmony_ciconst std::string AceAbility::START_PARAMS_KEY = "__startParams";
14023b3eb3cSopenharmony_ciconst std::string AceAbility::PAGE_URI = "url";
14123b3eb3cSopenharmony_ciconst std::string AceAbility::CONTINUE_PARAMS_KEY = "__remoteData";
14223b3eb3cSopenharmony_ci
14323b3eb3cSopenharmony_ciREGISTER_AA(AceAbility)
14423b3eb3cSopenharmony_civoid AceWindowListener::OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event)
14523b3eb3cSopenharmony_ci{
14623b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
14723b3eb3cSopenharmony_ci    callbackOwner_->OnDrag(x, y, event);
14823b3eb3cSopenharmony_ci}
14923b3eb3cSopenharmony_ci
15023b3eb3cSopenharmony_civoid AceWindowListener::OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info,
15123b3eb3cSopenharmony_ci    const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
15223b3eb3cSopenharmony_ci{
15323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
15423b3eb3cSopenharmony_ci    callbackOwner_->OnSizeChange(info, rsTransaction);
15523b3eb3cSopenharmony_ci}
15623b3eb3cSopenharmony_ci
15723b3eb3cSopenharmony_civoid AceWindowListener::SetBackgroundColor(uint32_t color)
15823b3eb3cSopenharmony_ci{
15923b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
16023b3eb3cSopenharmony_ci    callbackOwner_->SetBackgroundColor(color);
16123b3eb3cSopenharmony_ci}
16223b3eb3cSopenharmony_ci
16323b3eb3cSopenharmony_ciuint32_t AceWindowListener::GetBackgroundColor()
16423b3eb3cSopenharmony_ci{
16523b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(callbackOwner_, 0);
16623b3eb3cSopenharmony_ci    return callbackOwner_->GetBackgroundColor();
16723b3eb3cSopenharmony_ci}
16823b3eb3cSopenharmony_ci
16923b3eb3cSopenharmony_civoid AceWindowListener::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason,
17023b3eb3cSopenharmony_ci    const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
17123b3eb3cSopenharmony_ci{
17223b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
17323b3eb3cSopenharmony_ci    callbackOwner_->OnSizeChange(rect, reason, rsTransaction);
17423b3eb3cSopenharmony_ci}
17523b3eb3cSopenharmony_ci
17623b3eb3cSopenharmony_civoid AceWindowListener::OnModeChange(OHOS::Rosen::WindowMode mode, bool hasDeco)
17723b3eb3cSopenharmony_ci{
17823b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
17923b3eb3cSopenharmony_ci    callbackOwner_->OnModeChange(mode, hasDeco);
18023b3eb3cSopenharmony_ci}
18123b3eb3cSopenharmony_ci
18223b3eb3cSopenharmony_cibool AceWindowListener::OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const
18323b3eb3cSopenharmony_ci{
18423b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(callbackOwner_, false);
18523b3eb3cSopenharmony_ci    return callbackOwner_->OnInputEvent(keyEvent);
18623b3eb3cSopenharmony_ci}
18723b3eb3cSopenharmony_ci
18823b3eb3cSopenharmony_cibool AceWindowListener::OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const
18923b3eb3cSopenharmony_ci{
19023b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(callbackOwner_, false);
19123b3eb3cSopenharmony_ci    return callbackOwner_->OnInputEvent(pointerEvent);
19223b3eb3cSopenharmony_ci}
19323b3eb3cSopenharmony_ci
19423b3eb3cSopenharmony_cibool AceWindowListener::OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const
19523b3eb3cSopenharmony_ci{
19623b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(callbackOwner_, false);
19723b3eb3cSopenharmony_ci    return callbackOwner_->OnInputEvent(axisEvent);
19823b3eb3cSopenharmony_ci}
19923b3eb3cSopenharmony_ci
20023b3eb3cSopenharmony_civoid AceWindowListener::OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea avoidArea, OHOS::Rosen::AvoidAreaType type)
20123b3eb3cSopenharmony_ci{
20223b3eb3cSopenharmony_ci    CHECK_NULL_VOID(callbackOwner_);
20323b3eb3cSopenharmony_ci    return callbackOwner_->OnAvoidAreaChanged(avoidArea, type);
20423b3eb3cSopenharmony_ci}
20523b3eb3cSopenharmony_ci
20623b3eb3cSopenharmony_ciAceAbility::AceAbility() = default;
20723b3eb3cSopenharmony_ci
20823b3eb3cSopenharmony_civoid AceAbility::OnStart(const Want& want, sptr<AAFwk::SessionInfo> sessionInfo)
20923b3eb3cSopenharmony_ci{
21023b3eb3cSopenharmony_ci    Ability::OnStart(want, sessionInfo);
21123b3eb3cSopenharmony_ci    abilityId_ = Container::GenerateId<FA_CONTAINER>();
21223b3eb3cSopenharmony_ci    static std::once_flag onceFlag;
21323b3eb3cSopenharmony_ci    auto abilityContext = GetAbilityContext();
21423b3eb3cSopenharmony_ci    auto cacheDir = abilityContext->GetCacheDir();
21523b3eb3cSopenharmony_ci    std::call_once(onceFlag, [abilityContext, cacheDir]() {
21623b3eb3cSopenharmony_ci        SetHwIcuDirectory();
21723b3eb3cSopenharmony_ci        Container::UpdateCurrent(INSTANCE_ID_PLATFORM);
21823b3eb3cSopenharmony_ci        CapabilityRegistry::Register();
21923b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetPackageName(abilityContext->GetBundleName());
22023b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetDataFileDirPath(abilityContext->GetFilesDir());
22123b3eb3cSopenharmony_ci        auto applicationInfo = abilityContext->GetApplicationInfo();
22223b3eb3cSopenharmony_ci        if (applicationInfo) {
22323b3eb3cSopenharmony_ci            AceApplicationInfo::GetInstance().SetApiTargetVersion(applicationInfo->apiTargetVersion);
22423b3eb3cSopenharmony_ci            AceApplicationInfo::GetInstance().SetAppVersionName(applicationInfo->versionName);
22523b3eb3cSopenharmony_ci            AceApplicationInfo::GetInstance().SetAppVersionCode(applicationInfo->versionCode);
22623b3eb3cSopenharmony_ci        } else {
22723b3eb3cSopenharmony_ci            LOGE("ability start set application info failed,it may cause exception");
22823b3eb3cSopenharmony_ci            return;
22923b3eb3cSopenharmony_ci        }
23023b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetUid(IPCSkeleton::GetCallingUid());
23123b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetPid(IPCSkeleton::GetCallingRealPid());
23223b3eb3cSopenharmony_ci        ImageFileCache::GetInstance().SetImageCacheFilePath(cacheDir);
23323b3eb3cSopenharmony_ci        ImageFileCache::GetInstance().SetCacheFileInfo();
23423b3eb3cSopenharmony_ci        AceEngine::InitJsDumpHeadSignal();
23523b3eb3cSopenharmony_ci    });
23623b3eb3cSopenharmony_ci    AceNewPipeJudgement::InitAceNewPipeConfig();
23723b3eb3cSopenharmony_ci    // now choose pipeline using param set as package name, later enable for all.
23823b3eb3cSopenharmony_ci    auto apiCompatibleVersion = abilityContext->GetApplicationInfo()->apiCompatibleVersion;
23923b3eb3cSopenharmony_ci    auto apiReleaseType = abilityContext->GetApplicationInfo()->apiReleaseType;
24023b3eb3cSopenharmony_ci    auto apiTargetVersion = abilityContext->GetApplicationInfo()->apiTargetVersion;
24123b3eb3cSopenharmony_ci    auto useNewPipe = AceNewPipeJudgement::QueryAceNewPipeEnabledFA(
24223b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().GetPackageName(), apiCompatibleVersion, apiTargetVersion, apiReleaseType);
24323b3eb3cSopenharmony_ci    LOGI("AceAbility OnStart called, apiCompatibleVersion: %{public}d, apiTargetVersion: %{public}d, "
24423b3eb3cSopenharmony_ci         "and apiReleaseType: %{public}s, useNewPipe: %{public}d",
24523b3eb3cSopenharmony_ci        apiCompatibleVersion, apiTargetVersion, apiReleaseType.c_str(), useNewPipe);
24623b3eb3cSopenharmony_ci    OHOS::sptr<OHOS::Rosen::Window> window = Ability::GetWindow();
24723b3eb3cSopenharmony_ci    std::shared_ptr<AceAbility> self = std::static_pointer_cast<AceAbility>(shared_from_this());
24823b3eb3cSopenharmony_ci    OHOS::sptr<AceWindowListener> aceWindowListener = new AceWindowListener(self);
24923b3eb3cSopenharmony_ci    // register surface change callback and window mode change callback
25023b3eb3cSopenharmony_ci    window->RegisterWindowChangeListener(aceWindowListener);
25123b3eb3cSopenharmony_ci    // register drag event callback
25223b3eb3cSopenharmony_ci    window->RegisterDragListener(aceWindowListener);
25323b3eb3cSopenharmony_ci    // register Occupied Area callback
25423b3eb3cSopenharmony_ci    window->RegisterOccupiedAreaChangeListener(aceWindowListener);
25523b3eb3cSopenharmony_ci    // register ace ability handler callback
25623b3eb3cSopenharmony_ci    window->SetAceAbilityHandler(aceWindowListener);
25723b3eb3cSopenharmony_ci    // register input consumer callback
25823b3eb3cSopenharmony_ci    std::shared_ptr<AceWindowListener> aceInputConsumer = std::make_shared<AceWindowListener>(self);
25923b3eb3cSopenharmony_ci    window->SetInputEventConsumer(aceInputConsumer);
26023b3eb3cSopenharmony_ci
26123b3eb3cSopenharmony_ci    int32_t deviceWidth = 0;
26223b3eb3cSopenharmony_ci    int32_t deviceHeight = 0;
26323b3eb3cSopenharmony_ci    auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
26423b3eb3cSopenharmony_ci    if (defaultDisplay) {
26523b3eb3cSopenharmony_ci        density_ = defaultDisplay->GetVirtualPixelRatio();
26623b3eb3cSopenharmony_ci        deviceWidth = defaultDisplay->GetWidth();
26723b3eb3cSopenharmony_ci        deviceHeight = defaultDisplay->GetHeight();
26823b3eb3cSopenharmony_ci        LOGI("deviceWidth: %{public}d, deviceHeight: %{public}d, default density: %{public}f", deviceWidth,
26923b3eb3cSopenharmony_ci            deviceHeight, density_);
27023b3eb3cSopenharmony_ci    }
27123b3eb3cSopenharmony_ci    SystemProperties::InitDeviceInfo(deviceWidth, deviceHeight, deviceHeight >= deviceWidth ? 0 : 1, density_, false);
27223b3eb3cSopenharmony_ci    SystemProperties::SetColorMode(ColorMode::LIGHT);
27323b3eb3cSopenharmony_ci
27423b3eb3cSopenharmony_ci    std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig());
27523b3eb3cSopenharmony_ci    auto resourceManager = GetResourceManager();
27623b3eb3cSopenharmony_ci    if (resourceManager != nullptr) {
27723b3eb3cSopenharmony_ci        resourceManager->GetResConfig(*resConfig);
27823b3eb3cSopenharmony_ci        auto localeInfo = resConfig->GetLocaleInfo();
27923b3eb3cSopenharmony_ci        Platform::AceApplicationInfoImpl::GetInstance().SetResourceManager(resourceManager);
28023b3eb3cSopenharmony_ci        if (localeInfo != nullptr) {
28123b3eb3cSopenharmony_ci            auto language = localeInfo->getLanguage();
28223b3eb3cSopenharmony_ci            auto region = localeInfo->getCountry();
28323b3eb3cSopenharmony_ci            auto script = localeInfo->getScript();
28423b3eb3cSopenharmony_ci            AceApplicationInfo::GetInstance().SetLocale((language == nullptr) ? "" : language,
28523b3eb3cSopenharmony_ci                (region == nullptr) ? "" : region, (script == nullptr) ? "" : script, "");
28623b3eb3cSopenharmony_ci        } else {
28723b3eb3cSopenharmony_ci            LOGW("localeInfo is null.");
28823b3eb3cSopenharmony_ci            AceApplicationInfo::GetInstance().SetLocale("", "", "", "");
28923b3eb3cSopenharmony_ci        }
29023b3eb3cSopenharmony_ci        if (resConfig->GetColorMode() == OHOS::Global::Resource::ColorMode::DARK) {
29123b3eb3cSopenharmony_ci            SystemProperties::SetColorMode(ColorMode::DARK);
29223b3eb3cSopenharmony_ci            LOGI("UIContent set dark mode");
29323b3eb3cSopenharmony_ci        } else {
29423b3eb3cSopenharmony_ci            SystemProperties::SetColorMode(ColorMode::LIGHT);
29523b3eb3cSopenharmony_ci            LOGI("UIContent set light mode");
29623b3eb3cSopenharmony_ci        }
29723b3eb3cSopenharmony_ci        SystemProperties::SetDeviceAccess(
29823b3eb3cSopenharmony_ci            resConfig->GetInputDevice() == Global::Resource::InputDevice::INPUTDEVICE_POINTINGDEVICE);
29923b3eb3cSopenharmony_ci    } else {
30023b3eb3cSopenharmony_ci        LOGW("resourceManager is null.");
30123b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetLocale("", "", "", "");
30223b3eb3cSopenharmony_ci    }
30323b3eb3cSopenharmony_ci
30423b3eb3cSopenharmony_ci    auto packagePathStr = GetBundleCodePath();
30523b3eb3cSopenharmony_ci    auto moduleInfo = GetHapModuleInfo();
30623b3eb3cSopenharmony_ci    CHECK_NULL_VOID(moduleInfo);
30723b3eb3cSopenharmony_ci    packagePathStr += "/" + moduleInfo->package + "/";
30823b3eb3cSopenharmony_ci    std::shared_ptr<AbilityInfo> info = GetAbilityInfo();
30923b3eb3cSopenharmony_ci    std::string srcPath;
31023b3eb3cSopenharmony_ci    if (info != nullptr && !info->srcPath.empty()) {
31123b3eb3cSopenharmony_ci        srcPath = info->srcPath;
31223b3eb3cSopenharmony_ci    }
31323b3eb3cSopenharmony_ci    if (info != nullptr && !info->bundleName.empty()) {
31423b3eb3cSopenharmony_ci        AceApplicationInfo::GetInstance().SetPackageName(info->bundleName);
31523b3eb3cSopenharmony_ci    }
31623b3eb3cSopenharmony_ci
31723b3eb3cSopenharmony_ci    bool isHap = moduleInfo ? !moduleInfo->hapPath.empty() : false;
31823b3eb3cSopenharmony_ci    std::string& packagePath = isHap ? moduleInfo->hapPath : packagePathStr;
31923b3eb3cSopenharmony_ci    FrontendType frontendType = GetFrontendTypeFromManifest(packagePath, srcPath, isHap);
32023b3eb3cSopenharmony_ci    useNewPipe = useNewPipe && (frontendType == FrontendType::ETS_CARD || frontendType == FrontendType::DECLARATIVE_JS);
32123b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND
32223b3eb3cSopenharmony_ci    std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUiDirector;
32323b3eb3cSopenharmony_ci#ifndef NG_BUILD
32423b3eb3cSopenharmony_ci    if (SystemProperties::GetRosenBackendEnabled() && !useNewPipe) {
32523b3eb3cSopenharmony_ci        rsUiDirector = OHOS::Rosen::RSUIDirector::Create();
32623b3eb3cSopenharmony_ci        auto surfaceNode = window->GetSurfaceNode();
32723b3eb3cSopenharmony_ci        rsUiDirector->SetRSSurfaceNode(surfaceNode);
32823b3eb3cSopenharmony_ci        rsUiDirector->SetCacheDir(cacheDir);
32923b3eb3cSopenharmony_ci        rsUiDirector->Init();
33023b3eb3cSopenharmony_ci    }
33123b3eb3cSopenharmony_ci#endif
33223b3eb3cSopenharmony_ci#endif
33323b3eb3cSopenharmony_ci    AceApplicationInfo::GetInstance().SetAbilityName(info ? info->name : "");
33423b3eb3cSopenharmony_ci    std::string moduleName = info ? info->moduleName : "";
33523b3eb3cSopenharmony_ci    std::string moduleHapPath = info ? info->hapPath : "";
33623b3eb3cSopenharmony_ci
33723b3eb3cSopenharmony_ci    std::shared_ptr<ApplicationInfo> appInfo = GetApplicationInfo();
33823b3eb3cSopenharmony_ci    std::vector<ModuleInfo> moduleList = appInfo->moduleInfos;
33923b3eb3cSopenharmony_ci
34023b3eb3cSopenharmony_ci    std::string resPath;
34123b3eb3cSopenharmony_ci    for (const auto& module : moduleList) {
34223b3eb3cSopenharmony_ci        if (module.moduleName == moduleName && info != nullptr) {
34323b3eb3cSopenharmony_ci            std::regex pattern(ABS_BUNDLE_CODE_PATH + info->bundleName + FILE_SEPARATOR);
34423b3eb3cSopenharmony_ci            auto moduleSourceDir = std::regex_replace(module.moduleSourceDir, pattern, LOCAL_BUNDLE_CODE_PATH);
34523b3eb3cSopenharmony_ci            resPath = moduleSourceDir + "/assets/" + module.moduleName + FILE_SEPARATOR;
34623b3eb3cSopenharmony_ci            break;
34723b3eb3cSopenharmony_ci        }
34823b3eb3cSopenharmony_ci    }
34923b3eb3cSopenharmony_ci    std::string hapPath;
35023b3eb3cSopenharmony_ci    if (!moduleHapPath.empty()) {
35123b3eb3cSopenharmony_ci        if (moduleHapPath.find(ABS_BUNDLE_CODE_PATH) == std::string::npos) {
35223b3eb3cSopenharmony_ci            hapPath = moduleHapPath;
35323b3eb3cSopenharmony_ci        } else {
35423b3eb3cSopenharmony_ci            auto pos = moduleHapPath.find_last_of('/');
35523b3eb3cSopenharmony_ci            if (pos != std::string::npos) {
35623b3eb3cSopenharmony_ci                hapPath = LOCAL_BUNDLE_CODE_PATH + moduleHapPath.substr(pos + 1);
35723b3eb3cSopenharmony_ci                LOGI("In FA mode, hapPath:%{private}s", hapPath.c_str());
35823b3eb3cSopenharmony_ci            }
35923b3eb3cSopenharmony_ci        }
36023b3eb3cSopenharmony_ci    }
36123b3eb3cSopenharmony_ci
36223b3eb3cSopenharmony_ci    AceApplicationInfo::GetInstance().SetDebug(appInfo->debug, want.GetBoolParam("debugApp", false));
36323b3eb3cSopenharmony_ci
36423b3eb3cSopenharmony_ci#ifdef PLUGIN_COMPONENT_SUPPORTED
36523b3eb3cSopenharmony_ci    auto pluginUtils = std::make_shared<PluginUtilsImpl>();
36623b3eb3cSopenharmony_ci    PluginManager::GetInstance().SetAceAbility(this, pluginUtils);
36723b3eb3cSopenharmony_ci#endif
36823b3eb3cSopenharmony_ci#ifdef FORM_SUPPORTED
36923b3eb3cSopenharmony_ci    auto formUtils = std::make_shared<FormUtilsImpl>();
37023b3eb3cSopenharmony_ci    FormManager::GetInstance().SetFormUtils(formUtils);
37123b3eb3cSopenharmony_ci#endif
37223b3eb3cSopenharmony_ci    // create container
37323b3eb3cSopenharmony_ci    Platform::AceContainer::CreateContainer(abilityId_, frontendType, srcPath, shared_from_this(),
37423b3eb3cSopenharmony_ci        std::make_unique<AcePlatformEventCallback>([this]() { TerminateAbility(); },
37523b3eb3cSopenharmony_ci            [this](const std::string& address) {
37623b3eb3cSopenharmony_ci                AAFwk::Want want;
37723b3eb3cSopenharmony_ci                want.AddEntity(Want::ENTITY_BROWSER);
37823b3eb3cSopenharmony_ci                want.SetUri(address);
37923b3eb3cSopenharmony_ci                want.SetAction(ACTION_VIEWDATA);
38023b3eb3cSopenharmony_ci                this->StartAbility(want);
38123b3eb3cSopenharmony_ci            }),
38223b3eb3cSopenharmony_ci        false, useNewPipe);
38323b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
38423b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
38523b3eb3cSopenharmony_ci    container->SetToken(token_);
38623b3eb3cSopenharmony_ci    auto aceResCfg = container->GetResourceConfiguration();
38723b3eb3cSopenharmony_ci    aceResCfg.SetOrientation(SystemProperties::GetDeviceOrientation());
38823b3eb3cSopenharmony_ci    aceResCfg.SetDensity(SystemProperties::GetResolution());
38923b3eb3cSopenharmony_ci    aceResCfg.SetDeviceType(SystemProperties::GetDeviceType());
39023b3eb3cSopenharmony_ci    aceResCfg.SetColorMode(SystemProperties::GetColorMode());
39123b3eb3cSopenharmony_ci    aceResCfg.SetDeviceAccess(SystemProperties::GetDeviceAccess());
39223b3eb3cSopenharmony_ci    container->SetResourceConfiguration(aceResCfg);
39323b3eb3cSopenharmony_ci    container->SetPackagePathStr(resPath);
39423b3eb3cSopenharmony_ci    container->SetHapPath(hapPath);
39523b3eb3cSopenharmony_ci    container->SetBundlePath(abilityContext->GetBundleCodeDir());
39623b3eb3cSopenharmony_ci    container->SetFilesDataPath(abilityContext->GetFilesDir());
39723b3eb3cSopenharmony_ci    if (window->IsDecorEnable()) {
39823b3eb3cSopenharmony_ci        LOGI("Container modal is enabled.");
39923b3eb3cSopenharmony_ci        container->SetWindowModal(WindowModal::CONTAINER_MODAL);
40023b3eb3cSopenharmony_ci    }
40123b3eb3cSopenharmony_ci    container->SetWindowName(window->GetWindowName());
40223b3eb3cSopenharmony_ci    container->SetWindowId(window->GetWindowId());
40323b3eb3cSopenharmony_ci    SubwindowManager::GetInstance()->AddContainerId(window->GetWindowId(), abilityId_);
40423b3eb3cSopenharmony_ci    // create view.
40523b3eb3cSopenharmony_ci    auto aceView = Platform::AceViewOhos::CreateView(abilityId_);
40623b3eb3cSopenharmony_ci    Platform::AceViewOhos::SurfaceCreated(aceView, window);
40723b3eb3cSopenharmony_ci
40823b3eb3cSopenharmony_ci    if (srcPath.empty()) {
40923b3eb3cSopenharmony_ci        auto assetBasePathStr = { std::string("assets/js/default/"), std::string("assets/js/share/") };
41023b3eb3cSopenharmony_ci        Platform::AceContainer::AddAssetPath(abilityId_, packagePathStr, moduleInfo->hapPath, assetBasePathStr);
41123b3eb3cSopenharmony_ci    } else {
41223b3eb3cSopenharmony_ci        auto assetBasePathStr = { "assets/js/" + srcPath + "/", std::string("assets/js/share/"),
41323b3eb3cSopenharmony_ci            std::string("assets/js/") };
41423b3eb3cSopenharmony_ci        Platform::AceContainer::AddAssetPath(abilityId_, packagePathStr, moduleInfo->hapPath, assetBasePathStr);
41523b3eb3cSopenharmony_ci    }
41623b3eb3cSopenharmony_ci
41723b3eb3cSopenharmony_ci#ifndef NG_BUILD
41823b3eb3cSopenharmony_ci    if (!useNewPipe) {
41923b3eb3cSopenharmony_ci        Ace::Platform::UIEnvCallback callback = nullptr;
42023b3eb3cSopenharmony_ci#ifdef ENABLE_ROSEN_BACKEND
42123b3eb3cSopenharmony_ci        callback = [window, id = abilityId_, aceView, rsUiDirector](
42223b3eb3cSopenharmony_ci                       const OHOS::Ace::RefPtr<OHOS::Ace::PipelineContext>& context) mutable {
42323b3eb3cSopenharmony_ci            if (rsUiDirector) {
42423b3eb3cSopenharmony_ci                rsUiDirector->SetUITaskRunner(
42523b3eb3cSopenharmony_ci                    [taskExecutor = Platform::AceContainer::GetContainer(id)->GetTaskExecutor(), id](
42623b3eb3cSopenharmony_ci                        const std::function<void()>& task, uint32_t delay) {
42723b3eb3cSopenharmony_ci                        ContainerScope scope(id);
42823b3eb3cSopenharmony_ci                        taskExecutor->PostDelayedTask(
42923b3eb3cSopenharmony_ci                            task, TaskExecutor::TaskType::UI, delay, "ArkUIRenderServiceTask", PriorityType::HIGH);
43023b3eb3cSopenharmony_ci                    }, id);
43123b3eb3cSopenharmony_ci                if (context != nullptr) {
43223b3eb3cSopenharmony_ci                    context->SetRSUIDirector(rsUiDirector);
43323b3eb3cSopenharmony_ci                }
43423b3eb3cSopenharmony_ci                LOGI("Init Rosen Backend");
43523b3eb3cSopenharmony_ci            }
43623b3eb3cSopenharmony_ci        };
43723b3eb3cSopenharmony_ci#endif
43823b3eb3cSopenharmony_ci        // set view
43923b3eb3cSopenharmony_ci        Platform::AceContainer::SetView(aceView, density_, 0, 0, window, callback);
44023b3eb3cSopenharmony_ci    } else {
44123b3eb3cSopenharmony_ci        Platform::AceContainer::SetViewNew(aceView, density_, 0, 0, window);
44223b3eb3cSopenharmony_ci    }
44323b3eb3cSopenharmony_ci#else
44423b3eb3cSopenharmony_ci    Platform::AceContainer::SetViewNew(aceView, density_, 0, 0, window);
44523b3eb3cSopenharmony_ci#endif
44623b3eb3cSopenharmony_ci
44723b3eb3cSopenharmony_ci    Platform::AceViewOhos::SurfaceChanged(aceView, 0, 0, deviceHeight >= deviceWidth ? 0 : 1);
44823b3eb3cSopenharmony_ci
44923b3eb3cSopenharmony_ci    // action event handler
45023b3eb3cSopenharmony_ci    auto&& actionEventHandler = [this](const std::string& action) {
45123b3eb3cSopenharmony_ci        auto eventAction = JsonUtil::ParseJsonString(action);
45223b3eb3cSopenharmony_ci        auto bundleName = eventAction->GetValue("bundleName");
45323b3eb3cSopenharmony_ci        auto abilityName = eventAction->GetValue("abilityName");
45423b3eb3cSopenharmony_ci        auto params = eventAction->GetValue("params");
45523b3eb3cSopenharmony_ci        auto bundle = bundleName->GetString();
45623b3eb3cSopenharmony_ci        auto ability = abilityName->GetString();
45723b3eb3cSopenharmony_ci        LOGI("on Action called to event handler, bundle:%{public}s ability:%{public}s, params:%{public}s",
45823b3eb3cSopenharmony_ci            bundle.c_str(), ability.c_str(), params->GetString().c_str());
45923b3eb3cSopenharmony_ci        if (bundle.empty() || ability.empty()) {
46023b3eb3cSopenharmony_ci            LOGE("action ability or bundle is empty");
46123b3eb3cSopenharmony_ci            return;
46223b3eb3cSopenharmony_ci        }
46323b3eb3cSopenharmony_ci
46423b3eb3cSopenharmony_ci        AAFwk::Want want;
46523b3eb3cSopenharmony_ci        want.SetElementName(bundle, ability);
46623b3eb3cSopenharmony_ci        this->StartAbility(want);
46723b3eb3cSopenharmony_ci    };
46823b3eb3cSopenharmony_ci
46923b3eb3cSopenharmony_ci    // set window id & action event handler
47023b3eb3cSopenharmony_ci    auto context = Platform::AceContainer::GetContainer(abilityId_)->GetPipelineContext();
47123b3eb3cSopenharmony_ci    if (context) {
47223b3eb3cSopenharmony_ci        context->SetActionEventHandler(actionEventHandler);
47323b3eb3cSopenharmony_ci        context->SetGetWindowRectImpl([window]() -> Rect {
47423b3eb3cSopenharmony_ci            Rect rect;
47523b3eb3cSopenharmony_ci            CHECK_NULL_RETURN(window, rect);
47623b3eb3cSopenharmony_ci            auto windowRect = window->GetRect();
47723b3eb3cSopenharmony_ci            rect.SetRect(windowRect.posX_, windowRect.posY_, windowRect.width_, windowRect.height_);
47823b3eb3cSopenharmony_ci            return rect;
47923b3eb3cSopenharmony_ci        });
48023b3eb3cSopenharmony_ci        auto rsConfig = window->GetKeyboardAnimationConfig();
48123b3eb3cSopenharmony_ci        KeyboardAnimationCurve curveIn = {
48223b3eb3cSopenharmony_ci            rsConfig.curveIn.curveType_, rsConfig.curveIn.curveParams_, rsConfig.curveIn.duration_};
48323b3eb3cSopenharmony_ci        KeyboardAnimationCurve curveOut = {
48423b3eb3cSopenharmony_ci            rsConfig.curveOut.curveType_, rsConfig.curveOut.curveParams_, rsConfig.curveOut.duration_};
48523b3eb3cSopenharmony_ci        KeyboardAnimationConfig config = {curveIn, curveOut};
48623b3eb3cSopenharmony_ci        context->SetKeyboardAnimationConfig(config);
48723b3eb3cSopenharmony_ci        context->SetMinPlatformVersion(apiCompatibleVersion);
48823b3eb3cSopenharmony_ci
48923b3eb3cSopenharmony_ci        if (apiCompatibleVersion >= PLATFORM_VERSION_TEN && context->GetIsAppWindow()) {
49023b3eb3cSopenharmony_ci            context->UpdateSystemSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_SYSTEM));
49123b3eb3cSopenharmony_ci            context->UpdateCutoutSafeArea(container->GetViewSafeAreaByType(Rosen::AvoidAreaType::TYPE_CUTOUT));
49223b3eb3cSopenharmony_ci        }
49323b3eb3cSopenharmony_ci    }
49423b3eb3cSopenharmony_ci
49523b3eb3cSopenharmony_ci    // get url
49623b3eb3cSopenharmony_ci    std::string parsedPageUrl;
49723b3eb3cSopenharmony_ci    if (!remotePageUrl_.empty()) {
49823b3eb3cSopenharmony_ci        parsedPageUrl = remotePageUrl_;
49923b3eb3cSopenharmony_ci    } else if (!pageUrl_.empty()) {
50023b3eb3cSopenharmony_ci        parsedPageUrl = pageUrl_;
50123b3eb3cSopenharmony_ci    } else if (want.HasParameter(PAGE_URI)) {
50223b3eb3cSopenharmony_ci        parsedPageUrl = want.GetStringParam(PAGE_URI);
50323b3eb3cSopenharmony_ci    } else {
50423b3eb3cSopenharmony_ci        parsedPageUrl = "";
50523b3eb3cSopenharmony_ci    }
50623b3eb3cSopenharmony_ci
50723b3eb3cSopenharmony_ci    auto windowRect = window->GetRect();
50823b3eb3cSopenharmony_ci    if (!windowRect.IsUninitializedRect()) {
50923b3eb3cSopenharmony_ci        LOGW("notify window rect explicitly");
51023b3eb3cSopenharmony_ci        OnSizeChange(windowRect, OHOS::Rosen::WindowSizeChangeReason::UNDEFINED);
51123b3eb3cSopenharmony_ci    }
51223b3eb3cSopenharmony_ci    // run page.
51323b3eb3cSopenharmony_ci    Platform::AceContainer::RunPage(abilityId_, parsedPageUrl, want.GetStringParam(START_PARAMS_KEY));
51423b3eb3cSopenharmony_ci
51523b3eb3cSopenharmony_ci    if (!remoteData_.empty()) {
51623b3eb3cSopenharmony_ci        Platform::AceContainer::OnRestoreData(abilityId_, remoteData_);
51723b3eb3cSopenharmony_ci    }
51823b3eb3cSopenharmony_ci    LayoutInspector::SetCallback(abilityId_);
51923b3eb3cSopenharmony_ci}
52023b3eb3cSopenharmony_ci
52123b3eb3cSopenharmony_civoid AceAbility::OnStop()
52223b3eb3cSopenharmony_ci{
52323b3eb3cSopenharmony_ci    LOGI("AceAbility OnStop called ");
52423b3eb3cSopenharmony_ci    Ability::OnStop();
52523b3eb3cSopenharmony_ci    Platform::AceContainer::DestroyContainer(abilityId_);
52623b3eb3cSopenharmony_ci    abilityId_ = -1;
52723b3eb3cSopenharmony_ci}
52823b3eb3cSopenharmony_ci
52923b3eb3cSopenharmony_civoid AceAbility::OnActive()
53023b3eb3cSopenharmony_ci{
53123b3eb3cSopenharmony_ci    LOGI("AceAbility OnActive called ");
53223b3eb3cSopenharmony_ci    // AbilityManager will miss first OnForeground notification
53323b3eb3cSopenharmony_ci    if (isFirstActive_) {
53423b3eb3cSopenharmony_ci        Platform::AceContainer::OnShow(abilityId_);
53523b3eb3cSopenharmony_ci        isFirstActive_ = false;
53623b3eb3cSopenharmony_ci    }
53723b3eb3cSopenharmony_ci    Ability::OnActive();
53823b3eb3cSopenharmony_ci    Platform::AceContainer::OnActive(abilityId_);
53923b3eb3cSopenharmony_ci}
54023b3eb3cSopenharmony_ci
54123b3eb3cSopenharmony_civoid AceAbility::OnForeground(const Want& want)
54223b3eb3cSopenharmony_ci{
54323b3eb3cSopenharmony_ci    LOGI("AceAbility OnForeground called ");
54423b3eb3cSopenharmony_ci    Ability::OnForeground(want);
54523b3eb3cSopenharmony_ci    Platform::AceContainer::OnShow(abilityId_);
54623b3eb3cSopenharmony_ci}
54723b3eb3cSopenharmony_ci
54823b3eb3cSopenharmony_civoid AceAbility::OnBackground()
54923b3eb3cSopenharmony_ci{
55023b3eb3cSopenharmony_ci    LOGI("AceAbility OnBackground called ");
55123b3eb3cSopenharmony_ci    Ability::OnBackground();
55223b3eb3cSopenharmony_ci    Platform::AceContainer::OnHide(abilityId_);
55323b3eb3cSopenharmony_ci}
55423b3eb3cSopenharmony_ci
55523b3eb3cSopenharmony_civoid AceAbility::OnInactive()
55623b3eb3cSopenharmony_ci{
55723b3eb3cSopenharmony_ci    LOGI("AceAbility OnInactive called ");
55823b3eb3cSopenharmony_ci    Ability::OnInactive();
55923b3eb3cSopenharmony_ci    Platform::AceContainer::OnInactive(abilityId_);
56023b3eb3cSopenharmony_ci}
56123b3eb3cSopenharmony_ci
56223b3eb3cSopenharmony_civoid AceAbility::OnBackPressed()
56323b3eb3cSopenharmony_ci{
56423b3eb3cSopenharmony_ci    LOGI("AceAbility OnBackPressed called ");
56523b3eb3cSopenharmony_ci    if (!Platform::AceContainer::OnBackPressed(abilityId_)) {
56623b3eb3cSopenharmony_ci        Ability::OnBackPressed();
56723b3eb3cSopenharmony_ci    }
56823b3eb3cSopenharmony_ci}
56923b3eb3cSopenharmony_ci
57023b3eb3cSopenharmony_civoid AceAbility::OnNewWant(const Want& want)
57123b3eb3cSopenharmony_ci{
57223b3eb3cSopenharmony_ci    LOGI("AceAbility OnNewWant called ");
57323b3eb3cSopenharmony_ci    Ability::OnNewWant(want);
57423b3eb3cSopenharmony_ci    std::string params = want.GetStringParam(START_PARAMS_KEY);
57523b3eb3cSopenharmony_ci    Platform::AceContainer::OnNewRequest(abilityId_, params);
57623b3eb3cSopenharmony_ci    std::string data = want.ToString();
57723b3eb3cSopenharmony_ci    Platform::AceContainer::OnNewWant(abilityId_, data);
57823b3eb3cSopenharmony_ci}
57923b3eb3cSopenharmony_ci
58023b3eb3cSopenharmony_civoid AceAbility::OnRestoreAbilityState(const PacMap& inState)
58123b3eb3cSopenharmony_ci{
58223b3eb3cSopenharmony_ci    LOGI("AceAbility OnRestoreAbilityState called ");
58323b3eb3cSopenharmony_ci    Ability::OnRestoreAbilityState(inState);
58423b3eb3cSopenharmony_ci}
58523b3eb3cSopenharmony_ci
58623b3eb3cSopenharmony_civoid AceAbility::OnSaveAbilityState(PacMap& outState)
58723b3eb3cSopenharmony_ci{
58823b3eb3cSopenharmony_ci    LOGI("AceAbility OnSaveAbilityState called ");
58923b3eb3cSopenharmony_ci    Ability::OnSaveAbilityState(outState);
59023b3eb3cSopenharmony_ci}
59123b3eb3cSopenharmony_ci
59223b3eb3cSopenharmony_civoid AceAbility::OnConfigurationUpdated(const Configuration& configuration)
59323b3eb3cSopenharmony_ci{
59423b3eb3cSopenharmony_ci    Ability::OnConfigurationUpdated(configuration);
59523b3eb3cSopenharmony_ci
59623b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
59723b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
59823b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
59923b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
60023b3eb3cSopenharmony_ci    taskExecutor->PostTask(
60123b3eb3cSopenharmony_ci        [weakContainer = WeakPtr<Platform::AceContainer>(container), configuration]() {
60223b3eb3cSopenharmony_ci            auto container = weakContainer.Upgrade();
60323b3eb3cSopenharmony_ci            CHECK_NULL_VOID(container);
60423b3eb3cSopenharmony_ci            Platform::ParsedConfig parsedConfig;
60523b3eb3cSopenharmony_ci            parsedConfig.colorMode = configuration.GetItem(OHOS::AppExecFwk::GlobalConfigurationKey::SYSTEM_COLORMODE);
60623b3eb3cSopenharmony_ci            parsedConfig.deviceAccess =
60723b3eb3cSopenharmony_ci                configuration.GetItem(OHOS::AppExecFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE);
60823b3eb3cSopenharmony_ci            parsedConfig.languageTag = configuration.GetItem(OHOS::AppExecFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE);
60923b3eb3cSopenharmony_ci            parsedConfig.direction = configuration.GetItem(OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION);
61023b3eb3cSopenharmony_ci            parsedConfig.densitydpi =
61123b3eb3cSopenharmony_ci                configuration.GetItem(OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DENSITYDPI);
61223b3eb3cSopenharmony_ci            container->UpdateConfiguration(parsedConfig, configuration.GetName());
61323b3eb3cSopenharmony_ci        },
61423b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIAbilityUpdateConfiguration");
61523b3eb3cSopenharmony_ci    LOGI("AceAbility OnConfigurationUpdated called End, name:%{public}s", configuration.GetName().c_str());
61623b3eb3cSopenharmony_ci}
61723b3eb3cSopenharmony_ci
61823b3eb3cSopenharmony_civoid AceAbility::OnAbilityResult(int requestCode, int resultCode, const OHOS::AAFwk::Want& resultData)
61923b3eb3cSopenharmony_ci{
62023b3eb3cSopenharmony_ci    LOGI("AceAbility OnAbilityResult called ");
62123b3eb3cSopenharmony_ci    AbilityProcess::GetInstance()->OnAbilityResult(this, requestCode, resultCode, resultData);
62223b3eb3cSopenharmony_ci}
62323b3eb3cSopenharmony_ci
62423b3eb3cSopenharmony_cibool AceAbility::OnStartContinuation()
62523b3eb3cSopenharmony_ci{
62623b3eb3cSopenharmony_ci    LOGI("AceAbility OnStartContinuation called.");
62723b3eb3cSopenharmony_ci    bool ret = Platform::AceContainer::OnStartContinuation(abilityId_);
62823b3eb3cSopenharmony_ci    return ret;
62923b3eb3cSopenharmony_ci}
63023b3eb3cSopenharmony_ci
63123b3eb3cSopenharmony_cibool AceAbility::OnSaveData(OHOS::AAFwk::WantParams& saveData)
63223b3eb3cSopenharmony_ci{
63323b3eb3cSopenharmony_ci    LOGI("AceAbility OnSaveData called.");
63423b3eb3cSopenharmony_ci    std::string data = Platform::AceContainer::OnSaveData(abilityId_);
63523b3eb3cSopenharmony_ci    if (data == "false") {
63623b3eb3cSopenharmony_ci        return false;
63723b3eb3cSopenharmony_ci    }
63823b3eb3cSopenharmony_ci    auto json = JsonUtil::ParseJsonString(data);
63923b3eb3cSopenharmony_ci    if (!json) {
64023b3eb3cSopenharmony_ci        return false;
64123b3eb3cSopenharmony_ci    }
64223b3eb3cSopenharmony_ci    if (json->Contains(PAGE_URI)) {
64323b3eb3cSopenharmony_ci        saveData.SetParam(PAGE_URI, OHOS::AAFwk::String::Box(json->GetString(PAGE_URI)));
64423b3eb3cSopenharmony_ci    }
64523b3eb3cSopenharmony_ci    if (json->Contains(CONTINUE_PARAMS_KEY)) {
64623b3eb3cSopenharmony_ci        std::string params = json->GetObject(CONTINUE_PARAMS_KEY)->ToString();
64723b3eb3cSopenharmony_ci        saveData.SetParam(CONTINUE_PARAMS_KEY, OHOS::AAFwk::String::Box(params));
64823b3eb3cSopenharmony_ci    }
64923b3eb3cSopenharmony_ci    return true;
65023b3eb3cSopenharmony_ci}
65123b3eb3cSopenharmony_ci
65223b3eb3cSopenharmony_cibool AceAbility::OnRestoreData(OHOS::AAFwk::WantParams& restoreData)
65323b3eb3cSopenharmony_ci{
65423b3eb3cSopenharmony_ci    LOGI("AceAbility OnRestoreData called.");
65523b3eb3cSopenharmony_ci    if (restoreData.HasParam(PAGE_URI)) {
65623b3eb3cSopenharmony_ci        auto value = restoreData.GetParam(PAGE_URI);
65723b3eb3cSopenharmony_ci        OHOS::AAFwk::IString* ao = OHOS::AAFwk::IString::Query(value);
65823b3eb3cSopenharmony_ci        if (ao != nullptr) {
65923b3eb3cSopenharmony_ci            remotePageUrl_ = OHOS::AAFwk::String::Unbox(ao);
66023b3eb3cSopenharmony_ci        }
66123b3eb3cSopenharmony_ci    }
66223b3eb3cSopenharmony_ci    if (restoreData.HasParam(CONTINUE_PARAMS_KEY)) {
66323b3eb3cSopenharmony_ci        auto value = restoreData.GetParam(CONTINUE_PARAMS_KEY);
66423b3eb3cSopenharmony_ci        OHOS::AAFwk::IString* ao = OHOS::AAFwk::IString::Query(value);
66523b3eb3cSopenharmony_ci        if (ao != nullptr) {
66623b3eb3cSopenharmony_ci            remoteData_ = OHOS::AAFwk::String::Unbox(ao);
66723b3eb3cSopenharmony_ci        }
66823b3eb3cSopenharmony_ci    }
66923b3eb3cSopenharmony_ci    return true;
67023b3eb3cSopenharmony_ci}
67123b3eb3cSopenharmony_ci
67223b3eb3cSopenharmony_civoid AceAbility::OnCompleteContinuation(int result)
67323b3eb3cSopenharmony_ci{
67423b3eb3cSopenharmony_ci    Ability::OnCompleteContinuation(result);
67523b3eb3cSopenharmony_ci    LOGI("AceAbility OnCompleteContinuation called.");
67623b3eb3cSopenharmony_ci    Platform::AceContainer::OnCompleteContinuation(abilityId_, result);
67723b3eb3cSopenharmony_ci}
67823b3eb3cSopenharmony_ci
67923b3eb3cSopenharmony_civoid AceAbility::OnRemoteTerminated()
68023b3eb3cSopenharmony_ci{
68123b3eb3cSopenharmony_ci    LOGI("AceAbility OnRemoteTerminated called.");
68223b3eb3cSopenharmony_ci    Platform::AceContainer::OnRemoteTerminated(abilityId_);
68323b3eb3cSopenharmony_ci}
68423b3eb3cSopenharmony_ci
68523b3eb3cSopenharmony_civoid AceAbility::OnSizeChange(const OHOS::Rosen::Rect& rect, OHOS::Rosen::WindowSizeChangeReason reason,
68623b3eb3cSopenharmony_ci    const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
68723b3eb3cSopenharmony_ci{
68823b3eb3cSopenharmony_ci    LOGI("width: %{public}u, height: %{public}u, left: %{public}d, top: %{public}d", rect.width_, rect.height_,
68923b3eb3cSopenharmony_ci        rect.posX_, rect.posY_);
69023b3eb3cSopenharmony_ci    SystemProperties::SetDeviceOrientation(rect.height_ >= rect.width_ ? 0 : 1);
69123b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
69223b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
69323b3eb3cSopenharmony_ci    container->SetWindowPos(rect.posX_, rect.posY_);
69423b3eb3cSopenharmony_ci    auto pipelineContext = container->GetPipelineContext();
69523b3eb3cSopenharmony_ci    if (pipelineContext) {
69623b3eb3cSopenharmony_ci        pipelineContext->SetDisplayWindowRectInfo(
69723b3eb3cSopenharmony_ci            Rect(Offset(rect.posX_, rect.posY_), Size(rect.width_, rect.height_)));
69823b3eb3cSopenharmony_ci        pipelineContext->SetIsLayoutFullScreen(
69923b3eb3cSopenharmony_ci            Ability::GetWindow()->GetMode() == Rosen::WindowMode::WINDOW_MODE_FULLSCREEN);
70023b3eb3cSopenharmony_ci        auto isNeedAvoidWindowMode = SystemProperties::GetNeedAvoidWindow() &&
70123b3eb3cSopenharmony_ci            (Ability::GetWindow()->GetMode() == Rosen::WindowMode::WINDOW_MODE_FLOATING ||
70223b3eb3cSopenharmony_ci            Ability::GetWindow()->GetMode() == Rosen::WindowMode::WINDOW_MODE_SPLIT_PRIMARY ||
70323b3eb3cSopenharmony_ci            Ability::GetWindow()->GetMode() == Rosen::WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
70423b3eb3cSopenharmony_ci        pipelineContext->SetIsNeedAvoidWindow(isNeedAvoidWindowMode);
70523b3eb3cSopenharmony_ci    }
70623b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
70723b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
70823b3eb3cSopenharmony_ci    taskExecutor->PostTask(
70923b3eb3cSopenharmony_ci        [rect, density = density_, reason, container, rsTransaction]() {
71023b3eb3cSopenharmony_ci            auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView());
71123b3eb3cSopenharmony_ci            CHECK_NULL_VOID(aceView);
71223b3eb3cSopenharmony_ci            ViewportConfig config(rect.width_, rect.height_, density);
71323b3eb3cSopenharmony_ci            Platform::AceViewOhos::SetViewportMetrics(aceView, config);
71423b3eb3cSopenharmony_ci            Platform::AceViewOhos::SurfaceChanged(aceView, rect.width_, rect.height_,
71523b3eb3cSopenharmony_ci                rect.height_ >= rect.width_ ? 0 : 1, static_cast<WindowSizeChangeReason>(reason), rsTransaction);
71623b3eb3cSopenharmony_ci        },
71723b3eb3cSopenharmony_ci        TaskExecutor::TaskType::PLATFORM, "ArkUIAbilitySurfaceChanged");
71823b3eb3cSopenharmony_ci}
71923b3eb3cSopenharmony_ci
72023b3eb3cSopenharmony_civoid AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode, bool hasDeco)
72123b3eb3cSopenharmony_ci{
72223b3eb3cSopenharmony_ci    LOGI("OnModeChange, window mode is %{public}d", mode);
72323b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
72423b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
72523b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
72623b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
72723b3eb3cSopenharmony_ci    ContainerScope scope(abilityId_);
72823b3eb3cSopenharmony_ci    taskExecutor->PostTask(
72923b3eb3cSopenharmony_ci        [container, mode, hasDeco]() {
73023b3eb3cSopenharmony_ci            auto pipelineContext = container->GetPipelineContext();
73123b3eb3cSopenharmony_ci            CHECK_NULL_VOID(pipelineContext);
73223b3eb3cSopenharmony_ci            pipelineContext->ShowContainerTitle(mode == OHOS::Rosen::WindowMode::WINDOW_MODE_FLOATING, hasDeco);
73323b3eb3cSopenharmony_ci        },
73423b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIWindowModeChange");
73523b3eb3cSopenharmony_ci}
73623b3eb3cSopenharmony_ci
73723b3eb3cSopenharmony_civoid AceAbility::OnSizeChange(const sptr<OHOS::Rosen::OccupiedAreaChangeInfo>& info,
73823b3eb3cSopenharmony_ci    const std::shared_ptr<OHOS::Rosen::RSTransaction>& rsTransaction)
73923b3eb3cSopenharmony_ci{
74023b3eb3cSopenharmony_ci    auto rect = info->rect_;
74123b3eb3cSopenharmony_ci    auto type = info->type_;
74223b3eb3cSopenharmony_ci    Rect keyboardRect = Rect(rect.posX_, rect.posY_, rect.width_, rect.height_);
74323b3eb3cSopenharmony_ci    LOGI("AceAbility OccupiedAreaChange rect:%{public}s type: %{public}d", keyboardRect.ToString().c_str(), type);
74423b3eb3cSopenharmony_ci    if (type == OHOS::Rosen::OccupiedAreaType::TYPE_INPUT) {
74523b3eb3cSopenharmony_ci        auto container = Platform::AceContainer::GetContainer(abilityId_);
74623b3eb3cSopenharmony_ci        CHECK_NULL_VOID(container);
74723b3eb3cSopenharmony_ci        auto taskExecutor = container->GetTaskExecutor();
74823b3eb3cSopenharmony_ci        CHECK_NULL_VOID(taskExecutor);
74923b3eb3cSopenharmony_ci        ContainerScope scope(abilityId_);
75023b3eb3cSopenharmony_ci        taskExecutor->PostTask(
75123b3eb3cSopenharmony_ci            [container, keyboardRect, rsTransaction] {
75223b3eb3cSopenharmony_ci                auto context = container->GetPipelineContext();
75323b3eb3cSopenharmony_ci                CHECK_NULL_VOID(context);
75423b3eb3cSopenharmony_ci                context->OnVirtualKeyboardAreaChange(keyboardRect, rsTransaction);
75523b3eb3cSopenharmony_ci            },
75623b3eb3cSopenharmony_ci            TaskExecutor::TaskType::UI, "ArkUIAbilityVirtualKeyboardAreaChange");
75723b3eb3cSopenharmony_ci    }
75823b3eb3cSopenharmony_ci}
75923b3eb3cSopenharmony_ci
76023b3eb3cSopenharmony_civoid AceAbility::Dump(const std::vector<std::string>& params, std::vector<std::string>& info)
76123b3eb3cSopenharmony_ci{
76223b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
76323b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
76423b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
76523b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
76623b3eb3cSopenharmony_ci    ContainerScope scope(abilityId_);
76723b3eb3cSopenharmony_ci    taskExecutor->PostSyncTask(
76823b3eb3cSopenharmony_ci        [container, params, &info] { container->Dump(params, info); },
76923b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIAbilityDump");
77023b3eb3cSopenharmony_ci}
77123b3eb3cSopenharmony_ci
77223b3eb3cSopenharmony_civoid AceAbility::OnDrag(int32_t x, int32_t y, OHOS::Rosen::DragEvent event)
77323b3eb3cSopenharmony_ci{
77423b3eb3cSopenharmony_ci    LOGI("AceAbility OnDrag called ");
77523b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
77623b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
77723b3eb3cSopenharmony_ci    auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView());
77823b3eb3cSopenharmony_ci    CHECK_NULL_VOID(aceView);
77923b3eb3cSopenharmony_ci    DragEventAction action;
78023b3eb3cSopenharmony_ci    switch (event) {
78123b3eb3cSopenharmony_ci        case OHOS::Rosen::DragEvent::DRAG_EVENT_END:
78223b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_END;
78323b3eb3cSopenharmony_ci            break;
78423b3eb3cSopenharmony_ci        case OHOS::Rosen::DragEvent::DRAG_EVENT_OUT:
78523b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_OUT;
78623b3eb3cSopenharmony_ci            break;
78723b3eb3cSopenharmony_ci        case OHOS::Rosen::DragEvent::DRAG_EVENT_MOVE:
78823b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_MOVE;
78923b3eb3cSopenharmony_ci            break;
79023b3eb3cSopenharmony_ci        case OHOS::Rosen::DragEvent::DRAG_EVENT_IN:
79123b3eb3cSopenharmony_ci        default:
79223b3eb3cSopenharmony_ci            action = DragEventAction::DRAG_EVENT_START;
79323b3eb3cSopenharmony_ci            break;
79423b3eb3cSopenharmony_ci    }
79523b3eb3cSopenharmony_ci
79623b3eb3cSopenharmony_ci    aceView->ProcessDragEvent(x, y, action);
79723b3eb3cSopenharmony_ci}
79823b3eb3cSopenharmony_ci
79923b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const
80023b3eb3cSopenharmony_ci{
80123b3eb3cSopenharmony_ci    auto container = AceType::DynamicCast<Platform::AceContainer>(AceEngine::Get().GetContainer(abilityId_));
80223b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(container, false);
80323b3eb3cSopenharmony_ci    container->SetCurPointerEvent(pointerEvent);
80423b3eb3cSopenharmony_ci    auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView());
80523b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(aceView, false);
80623b3eb3cSopenharmony_ci    aceView->DispatchTouchEvent(aceView, pointerEvent);
80723b3eb3cSopenharmony_ci    return true;
80823b3eb3cSopenharmony_ci}
80923b3eb3cSopenharmony_ci
81023b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const
81123b3eb3cSopenharmony_ci{
81223b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
81323b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(container, false);
81423b3eb3cSopenharmony_ci    auto aceView = AceType::DynamicCast<Platform::AceViewOhos>(container->GetAceView());
81523b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(aceView, false);
81623b3eb3cSopenharmony_ci    int32_t keyCode = keyEvent->GetKeyCode();
81723b3eb3cSopenharmony_ci    int32_t keyAction = keyEvent->GetKeyAction();
81823b3eb3cSopenharmony_ci    if (keyCode == MMI::KeyEvent::KEYCODE_BACK && keyAction == MMI::KeyEvent::KEY_ACTION_UP) {
81923b3eb3cSopenharmony_ci        LOGI("OnInputEvent: Platform AceContainer OnBackPressed called");
82023b3eb3cSopenharmony_ci        if (Platform::AceContainer::OnBackPressed(abilityId_)) {
82123b3eb3cSopenharmony_ci            return true;
82223b3eb3cSopenharmony_ci        }
82323b3eb3cSopenharmony_ci        return false;
82423b3eb3cSopenharmony_ci    }
82523b3eb3cSopenharmony_ci    LOGI("OnInputEvent: dispatch key to arkui");
82623b3eb3cSopenharmony_ci    if (aceView->DispatchKeyEvent(aceView, keyEvent)) {
82723b3eb3cSopenharmony_ci        return true;
82823b3eb3cSopenharmony_ci    }
82923b3eb3cSopenharmony_ci    return false;
83023b3eb3cSopenharmony_ci}
83123b3eb3cSopenharmony_ci
83223b3eb3cSopenharmony_cibool AceAbility::OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const
83323b3eb3cSopenharmony_ci{
83423b3eb3cSopenharmony_ci    return false;
83523b3eb3cSopenharmony_ci}
83623b3eb3cSopenharmony_ci
83723b3eb3cSopenharmony_civoid AceAbility::SetBackgroundColor(uint32_t color)
83823b3eb3cSopenharmony_ci{
83923b3eb3cSopenharmony_ci    LOGI("AceAbilityHandler SetBackgroundColor color is %{public}u", color);
84023b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
84123b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
84223b3eb3cSopenharmony_ci    ContainerScope scope(abilityId_);
84323b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
84423b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
84523b3eb3cSopenharmony_ci    taskExecutor->PostSyncTask(
84623b3eb3cSopenharmony_ci        [container, bgColor = color]() {
84723b3eb3cSopenharmony_ci            auto pipelineContext = container->GetPipelineContext();
84823b3eb3cSopenharmony_ci            CHECK_NULL_VOID(pipelineContext);
84923b3eb3cSopenharmony_ci            pipelineContext->SetAppBgColor(Color(bgColor));
85023b3eb3cSopenharmony_ci        },
85123b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUISetAppBackgroundColor");
85223b3eb3cSopenharmony_ci}
85323b3eb3cSopenharmony_ci
85423b3eb3cSopenharmony_ciuint32_t AceAbility::GetBackgroundColor()
85523b3eb3cSopenharmony_ci{
85623b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer(abilityId_);
85723b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(container, 0x000000);
85823b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
85923b3eb3cSopenharmony_ci    CHECK_NULL_RETURN(taskExecutor, 0x000000);
86023b3eb3cSopenharmony_ci    ContainerScope scope(abilityId_);
86123b3eb3cSopenharmony_ci    uint32_t bgColor = 0x000000;
86223b3eb3cSopenharmony_ci    taskExecutor->PostSyncTask(
86323b3eb3cSopenharmony_ci        [&bgColor, container]() {
86423b3eb3cSopenharmony_ci            CHECK_NULL_VOID(container);
86523b3eb3cSopenharmony_ci            auto pipelineContext = container->GetPipelineContext();
86623b3eb3cSopenharmony_ci            CHECK_NULL_VOID(pipelineContext);
86723b3eb3cSopenharmony_ci            bgColor = pipelineContext->GetAppBgColor().GetValue();
86823b3eb3cSopenharmony_ci        },
86923b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIAbilityGetAppBackgroundColor");
87023b3eb3cSopenharmony_ci
87123b3eb3cSopenharmony_ci    LOGI("AceAbilityHandler GetBackgroundColor, value is %{public}u", bgColor);
87223b3eb3cSopenharmony_ci    return bgColor;
87323b3eb3cSopenharmony_ci}
87423b3eb3cSopenharmony_ci
87523b3eb3cSopenharmony_civoid AceAbility::OnAvoidAreaChanged(const OHOS::Rosen::AvoidArea& avoidArea, OHOS::Rosen::AvoidAreaType type)
87623b3eb3cSopenharmony_ci{
87723b3eb3cSopenharmony_ci    auto container = Platform::AceContainer::GetContainer((abilityId_));
87823b3eb3cSopenharmony_ci    CHECK_NULL_VOID(container);
87923b3eb3cSopenharmony_ci    auto pipeline = container->GetPipelineContext();
88023b3eb3cSopenharmony_ci    CHECK_NULL_VOID(
88123b3eb3cSopenharmony_ci        pipeline && pipeline->GetMinPlatformVersion() >= PLATFORM_VERSION_TEN && pipeline->GetIsAppWindow());
88223b3eb3cSopenharmony_ci    LOGI("AceAbility OnAvoidAreaChanged type:%{public}d, avoidArea:topRect:x:%{public}d, y:%{public}d, "
88323b3eb3cSopenharmony_ci         "width:%{public}d, height%{public}d",
88423b3eb3cSopenharmony_ci        type, avoidArea.topRect_.posX_, avoidArea.topRect_.posY_, (int32_t)avoidArea.topRect_.width_,
88523b3eb3cSopenharmony_ci        (int32_t)avoidArea.topRect_.height_);
88623b3eb3cSopenharmony_ci    auto taskExecutor = container->GetTaskExecutor();
88723b3eb3cSopenharmony_ci    CHECK_NULL_VOID(taskExecutor);
88823b3eb3cSopenharmony_ci    auto safeArea = ConvertAvoidArea(avoidArea);
88923b3eb3cSopenharmony_ci    ContainerScope scope(abilityId_);
89023b3eb3cSopenharmony_ci    taskExecutor->PostTask(
89123b3eb3cSopenharmony_ci        [pipeline, safeArea, type]() {
89223b3eb3cSopenharmony_ci            if (type == OHOS::Rosen::AvoidAreaType::TYPE_SYSTEM) {
89323b3eb3cSopenharmony_ci                pipeline->UpdateSystemSafeArea(safeArea);
89423b3eb3cSopenharmony_ci            } else if (type == OHOS::Rosen::AvoidAreaType::TYPE_CUTOUT) {
89523b3eb3cSopenharmony_ci                pipeline->UpdateCutoutSafeArea(safeArea);
89623b3eb3cSopenharmony_ci            }
89723b3eb3cSopenharmony_ci        },
89823b3eb3cSopenharmony_ci        TaskExecutor::TaskType::UI, "ArkUIAbilityAvoidAreaChanged");
89923b3eb3cSopenharmony_ci}
90023b3eb3cSopenharmony_ci
90123b3eb3cSopenharmony_ci} // namespace Ace
90223b3eb3cSopenharmony_ci} // namespace OHOS
903