• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "input_method_agent_service_impl.h"
17 
18 #include "global.h"
19 #include "input_method_ability.h"
20 #include "ipc_skeleton.h"
21 #include "itypes_util.h"
22 #include "task_manager.h"
23 #include "tasks/task_imsa.h"
24 #include "input_method_tools.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28 using namespace MessageID;
InputMethodAgentServiceImpl()29 InputMethodAgentServiceImpl::InputMethodAgentServiceImpl() {}
30 
~InputMethodAgentServiceImpl()31 InputMethodAgentServiceImpl::~InputMethodAgentServiceImpl() {}
32 
DispatchKeyEvent(const MiscServices::KeyEventValue & keyEvent,uint64_t cbId,const sptr<IRemoteObject> & channelObject)33 ErrCode InputMethodAgentServiceImpl::DispatchKeyEvent(
34     const MiscServices::KeyEventValue &keyEvent, uint64_t cbId, const sptr<IRemoteObject> &channelObject)
35 {
36     return InputMethodAbility::GetInstance().DispatchKeyEvent(keyEvent.event, cbId, channelObject);
37 }
38 
SetCallingWindow(uint32_t windowId)39 ErrCode InputMethodAgentServiceImpl::SetCallingWindow(uint32_t windowId)
40 {
41     InputMethodAbility::GetInstance().SetCallingWindow(windowId);
42     return ERR_OK;
43 }
44 
OnCursorUpdate(int32_t positionX,int32_t positionY,int height)45 ErrCode InputMethodAgentServiceImpl::OnCursorUpdate(int32_t positionX, int32_t positionY, int height)
46 {
47     auto task = std::make_shared<TaskImsaOnCursorUpdate>(positionX, positionY, height);
48     TaskManager::GetInstance().PostTask(task);
49     return ERR_OK;
50 }
51 
OnSelectionChange(const std::string & text,int32_t oldBegin,int32_t oldEnd,int32_t newBegin,int32_t newEnd)52 ErrCode InputMethodAgentServiceImpl::OnSelectionChange(
53     const std::string& text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
54 {
55     std::u16string u16text = Str8ToStr16(text);
56     auto task = std::make_shared<TaskImsaOnSelectionChange>(u16text, oldBegin, oldEnd, newBegin, newEnd);
57     TaskManager::GetInstance().PostTask(task);
58     return ERR_OK;
59 }
60 
SendPrivateCommand(const Value & value)61 ErrCode InputMethodAgentServiceImpl::SendPrivateCommand(
62     const Value &value)
63 {
64     if (!InputMethodAbility::GetInstance().IsDefaultIme()) {
65         IMSA_HILOGE("current is not default ime!");
66         return ErrorCode::ERROR_NOT_DEFAULT_IME;
67     }
68     std::unordered_map<std::string, PrivateDataValue> privateCommand;
69     privateCommand = value.valueMap;
70     auto task = std::make_shared<TaskImsaSendPrivateCommand>(privateCommand);
71     TaskManager::GetInstance().PostTask(task);
72     return ERR_OK;
73 }
74 
OnAttributeChange(const InputAttributeInner & attributeInner)75 ErrCode InputMethodAgentServiceImpl::OnAttributeChange(const InputAttributeInner &attributeInner)
76 {
77     InputAttribute attribute = InputMethodTools::GetInstance().InnerToAttribute(attributeInner);
78     auto task = std::make_shared<TaskImsaAttributeChange>(attribute);
79     TaskManager::GetInstance().PostTask(task);
80     return ERR_OK;
81 }
82 
SendMessage(const ArrayBuffer & arraybuffer)83 ErrCode InputMethodAgentServiceImpl::SendMessage(const ArrayBuffer &arraybuffer)
84 {
85     return InputMethodAbility::GetInstance().RecvMessage(arraybuffer);
86 }
87 
DiscardTypingText()88 ErrCode InputMethodAgentServiceImpl::DiscardTypingText()
89 {
90     IMSA_HILOGD("DiscardTypingText run");
91     std::string type = "discardTypingText";
92     auto ret = InputMethodAbility::GetInstance().IsCallbackRegistered(type);
93     if (!ret) {
94         IMSA_HILOGE("callback not registered");
95         return ErrorCode::ERROR_MSG_HANDLER_NOT_REGIST;
96     }
97     auto task = std::make_shared<TaskImsaDiscardTypingText>();
98     TaskManager::GetInstance().PostTask(task);
99     return ErrorCode::NO_ERROR;
100 }
101 
OnFunctionKey(int32_t funcKey)102 ErrCode InputMethodAgentServiceImpl::OnFunctionKey(int32_t funcKey)
103 {
104     auto task = std::make_shared<TaskImsaOnFunctionKey>(funcKey);
105     TaskManager::GetInstance().PostTask(task);
106     return ERR_OK;
107 }
108 
ResponseDataChannel(uint64_t msgId,int code,const ResponseDataInner & msg)109 ErrCode InputMethodAgentServiceImpl::ResponseDataChannel(uint64_t msgId, int code, const ResponseDataInner &msg)
110 {
111     return InputMethodAbility::GetInstance().OnResponse(msgId, code, msg.rspData);
112 }
113 } // namespace MiscServices
114 } // namespace OHOS