Signed-off-by: “wangdongqi” <“wangdongqi2@huawei.com”>

Changes to be committed:
This commit is contained in:
“wangdongqi” 2024-05-18 17:56:21 +08:00
parent 5628b30b9e
commit ca30b7be49
7 changed files with 53 additions and 6 deletions

View File

@ -48,7 +48,8 @@
"graphic_2d",
"config_policy",
"data_share",
"resource_schedule_service"
"resource_schedule_service",
"memmgr"
],
"third_party": [
"cJSON"

View File

@ -101,6 +101,7 @@ ohos_shared_library("inputmethod_service") {
"init:libbegetutil",
"input:libmmi-client",
"ipc:ipc_single",
"memmgr:memmgrclient",
"os_account:os_account_innerkits",
"resource_schedule_service:ressched_client",
"safwk:system_ability_fwk",
@ -174,6 +175,7 @@ ohos_static_library("inputmethod_service_static") {
"init:libbegetutil",
"input:libmmi-client",
"ipc:ipc_single",
"memmgr:memmgrclient",
"os_account:os_account_innerkits",
"resource_schedule_service:ressched_client",
"safwk:system_ability_fwk",

View File

@ -42,6 +42,7 @@ public:
bool SubscribeEvent(const std::string &event);
bool SubscribeKeyboardEvent(KeyHandle handle);
bool SubscribeWindowManagerService(FocusHandle handle, Handler inputHandler);
bool SubscribeMemMgrService(const Handler &handler);
bool SubscribeAccountManagerService(Handler handle);
bool UnsubscribeEvent();
// only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING

View File

@ -120,7 +120,7 @@ private:
void InitServiceHandler();
int32_t GetCurrentUserIdFromOsAccount();
void HandleUserChanged(int32_t userId);
int32_t StartImeWhenWmsReady();
int32_t RestartCurrentIme();
void HandleWmsReady(int32_t userId);
int32_t InitAccountMonitor();
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
@ -135,6 +135,7 @@ private:
int32_t InitKeyEventMonitor();
bool InitWmsMonitor();
void InitSystemLanguageMonitor();
bool InitMemMgrMonitor();
void InitWmsConnectionMonitor();
int32_t SwitchByCombinationKey(uint32_t state);
int32_t SwitchMode();

View File

@ -139,6 +139,30 @@ bool ImCommonEventManager::SubscribeWindowManagerService(FocusHandle handle, Han
return true;
}
bool ImCommonEventManager::SubscribeMemMgrService(const Handler &handler)
{
auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (abilityManager == nullptr) {
IMSA_HILOGE("abilityManager is nullptr");
return false;
}
sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([handler]() {
if (handler != nullptr) {
handler();
}
});
if (listener == nullptr) {
IMSA_HILOGE("failed to create listener");
return false;
}
int32_t ret = abilityManager->SubscribeSystemAbility(MEMORY_MANAGER_SA_ID, listener);
if (ret != ERR_OK) {
IMSA_HILOGE("subscribe system ability failed, ret = %{public}d", ret);
return false;
}
return true;
}
bool ImCommonEventManager::SubscribeAccountManagerService(Handler handler)
{
auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
@ -243,7 +267,8 @@ void ImCommonEventManager::SystemAbilityStatusChangeListener::OnAddSystemAbility
{
IMSA_HILOGD("systemAbilityId: %{public}d", systemAbilityId);
if (systemAbilityId != COMMON_EVENT_SERVICE_ID && systemAbilityId != MULTIMODAL_INPUT_SERVICE_ID
&& systemAbilityId != WINDOW_MANAGER_SERVICE_ID && systemAbilityId != SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN) {
&& systemAbilityId != WINDOW_MANAGER_SERVICE_ID && systemAbilityId != SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN
&& systemAbilityId != MEMORY_MANAGER_SA_ID) {
return;
}
if (func_ != nullptr) {

View File

@ -32,6 +32,7 @@
#include "iservice_registry.h"
#include "itypes_util.h"
#include "key_event.h"
#include "mem_mgr_client.h"
#include "message_handler.h"
#include "native_token_info.h"
#include "os_account_manager.h"
@ -174,7 +175,7 @@ void InputMethodSystemAbility::HandleUserChanged(int32_t userId)
ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr);
}
int32_t InputMethodSystemAbility::StartImeWhenWmsReady()
int32_t InputMethodSystemAbility::RestartCurrentIme()
{
if (imeStarting_.exchange(true)) {
IMSA_HILOGD("do starting");
@ -196,7 +197,7 @@ void InputMethodSystemAbility::HandleWmsReady(int32_t userId)
if (userId != userId_) {
HandleUserChanged(userId);
}
StartImeWhenWmsReady();
RestartCurrentIme();
}
void InputMethodSystemAbility::OnStop()
@ -204,6 +205,7 @@ void InputMethodSystemAbility::OnStop()
IMSA_HILOGI("OnStop started.");
serviceHandler_ = nullptr;
state_ = ServiceRunningState::STATE_NOT_START;
Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 0, INPUT_METHOD_SYSTEM_ABILITY_ID);
}
void InputMethodSystemAbility::InitServiceHandler()
@ -859,7 +861,7 @@ int32_t InputMethodSystemAbility::OnUserStarted(const Message *msg)
IMSA_HILOGI("wms not ready, wait");
return ErrorCode::NO_ERROR;
}
return StartImeWhenWmsReady();
return RestartCurrentIme();
}
int32_t InputMethodSystemAbility::OnUserRemoved(const Message *msg)
@ -1060,6 +1062,8 @@ void InputMethodSystemAbility::InitMonitors()
int32_t ret = InitAccountMonitor();
IMSA_HILOGI("init account monitor, ret: %{public}d", ret);
StartUserIdListener();
ret = InitMemMgrMonitor();
IMSA_HILOGI("init MemMgr monitor, ret: %{public}d", ret);
ret = InitKeyEventMonitor();
IMSA_HILOGI("init KeyEvent monitor, ret: %{public}d", ret);
ret = InitWmsMonitor();
@ -1114,6 +1118,14 @@ bool InputMethodSystemAbility::InitWmsMonitor()
});
}
bool InputMethodSystemAbility::InitMemMgrMonitor()
{
return ImCommonEventManager::GetInstance()->SubscribeMemMgrService([this]() {
IMSA_HILOGI("MemMgr start");
Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), 1, 1, INPUT_METHOD_SYSTEM_ABILITY_ID);
});
}
void InputMethodSystemAbility::InitWmsConnectionMonitor()
{
WmsConnectionMonitorManager::GetInstance().RegisterWMSConnectionChangedListener(

View File

@ -26,6 +26,7 @@
#include "input_type_manager.h"
#include "ipc_skeleton.h"
#include "iservice_registry.h"
#include "mem_mgr_client.h"
#include "message_parcel.h"
#include "parcel.h"
#include "scene_board_judgement.h"
@ -329,6 +330,7 @@ int32_t PerUserSession::OnRequestShowInput()
}
InputMethodSysEvent::GetInstance().ReportImeState(
ImeState::BIND, data->pid, ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName);
Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, INPUT_METHOD_SYSTEM_ABILITY_ID);
auto currentClient = GetCurrentClient();
if (currentClient != nullptr) {
UpdateClientInfo(currentClient->AsObject(), { { UpdateFlag::ISSHOWKEYBOARD, true } });
@ -457,6 +459,7 @@ void PerUserSession::DeactivateClient(const sptr<IInputClient> &client)
});
InputMethodSysEvent::GetInstance().ReportImeState(
ImeState::UNBIND, data->pid, ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName);
Memory::MemMgrClient::GetInstance().SetCritical(getpid(), false, INPUT_METHOD_SYSTEM_ABILITY_ID);
}
bool PerUserSession::IsProxyImeEnable()
@ -520,6 +523,7 @@ int32_t PerUserSession::BindClientWithIme(
if (type == ImeType::IME) {
InputMethodSysEvent::GetInstance().ReportImeState(
ImeState::BIND, data->pid, ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName);
Memory::MemMgrClient::GetInstance().SetCritical(getpid(), true, INPUT_METHOD_SYSTEM_ABILITY_ID);
}
if (!isBindFromClient && clientInfo->client->OnInputReady(data->agent) != ErrorCode::NO_ERROR) {
IMSA_HILOGE("start client input failed, ret: %{public}d", ret);
@ -566,6 +570,7 @@ void PerUserSession::StopImeInput(ImeType currentType, const sptr<IRemoteObject>
if (ret == ErrorCode::NO_ERROR && currentType == ImeType::IME) {
InputMethodSysEvent::GetInstance().ReportImeState(
ImeState::UNBIND, data->pid, ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName);
Memory::MemMgrClient::GetInstance().SetCritical(getpid(), false, INPUT_METHOD_SYSTEM_ABILITY_ID);
}
}