diff --git a/adapter/ohos/entrance/ace_container.cpp b/adapter/ohos/entrance/ace_container.cpp index 79273679ab6..a88c42be6dc 100644 --- a/adapter/ohos/entrance/ace_container.cpp +++ b/adapter/ohos/entrance/ace_container.cpp @@ -44,6 +44,7 @@ #include "adapter/ohos/osal/resource_adapter_impl_v2.h" #include "adapter/ohos/osal/system_bar_style_ohos.h" #include "adapter/ohos/osal/view_data_wrap_ohos.h" +#include "adapter/ohos/osal/window_utils.h" #include "base/i18n/localization.h" #include "base/json/json_util.h" #include "base/log/ace_trace.h" @@ -981,6 +982,7 @@ void AceContainer::InitializeCallback() CHECK_NULL_VOID(container); auto aceContainer = DynamicCast(container); CHECK_NULL_VOID(aceContainer); + aceContainer->UpdateResourceDensity(density); aceContainer->NotifyDensityUpdate(); } }; @@ -3296,4 +3298,25 @@ void AceContainer::RemoveWatchSystemParameter() SystemProperties::RemoveWatchSystemParameter( ENABLE_PERFORMANCE_MONITOR_KEY, this, SystemProperties::EnableSystemParameterPerformanceMonitorCallback); } + +void AceContainer::UpdateResourceOrientation(int32_t orientation) +{ + DeviceOrientation newOrientation = WindowUtils::GetDeviceOrientation(orientation); + auto resConfig = GetResourceConfiguration(); + resConfig.SetOrientation(newOrientation); + if (SystemProperties::GetResourceDecoupling()) { + ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false); + } + SetResourceConfiguration(resConfig); +} + +void AceContainer::UpdateResourceDensity(double density) +{ + auto resConfig = GetResourceConfiguration(); + resConfig.SetDensity(density); + if (SystemProperties::GetResourceDecoupling()) { + ResourceManager::GetInstance().UpdateResourceConfig(resConfig, false); + } + SetResourceConfiguration(resConfig); +} } // namespace OHOS::Ace::Platform diff --git a/adapter/ohos/entrance/ace_container.h b/adapter/ohos/entrance/ace_container.h index 20bd43a1384..3a723441ecc 100644 --- a/adapter/ohos/entrance/ace_container.h +++ b/adapter/ohos/entrance/ace_container.h @@ -685,6 +685,8 @@ public: return paramUie_; } + void UpdateResourceOrientation(int32_t orientation); + void UpdateResourceDensity(double density); private: virtual bool MaybeRelease() override; void InitializeFrontend(); diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index 32a210ea051..d62f3aebc32 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -184,16 +184,16 @@ void AddResConfigInfo( aceResCfg.SetAppHasDarkRes(resConfig->GetAppDarkRes()); auto preferredLocaleInfo = resConfig->GetPreferredLocaleInfo(); if (preferredLocaleInfo != nullptr) { - std::string preferredlanguage = preferredLocaleInfo->getLanguage(); + std::string preferredLanguage = preferredLocaleInfo->getLanguage(); std::string script = preferredLocaleInfo->getScript(); std::string country = preferredLocaleInfo->getCountry(); if (!script.empty()) { - preferredlanguage += "-" + script; + preferredLanguage += "-" + script; } if (!country.empty()) { - preferredlanguage += "-" + country; + preferredLanguage += "-" + country; } - aceResCfg.SetPreferredLanguage(preferredlanguage); + aceResCfg.SetPreferredLanguage(preferredLanguage); } } @@ -2485,10 +2485,18 @@ void UIContentImpl::UpdateViewportConfigWithAnimation(const ViewportConfig& conf CHECK_NULL_VOID(aceView); Platform::AceViewOhos::SetViewportMetrics(aceView, modifyConfig); // update density into pipeline }; + auto updateDeviceOrientationTask = [container, modifyConfig, reason]() { + if (reason == OHOS::Rosen::WindowSizeChangeReason::ROTATION) { + container->UpdateResourceOrientation(modifyConfig.Orientation()); + } + }; if (taskExecutor->WillRunOnCurrentThread(TaskExecutor::TaskType::UI)) { updateDensityTask(); // ensure density has been updated before load first page + updateDeviceOrientationTask(); } else { taskExecutor->PostTask(std::move(updateDensityTask), TaskExecutor::TaskType::UI, "ArkUIUpdateDensity"); + taskExecutor->PostTask( + std::move(updateDeviceOrientationTask), TaskExecutor::TaskType::UI, "ArkUIDeviceOrientation"); } RefPtr safeAreaManager = nullptr; auto pipelineContext = container->GetPipelineContext(); diff --git a/adapter/ohos/osal/BUILD.gn b/adapter/ohos/osal/BUILD.gn index e87049e3f1f..b497887333e 100644 --- a/adapter/ohos/osal/BUILD.gn +++ b/adapter/ohos/osal/BUILD.gn @@ -79,6 +79,7 @@ template("ace_osal_ohos_source_set") { "trace_id_impl.cpp", "view_data_wrap_ohos.cpp", "want_wrap_ohos.cpp", + "window_utils.cpp", ] external_deps += [ diff --git a/adapter/ohos/osal/system_properties.cpp b/adapter/ohos/osal/system_properties.cpp index c47596a3159..45c7db03290 100644 --- a/adapter/ohos/osal/system_properties.cpp +++ b/adapter/ohos/osal/system_properties.cpp @@ -24,6 +24,7 @@ #include "parameters.h" #include "adapter/ohos/entrance/ace_container.h" +#include "adapter/ohos/osal/window_utils.h" #include "core/common/ace_application_info.h" #ifdef OHOS_STANDARD_SYSTEM #include "systemcapability.h" @@ -64,8 +65,6 @@ constexpr char DISABLE_WINDOW_ANIMATION_PATH[] = "/etc/disable_window_size_anima #endif constexpr int32_t CONVERT_ASTC_THRESHOLD = 2; -using RsOrientation = Rosen::DisplayOrientation; - bool IsOpIncEnabled() { return (system::GetParameter(IS_OPINC_ENABLE, "2") == "2"); @@ -585,10 +584,7 @@ void SystemProperties::InitDeviceInfo( ACE_WEAK_SYM void SystemProperties::SetDeviceOrientation(int32_t orientation) { - int32_t newOrientation = ((orientation == static_cast(RsOrientation::LANDSCAPE)) || - (orientation == static_cast(RsOrientation::LANDSCAPE_INVERTED))) - ? ORIENTATION_LANDSCAPE - : ORIENTATION_PORTRAIT; + auto newOrientation = static_cast(WindowUtils::GetDeviceOrientation(orientation)); if (newOrientation == ORIENTATION_PORTRAIT && orientation_ != DeviceOrientation::PORTRAIT) { Swap(deviceWidth_, deviceHeight_); orientation_ = DeviceOrientation::PORTRAIT; diff --git a/adapter/ohos/osal/window_utils.cpp b/adapter/ohos/osal/window_utils.cpp new file mode 100644 index 00000000000..b4d73a84c2d --- /dev/null +++ b/adapter/ohos/osal/window_utils.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "adapter/ohos/osal/window_utils.h" + +#include "dm/dm_common.h" + +namespace OHOS::Ace { +DeviceOrientation WindowUtils::GetDeviceOrientation(int32_t windowOrientation) +{ + DeviceOrientation newOrientation = + ((windowOrientation == static_cast(Rosen::DisplayOrientation::LANDSCAPE)) || + (windowOrientation == static_cast(Rosen::DisplayOrientation::LANDSCAPE_INVERTED))) + ? DeviceOrientation::LANDSCAPE + : DeviceOrientation::PORTRAIT; + return newOrientation; +} +} // namespace OHOS::Ace diff --git a/adapter/ohos/osal/window_utils.h b/adapter/ohos/osal/window_utils.h new file mode 100644 index 00000000000..45a832f9759 --- /dev/null +++ b/adapter/ohos/osal/window_utils.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WINDOW_UTILS_H +#define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_WINDOW_UTILS_H + +#include "base/utils/device_config.h" +#include "base/utils/macros.h" + +namespace OHOS::Ace { +class ACE_FORCE_EXPORT WindowUtils final { +public: + static DeviceOrientation GetDeviceOrientation(int32_t windowOrientation); +}; +} // namespace OHOS::Ace + +#endif diff --git a/build/libace.map b/build/libace.map index e55afc95715..2f9d83c3708 100644 --- a/build/libace.map +++ b/build/libace.map @@ -86,6 +86,7 @@ OHOS::Ace::Matrix4::*; OHOS::Ace::NG::DragDropFuncWrapper::*; OHOS::Ace::NG::DragDropGlobalController::*; + OHOS::Ace::WindowUtils::*; OHOS::Ace::ColumnModel::*; OHOS::Ace::FlexModel::*;