mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-18 17:24:37 -04:00
@@ -355,9 +355,9 @@ using namespace MessageID;
|
||||
}
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
|
||||
&&data.WriteRemoteObject(mClient->AsObject().GetRefPtr())
|
||||
&&data.WriteInt32(keyEvent->GetKeyCode())
|
||||
&&data.WriteInt32(keyEvent->GetKeyAction()))) {
|
||||
&& data.WriteRemoteObject(mClient->AsObject().GetRefPtr())
|
||||
&& data.WriteInt32(keyEvent->GetKeyCode())
|
||||
&& data.WriteInt32(keyEvent->GetKeyAction()))) {
|
||||
return false;
|
||||
}
|
||||
mImms->DispatchKey(data);
|
||||
|
||||
@@ -70,11 +70,11 @@ namespace MiscServices {
|
||||
void WorkThread();
|
||||
PerUserSetting *GetUserSetting(int32_t userId);
|
||||
PerUserSession *GetUserSession(int32_t userId);
|
||||
void StartInputService();
|
||||
int32_t OnUserStarted(const Message *msg);
|
||||
int32_t OnUserStopped(const Message *msg);
|
||||
int32_t OnUserUnlocked(const Message *msg);
|
||||
int32_t OnUserLocked(const Message *msg);
|
||||
int32_t OnPrepareInput(Message *msg);
|
||||
int32_t OnHandleMessage(Message *msg);
|
||||
int32_t OnRemotePeerDied(const Message *msg);
|
||||
int32_t OnSettingChanged(const Message *msg);
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace MiscServices {
|
||||
void CreateWorkThread(MessageHandler& handler);
|
||||
void JoinWorkThread();
|
||||
void SetInputMethodAbility(sptr<InputMethodAbility> &inputMethodAbility);
|
||||
static void BindInputAbility();
|
||||
static bool StartInputService();
|
||||
private:
|
||||
int userId_; // the id of the user to whom the object is linking
|
||||
int userState; // the state of the user to whom the object is linking
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace MiscServices {
|
||||
|
||||
void InputMethodSystemAbility::OnStart()
|
||||
{
|
||||
IMSA_HILOGI("Enter OnStart.");
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnStart.");
|
||||
if (state_ == ServiceRunningState::STATE_RUNNING) {
|
||||
IMSA_HILOGI("ImsaService is already running.");
|
||||
return;
|
||||
@@ -123,6 +123,7 @@ namespace MiscServices {
|
||||
}
|
||||
IMSA_HILOGI("Publish ErrorCode::NO_ERROR.");
|
||||
state_ = ServiceRunningState::STATE_RUNNING;
|
||||
StartInputService();
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -169,6 +170,27 @@ namespace MiscServices {
|
||||
setting->Initialize();
|
||||
}
|
||||
|
||||
void InputMethodSystemAbility::StartInputService() {
|
||||
PerUserSession *session = GetUserSession(0);
|
||||
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it = msgHandlers.find(0);
|
||||
if (it == msgHandlers.end()) {
|
||||
IMSA_HILOGE("InputMethodSystemAbility::StartInputService() need start handler");
|
||||
MessageHandler *handler = new MessageHandler();
|
||||
if (session == nullptr) {
|
||||
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr");
|
||||
}
|
||||
session->CreateWorkThread(*handler);
|
||||
msgHandlers.insert(std::pair<int32_t, MessageHandler*>(0, handler));
|
||||
}
|
||||
|
||||
if (!session->StartInputService()) {
|
||||
IMSA_HILOGE("StartInputService failed. Try again 10s later");
|
||||
auto callback = [=]() { StartInputService(); };
|
||||
serviceHandler_->PostTask(callback, INIT_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
/*! Get the state of user
|
||||
\n This API is added for unit test.
|
||||
\param userID the id of given user
|
||||
@@ -406,10 +428,7 @@ namespace MiscServices {
|
||||
OnSettingChanged(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_PREPARE_INPUT: {
|
||||
OnPrepareInput(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_PREPARE_INPUT:
|
||||
case MSG_ID_RELEASE_INPUT:
|
||||
case MSG_ID_START_INPUT:
|
||||
case MSG_ID_STOP_INPUT:
|
||||
@@ -600,43 +619,6 @@ namespace MiscServices {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
/*! Prepare input. Called by an input client.
|
||||
\n Run in work thread of input method management service
|
||||
\param msg the parameters from remote client are saved in msg->msgContent_
|
||||
\return ErrorCode::NO_ERROR
|
||||
\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked
|
||||
*/
|
||||
int32_t InputMethodSystemAbility::OnPrepareInput(Message *msg)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodSystemAbility::OnPrepareInput");
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
int32_t userId = data->ReadInt32();
|
||||
|
||||
PerUserSetting *setting = GetUserSetting(userId);
|
||||
if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) {
|
||||
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput errorCode = ErrorCode::ERROR_USER_NOT_UNLOCKED");
|
||||
return ErrorCode::ERROR_USER_NOT_UNLOCKED;
|
||||
}
|
||||
|
||||
std::map<int32_t, MessageHandler*>::const_iterator it = msgHandlers.find(userId);
|
||||
if (it == msgHandlers.end()) {
|
||||
PerUserSession *session = GetUserSession(userId);
|
||||
MessageHandler *handler = new MessageHandler();
|
||||
if (session == nullptr) {
|
||||
IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr");
|
||||
}
|
||||
session->CreateWorkThread(*handler);
|
||||
msgHandlers.insert(std::pair<int32_t, MessageHandler*>(userId, handler));
|
||||
it = msgHandlers.find(userId);
|
||||
}
|
||||
|
||||
if (it != msgHandlers.end()) {
|
||||
MessageHandler *handler = it->second;
|
||||
handler->SendMessage(msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Handle message
|
||||
\param msgId the id of message to run
|
||||
\msg the parameters are saved in msg->msgContent_
|
||||
|
||||
Reference in New Issue
Block a user