From 9be957d2e502df3c0fb186a0eb53797342bff6e8 Mon Sep 17 00:00:00 2001 From: kangpeng9771 Date: Fri, 5 Sep 2025 17:47:33 +0800 Subject: [PATCH] test Signed-off-by: kangpeng9771 --- common/include/global.h | 1 + .../js/napi/inputmethodability/js_panel.cpp | 54 ++++ .../js/napi/inputmethodability/js_panel.h | 4 + .../js/napi/inputmethodclient/js_utils.cpp | 2 + .../js/napi/inputmethodclient/js_utils.h | 1 + .../include/input_method_panel.h | 8 +- .../inputmethod_ability/include/panel_info.h | 6 + .../src/input_method_panel.cpp | 100 +++++- .../cpp_test/src/input_method_panel_test.cpp | 289 ++++++++++++++++++ .../src/InputMethodWithAttachTest.js | 25 +- .../model/KeyboardController.ts | 19 ++ 11 files changed, 504 insertions(+), 5 deletions(-) diff --git a/common/include/global.h b/common/include/global.h index 7158372cc..f03dae955 100644 --- a/common/include/global.h +++ b/common/include/global.h @@ -135,6 +135,7 @@ enum { ERROR_IME_HAS_STARTED, ERROR_OPERATION_NOT_ALLOWED, ERROR_REQUEST_RATE_EXCEEDED, + ERROR_INVALID_DISPLAYID, ERROR_IMSA_END, }; }; // namespace ErrorCode diff --git a/frameworks/js/napi/inputmethodability/js_panel.cpp b/frameworks/js/napi/inputmethodability/js_panel.cpp index 69e39652d..776d857d9 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.cpp +++ b/frameworks/js/napi/inputmethodability/js_panel.cpp @@ -65,6 +65,7 @@ napi_value JsPanel::Init(napi_env env) DECLARE_NAPI_FUNCTION("getImmersiveMode", GetImmersiveMode), DECLARE_NAPI_FUNCTION("setImmersiveEffect", SetImmersiveEffect), DECLARE_NAPI_FUNCTION("setKeepScreenOn", SetKeepScreenOn), + DECLARE_NAPI_FUNCTION("getSystemPanelCurrentInsets", GetSystemPanelCurrentInsets), }; NAPI_CALL(env, napi_define_class(env, CLASS_NAME.c_str(), CLASS_NAME.size(), JsNew, nullptr, sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor)); @@ -917,5 +918,58 @@ napi_value JsPanel::SetKeepScreenOn(napi_env env, napi_callback_info info) AsyncCall asyncCall(env, info, ctxt, 1); return asyncCall.Call(env, exec, "setKeepScreenOn"); } + +napi_value JsPanel::WriteCurrentInsetsOutput(napi_env env, SystemPanelInsets systemPanelInsets) +{ + napi_value jsObject = nullptr; + napi_create_object(env, &jsObject); + bool ret = + JsUtil::Object::WriteProperty(env, jsObject, "left", systemPanelInsets.left); + ret = ret && + JsUtil::Object::WriteProperty(env, jsObject, "right", systemPanelInsets.right); + ret = ret && + JsUtil::Object::WriteProperty(env, jsObject, "bottom", systemPanelInsets.bottom); + return ret ? jsObject : JsUtil::Const::Null(env); +} + +napi_value JsPanel::GetSystemPanelCurrentInsets(napi_env env, napi_callback_info info) +{ + auto ctxt = std::make_shared(env, info); + auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status { + PARAM_CHECK_RETURN(env, ctxt->inputMethodPanel != nullptr, "panel is null", TYPE_NONE, napi_generic_failure); + PARAM_CHECK_RETURN(env, argc > 0, "at least one parameters is required", TYPE_NONE, napi_generic_failure); + uint32_t displayId = 0; + PARAM_CHECK_RETURN(env, JsUtils::GetValue(env, argv[0], displayId) == napi_ok, "failed to get displayId", + TYPE_NONE, napi_generic_failure); + ctxt->displayId = static_cast(displayId); + ctxt->info = { std::chrono::system_clock::now(), JsEvent::GET_SYSTEM_PANEL_CURRENT_INSETS }; + jsQueue_.Push(ctxt->info); + return napi_ok; + }; + auto exec = [ctxt](AsyncCall::Context *ctx) { + jsQueue_.Wait(ctxt->info); + if (ctxt->inputMethodPanel == nullptr) { + IMSA_HILOGE("inputMethodPanel_ is nullptr!"); + jsQueue_.Pop(); + return napi_generic_failure; + } + auto ret = ctxt->inputMethodPanel->GetSystemPanelCurrentInsets(ctxt->displayId, ctxt->systemPanelInsets); + jsQueue_.Pop(); + if (ret == ErrorCode::NO_ERROR) { + ctxt->SetState(napi_ok); + return napi_ok; + } + ctxt->SetErrorCode(ret); + return napi_generic_failure; + }; + auto output = [ctxt](napi_env env, napi_value *result) -> napi_status { + *result = WriteCurrentInsetsOutput(env, ctxt->systemPanelInsets); + return napi_ok; + }; + ctxt->SetAction(std::move(input), std::move(output)); + // 1 means JsAPI:getSystemPanelInsets has 1 params at most. + AsyncCall asyncCall(env, info, ctxt, 1); + return asyncCall.Call(env, exec, "getSystemPanelCurrentInsets"); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inputmethodability/js_panel.h b/frameworks/js/napi/inputmethodability/js_panel.h index e2345c059..9e4bf66f7 100644 --- a/frameworks/js/napi/inputmethodability/js_panel.h +++ b/frameworks/js/napi/inputmethodability/js_panel.h @@ -44,6 +44,7 @@ enum class JsEvent : uint32_t { SET_IMMERSIVE_MODE, GET_IMMERSIVE_MODE, SET_IMMERSIVE_EFFECT, + GET_SYSTEM_PANEL_CURRENT_INSETS, EVENT_END, }; @@ -97,6 +98,7 @@ public: static napi_value GetImmersiveMode(napi_env env, napi_callback_info info); static napi_value SetImmersiveEffect(napi_env env, napi_callback_info info); static napi_value SetKeepScreenOn(napi_env env, napi_callback_info info); + static napi_value GetSystemPanelCurrentInsets(napi_env env, napi_callback_info info); private: struct PanelContentContext : public AsyncCall::Context { @@ -113,6 +115,7 @@ private: int32_t y = 0; uint64_t displayId = 0; bool isKeepScreenOn = false; + SystemPanelInsets systemPanelInsets = {0, 0, 0}; std::shared_ptr inputMethodPanel = nullptr; std::shared_ptr contentStorage = nullptr; JsEventInfo info; @@ -154,6 +157,7 @@ private: napi_env env, size_t argc, napi_value *argv, std::shared_ptr ctxt); static void AdjustLayoutParam(std::shared_ptr ctxt); static void AdjustEnhancedLayoutParam(std::shared_ptr ctxt); + static napi_value WriteCurrentInsetsOutput(napi_env env, SystemPanelInsets systemPanelInsets); static const std::string CLASS_NAME; static constexpr size_t ARGC_MAX = 6; diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index eb1c266ef..46353c0e4 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -94,6 +94,7 @@ const std::map JsUtils::ERROR_CODE_MAP = { { ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL, EXCEPTION_IMCLIENT }, { ErrorCode::ERROR_IMA_INVALID_IMMERSIVE_EFFECT, EXCEPTION_INVALID_IMMERSIVE_EFFECT }, { ErrorCode::ERROR_IMA_PRECONDITION_REQUIRED, EXCEPTION_PRECONDITION_REQUIRED }, + { ErrorCode::ERROR_INVALID_DISPLAYID, EXCEPTION_INVALID_DISPLAYID }, }; const std::map JsUtils::ERROR_CODE_CONVERT_MESSAGE_MAP = { @@ -129,6 +130,7 @@ const std::map JsUtils::ERROR_CODE_CONVERT_MESSAGE_MAP = { 2.The fluid light mode can only be used when the gradient mode is enabled.\n\ 3.When the gradient mode is not enabled, the gradient height can only be 0." }, { EXCEPTION_PRECONDITION_REQUIRED, "this operation must be called after adjustPanelRect or resize." }, + { EXCEPTION_INVALID_DISPLAYID, "invalid display id." }, }; const std::map JsUtils::PARAMETER_TYPE = { diff --git a/frameworks/js/napi/inputmethodclient/js_utils.h b/frameworks/js/napi/inputmethodclient/js_utils.h index 71797468f..166330947 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.h +++ b/frameworks/js/napi/inputmethodclient/js_utils.h @@ -58,6 +58,7 @@ enum IMFErrorCode : int32_t { EXCEPTION_OPERATE_DEFAULTIME = 12800019, EXCEPTION_INVALID_IMMERSIVE_EFFECT = 12800020, EXCEPTION_PRECONDITION_REQUIRED = 12800021, + EXCEPTION_INVALID_DISPLAYID = 12800022, }; enum TypeCode : int32_t { diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index bc995a06d..31dea8808 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -83,6 +83,7 @@ public: bool IsInMainDisplay(); int32_t SetImmersiveEffect(const ImmersiveEffect &effect); int32_t SetKeepScreenOn(bool isKeepScreenOn); + int32_t GetSystemPanelCurrentInsets(uint64_t displayId, SystemPanelInsets &systemPanelInsets); uint32_t windowId_ = INVALID_WINDOW_ID; private: @@ -158,7 +159,6 @@ private: int32_t InitAdjustInfo(); int32_t GetAdjustInfo(PanelFlag panelFlag, FullPanelAdjustInfo &fullPanelAdjustInfo); - void UpdateResizeParams(); void UpdateHotAreas(); void UpdateLayoutInfo(PanelFlag panelFlag, const LayoutParams ¶ms, const EnhancedLayoutParams &enhancedParams, @@ -171,7 +171,7 @@ private: sptr GetCurDisplay(); uint64_t GetCurDisplayId(); - bool IsNeedConfig(); + bool IsNeedConfig(bool ignoreIsMainDisplay = false); int32_t IsValidParam(const ImmersiveEffect &effect, const Rosen::KeyboardLayoutParams &layoutParams); int32_t AdjustLayout(const Rosen::KeyboardLayoutParams ¶m); int32_t AdjustLayout(const Rosen::KeyboardLayoutParams ¶m, const ImmersiveEffect &effect); @@ -200,6 +200,8 @@ private: void StoreImmersiveMode(ImmersiveMode mode); CallbackFunc GetPanelHeightCallback(); + bool IsVectorsEqual(const std::vector& vec1, const std::vector& vec2); + int32_t AreaInsets(SystemPanelInsets &systemPanelInsets, sptr displayPtr); sptr window_ = nullptr; sptr winOption_ = nullptr; @@ -259,6 +261,8 @@ private: ImmersiveEffect immersiveEffect_ { 0, GradientMode::NONE, FluidLightMode::NONE }; std::mutex changeYMutex_; ChangeY changeY_; + + std::mutex getInsetsMutex_; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/include/panel_info.h b/frameworks/native/inputmethod_ability/include/panel_info.h index e10d0bf9d..ec09e2037 100644 --- a/frameworks/native/inputmethod_ability/include/panel_info.h +++ b/frameworks/native/inputmethod_ability/include/panel_info.h @@ -99,6 +99,12 @@ struct ImmersiveEffect { return ss.str(); } }; + +struct SystemPanelInsets { + int32_t left{ 0 }; + int32_t right{ 0 }; + int32_t bottom{ 0 }; +}; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp index 37aeb8c67..9cb49f99c 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp @@ -2155,7 +2155,7 @@ std::vector InputMethodPanel::GetIgnoreAdjustInputTypes() return ignoreAdjustInputTypes_; } -bool InputMethodPanel::IsNeedConfig() +bool InputMethodPanel::IsNeedConfig(bool ignoreIsMainDisplay) { bool needConfig = true; bool isSpecialInputType = false; @@ -2174,7 +2174,10 @@ bool InputMethodPanel::IsNeedConfig() return static_cast(inputType) == mInputType; }); isSpecialInputType = (it != ignoreAdjustInputTypes.end()); - if (isSpecialInputType || !IsInMainDisplay()) { + if (isSpecialInputType) { + needConfig = false; + } + if (!ignoreIsMainDisplay && !IsInMainDisplay()) { needConfig = false; } IMSA_HILOGD("isNeedConfig is %{public}d", needConfig); @@ -2243,5 +2246,98 @@ void InputMethodPanel::SetChangeY(ChangeY changeY) std::lock_guard lock(changeYMutex_); changeY_ = changeY; } + +bool InputMethodPanel::IsVectorsEqual(const std::vector& vec1, const std::vector& vec2) +{ + return vec1 == vec2; +} + +int32_t InputMethodPanel::AreaInsets(SystemPanelInsets &systemPanelInsets, sptr display) +{ + if (display == nullptr) { + IMSA_HILOGE("display is null!"); + return ErrorCode::ERROR_NULL_POINTER; + } + std::lock_guard lock(getInsetsMutex_); + std::vector configs; + auto isSuccess = SysCfgParser::ParsePanelAdjust(configs); + if (!isSuccess) { + systemPanelInsets = { 0, 0, 0 }; + return ErrorCode::NO_ERROR; + } + auto displayInfo = display->GetDisplayInfo(); + if (displayInfo == nullptr) { + IMSA_HILOGE("GetDisplayInfo failed!"); + return ErrorCode::ERROR_WINDOW_MANAGER; + } + float densityDpi = displayInfo->GetDensityInCurResolution(); + if (densityDpi <= 0) { + IMSA_HILOGE("densityDpi failed!"); + return ErrorCode::ERROR_WINDOW_MANAGER; + } + + auto width = displayInfo->GetWidth(); + auto height = displayInfo->GetHeight(); + IMSA_HILOGI("display getDensityDpi: %{public}f, width : %{public}d, height: %{public}d", + densityDpi, width, height); + + bool isPortrait = width < height ? true :false; + auto keys = GetScreenStatus(panelFlag_); + auto styleKey = isPortrait ? std::get<1>(keys) : std::get<0>(keys); + for (const auto &config : configs) { + if (IsVectorsEqual(config.style, styleKey)) { + systemPanelInsets.left = static_cast(config.left * densityDpi); + systemPanelInsets.right = static_cast(config.right * densityDpi); + systemPanelInsets.bottom = static_cast(config.bottom * densityDpi); + return ErrorCode::NO_ERROR; + } + } + systemPanelInsets = { 0, 0, 0 }; + return ErrorCode::NO_ERROR; +} + +int32_t InputMethodPanel::GetSystemPanelCurrentInsets(uint64_t displayId, SystemPanelInsets &systemPanelInsets) +{ + IMSA_HILOGD("enter!!"); + if (window_ == nullptr) { + IMSA_HILOGE("window_ is nullptr!"); + return ErrorCode::ERROR_WINDOW_MANAGER; + } + if (panelType_ == PanelType::STATUS_BAR) { + IMSA_HILOGE("invalid panel type!"); + return ErrorCode::ERROR_INVALID_PANEL_TYPE; + } + if (panelFlag_ == PanelFlag::FLG_CANDIDATE_COLUMN) { + IMSA_HILOGE("panelFlag_ is candidate column"); + return ErrorCode::ERROR_INVALID_PANEL_FLAG; + } + auto specifyDisplay = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); + if (specifyDisplay == nullptr) { + IMSA_HILOGE("get display info err:%{public}" PRIu64 "!", displayId); + return ErrorCode::ERROR_INVALID_DISPLAYID; + } + auto primaryDisplay = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); + if (primaryDisplay == nullptr) { + IMSA_HILOGE("primaryDisplay failed!"); + systemPanelInsets = { 0, 0, 0 }; + return ErrorCode::ERROR_WINDOW_MANAGER; + } + if (primaryDisplay->GetId() != displayId) { + IMSA_HILOGD("is not main display"); + systemPanelInsets = { 0, 0, 0 }; + return ErrorCode::NO_ERROR; + } + if (!IsNeedConfig(true)) { + IMSA_HILOGD("is special InputType"); + systemPanelInsets = { 0, 0, 0 }; + return ErrorCode::NO_ERROR; + } + auto code = AreaInsets(systemPanelInsets, specifyDisplay); + if (code != ErrorCode::NO_ERROR) { + return code; + } + IMSA_HILOGD("GetSystemPanelInsets success!!"); + return ErrorCode::NO_ERROR; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/cpp_test/src/input_method_panel_test.cpp b/test/unittest/cpp_test/src/input_method_panel_test.cpp index 9ac6edf12..d1d82f684 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -80,6 +80,7 @@ enum ListeningStatus : uint32_t { OFF, NONE }; + class InputMethodPanelTest : public testing::Test { public: static void SetUpTestCase(void); @@ -2618,5 +2619,293 @@ HWTEST_F(InputMethodPanelTest, TestInitAdjustInfo, TestSize.Level0) ret = panel->InitAdjustInfo(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); } + +/** + * @tc.name: testGetSystemPanelInsets1 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets1, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets1 start."); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + uint64_t displayId = 0; + ret = inputMethodPanel->GetDisplayId(displayId); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + SystemPanelInsets panelInsets = {0, 0, 0}; + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets2 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets2, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets2 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD; + panelInfo.panelFlag = PanelFlag::FLG_FLOATING; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 0; + inputMethodPanel->GetDisplayId(displayId); + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets3 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets3, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets3 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::STATUS_BAR; + panelInfo.panelFlag = PanelFlag::FLG_CANDIDATE_COLUMN; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 0; + inputMethodPanel->GetDisplayId(displayId); + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_TYPE); + + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets4 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets4, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets4 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD; + panelInfo.panelFlag = PanelFlag::FLG_CANDIDATE_COLUMN; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 0; + inputMethodPanel->GetDisplayId(displayId); + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PANEL_FLAG); + + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets5 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets5, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets5 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD;; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 10; + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_DISPLAYID); + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets6 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets6, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets6 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD;; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 0; + + InputMethodPanelTest::DestroyPanel(inputMethodPanel); + inputMethodPanel->window_ = nullptr; + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::ERROR_WINDOW_MANAGER); +} + +/** + * @tc.name: testGetSystemPanelInsets7 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets7, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets7 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD;; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + + SystemPanelInsets panelInsets = {0, 0, 0}; + uint64_t displayId = 0; + + ima_.inputType_ = InputType::SECURITY_INPUT; + ret = inputMethodPanel->GetSystemPanelCurrentInsets(displayId, panelInsets); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_EQ(0, panelInsets.left); + EXPECT_EQ(0, panelInsets.right); + EXPECT_EQ(0, panelInsets.bottom); +} + +/** + * @tc.name: testGetSystemPanelInsets8 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets8, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets8 start."); + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + + std::vector vec1 = { "123", "234"}; + std::vector vec2 = { "123" }; + + bool ret = inputMethodPanel->IsVectorsEqual(vec1, vec2); + EXPECT_EQ(ret, false); + + vec2 = { "123", "345" }; + ret = inputMethodPanel->IsVectorsEqual(vec1, vec2); + EXPECT_EQ(ret, false); +} + +/** + * @tc.name: testGetSystemPanelInsets9 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets9, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets9 start."); + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + + std::vector vec1 = {}; + std::vector vec2 = {}; + bool ret = inputMethodPanel->IsVectorsEqual(vec1, vec2); + EXPECT_EQ(ret, true); + + vec1 = { "123", "234"}; + ret = inputMethodPanel->IsVectorsEqual(vec1, vec2); + EXPECT_EQ(ret, false); + + vec2 = { "123", "234"}; + ret = inputMethodPanel->IsVectorsEqual(vec1, vec2); + EXPECT_EQ(ret, true); +} + +/** + * @tc.name: testGetSystemPanelInsets10 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets10, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets10 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD;; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + ima_.inputType_ = InputType::SECURITY_INPUT; + + std::vector inputTypes{static_cast(InputType::SECURITY_INPUT)}; + inputMethodPanel->SetIgnoreAdjustInputTypes(inputTypes); + + bool isNeedConfig = inputMethodPanel->IsNeedConfig(true); + EXPECT_EQ(isNeedConfig, false); + isNeedConfig = inputMethodPanel->IsNeedConfig(false); + EXPECT_EQ(isNeedConfig, false); + + ima_.inputType_ = InputType::NONE; + isNeedConfig = inputMethodPanel->IsNeedConfig(false); + EXPECT_EQ(isNeedConfig, true); + isNeedConfig = inputMethodPanel->IsNeedConfig(true); + EXPECT_EQ(isNeedConfig, true); + + InputMethodPanelTest::DestroyPanel(inputMethodPanel); +} + +/** + * @tc.name: testGetSystemPanelInsets11 + * @tc.desc: Test GetSystemPanelInsets. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testGetSystemPanelInsets11, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testGetSystemPanelInsets11 start."); + + AccessScope scope(currentImeTokenId_, currentImeUid_); + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo; + panelInfo.panelType = PanelType::SOFT_KEYBOARD;; + panelInfo.panelFlag = PanelFlag::FLG_FIXED; + auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + SystemPanelInsets panelInsets = {0, 0, 0}; + inputMethodPanel->panelFlag_ = PanelFlag::FLG_FIXED; + auto display = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); + ret = inputMethodPanel->AreaInsets(panelInsets, display); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + inputMethodPanel->panelFlag_ = PanelFlag::FLG_FLOATING; + ret = inputMethodPanel->AreaInsets(panelInsets, display); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + display = Rosen::DisplayManager::GetInstance().GetDisplayById(1000); + ret = inputMethodPanel->AreaInsets(panelInsets, display); + EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/napi_test/src/InputMethodWithAttachTest.js b/test/unittest/napi_test/src/InputMethodWithAttachTest.js index 109ecd886..7e9b5c4a6 100644 --- a/test/unittest/napi_test/src/InputMethodWithAttachTest.js +++ b/test/unittest/napi_test/src/InputMethodWithAttachTest.js @@ -44,7 +44,8 @@ describe('InputMethodWithAttachTest', function () { ADJUST_SUCCESS: 19, SET_PREVIEW_TEXT: 20, FINISH_TEXT_PREVIEW: 21, - SET_KEEP_SCREEN_ON: 22 + SET_KEEP_SCREEN_ON: 22, + GET_SYSTEM_PANEL_INSETS: 23 } beforeAll(async function (done) { @@ -683,6 +684,28 @@ describe('InputMethodWithAttachTest', function () { } }); + /* + * @tc.number inputmethod_test_getSystemPanelInsets_001 + * @tc.name Test Indicates the input method which will replace the current one. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_getSystemPanelInsets_001', 0, async function (done) { + console.info('************* inputmethod_test_getSystemPanelInsets_001 Test start*************'); + let inputMethodCtrl = inputMethod.getController(); + await inputMethodCtrl.showSoftKeyboard(); + try { + let subscribeInfo = { + events: ['getSystemPanelInsets'] + }; + subscribe(subscribeInfo, TEST_FUNCTION.GET_SYSTEM_PANEL_INSETS, done); + } catch(error) { + console.info(`inputmethod_test_getSystemPanelInsets_001 result: ${JSON.stringify(error)}`); + expect().assertFail(); + done(); + } + }); + /* * @tc.number inputmethod_test_getSystemPanelInsets_001 * @tc.name Test Indicates the input method which will replace the current one. diff --git a/test/unittest/resource/bundle_dependencies/extImfBundle/entry/src/main/ets/InputMethodExtAbility/model/KeyboardController.ts b/test/unittest/resource/bundle_dependencies/extImfBundle/entry/src/main/ets/InputMethodExtAbility/model/KeyboardController.ts index 6b16505fa..99d5c7426 100644 --- a/test/unittest/resource/bundle_dependencies/extImfBundle/entry/src/main/ets/InputMethodExtAbility/model/KeyboardController.ts +++ b/test/unittest/resource/bundle_dependencies/extImfBundle/entry/src/main/ets/InputMethodExtAbility/model/KeyboardController.ts @@ -53,6 +53,7 @@ enum TEST_FUNCTION { SET_PREVIEW_TEXT, FINISH_TEXT_PREVIEW, SET_KEEP_SCREEN_ON, + GET_SYSTEM_PANEL_INSETS, } export class KeyboardController { @@ -196,6 +197,9 @@ export class KeyboardController { case TEST_FUNCTION.SET_KEEP_SCREEN_ON: this.setKeepScreenOn(); break; + case TEST_FUNCTION.GET_SYSTEM_PANEL_INSETS: + this.getSystemPanelInsets(); + break; default: break; } @@ -203,6 +207,21 @@ export class KeyboardController { }) } + private async getSystemPanelInsets() { + try { + let displayId: number = await this.panel.getDisplayId(); + let insets = await this.panel.getSystemPanelCurrentInsets(displayId); + if (insets === undefined || insets === null) { + console.log('[getSystemPanelInsets] failed, insets is null.' ) + this.publishCommonEvent('getSystemPanelInsets', TEST_RESULT_CODE.FAILED); + } + this.publishCommonEvent('getSystemPanelInsets', TEST_RESULT_CODE.SUCCESS); + } catch (err) { + console.log('[getSystemPanelInsets] failed.' ) + this.publishCommonEvent('getSystemPanelInsets', TEST_RESULT_CODE.FAILED); + } + } + private async setKeepScreenOn() { try { await this.panel.setKeepScreenOn(true); -- Gitee