mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-27 00:41:04 +00:00
commit
0838d1ec4b
@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
using FocusHandle = std::function<void(int32_t, int32_t)>;
|
||||
using FocusHandle = std::function<void(bool, int32_t, int32_t)>;
|
||||
class FocusMonitorManager {
|
||||
public:
|
||||
static FocusMonitorManager &GetInstance();
|
||||
|
@ -21,6 +21,11 @@ namespace OHOS {
|
||||
namespace MiscServices {
|
||||
void FocusChangedListener::OnFocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo)
|
||||
{
|
||||
if (focusChangeInfo == nullptr || focusHandle_ == nullptr) {
|
||||
IMSA_HILOGE("error nullptr");
|
||||
return;
|
||||
}
|
||||
focusHandle_(true, focusChangeInfo->pid_, focusChangeInfo->uid_);
|
||||
}
|
||||
|
||||
void FocusChangedListener::OnUnfocused(const sptr<Rosen::FocusChangeInfo> &focusChangeInfo)
|
||||
@ -29,7 +34,7 @@ void FocusChangedListener::OnUnfocused(const sptr<Rosen::FocusChangeInfo> &focus
|
||||
IMSA_HILOGE("error nullptr");
|
||||
return;
|
||||
}
|
||||
focusHandle_(focusChangeInfo->pid_, focusChangeInfo->uid_);
|
||||
focusHandle_(false, focusChangeInfo->pid_, focusChangeInfo->uid_);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -84,6 +84,7 @@ public:
|
||||
void StopInputService(std::string imeId);
|
||||
int32_t OnSwitchIme(const Property &property, const SubProperty &subProperty, bool isSubtypeSwitch);
|
||||
void UpdateCurrentUserId(int32_t userId);
|
||||
void OnFocused(int32_t pid, int32_t uid);
|
||||
void OnUnfocused(int32_t pid, int32_t uid);
|
||||
bool CheckFocused(uint32_t tokenId);
|
||||
int32_t OnPanelStatusChange(const InputWindowStatus &status, const InputWindowInfo &windowInfo);
|
||||
@ -137,6 +138,8 @@ private:
|
||||
void SetAgent(sptr<IInputMethodAgent> agent);
|
||||
sptr<IInputMethodAgent> GetAgent();
|
||||
sptr<AAFwk::IAbilityManager> GetAbilityManagerService();
|
||||
bool IsCurrentClient(int32_t pid, int32_t uid);
|
||||
void UnbindClient(const sptr<IInputClient> &client);
|
||||
|
||||
static inline bool IsValid(int32_t index)
|
||||
{
|
||||
|
@ -747,9 +747,10 @@ int32_t InputMethodSystemAbility::InitKeyEventMonitor()
|
||||
bool InputMethodSystemAbility::InitFocusChangeMonitor()
|
||||
{
|
||||
return ImCommonEventManager::GetInstance()->SubscribeWindowManagerService(
|
||||
[this](int32_t pid, int32_t uid) { return userSession_->OnUnfocused(pid, uid); },
|
||||
[this](int32_t userId) { StartInputService(ImeInfoInquirer::GetInstance().GetStartedIme(userId_)); }
|
||||
);
|
||||
[this](bool isOnFocused, int32_t pid, int32_t uid) {
|
||||
return isOnFocused ? userSession_->OnFocused(pid, uid) : userSession_->OnUnfocused(pid, uid);
|
||||
},
|
||||
[this](int32_t userId) { StartInputService(ImeInfoInquirer::GetInstance().GetStartedIme(userId_)); });
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -536,27 +536,66 @@ void PerUserSession::SetAgent(sptr<IInputMethodAgent> agent)
|
||||
agent_ = agent;
|
||||
}
|
||||
|
||||
void PerUserSession::OnUnfocused(int32_t pid, int32_t uid)
|
||||
void PerUserSession::OnFocused(int32_t pid, int32_t uid)
|
||||
{
|
||||
if (IsCurrentClient(pid, uid)) {
|
||||
IMSA_HILOGD("pid[%{public}d] same as current client", pid);
|
||||
return;
|
||||
}
|
||||
auto client = GetCurrentClient();
|
||||
if (client == nullptr) {
|
||||
IMSA_HILOGD("no client in bound state");
|
||||
return;
|
||||
}
|
||||
auto clientInfo = GetClientInfo(client->AsObject());
|
||||
if (clientInfo == nullptr) {
|
||||
IMSA_HILOGI("focus shifts to pid: %{public}d, start unbinding", pid);
|
||||
UnbindClient(client);
|
||||
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNFOCUSED);
|
||||
}
|
||||
|
||||
void PerUserSession::OnUnfocused(int32_t pid, int32_t uid)
|
||||
{
|
||||
if (IsCurrentClient(pid, uid)) {
|
||||
IMSA_HILOGD("pid[%{public}d] same as current client", pid);
|
||||
return;
|
||||
}
|
||||
if (clientInfo->pid != pid || clientInfo->uid != uid) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mtx);
|
||||
for (const auto &mapClient : mapClients_) {
|
||||
if (mapClient.second->pid == pid) {
|
||||
IMSA_HILOGI("clear unfocused client info: %{public}d", pid);
|
||||
UnbindClient(mapClient.second->client);
|
||||
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNFOCUSED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PerUserSession::UnbindClient(const sptr<IInputClient> &client)
|
||||
{
|
||||
if (client == nullptr) {
|
||||
IMSA_HILOGE("client is nullptr");
|
||||
return;
|
||||
}
|
||||
IMSA_HILOGI("current client is unfocused, start unbinding");
|
||||
int32_t ret = client->OnInputStop();
|
||||
IMSA_HILOGI("OnInputStop ret: %{public}d", ret);
|
||||
ret = OnReleaseInput(client);
|
||||
InputMethodSysEvent::OperateSoftkeyboardBehaviour(IME_HIDE_UNFOCUSED);
|
||||
IMSA_HILOGI("release input ret: %{public}d", ret);
|
||||
}
|
||||
|
||||
bool PerUserSession::IsCurrentClient(int32_t pid, int32_t uid)
|
||||
{
|
||||
auto client = GetCurrentClient();
|
||||
if (client == nullptr) {
|
||||
IMSA_HILOGD("no client in bound state");
|
||||
return false;
|
||||
}
|
||||
auto clientInfo = GetClientInfo(client->AsObject());
|
||||
if (clientInfo == nullptr) {
|
||||
IMSA_HILOGE("failed to get client info");
|
||||
return false;
|
||||
}
|
||||
return clientInfo->pid == pid && clientInfo->uid == uid;
|
||||
}
|
||||
|
||||
sptr<AAFwk::IAbilityManager> PerUserSession::GetAbilityManagerService()
|
||||
{
|
||||
IMSA_HILOGD("InputMethodSystemAbility::GetAbilityManagerService start");
|
||||
|
Loading…
Reference in New Issue
Block a user