diff --git a/common/include/global.h b/common/include/global.h index aa4e5603e184c0db3229180dae38ef18b28c61ee..8569df164f9a310a2701b5717db8fc15bf83969a 100644 --- a/common/include/global.h +++ b/common/include/global.h @@ -113,6 +113,8 @@ enum { ERROR_INVALID_PRIVATE_COMMAND = 43, ERROR_OS_ACCOUNT = 44, ERROR_RES_ERROR = 46, + ERROR_SCENE_UNSUPPORTED, + ERROR_PRIVATE_COMMAND_IS_EMPTY, }; }; // namespace ErrorCode diff --git a/frameworks/native/inputmethod_ability/include/i_input_method_core.h b/frameworks/native/inputmethod_ability/include/i_input_method_core.h index fb035c53f44208370750219121696d928676f682..55a0d35b2044ebd54461f157018236fdf062d6f7 100644 --- a/frameworks/native/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/native/inputmethod_ability/include/i_input_method_core.h @@ -47,6 +47,7 @@ public: SECURITY_CHANGE, ON_CLIENT_INACTIVE, ON_CONNECT_SYSTEM_CMD, + ON_SEND_PRIVATE_DATA, CORE_CMD_END, }; @@ -64,6 +65,7 @@ public: virtual int32_t OnSecurityChange(int32_t security) = 0 ; virtual int32_t OnConnectSystemCmd(const sptr &channel, sptr &agent) = 0 ; virtual void OnClientInactive(const sptr &channel) = 0; + virtual int32_t OnSendPrivateData(const std::unordered_map &privateCommand) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index a3ee949c87f31cfe24681f6b59429f753ad2d339..525a0adecb698ebe8707f08a2fe7bfbaa6e8f412 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -100,6 +100,7 @@ public: SysPanelStatus &sysPanelStatus); InputAttribute GetInputAttribute(); int32_t OnStopInputService(bool isTerminateIme); + int32_t OnSendPrivateData(const std::unordered_map &privateCommand); private: std::thread workThreadHandler; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h index 1388fa968985ef24e72ee04e21b777570ba905b6..c96c8991e8217f84250cfab5f8283dfd06b8cbc5 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h @@ -45,7 +45,8 @@ public: int32_t OnSecurityChange(int32_t security) override; int32_t OnConnectSystemCmd(const sptr &channel, sptr &agent) override; void OnClientInactive(const sptr &channel) override; - + int32_t OnSendPrivateData(const std::unordered_map &privateCommand) override; + private: static inline BrokerDelegator delegator_; using ParcelHandler = std::function; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h index aaa8e78581d0323208a5f4e4e31d33f38d3a6f90..bb3abd8ee5e8f614ad2995caedaaee3e9636bb12 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h @@ -48,6 +48,7 @@ public: int32_t OnConnectSystemCmd(const sptr &channel, sptr &agent) override; void OnClientInactive(const sptr &channel) override; void SetMessageHandler(MessageHandler *msgHandler); + int32_t OnSendPrivateData(const std::unordered_map &privateCommand) override; private: MessageHandler *msgHandler_; @@ -63,6 +64,7 @@ private: int32_t SecurityChangeOnRemote(MessageParcel &data, MessageParcel &reply); int32_t OnClientInactiveOnRemote(MessageParcel &data, MessageParcel &reply); int32_t OnConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t OnSendPrivateDataOnRemote(MessageParcel &data, MessageParcel &reply); using ParcelHandler = std::function; int32_t SendMessage(int code, ParcelHandler input = nullptr); using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &); @@ -79,6 +81,7 @@ private: [SECURITY_CHANGE] = &InputMethodCoreStub::SecurityChangeOnRemote, [ON_CLIENT_INACTIVE] = &InputMethodCoreStub::OnClientInactiveOnRemote, [ON_CONNECT_SYSTEM_CMD] = &InputMethodCoreStub::OnConnectSystemCmdOnRemote, + [ON_SEND_PRIVATE_DATA] = &InputMethodCoreStub::OnSendPrivateDataOnRemote, }; }; } // namespace MiscServices diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 5abb3174495e93655dbe4e2229862b488e4a1ce4..6a45f84c4df404ceae854d649a305e43fff6aefd 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -1332,5 +1332,15 @@ void InputMethodAbility::NotifyPanelStatusInfo( controlChannel->HideKeyboardSelf(); } } + +int32_t InputMethodAbility::OnSendPrivateData(const std::unordered_map &privateCommand) +{ + auto ret = ReceivePrivateCommand(privateCommand); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("OnSendPrivateData failed!"); + } + IMSA_HILOGE("InputMethodAbility ReceivePrivateCommand success."); + return ret; +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp index c335b20f343c9a2f62f8923e69db0f56b8de41d3..6146772c132b85739a3ed409eba12def2afb7026 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp @@ -142,5 +142,14 @@ int32_t InputMethodCoreProxy::SendRequest(int code, ParcelHandler input, ParcelH } return ret; } + +int32_t InputMethodCoreProxy::OnSendPrivateData(const std::unordered_map &privateCommand) +{ + return SendRequest( + ON_SEND_PRIVATE_DATA, + [&privateCommand](MessageParcel &parcel) { + return ITypesUtil::Marshal(parcel, privateCommand); + }, nullptr); +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp index 6e5fc7661af096622ccc5fbcad1b6088599aac73..a34e91e6b1d2d5f2ac2ad3d4791c8c8659f46009 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp @@ -277,5 +277,21 @@ int32_t InputMethodCoreStub::SendMessage(int code, ParcelHandler input) msgHandler_->SendMessage(msg); return ErrorCode::NO_ERROR; } + +int32_t InputMethodCoreStub::OnSendPrivateData(const std::unordered_map &privateCommand) +{ + return InputMethodAbility::GetInstance()->OnSendPrivateData(privateCommand); +} + +int32_t InputMethodCoreStub::OnSendPrivateDataOnRemote(MessageParcel &data, MessageParcel &reply) +{ + std::unordered_map privateCommand; + if (!ITypesUtil::Unmarshal(data, privateCommand)) { + IMSA_HILOGE("failed to read message parcel!"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + auto ret = OnSendPrivateData(privateCommand); + return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h index aa76b2683a1645b587600f13d2c2da21254b7135..007c5c9ad7cc56ed19420ee85bc56f8220446e4f 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -79,6 +79,7 @@ public: // Deprecated because of no permission check, kept for compatibility int32_t HideCurrentInputDeprecated() override; int32_t ShowCurrentInputDeprecated() override; + int32_t SendPrivateData(const std::unordered_map &privateCommand) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 0551cb84dff4e1443dffe320f1f1a7e1096aa7cd..8390d5bb3bf7641914a5f5ed53dc93b8809d3fb8 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1396,5 +1396,14 @@ int32_t InputMethodController::FinishTextPreview() } return ErrorCode::NO_ERROR; } + +int32_t InputMethodController::SendPrivateData(const std::unordered_map &privateCommand) +{ + auto proxy = GetSystemAbilityProxy(); + if (proxy == nullptr) { + IMSA_HILOGE("proxy is nullptr!"); + return ErrorCode::ERROR_NULL_POINTER; + } + return proxy->SendPrivateData(privateCommand); } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp index d4ca3d9aecc7d6167f09456018d09675d1be00ae..14f892d4519c96a63983cea3855ccb72b86525b3 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -333,5 +333,14 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input } return ErrorCode::NO_ERROR; } + +int32_t InputMethodSystemAbilityProxy::SendPrivateData( + const std::unordered_map &privateCommand) +{ + return SendRequest(static_cast(InputMethodInterfaceCode::SEND_PRIVATE_DATA), + [&privateCommand](MessageParcel &parcel) { + return ITypesUtil::Marshal(parcel, privateCommand); + }, nullptr); +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index c4690e3eae01f926e4a09b81d2bf3073d7ae1def..5093bf8c24672c4746cd20d83da6f4e1f85c2b7c 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -802,6 +802,17 @@ public: */ IMF_API void Reset(); + /** + * @brief Send Private Data. + * + * This function only available special service apply. + * + * @param privateCommand Indicates the private data information. + * @return Returns 0 for success, others for failure. + * @since 18 + */ + IMF_API int32_t SendPrivateData(const std::unordered_map &privateCommand); + private: InputMethodController(); ~InputMethodController(); diff --git a/services/identity_checker/include/identity_checker.h b/services/identity_checker/include/identity_checker.h index c26b07bab6f34a30b4aeb757541bf49b82f3bf8f..0dacc2fef97bcd6dfacbfc9133dc5612e94bf6b4 100644 --- a/services/identity_checker/include/identity_checker.h +++ b/services/identity_checker/include/identity_checker.h @@ -36,6 +36,7 @@ public: { return false; }; + virtual bool IsSpecialSaUid() = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/identity_checker/include/identity_checker_impl.h b/services/identity_checker/include/identity_checker_impl.h index be998fae04fe802d0205c710382edb88204f715b..35c4fd332b7eb8958c3bcd2f9c226aa75619ef8a 100644 --- a/services/identity_checker/include/identity_checker_impl.h +++ b/services/identity_checker/include/identity_checker_impl.h @@ -30,6 +30,7 @@ public: bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override; std::string GetBundleNameByToken(uint32_t tokenId) override; bool IsFocusedUIExtension(uint32_t callingTokenId) override; + bool IsSpecialSaUid() override; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/identity_checker/src/identity_checker_impl.cpp b/services/identity_checker/src/identity_checker_impl.cpp index 0ef2cd6f4242530f711b19f3078f328addf36859..ac87943e3610b1a09e7497e752e38ffb49289a75 100644 --- a/services/identity_checker/src/identity_checker_impl.cpp +++ b/services/identity_checker/src/identity_checker_impl.cpp @@ -20,6 +20,7 @@ #include "accesstoken_kit.h" #include "global.h" #include "tokenid_kit.h" +#include "ipc_skeleton.h" #ifdef SCENE_BOARD_ENABLE #include "window_manager_lite.h" #else @@ -115,5 +116,11 @@ std::string IdentityCheckerImpl::GetBundleNameByToken(uint32_t tokenId) } return info.bundleName; } + +bool IdentityCheckerImpl::IsSpecialSaUid() +{ + auto callingUid = IPCSkeleton::GetCallingUid(); + return ImeInfoInquirer::GetInstance().IsSpecialSaUid(callingUid); +} } // namespace MiscServices } // namespace OHOS diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index 86c5c5158422e77c9992d89eaa50a5bce6aa8818..569a6093602a768e0dfe9ce76f86c02866d0b971 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -36,6 +36,7 @@ #include "message_parcel.h" #include "panel_info.h" #include "input_method_types.h" +#include "input_method_utils.h" namespace OHOS { namespace MiscServices { @@ -80,6 +81,7 @@ public: // Deprecated because of no permission check, and keep for compatibility virtual int32_t HideCurrentInputDeprecated() = 0; virtual int32_t ShowCurrentInputDeprecated() = 0; + virtual int32_t SendPrivateData(const std::unordered_map &privateCommand) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/include/ime_cfg_manager.h b/services/include/ime_cfg_manager.h index 32176f2dc4eda03e64a37108b3bb7e3c33398401..49b61638661748258c44b893d0b165527dc620ea 100644 --- a/services/include/ime_cfg_manager.h +++ b/services/include/ime_cfg_manager.h @@ -22,6 +22,7 @@ #include #include "serializable.h" +#include "input_method_utils.h" namespace OHOS { namespace MiscServices { struct ImePersistInfo : public Serializable { @@ -61,11 +62,16 @@ struct ImePersistCfg : public Serializable { } }; +struct ImeExtendInfo { + std::unordered_map privateCommand; +}; + struct ImeNativeCfg { std::string imeId; std::string bundleName; std::string subName; std::string extName; + ImeExtendInfo imeExtendInfo; }; class ImeCfgManager { diff --git a/services/include/ime_info_inquirer.h b/services/include/ime_info_inquirer.h index 78bad24a76a2d112d90e686177287f9cba7fd121..6e81fd2daf7e60466c6fb35fc1295b73b193f09a 100644 --- a/services/include/ime_info_inquirer.h +++ b/services/include/ime_info_inquirer.h @@ -105,6 +105,7 @@ public: bool IsRunningIme(int32_t userId, const std::string &bundleName); std::vector GetRunningIme(int32_t userId); bool IsImeInstalled(const int32_t userId, const std::string &bundleName, const std::string &extName); + bool IsSpecialSaUid(int32_t callingUid); private: ImeInfoInquirer() = default; diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index b68460c7898da333798fd23b2babe7ee5995f35d..58816fffbd1b92fc36992d124f79e4eecdc65a33 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -39,6 +39,7 @@ #include "system_ability.h" #include "input_method_types.h" + namespace OHOS { namespace MiscServices { enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; @@ -90,6 +91,7 @@ public: int Dump(int fd, const std::vector &args) override; void DumpAllMethod(int fd); int32_t IsDefaultIme() override; + int32_t SendPrivateData(const std::unordered_map &privateCommand) override; protected: void OnStart() override; diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index 2ed222cde61cc779a0f85ed8b53819278aca1c5e..5da2b8870a889d9c1fe8a79e62c915606ae31e49 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -105,6 +105,8 @@ private: int32_t InitConnectOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t SendPrivateDataOnRemote(MessageParcel &data, MessageParcel &reply); + using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &); static inline constexpr RequestHandler HANDLERS[static_cast(InputMethodInterfaceCode::IMS_CMD_END)] = { &InputMethodSystemAbilityStub::InvalidRequest, @@ -176,6 +178,8 @@ private: &InputMethodSystemAbilityStub::IsCurrentImeByPidOnRemote, [static_cast(InputMethodInterfaceCode::INIT_CONNECT)] = &InputMethodSystemAbilityStub::InitConnectOnRemote, + [static_cast(InputMethodInterfaceCode::SEND_PRIVATE_DATA)] = + &InputMethodSystemAbilityStub::SendPrivateDataOnRemote, }; }; } // namespace OHOS::MiscServices diff --git a/services/include/inputmethod_service_ipc_interface_code.h b/services/include/inputmethod_service_ipc_interface_code.h index 959b6ed77f76279e51727afcdba1da0e952df0fa..f722e1be03e019189b23466352f4e23b5b9e2dab 100644 --- a/services/include/inputmethod_service_ipc_interface_code.h +++ b/services/include/inputmethod_service_ipc_interface_code.h @@ -55,6 +55,7 @@ enum class InputMethodInterfaceCode { CONNECT_SYSTEM_CMD, IS_CURRENT_IME_BY_PID, INIT_CONNECT, + SEND_PRIVATE_DATA, IMS_CMD_END, }; } // namespace MiscServices diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 1790fa507e584f9bdecf6a30357d588d3ba64df3..dd68c42af3e4374db7d15f667b06473049f4cefc 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -87,6 +87,7 @@ struct ImeData { freezeMgr(std::make_shared(imePid)) { } + ImeExtendInfo imeExtendInfo; }; /**@class PerUserSession * @@ -146,6 +147,8 @@ public: int32_t RestoreCurrentIme(); std::shared_ptr GetImeNativeCfg(int32_t userId, const std::string &bundleName, const std::string &subName); + bool SpecialScenarioCheck(); + int32_t SpecialSendPrivateData(const std::unordered_map &privateCommand); private: struct ResetManager { @@ -242,6 +245,9 @@ private: bool HandleFirstStart(const std::shared_ptr &ime, bool isStopCurrentIme); bool HandleStartImeTimeout(const std::shared_ptr &ime); bool CheckInputTypeToStart(std::shared_ptr &imeToStart); + int32_t InitImeData(const std::pair &ime, + const std::shared_ptr &imeNativeCfg = nullptr); + int32_t SendPrivateData(const std::unordered_map &privateCommand); std::mutex imeStartLock_; BlockData isImeStarted_{ MAX_IME_START_TIME, false }; diff --git a/services/include/sys_cfg_parser.h b/services/include/sys_cfg_parser.h index c7b5c51fc79fb24ab4624332762a148de3ce4eb2..d538b50307db1f3e14421bb08b1c39bb308bdc87 100644 --- a/services/include/sys_cfg_parser.h +++ b/services/include/sys_cfg_parser.h @@ -30,12 +30,14 @@ struct SystemConfig : public Serializable { std::string defaultInputMethod; bool enableInputMethodFeature = false; bool enableFullExperienceFeature = false; + std::unordered_set specialSaUidList; bool Unmarshal(cJSON *node) override { GetValue(node, GET_NAME(systemInputMethodConfigAbility), systemInputMethodConfigAbility); GetValue(node, GET_NAME(defaultInputMethod), defaultInputMethod); GetValue(node, GET_NAME(enableInputMethodFeature), enableInputMethodFeature); GetValue(node, GET_NAME(enableFullExperienceFeature), enableFullExperienceFeature); + GetValue(node, GET_NAME(specialSaUidList), specialSaUidList); return true; } }; diff --git a/services/src/ime_info_inquirer.cpp b/services/src/ime_info_inquirer.cpp index d4c8e5ce3a9ceddbd3ba5294953f29c89485f39e..74e70da8e2d90c1baa310a0376c69125fcd0783f 100644 --- a/services/src/ime_info_inquirer.cpp +++ b/services/src/ime_info_inquirer.cpp @@ -91,6 +91,11 @@ bool ImeInfoInquirer::QueryImeExtInfos(const int32_t userId, std::vector &extInfos) { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 8e36cd4c0f518fdbedd149a7237db0214216c416..0661272ccf0ef5a19d389367662b69816a4814af 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -1816,5 +1816,32 @@ void InputMethodSystemAbility::NeedHideWhenSwitchInputType(int32_t userId, bool } needHide = currentImeCfg->bundleName == ime.bundleName; } + +int32_t InputMethodSystemAbility::SendPrivateData( + const std::unordered_map &privateCommand) +{ + if (privateCommand.empty()) { + IMSA_HILOGE("privateCommand is empty!"); + return ErrorCode::ERROR_PRIVATE_COMMAND_IS_EMPTY; + } + if (!identityChecker_->IsSpecialSaUid()) { + IMSA_HILOGE("uid failed, not permission!"); + return ErrorCode::ERROR_STATUS_PERMISSION_DENIED; + } + auto session = UserSessionManager::GetInstance().GetUserSession(userId_); + if (session == nullptr) { + IMSA_HILOGE("UserId: %{public}d session is nullptr!", userId_); + return ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND; + } + if (!session->SpecialScenarioCheck()) { + IMSA_HILOGE("Special check permission failed!"); + return ErrorCode::ERROR_SCENE_UNSUPPORTED; + } + auto ret = session->SpecialSendPrivateData(privateCommand); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Special send private data failed, ret: %{public}d!", ret); + } + return ret; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index dd4e78dd83e33d326e09db13dd250a48fe624972..3d41ac2224374e0a3c3bc71b2e51b34be07462b8 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -412,5 +412,15 @@ int32_t InputMethodSystemAbilityStub::InitConnectOnRemote(MessageParcel &data, M { return reply.WriteInt32(InitConnect()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } + +int32_t InputMethodSystemAbilityStub::SendPrivateDataOnRemote(MessageParcel &data, MessageParcel &reply) +{ + std::unordered_map privateCommand; + if (!ITypesUtil::Unmarshal(data, privateCommand)) { + IMSA_HILOGE("failed to read message parcel!"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + return reply.WriteInt32(SendPrivateData(privateCommand)) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index a32647a306fd65e3bd226c183b5a6ec7c49ce1b2..3027b4e0413cef663e65fe060026fe2313311e4a 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1748,5 +1748,77 @@ bool PerUserSession::CheckInputTypeToStart(std::shared_ptr &imeToS imeToStart = GetImeNativeCfg(userId_, currentInputTypeIme.bundleName, currentInputTypeIme.subName); return true; } + +bool PerUserSession::SpecialScenarioCheck() +{ + auto clientInfo = GetCurrentClientInfo(); + if (clientInfo == nullptr) { + IMSA_HILOGE("send failed, not input Status!"); + return false; + } + if (clientInfo->config.inputAttribute.GetSecurityFlag()) { + IMSA_HILOGE("send failed, is special input box!"); + return false; + } + if (clientInfo->bindImeType == ImeType::PROXY_IME) { + IMSA_HILOGE("send failed, is collaborative input!"); + return false; + } + if (ScreenLock::ScreenLockManager::GetInstance()->IsScreenLocked()) { + IMSA_HILOGE("send failed, is screen locked"); + return false; + } + return true; +} + +int32_t PerUserSession::SpecialSendPrivateData(const std::unordered_map &privateCommand) +{ + auto defaultIme = ImeInfoInquirer::GetInstance().GetDefaultImeCfg(); + if (defaultIme == nullptr) { + IMSA_HILOGE("failed to get default ime!"); + return ErrorCode::ERROR_IMSA_DEFAULT_IME_NOT_FOUND; + } + auto imeData = GetReadyImeData(ImeType::IME); + if (imeData == nullptr) { + auto ret = StartIme(defaultIme, true); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("notify start ime failed, ret: %{public}d!", ret); + } + return ErrorCode::ERROR_IMSA_DEFAULT_IME_NOT_FOUND; + } + if (defaultIme->bundleName == imeData->ime.first) { + auto ret = SendPrivateData(privateCommand); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Notify send private data failed, ret: %{public}d!", ret); + } + return ret; + } + defaultIme->imeExtendInfo.privateCommand = privateCommand; + auto ret = StartIme(defaultIme); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("notify start ime failed, ret: %{public}d!", ret); + } + return ret; +} + +int32_t PerUserSession::SendPrivateData(const std::unordered_map &privateCommand) +{ + auto data = GetReadyImeData(ImeType::IME); + if (data == nullptr) { + IMSA_HILOGE("data is nullptr"); + return ErrorCode::ERROR_IME_NOT_STARTED; + } + auto ret = RequestIme(data, RequestType::NORMAL, + [&data, &privateCommand] { return data->core->OnSendPrivateData(privateCommand); }); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("notify send private data failed, ret: %{public}d!", ret); + } + if (!data->imeExtendInfo.privateCommand.empty()) { + data->imeExtendInfo.privateCommand.clear(); + } + IMSA_HILOGI("notify send private data success."); + return ret; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file