From 3aa4d3edb5c01061f7ccef0a9d0843185d5385d4 Mon Sep 17 00:00:00 2001 From: blc Date: Fri, 5 Sep 2025 16:45:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=8D=E8=B4=9F=E8=BD=BD=E4=BC=98=E5=8C=96dm?= =?UTF-8?q?s=E8=B0=83=E7=94=A8=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: blc --- .../src/js_inputmethod_extension.cpp | 19 ++++++++++++++++--- .../src/cj_inputmethod_extension.cpp | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/frameworks/kits/extension/src/js_inputmethod_extension.cpp b/frameworks/kits/extension/src/js_inputmethod_extension.cpp index f6a5b978c..bfc8e19c3 100644 --- a/frameworks/kits/extension/src/js_inputmethod_extension.cpp +++ b/frameworks/kits/extension/src/js_inputmethod_extension.cpp @@ -18,6 +18,7 @@ #include "ability_handler.h" #include "ability_info.h" #include "configuration_utils.h" +#include "display_info.h" #include "global.h" #include "input_method_ability.h" #include "inputmethod_extension_ability_service_impl.h" @@ -31,6 +32,7 @@ #include "napi_common_util.h" #include "napi_common_want.h" #include "napi_remote_object.h" +#include "parameters.h" #include "tasks/task_ams.h" #include "tasks/task_imsa.h" #include "task_manager.h" @@ -40,6 +42,8 @@ namespace AbilityRuntime { namespace { constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; +const std::string FOLD_SCREEN_TYPE = OHOS::system::GetParameter("const.window.foldscreen.type", "0,0,0,0"); +constexpr const char *EXTEND_FOLD_TYPE = "4"; } // namespace JsInputMethodExtension *JsInputMethodExtension::jsInputMethodExtension = nullptr; using namespace OHOS::AppExecFwk; @@ -428,6 +432,10 @@ void JsInputMethodExtension::OnDestroy(Rosen::DisplayId displayId) void JsInputMethodExtension::CheckNeedAdjustKeyboard(Rosen::DisplayId displayId) { + if (FOLD_SCREEN_TYPE.empty() || FOLD_SCREEN_TYPE[0] != *EXTEND_FOLD_TYPE) { + IMSA_HILOGD("The current device is a non-foldable device."); + return; + } auto displayPtr = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); if (displayPtr == nullptr) { return; @@ -437,9 +445,14 @@ void JsInputMethodExtension::CheckNeedAdjustKeyboard(Rosen::DisplayId displayId) return; } auto foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus(); - auto width = displayPtr->GetWidth(); - auto height = displayPtr->GetHeight(); - auto rotation = displayPtr->GetRotation(); + auto displayInfo = displayPtr->GetDisplayInfo(); + if (displayInfo == nullptr) { + IMSA_HILOGE("displayInfo is nullptr"); + return; + } + auto width = displayInfo->GetWidth(); + auto height = displayInfo->GetHeight(); + auto rotation = displayInfo->GetRotation(); IMSA_HILOGD("display width: %{public}d, height: %{public}d, rotation: %{public}d, foldStatus: %{public}d", width, height, rotation, foldStatus); if (!cacheDisplay_.IsEmpty()) { diff --git a/frameworks/kits/extension_cj/src/cj_inputmethod_extension.cpp b/frameworks/kits/extension_cj/src/cj_inputmethod_extension.cpp index 7a40715cd..e71b06723 100644 --- a/frameworks/kits/extension_cj/src/cj_inputmethod_extension.cpp +++ b/frameworks/kits/extension_cj/src/cj_inputmethod_extension.cpp @@ -16,10 +16,12 @@ #include "cj_inputmethod_extension.h" #include "ability_handler.h" #include "configuration_utils.h" +#include "display_info.h" #include "global.h" #include "inputmethod_extension_ability_service_impl.h" #include "inputmethod_trace.h" #include "iservice_registry.h" +#include "parameters.h" #include "system_ability_definition.h" #include "task_manager.h" #include "tasks/task_ams.h" @@ -33,6 +35,8 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::MiscServices; constexpr int32_t SUCCESS_CODE = 0; +const std::string FOLD_SCREEN_TYPE = OHOS::system::GetParameter("const.window.foldscreen.type", "0,0,0,0"); +constexpr const char *EXTEND_FOLD_TYPE = "4"; extern "C" __attribute__((visibility("default"))) InputMethodExtension *OHOS_ABILITY_CjInputMethodExtension() { @@ -186,6 +190,10 @@ void CjInputMethodExtension::OnDestroy(Rosen::DisplayId displayId) void CjInputMethodExtension::CheckNeedAdjustKeyboard(Rosen::DisplayId displayId) { + if (FOLD_SCREEN_TYPE.empty() || FOLD_SCREEN_TYPE[0] != *EXTEND_FOLD_TYPE) { + IMSA_HILOGD("The current device is a non-foldable device."); + return; + } auto displayPtr = Rosen::DisplayManager::GetInstance().GetDefaultDisplaySync(); if (displayPtr == nullptr) { return; @@ -195,9 +203,14 @@ void CjInputMethodExtension::CheckNeedAdjustKeyboard(Rosen::DisplayId displayId) return; } auto foldStatus = Rosen::DisplayManager::GetInstance().GetFoldStatus(); - auto width = displayPtr->GetWidth(); - auto height = displayPtr->GetHeight(); - auto rotation = displayPtr->GetRotation(); + auto displayInfo = displayPtr->GetDisplayInfo(); + if (displayInfo == nullptr) { + IMSA_HILOGE("displayInfo is nullptr"); + return; + } + auto width = displayInfo->GetWidth(); + auto height = displayInfo->GetHeight(); + auto rotation = displayInfo->GetRotation(); IMSA_HILOGD("display width: %{public}d, height: %{public}d, rotation: %{public}d, foldStatus: %{public}d", width, height, rotation, foldStatus); if (!cacheDisplay_.IsEmpty()) { -- Gitee