mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-26 16:31:40 +00:00
!1579 修改开机获取缓存大小写输入法错误的问题
Merge pull request !1579 from mashaoyin/master
This commit is contained in:
commit
3204f4fe06
@ -40,7 +40,7 @@ public:
|
||||
~ImCommonEventManager();
|
||||
static sptr<ImCommonEventManager> GetInstance();
|
||||
bool SubscribeEvent();
|
||||
bool SubscribeKeyboardEvent(KeyHandle handle);
|
||||
bool SubscribeKeyboardEvent(const Handler &handler);
|
||||
bool SubscribeWindowManagerService(const Handler &handler);
|
||||
bool SubscribeMemMgrService(const Handler &handler);
|
||||
bool SubscribeAccountManagerService(Handler handle);
|
||||
|
@ -138,6 +138,7 @@ private:
|
||||
void HandleDataShareReady();
|
||||
void HandleOsAccountStarted();
|
||||
void HandleFocusChanged(bool isFocused, int32_t pid, int32_t uid);
|
||||
void HandleImeCfgCapsState();
|
||||
void StopImeInBackground();
|
||||
int32_t InitAccountMonitor();
|
||||
static std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
|
||||
@ -169,12 +170,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 ModifyImeCfgWithWrongCaps();
|
||||
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;
|
||||
|
@ -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);
|
||||
|
@ -94,7 +94,7 @@ bool ImCommonEventManager::SubscribeEvent()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ImCommonEventManager::SubscribeKeyboardEvent(KeyHandle handle)
|
||||
bool ImCommonEventManager::SubscribeKeyboardEvent(const Handler &handler)
|
||||
{
|
||||
IMSA_HILOGI("ImCommonEventManager::SubscribeKeyboardEvent start.");
|
||||
auto abilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
@ -102,10 +102,10 @@ bool ImCommonEventManager::SubscribeKeyboardEvent(KeyHandle handle)
|
||||
IMSA_HILOGE("SubscribeKeyboardEvent abilityManager is nullptr!");
|
||||
return false;
|
||||
}
|
||||
sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([handle]() {
|
||||
int32_t ret = KeyboardEvent::GetInstance().AddKeyEventMonitor(handle);
|
||||
IMSA_HILOGI("SubscribeKeyboardEvent add monitor: %{public}s.",
|
||||
ret == ErrorCode::NO_ERROR ? "success" : "failed");
|
||||
sptr<ISystemAbilityStatusChange> listener = new (std::nothrow) SystemAbilityStatusChangeListener([handler]() {
|
||||
if (handler != nullptr) {
|
||||
handler();
|
||||
}
|
||||
});
|
||||
if (listener == nullptr) {
|
||||
IMSA_HILOGE("listener is nullptr!");
|
||||
|
@ -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,6 +1001,7 @@ void InputMethodSystemAbility::WorkThread()
|
||||
break;
|
||||
}
|
||||
case MSG_ID_BUNDLE_SCAN_FINISHED: {
|
||||
HandleBundleScanFinished();
|
||||
break;
|
||||
}
|
||||
case MSG_ID_DATA_SHARE_READY: {
|
||||
@ -1398,8 +1400,15 @@ int32_t InputMethodSystemAbility::InitAccountMonitor()
|
||||
int32_t InputMethodSystemAbility::InitKeyEventMonitor()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbility::InitKeyEventMonitor start.");
|
||||
bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent(
|
||||
[this](uint32_t keyCode) { return SwitchByCombinationKey(keyCode); });
|
||||
auto handler = [this](){
|
||||
auto switchTrigger = [this](uint32_t keyCode) { return SwitchByCombinationKey(keyCode);};
|
||||
int32_t ret = KeyboardEvent::GetInstance().AddKeyEventMonitor(switchTrigger);
|
||||
IMSA_HILOGI("SubscribeKeyboardEvent add monitor: %{public}s.",
|
||||
ret == ErrorCode::NO_ERROR ? "success" : "failed");
|
||||
// Check device capslock status and ime cfg corrent, when device power-up.
|
||||
HandleImeCfgCapsState();
|
||||
};
|
||||
bool ret = ImCommonEventManager::GetInstance()->SubscribeKeyboardEvent(handler);
|
||||
return ret ? ErrorCode::NO_ERROR : ErrorCode::ERROR_SERVICE_START_FAILED;
|
||||
}
|
||||
|
||||
@ -1846,5 +1855,78 @@ void InputMethodSystemAbility::NeedHideWhenSwitchInputType(int32_t userId, bool
|
||||
}
|
||||
needHide = currentImeCfg->bundleName == ime.bundleName;
|
||||
}
|
||||
|
||||
void InputMethodSystemAbility::HandleBundleScanFinished()
|
||||
{
|
||||
isBundleScanFinished_.store(true);
|
||||
HandleImeCfgCapsState();
|
||||
}
|
||||
|
||||
bool InputMethodSystemAbility::ModifyImeCfgWithWrongCaps()
|
||||
{
|
||||
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("UserId: %{public}d session is nullptr!", userId_);
|
||||
return;
|
||||
}
|
||||
if (!session->IsSaReady(MULTIMODAL_INPUT_SERVICE_ID)) {
|
||||
IMSA_HILOGE("MMI service is not ready.");
|
||||
return;
|
||||
}
|
||||
if (!ModifyImeCfgWithWrongCaps()) {
|
||||
IMSA_HILOGE("Check ImeCfg capslock state correct failed!");
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -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!");
|
||||
|
Loading…
Reference in New Issue
Block a user