diff --git a/services/BUILD.gn b/services/BUILD.gn index 7561e62108580c45bb8980f5980322752d824a8d..6679ece9eeb0914487af9f1cf8ebb0af21493f61 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -24,6 +24,7 @@ config("inputmethod_services_native_config") { "${inputmethod_path}/frameworks/native/inputmethod_controller/include", "${inputmethod_path}/interfaces/inner_api/inputmethod_ability/include", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller/include", + "${inputmethod_path}/services/adapter/display_adapter/include", "${inputmethod_path}/services/adapter/focus_monitor/include", "${inputmethod_path}/services/adapter/ime_connection_manager/include", "${inputmethod_path}/services/adapter/keyboard/include", @@ -58,6 +59,7 @@ ohos_shared_library("inputmethod_service") { "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_client_info.cpp", "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_tools.cpp", "${inputmethod_path}/frameworks/native/inputmethod_controller/src/input_method_utils.cpp", + "${inputmethod_path}/services/adapter/display_adapter/src/display_adapter.cpp", "${inputmethod_path}/services/adapter/focus_monitor/src/focus_change_listener.cpp", "${inputmethod_path}/services/adapter/focus_monitor/src/focus_monitor_manager.cpp", "${inputmethod_path}/services/adapter/ime_connection_manager/src/ime_connection.cpp", @@ -171,6 +173,7 @@ ohos_static_library("inputmethod_service_static") { "-Oz", ] sources = [ + "adapter/display_adapter/src/display_adapter.cpp", "adapter/focus_monitor/src/focus_change_listener.cpp", "adapter/focus_monitor/src/focus_monitor_manager.cpp", "adapter/ime_connection_manager/src/ime_connection.cpp", diff --git a/services/adapter/display_adapter/include/display_adapter.h b/services/adapter/display_adapter/include/display_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..f9eac38f94fd3c4f8eae9f3dda88d3dce926a136 --- /dev/null +++ b/services/adapter/display_adapter/include/display_adapter.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 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 INPUTMETHOD_IMF_DISPLAY_ADAPTER_H +#define INPUTMETHOD_IMF_DISPLAY_ADAPTER_H + +#include +#include + +namespace OHOS { +namespace MiscServices { +class DisplayAdapter final { +public: + static std::string GetDisplayName(uint64_t displayId); + static uint64_t GetDefaultDisplayId(); +}; +} // namespace MiscServices +} // namespace OHOS + +#endif //INPUTMETHOD_IMF_DISPLAY_ADAPTER_H \ No newline at end of file diff --git a/services/adapter/display_adapter/src/display_adapter.cpp b/services/adapter/display_adapter/src/display_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9634b7b74077a7e25b8a3c3e4a5e21c9d9de17f3 --- /dev/null +++ b/services/adapter/display_adapter/src/display_adapter.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2025 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 "display_adapter.h" + +#include + +#include "display_info.h" +#include "display_manager_lite.h" +#include "global.h" + +namespace OHOS { +namespace MiscServices { +using namespace OHOS::Rosen; +std::string DisplayAdapter::GetDisplayName(uint64_t displayId) +{ + sptr display = DisplayManagerLite::GetInstance().GetDisplayById(displayId); + if (display == nullptr) { + IMSA_HILOGE("display is null!"); + return ""; + } + sptr displayInfo = display->GetDisplayInfo(); + if (displayInfo == nullptr) { + IMSA_HILOGE("displayInfo is null!"); + return ""; + } + return displayInfo->GetName(); +} + +uint64_t DisplayAdapter::GetDefaultDisplayId() +{ + return DisplayManagerLite::GetInstance().GetDefaultDisplayId(); +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/services/include/ime_info_inquirer.h b/services/include/ime_info_inquirer.h index 54d7ae8be21645f420ffa546e0d54b81cab3080d..d99de2814052828a77871cadf56f217fbb9019d0 100644 --- a/services/include/ime_info_inquirer.h +++ b/services/include/ime_info_inquirer.h @@ -105,6 +105,7 @@ public: bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName); bool IsInputMethodExtension(pid_t pid); bool IsRestrictedDefaultImeByDisplay(uint64_t displayId); + bool IsRestrictedMainDisplayId(uint64_t displayId); bool IsDynamicStartIme(); std::unordered_set GetDisableNumKeyAppDeviceTypes(); bool IsCapacitySupport(const std::string &capacityName); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 8d749c9d157960f313eecbef24b7cb7117eff4a2..75aa943f1f84713778475dfd969941b3689e89c6 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -161,7 +161,7 @@ public: bool IsSaReady(int32_t saId); void TryUnloadSystemAbility(); void OnCallingDisplayIdChanged(const int32_t windowId, const int32_t callingPid, const uint64_t displayId); - ImfCallingWindowInfo GetCallingWindowInfo(const InputClientInfo &clientInfo); + ImfCallingWindowInfo GetFinalCallingWindowInfo(const InputClientInfo &clientInfo); bool SpecialScenarioCheck(); bool IsScreenLockOrSecurityFlag(); int32_t SpecialSendPrivateData(const std::unordered_map &privateCommand); @@ -273,6 +273,7 @@ private: bool GetInputTypeToStart(std::shared_ptr &imeToStart); void HandleBindImeChanged(InputClientInfo &newClientInfo, const std::shared_ptr &clientGroup); int32_t NotifyCallingDisplayChanged(uint64_t displayId); + ImfCallingWindowInfo GetCallingWindowInfo(const InputClientInfo &clientInfo); bool GetCallingWindowInfo(const InputClientInfo &clientInfo, Rosen::CallingWindowInfo &callingWindowInfo); int32_t SendPrivateData(const std::unordered_map &privateCommand); void ClearRequestKeyboardReason(std::shared_ptr &clientInfo); diff --git a/services/include/sys_cfg_parser.h b/services/include/sys_cfg_parser.h index 664f7c1d3fdda77042138e44179a86c6211c668a..4c24401d87e66d92dcd92dcff874e77b8f54986e 100644 --- a/services/include/sys_cfg_parser.h +++ b/services/include/sys_cfg_parser.h @@ -34,6 +34,7 @@ struct SystemConfig : public Serializable { std::unordered_set proxyImeUidList; std::unordered_set specialSaUidList; std::unordered_set defaultImeScreenList; + std::unordered_set defaultMainDisplayScreenList; std::unordered_set supportedCapacityList; std::string dynamicStartImeSysParam; std::string dynamicStartImeValue; @@ -53,6 +54,7 @@ struct SystemConfig : public Serializable { GetValue(node, GET_NAME(proxyImeUidList), proxyImeUidList); GetValue(node, GET_NAME(specialSaUidList), specialSaUidList); GetValue(node, GET_NAME(defaultImeScreenList), defaultImeScreenList); + GetValue(node, GET_NAME(defaultMainDisplayScreenList), defaultMainDisplayScreenList); GetValue(node, GET_NAME(supportedCapacityList), supportedCapacityList); GetValue(node, GET_NAME(dynamicStartImeSysParam), dynamicStartImeSysParam); GetValue(node, GET_NAME(dynamicStartImeValue), dynamicStartImeValue); diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index 73d83a1e7f76dd1fa4f99d699f7f70d14ba0638a..5c06d246e242525bf8ce8a3633ec16934640934c 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -27,8 +27,7 @@ #include "parameters.h" #include "singleton.h" #include "system_ability_definition.h" -#include "display_manager_lite.h" -#include "display_info.h" +#include "display_adapter.h" namespace OHOS { namespace MiscServices { @@ -1227,20 +1226,17 @@ bool ImeInfoInquirer::IsInputMethodExtension(pid_t pid) bool ImeInfoInquirer::IsRestrictedDefaultImeByDisplay(uint64_t displayId) { - sptr display = Rosen::DisplayManagerLite::GetInstance().GetDisplayById(displayId); - if (display == nullptr) { - IMSA_HILOGE("display is null!"); - return false; - } - sptr displayInfo = display->GetDisplayInfo(); - if (displayInfo == nullptr) { - IMSA_HILOGE("displayInfo is null!"); - return false; - } - auto screenName = displayInfo->GetName(); + auto screenName = DisplayAdapter::GetDisplayName(displayId); return systemConfig_.defaultImeScreenList.find(screenName) != systemConfig_.defaultImeScreenList.end(); } +bool ImeInfoInquirer::IsRestrictedMainDisplayId(uint64_t displayId) +{ + auto screenName = DisplayAdapter::GetDisplayName(displayId); + return systemConfig_.defaultMainDisplayScreenList.find(screenName) != + systemConfig_.defaultMainDisplayScreenList.end(); +} + bool ImeInfoInquirer::IsDynamicStartIme() { if (systemConfig_.dynamicStartImeSysParam.empty()) { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index af92b18f940c25e6310a9d56d3f09b5c99886406..a738fe4965268d4a1dbfd7b9c9c3746beaaabfbc 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -594,7 +594,7 @@ int32_t InputMethodSystemAbility::GenerateClientInfo(int32_t userId, InputClient clientInfo.name = ImfHiSysEventUtil::GetAppName(tokenId); auto session = UserSessionManager::GetInstance().GetUserSession(userId); if (session != nullptr) { - auto callingWindowInfo = session->GetCallingWindowInfo(clientInfo); + auto callingWindowInfo = session->GetFinalCallingWindowInfo(clientInfo); clientInfo.config.inputAttribute.windowId = callingWindowInfo.windowId; clientInfo.config.inputAttribute.callingDisplayId = callingWindowInfo.displayId; clientInfo.config.inputAttribute.needAutoInputNumkey = diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index ab28232a5195fc1e2dd4d4c6b3ba517028efcf4c..ac6bdd1623c7e96da3f6f1e87e76027d42be43a1 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -48,6 +48,7 @@ #include "ime_state_manager_factory.h" #include "inputmethod_trace.h" #include "notify_service_impl.h" +#include "display_adapter.h" namespace OHOS { namespace MiscServices { @@ -1534,7 +1535,7 @@ int32_t PerUserSession::OnSetCallingWindow(uint32_t callingWindowId, clientGroup->NotifyInputStartToClients(callingWindowId, static_cast(clientInfo->requestKeyboardReason)); if (callingWindowId != INVALID_WINDOW_ID) { - auto callingWindowInfo = GetCallingWindowInfo(*clientInfo); + auto callingWindowInfo = GetFinalCallingWindowInfo(*clientInfo); clientInfo->config.inputAttribute.windowId = callingWindowInfo.windowId; bool isNotifyDisplayChanged = clientInfo->config.inputAttribute.callingDisplayId != callingWindowInfo.displayId && @@ -2501,6 +2502,17 @@ int32_t PerUserSession::NotifyCallingDisplayChanged(uint64_t displayId) return ret; } +ImfCallingWindowInfo PerUserSession::GetFinalCallingWindowInfo(const InputClientInfo &clientInfo) +{ + auto windowInfo = GetCallingWindowInfo(clientInfo); + if (SceneBoardJudgement::IsSceneBoardEnabled() && + ImeInfoInquirer::GetInstance().IsRestrictedMainDisplayId(windowInfo.displayId)) { + IMSA_HILOGI("get default displayId"); + windowInfo.displayId = DisplayAdapter::GetDefaultDisplayId(); + } + return windowInfo; +} + ImfCallingWindowInfo PerUserSession::GetCallingWindowInfo(const InputClientInfo &clientInfo) { InputMethodSyncTrace tracer("GetCallingWindowInfo trace"); diff --git a/test/unittest/cpp_test/src/input_method_private_member_test.cpp b/test/unittest/cpp_test/src/input_method_private_member_test.cpp index b22bb83fa9afaba1318c677d24ded26470f3a2ae..4826653ddb268d9f41f2063eadd7912076e0f467 100644 --- a/test/unittest/cpp_test/src/input_method_private_member_test.cpp +++ b/test/unittest/cpp_test/src/input_method_private_member_test.cpp @@ -53,6 +53,8 @@ #include "keyboard_event.h" #include "os_account_manager.h" #include "tdd_util.h" +#include "window_adapter.h" +#include "display_adapter.h" using namespace testing::ext; using namespace testing::mt; @@ -2946,5 +2948,27 @@ HWTEST_F(InputMethodPrivateMemberTest, IMSA_IsTmpIme, TestSize.Level0) ret = systemAbility.IsTmpImeSwitchSubtype(MAIN_USER_ID, tokenId, switchInfo); EXPECT_TRUE(ret); } + +/** + * @tc.name: PerUserSession_GetFinalCallingWindowInfo + * @tc.desc: PerUserSession_GetFinalCallingWindowInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InputMethodPrivateMemberTest, PerUserSession_GetFinalCallingWindowInfo, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPrivateMemberTest::PerUserSession_GetFinalCallingWindowInfo start."); + auto userSession = std::make_shared(MAIN_USER_ID); + Rosen::CallingWindowInfo callingWindowInfo; + Rosen::FocusChangeInfo focusInfo; + WindowAdapter::GetFocusInfo(focusInfo); + WindowAdapter::GetCallingWindowInfo(focusInfo.windowId_, userSession->userId_, callingWindowInfo); + auto screenName = DisplayAdapter::GetDisplayName(callingWindowInfo.displayId_); + ImeInfoInquirer::GetInstance().systemConfig_.defaultMainDisplayScreenList.insert(screenName); + InputClientInfo clientInfo; + clientInfo.config.windowId = focusInfo.windowId_; + ImfCallingWindowInfo windowInfo = userSession->GetFinalCallingWindowInfo(clientInfo); + EXPECT_TRUE(windowInfo.displayId == DisplayAdapter::GetDefaultDisplayId()); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file