diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index 093df774796b305ede00343724632411c00c5031..0ca9838269167bf850a8daef4e7754ebe5c9bb1d 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -179,6 +179,7 @@ private: void SetHotAreas(const HotAreas &hotAreas); HotAreas GetHotAreas(); sptr GetCurDisplay(); + uint64_t GetCurDisplayId(); void SetIgnoreAdjustInputTypes(const std::vector &inputTypes); std::vector GetIgnoreAdjustInputTypes(); bool IsNeedConfig(); @@ -210,6 +211,7 @@ private: std::mutex panelAdjustLock_; std::map, PanelAdjustInfo> panelAdjust_; std::mutex adjustInfoInitLock_; + uint64_t adjustInfoDisplayId_ = 0; std::atomic isAdjustInfoInitialized_{ false }; std::atomic isIgnorePanelAdjustInitialized_{ false }; std::mutex ignoreAdjustInputTypeLock_; diff --git a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp index 182aefd3697472cc1a475179a8b49b072c5aae2d..27ae4e5b0e6ebaf707a293a21d232d744d025823 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp @@ -1017,16 +1017,15 @@ int32_t InputMethodPanel::UpdateRegion(std::vector region) int32_t InputMethodPanel::InitAdjustInfo() { - if (isAdjustInfoInitialized_.load()) { - return ErrorCode::NO_ERROR; - } std::lock_guard initLk(adjustInfoInitLock_); - if (isAdjustInfoInitialized_.load()) { + auto curDisplayId = GetCurDisplayId(); + if (isAdjustInfoInitialized_.load() && adjustInfoDisplayId_ == curDisplayId) { return ErrorCode::NO_ERROR; } std::vector configs; auto isSuccess = SysCfgParser::ParsePanelAdjust(configs); if (!isSuccess) { + adjustInfoDisplayId_ = curDisplayId; isAdjustInfoInitialized_.store(true); return ErrorCode::NO_ERROR; } @@ -1045,6 +1044,7 @@ int32_t InputMethodPanel::InitAdjustInfo() .bottom = static_cast(config.bottom * densityDpi) }; panelAdjust_.insert({ config.style, info }); } + adjustInfoDisplayId_ = curDisplayId; isAdjustInfoInitialized_.store(true); return ErrorCode::NO_ERROR; } @@ -2249,7 +2249,7 @@ HotAreas InputMethodPanel::GetHotAreas() sptr InputMethodPanel::GetCurDisplay() { IMSA_HILOGD("enter!!"); - uint64_t displayId = InputMethodAbility::GetInstance().GetInputAttribute().callingDisplayId; + uint64_t displayId = GetCurDisplayId(); auto displayInfo = Rosen::DisplayManager::GetInstance().GetDisplayById(displayId); if (displayInfo == nullptr) { IMSA_HILOGE("get display info err:%{public}" PRIu64 "!", displayId); @@ -2258,15 +2258,15 @@ sptr InputMethodPanel::GetCurDisplay() return displayInfo; } +uint64_t InputMethodPanel::GetCurDisplayId() +{ + return InputMethodAbility::GetInstance().GetInputAttribute().callingDisplayId; +} + bool InputMethodPanel::IsInMainDisplay() { IMSA_HILOGD("enter!!"); - uint64_t displayId = 0; - auto ret = GetDisplayId(displayId); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("GetDisplayId err:%{public}d!", ret); - return true; - } + uint64_t displayId = GetCurDisplayId(); auto primaryDisplay = Rosen::DisplayManager::GetInstance().GetPrimaryDisplaySync(); if (primaryDisplay == nullptr) { IMSA_HILOGE("primaryDisplay failed!"); 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 7ca6c45286f352dba5eb0179db95625da56814b6..2727465760f777bda5cbc9a5b9f3860ebe0c4506 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -2567,5 +2567,32 @@ HWTEST_F(InputMethodPanelTest, RestoreConfigWhenAdjustFails, TestSize.Level1) EXPECT_EQ(panel->immersiveEffect_.gradientHeight, GRADIENT_HEIGHT); EXPECT_EQ(panel->immersiveEffect_.gradientMode, GradientMode::LINEAR_GRADIENT); } + +/** + * @tc.name: TestInitAdjustInfo + * @tc.desc: Test InitAdjustInfo + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, TestInitAdjustInfo, TestSize.Level1) +{ + IMSA_HILOGI("InputMethodPanelTest::TestInitAdjustInfo"); + auto panel = std::make_shared(); + InputMethodAbility::GetInstance().inputAttribute_.callingDisplayId = 0; + panel->isAdjustInfoInitialized_ = false; + panel->adjustInfoDisplayId_ = 0; + panel->panelAdjust_.clear(); + auto ret = panel->InitAdjustInfo(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + panel->isAdjustInfoInitialized_ = true; + panel->adjustInfoDisplayId_ = 1000; + panel->panelAdjust_.clear(); + ret = panel->InitAdjustInfo(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + panel->isAdjustInfoInitialized_ = true; + panel->adjustInfoDisplayId_ = 0; + panel->panelAdjust_.clear(); + ret = panel->InitAdjustInfo(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file