Signed-off-by: ma-shaoyin <mashaoyin1@huawei.com>

修改开机获取缓存大小写输入法错误的问题
This commit is contained in:
ma-shaoyin 2024-11-13 16:27:40 +08:00
parent e531174b1f
commit 56595f2842
6 changed files with 120 additions and 7 deletions

View File

@ -44,6 +44,7 @@ public:
bool SubscribeWindowManagerService(const Handler &handler);
bool SubscribeMemMgrService(const Handler &handler);
bool SubscribeAccountManagerService(Handler handle);
bool SubscribeMMIService(const Handler &handler);
bool UnsubscribeEvent();
// only public the status change of softKeyboard in FLG_FIXED or FLG_FLOATING
int32_t PublishPanelStatusChangeEvent(int32_t userId, const InputWindowStatus &status, const ImeWindowInfo &info);

View File

@ -137,6 +137,7 @@ private:
void HandleMemStarted();
void HandleOsAccountStarted();
void HandleFocusChanged(bool isFocused, int32_t pid, int32_t uid);
void HandleImeCfgCapsState();
void StopImeInBackground();
int32_t InitAccountMonitor();
int32_t RegisterDataShareObserver();
@ -148,6 +149,7 @@ private:
bool stop_ = false;
void InitMonitors();
int32_t InitKeyEventMonitor();
bool InitMmiMonitor();
bool InitWmsMonitor();
void InitSystemLanguageMonitor();
bool InitMemMgrMonitor();
@ -169,12 +171,15 @@ private:
int32_t StartInputType(int32_t userId, InputType type);
// if switch input type need to switch ime, then no need to hide panel first.
void NeedHideWhenSwitchInputType(int32_t userId, bool &needHide);
bool GetDeviceFunctionKeyState(int32_t functionKey, bool &isEnable);
bool CheckImeCfgCapsCorrect();
void HandleBundleScanFinished();
std::mutex checkMutex_;
void DatashareCallback(const std::string &key);
std::atomic<bool> enableImeOn_ = false;
std::atomic<bool> enableSecurityMode_ = false;
std::atomic<bool> isBundleScanFinished_ = false;
std::atomic<bool> isScbEnable_ = false;
std::mutex switchImeMutex_;
std::atomic<bool> switchTaskExecuting_ = false;

View File

@ -148,6 +148,7 @@ public:
std::shared_ptr<ImeNativeCfg> GetImeNativeCfg(int32_t userId, const std::string &bundleName,
const std::string &subName);
int32_t OnSetCallingWindow(uint32_t callingWindowId, sptr<IInputClient> client);
bool IsSaReady(int32_t saId);
private:
struct ResetManager {
@ -232,7 +233,6 @@ private:
bool WaitForCurrentImeStop();
void NotifyImeStopFinished();
bool GetCurrentUsingImeId(ImeIdentification &imeId);
bool IsReady(int32_t saId);
AAFwk::Want GetWant(const std::shared_ptr<ImeNativeCfg> &ime);
bool StartCurrentIme(const std::shared_ptr<ImeNativeCfg> &ime);
bool StartNewIme(const std::shared_ptr<ImeNativeCfg> &ime);

View File

@ -191,6 +191,30 @@ bool ImCommonEventManager::SubscribeAccountManagerService(Handler handler)
return true;
}
bool ImCommonEventManager::SubscribeMMIService(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(MULTIMODAL_INPUT_SERVICE_ID, listener);
if (ret != ERR_OK) {
IMSA_HILOGE("subscribe system ability failed, ret: %{public}d", ret);
return false;
}
return true;
}
bool ImCommonEventManager::UnsubscribeEvent()
{
return true;

View File

@ -27,6 +27,7 @@
#include "im_common_event_manager.h"
#include "ime_cfg_manager.h"
#include "ime_info_inquirer.h"
#include "input_manager.h"
#include "input_client_info.h"
#include "input_method_utils.h"
#include "input_type_manager.h"
@ -1000,8 +1001,7 @@ void InputMethodSystemAbility::WorkThread()
break;
}
case MSG_ID_BUNDLE_SCAN_FINISHED: {
RegisterDataShareObserver();
FullImeInfoManager::GetInstance().Init();
HandleBundleScanFinished();
break;
}
case MSG_ID_PACKAGE_ADDED:
@ -1367,6 +1367,8 @@ void InputMethodSystemAbility::InitMonitors()
IMSA_HILOGI("init KeyEvent monitor, ret: %{public}d.", ret);
ret = InitWmsMonitor();
IMSA_HILOGI("init wms monitor, ret: %{public}d.", ret);
ret = InitMmiMonitor();
IMSA_HILOGI("init MMI monitor, ret: %{public}d.", ret);
InitSystemLanguageMonitor();
if (ImeInfoInquirer::GetInstance().IsEnableInputMethod()) {
IMSA_HILOGW("Enter enable mode.");
@ -1849,5 +1851,86 @@ void InputMethodSystemAbility::NeedHideWhenSwitchInputType(int32_t userId, bool
}
needHide = currentImeCfg->bundleName == ime.bundleName;
}
void InputMethodSystemAbility::HandleBundleScanFinished()
{
isBundleScanFinished_.store(true);
RegisterDataShareObserver();
FullImeInfoManager::GetInstance().Init();
HandleImeCfgCapsState();
}
bool InputMethodSystemAbility::CheckImeCfgCapsCorrect()
{
bool isCapsEnable = false;
if (!GetDeviceFunctionKeyState(MMI::KeyEvent::CAPS_LOCK_FUNCTION_KEY, isCapsEnable)) {
IMSA_HILOGE("Get capslock function key state failed!");
return false;
}
auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
if (currentImeCfg == nullptr) {
IMSA_HILOGE("currentImeCfg is nullptr!");
return false;
}
auto info = ImeInfoInquirer::GetInstance().GetImeInfo(userId_, currentImeCfg->bundleName, currentImeCfg->subName);
if (info == nullptr) {
IMSA_HILOGE("ime info is nullptr!");
return false;
}
bool imeCfgCapsEnable = info->subProp.mode == "upper";
if (imeCfgCapsEnable == isCapsEnable) {
IMSA_HILOGE("current caps state is correct.");
return true;
}
auto condition = isCapsEnable ? Condition::UPPER : Condition::LOWER;
auto correctIme = ImeInfoInquirer::GetInstance().FindTargetSubtypeByCondition(info->subProps, condition);
if (correctIme == nullptr) {
IMSA_HILOGE("correctIme is empty!");
return false;
}
std::string correctImeName = info->prop.name + "/" + info->prop.id;
ImeCfgManager::GetInstance().ModifyImeCfg({ userId_, correctImeName, correctIme->id, false });
IMSA_HILOGD("adjust imeCfg caps success! current imeName: %{public}s, subName: %{public}s",
correctImeName.c_str(), correctIme->id.c_str());
return true;
}
bool InputMethodSystemAbility::GetDeviceFunctionKeyState(int32_t functionKey, bool &isEnable)
{
auto multiInputMgr = MMI::InputManager::GetInstance();
if (multiInputMgr == nullptr) {
IMSA_HILOGE("multiInputMgr is nullptr");
return false;
}
isEnable = multiInputMgr->GetFunctionKeyState(functionKey);
IMSA_HILOGD("The function key: %{public}d, isEnable: %{public}d", functionKey, isEnable);
return true;
}
void InputMethodSystemAbility::HandleImeCfgCapsState()
{
if (!isBundleScanFinished_.load()) {
IMSA_HILOGE("Bundle scan is not ready.");
return;
}
auto session = UserSessionManager::GetInstance().GetUserSession(userId_);
if (session == nullptr) {
IMSA_HILOGE("%{public}d session is nullptr!", userId_);
return;
}
if (!session->IsSaReady(MULTIMODAL_INPUT_SERVICE_ID)) {
IMSA_HILOGE("MMI service is not ready.");
return;
}
if (!CheckImeCfgCapsCorrect()) {
IMSA_HILOGE("Check ImeCfg capslock state correct failed!");
}
}
bool InputMethodSystemAbility::InitMmiMonitor()
{
IMSA_HILOGI("InputMethodSystemAbility::InitMmiMonitor start.");
return ImCommonEventManager::GetInstance()->SubscribeMMIService([this]() { HandleImeCfgCapsState(); });
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -1455,10 +1455,10 @@ bool PerUserSession::IsWmsReady()
IMSA_HILOGD("scb enable");
return WmsConnectionObserver::IsWmsConnected(userId_);
}
return IsReady(WINDOW_MANAGER_SERVICE_ID);
return IsSaReady(WINDOW_MANAGER_SERVICE_ID);
}
bool PerUserSession::IsReady(int32_t saId)
bool PerUserSession::IsSaReady(int32_t saId)
{
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (saMgr == nullptr) {
@ -1492,7 +1492,7 @@ void PerUserSession::AddRestartIme()
bool PerUserSession::RestartIme()
{
auto task = [this]() {
if (IsReady(MEMORY_MANAGER_SA_ID) && IsWmsReady() && runningIme_.empty()) {
if (IsSaReady(MEMORY_MANAGER_SA_ID) && IsWmsReady() && runningIme_.empty()) {
auto ret = StartCurrentIme(true);
if (!ret) {
IMSA_HILOGE("start ime failed!");