From 9a5a26b17ca3918fc8a0cf00c37b8b764c016b0d Mon Sep 17 00:00:00 2001 From: houjiahui1 Date: Wed, 14 May 2025 21:48:25 +0800 Subject: [PATCH] Input method process exits in a scenario with large memory. Signed-off-by: houjiahui1 --- .../IInputMethodSystemAbility.idl | 1 + .../src/input_method_controller.cpp | 11 +++++++++++ .../include/input_method_controller.h | 2 ++ services/include/input_method_system_ability.h | 1 + services/include/peruser_session.h | 6 ++++++ services/src/input_method_system_ability.cpp | 12 ++++++++++++ services/src/peruser_session.cpp | 18 ++++++++++++++++++ 7 files changed, 51 insertions(+) diff --git a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl index e24a1faf0..cbf590478 100644 --- a/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl +++ b/frameworks/native/inputmethod_controller/IInputMethodSystemAbility.idl @@ -60,6 +60,7 @@ interface OHOS.MiscServices.IInputMethodSystemAbility { void EnableIme([in] String bundleName, [out] boolean resultValue); void ConnectSystemCmd([in] IRemoteObject channel, [out] IRemoteObject agent); void GetInputMethodState([out] int state); + void UpdateBigMemoryState([in] int memoryState); void IsSystemApp([out] boolean resultValue); void HideCurrentInputDeprecated(); void ShowCurrentInputDeprecated(); diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index c9009bee9..0f1ece802 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1626,6 +1626,17 @@ int32_t InputMethodController::GetInputMethodState(EnabledStatus &state) return ret; } +int32_t InputMethodController::UpdateBigMemoryState(const int32_t memoryState) +{ + IMSA_HILOGD("called."); + auto proxy = GetSystemAbilityProxy(); + if (proxy == nullptr) { + IMSA_HILOGE("proxy is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; + } + return proxy->UpdateBigMemoryState(memoryState); +} + int32_t InputMethodController::SetPreviewText(const std::string &text, const Range &range) { auto ret = SetPreviewTextInner(text, range); 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 b14b45adb..7fccd3d8a 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -907,6 +907,8 @@ public: IMF_API void ReportBaseTextOperation(int32_t eventCode, int32_t errCode); + IMF_API int32_t UpdateBigMemoryState(const int32_t memoryState); + IMF_API void UpdateTextPreviewState(bool isSupport); /** diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 3ccc7346f..ebc13e187 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -88,6 +88,7 @@ public: ErrCode EnableIme(const std::string &bundleName, bool& resultValue) override; ErrCode GetInputMethodState(int32_t &status) override; ErrCode IsSystemApp(bool& resultValue) override; + ErrCode UpdateBigMemoryState(const int32_t memoryState) override; int32_t RegisterProxyIme( uint64_t displayId, const sptr &core, const sptr &agent) override; int32_t UnregisterProxyIme(uint64_t displayId) override; diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index c7de5b2fd..964e24e36 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -55,6 +55,10 @@ enum class ImeAction : uint32_t { DO_ACTION_IN_NULL_IME_DATA, DO_ACTION_IN_IME_EVENT_CONVERT_FAILED, }; +enum BigMemoryState : int32_t { + BIG_MEMORY_START = 2, + BIG_MEMORY_END = 3, +}; struct ImeData { static constexpr int64_t START_TIME_OUT = 8000; sptr core{ nullptr }; @@ -149,6 +153,7 @@ public: int32_t SpecialSendPrivateData(const std::unordered_map &privateCommand); uint64_t GetDisplayGroupId(uint64_t displayId); bool IsDefaultDisplayGroup(uint64_t displayId); + int32_t UpdateBigMemoryState(const int32_t memoryState); private: struct ResetManager { @@ -277,6 +282,7 @@ private: std::atomic agentDisplayId_{ DEFAULT_DISPLAY_ID }; std::mutex clientGroupLock_{}; std::unordered_map> clientGroupMap_; + std::atomic memoryState_ = BigMemoryState::BIG_MEMORY_END; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index a16e64851..171a7beb9 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -2453,6 +2453,18 @@ ErrCode InputMethodSystemAbility::GetInputMethodState(int32_t& status) return ErrorCode::NO_ERROR; } +int32_t InputMethodSystemAbility::UpdateBigMemoryState(const int32_t memoryState) +{ + IMSA_HILOGD("UpdateBigMemory start."); + auto userId = GetCallingUserId(); + auto session = UserSessionManager::GetInstance().GetUserSession(userId_); + if (session == nullptr) { + IMSA_HILOGE("%{public}d session is nullptr.", userId); + return ErrorCode::ERROR_NULL_POINTER; + } + return session->UpdateBigMemoryState(memoryState); +} + int32_t InputMethodSystemAbility::GetInputMethodState( int32_t userId, const std::string &bundleName, EnabledStatus &status) { diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 9fe291ebc..50223e970 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -766,6 +766,20 @@ int32_t PerUserSession::OnUnregisterProxyIme(uint64_t displayId) return ErrorCode::NO_ERROR; } +int32_t PerUserSession::UpdateBigMemoryState(const int32_t memoryState) +{ + if (memoryState_ == memoryState) { + IMSA_HILOGI("big memory state: Duplicate message."); + return ErrorCode::NO_ERROR; + } + memoryState_ = memoryState; + IMSA_HILOGI("big memory state: %{public}d", memoryState); + if (memoryState_ == BigMemoryState::BIG_MEMORY_END) { + StartImeIfInstalled(); + } + return ErrorCode::NO_ERROR; +} + int32_t PerUserSession::OnUnRegisteredProxyIme(UnRegisteredType type, const sptr &core) { IMSA_HILOGD("proxy unregister type: %{public}d.", type); @@ -823,6 +837,10 @@ void PerUserSession::StartImeInImeDied() IMSA_HILOGW("not ready to start ime."); return; } + if (memoryState_ == BigMemoryState::BIG_MEMORY_START) { + IMSA_HILOGI("big memory start, do not restart."); + return; + } StartImeIfInstalled(); } -- Gitee