From c8da8d4851d22f280c35d4feecdb2049b41049c5 Mon Sep 17 00:00:00 2001 From: guojin31 Date: Mon, 14 Apr 2025 16:27:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E6=94=AF=E6=8C=81=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=B3=95=E4=B8=8D=E5=A4=AA=E9=AB=98=E7=9A=84=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guojin31 --- .../include/input_method_ability.h | 1 + .../include/input_method_panel.h | 5 +++ .../src/input_method_ability.cpp | 5 +++ .../src/input_method_panel.cpp | 38 +++++++++++++++++-- services/include/sys_cfg_parser.h | 17 +++++++++ services/src/sys_cfg_parser.cpp | 13 +++++++ .../src/input_method_ability_test.cpp | 16 ++++++++ .../cpp_test/src/json_operate_test.cpp | 34 ++++++++++++++++- 8 files changed, 124 insertions(+), 5 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 298296e40..11591f1e1 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -85,6 +85,7 @@ public: bool IsCurrentIme(); bool IsEnable(); bool IsSystemApp(); + InputType GetInputType(); int32_t ExitCurrentInputType(); int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); int32_t GetSecurityMode(int32_t &security); diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index bc243f073..5f90c1720 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -177,6 +177,8 @@ private: void SetHotAreas(const HotAreas &hotAreas); HotAreas GetHotAreas(); sptr GetCurDisplay(); + void SetIgnoreAdjustInputTypes(const std::vector &inputTypes); + std::vector GetIgnoreAdjustInputTypes(); bool IsNeedConfig(); sptr window_ = nullptr; sptr winOption_ = nullptr; @@ -197,6 +199,9 @@ private: std::map, PanelAdjustInfo> panelAdjust_; std::mutex adjustInfoInitLock_; std::atomic isAdjustInfoInitialized_{ false }; + std::atomic isIgnorePanelAdjustInitialized_{ false }; + std::mutex ignoreAdjustInputTypeLock_; + std::vector ignoreAdjustInputTypes_; std::mutex hotAreasLock_; HotAreas hotAreas_; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index f6e9f566f..c2651eb5c 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -321,6 +321,11 @@ void InputMethodAbility::OnSetInputType(InputType inputType) } } +InputType InputMethodAbility::GetInputType() +{ + return inputType_; +} + void InputMethodAbility::ClearDataChannel(const sptr &channel) { std::lock_guard lock(dataChannelLock_); diff --git a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp index 7f12979e3..93ed1cc26 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_panel.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_panel.cpp @@ -1951,14 +1951,44 @@ bool InputMethodPanel::IsInMainDisplay() return primaryDisplay->GetId() == displayId; } +void InputMethodPanel::SetIgnoreAdjustInputTypes(const std::vector &inputTypes) +{ + std::lock_guard lock(ignoreAdjustInputTypeLock_); + ignoreAdjustInputTypes_ = inputTypes; +} + +std::vector InputMethodPanel::GetIgnoreAdjustInputTypes() +{ + std::lock_guard lock(ignoreAdjustInputTypeLock_); + return ignoreAdjustInputTypes_; +} + bool InputMethodPanel::IsNeedConfig() { - auto instance = InputMethodAbility::GetInstance(); bool needConfig = true; - if ((instance != nullptr && instance->GetInputAttribute().GetSecurityFlag()) || - !IsInMainDisplay()) { - needConfig = false; + bool isSpecialInputType = false; + auto instance = InputMethodAbility::GetInstance(); + if (instance != nullptr) { + auto inputType = instance->GetInputType(); + if (!isIgnorePanelAdjustInitialized_.load()) { + IgnoreSysPanelAdjust ignoreSysPanelAdjust; + auto isSuccess = SysCfgParser::ParseIgnoreSysPanelAdjust(ignoreSysPanelAdjust); + if (isSuccess) { + SetIgnoreAdjustInputTypes(ignoreSysPanelAdjust.inputType); + } + isIgnorePanelAdjustInitialized_.store(true); + } + std::vector ignoreAdjustInputTypes = GetIgnoreAdjustInputTypes(); + auto it = std::find_if( + ignoreAdjustInputTypes.begin(), ignoreAdjustInputTypes.end(), [inputType](const int32_t &mInputType) { + return static_cast(inputType) == mInputType; + }); + isSpecialInputType = (it != ignoreAdjustInputTypes.end()); + } + if (isSpecialInputType || !IsInMainDisplay()) { + needConfig = false; } + IMSA_HILOGD("isNeedConfig is %{public}d", needConfig); return needConfig; } } // namespace MiscServices diff --git a/services/include/sys_cfg_parser.h b/services/include/sys_cfg_parser.h index b9a5110b8..6562fe6f4 100644 --- a/services/include/sys_cfg_parser.h +++ b/services/include/sys_cfg_parser.h @@ -124,12 +124,29 @@ struct DefaultFullImeCfg : Serializable { } }; +struct IgnoreSysPanelAdjust : public Serializable { + std::vector inputType; + bool Unmarshal(cJSON *node) override + { + return GetValue(node, GET_NAME(inputType), inputType); + } +}; + +struct IgnoreSysPanelAdjustCfg : public Serializable { + IgnoreSysPanelAdjust ignoreSysPanelAdjust; + bool Unmarshal(cJSON *node) override + { + return GetValue(node, GET_NAME(ignoreSysPanelAdjust), ignoreSysPanelAdjust); + } +}; + class SysCfgParser { public: static bool ParseSystemConfig(SystemConfig &systemConfig); static bool ParseInputType(std::vector &inputType); static bool ParsePanelAdjust(std::vector &sysPanelAdjust); static bool ParseDefaultFullIme(std::vector &defaultFullImeList); + static bool ParseIgnoreSysPanelAdjust(IgnoreSysPanelAdjust &ignoreSysPanelAdjust); private: static std::string GetSysCfgContent(const std::string &key); diff --git a/services/src/sys_cfg_parser.cpp b/services/src/sys_cfg_parser.cpp index a7e503710..0d4ac867e 100644 --- a/services/src/sys_cfg_parser.cpp +++ b/services/src/sys_cfg_parser.cpp @@ -71,6 +71,19 @@ bool SysCfgParser::ParseDefaultFullIme(std::vector &defaultF return ret; } +bool SysCfgParser::ParseIgnoreSysPanelAdjust(IgnoreSysPanelAdjust &ignoreSysPanelAdjust) +{ + auto content = GetSysCfgContent(GET_NAME(ignoreSysPanelAdjust)); + if (content.empty()) { + IMSA_HILOGD("content is empty"); + return false; + } + IgnoreSysPanelAdjustCfg ignoreSysPanelAdjustCfg; + auto ret = ignoreSysPanelAdjustCfg.Unmarshall(content); + ignoreSysPanelAdjust = ignoreSysPanelAdjustCfg.ignoreSysPanelAdjust; + return ret; +} + std::string SysCfgParser::GetSysCfgContent(const std::string &key) { std::string content; diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 38cad9a00..1e8483afe 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -1195,6 +1195,22 @@ HWTEST_F(InputMethodAbilityTest, testAdjustKeyboard_001, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); } +/** + * @tc.name: testGetInputType_001 + * @tc.desc: get inputType + * @tc.type: FUNC + * @tc.require: + * @tc.author: guojin + */ +HWTEST_F(InputMethodAbilityTest, testGetInputType_001, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbility testGetInputType_001 START"); + imc_->Attach(textListener_); + + InputType inputType = inputMethodAbility_->GetInputType(); + EXPECT_EQ(inputType, InputType::NONE); +} + /** * @tc.name: testOnSecurityChange * @tc.desc: OnSecurityChange diff --git a/test/unittest/cpp_test/src/json_operate_test.cpp b/test/unittest/cpp_test/src/json_operate_test.cpp index f47520e35..c6987d26a 100644 --- a/test/unittest/cpp_test/src/json_operate_test.cpp +++ b/test/unittest/cpp_test/src/json_operate_test.cpp @@ -73,7 +73,7 @@ public: static constexpr const char *SYS_PANEL_ADJUST = "{\"sysPanelAdjust\":" "[{\"style\": [\"fix\",\"default\",\"landscape\"]," "\"top\": 1,\"left\": 2,\"right\": 3,\"bottom\": 4}]}"; - + static constexpr const char *IGNORE_SYS_PANEL_ADJUST = "{\"ignoreSysPanelAdjust\":{\"inputType\": [0, 1, 3]}}"; static void SetUpTestCase() { } static void TearDownTestCase() { } void SetUp() { } @@ -339,6 +339,38 @@ HWTEST_F(JsonOperateTest, testParseSysPanelAdjust001, TestSize.Level1) EXPECT_EQ(panelAdjust[0].bottom, 4); } +/** +@tc.name: testParseIgnoreSysPanelAdjust001 +@tc.desc: parse IgnoreSysPanelAdjust +@tc.type: FUNC +@tc.require: +*/ +HWTEST_F(JsonOperateTest, testParseIgnoreSysPanelAdjust001, TestSize.Level1) +{ + IMSA_HILOGI("JsonOperateTest testParseIgnoreSysPanelAdjust001 START"); + IgnoreSysPanelAdjustCfg ignoreSysPanelAdjustCfg; + auto ret = ignoreSysPanelAdjustCfg.Unmarshall(""); + ASSERT_FALSE(ret); +} + +/** +@tc.name: testParseIgnoreSysPanelAdjust002 +@tc.desc: parse IgnoreSysPanelAdjust +@tc.type: FUNC +@tc.require: +*/ +HWTEST_F(JsonOperateTest, testParseIgnoreSysPanelAdjust002, TestSize.Level1) +{ + IMSA_HILOGI("JsonOperateTest testParseIgnoreSysPanelAdjust002 START"); + IgnoreSysPanelAdjustCfg ignoreSysPanelAdjustCfg; + auto ret = ignoreSysPanelAdjustCfg.Unmarshall(IGNORE_SYS_PANEL_ADJUST); + ASSERT_TRUE(ret); + auto ignoreSysPanelAdjust = ignoreSysPanelAdjustCfg.ignoreSysPanelAdjust; + EXPECT_EQ(ignoreSysPanelAdjust.inputType[0], 0); + EXPECT_EQ(ignoreSysPanelAdjust.inputType[1], 1); + EXPECT_EQ(ignoreSysPanelAdjust.inputType[2], 3); +} + /** * @tc.name: testGetDumpInfo * @tc.desc: parse GetDumpInfo -- Gitee