mirror of
https://github.com/openharmony/miscservices_inputmethod.git
synced 2026-07-19 12:08:05 -04:00
解决没有绑定输入法时,还消费物理按键的问题
Signed-off-by: zhouyongfei <zhouyongfei@huawei.com>
This commit is contained in:
@@ -34,6 +34,7 @@ namespace MiscServices {
|
||||
public:
|
||||
enum {
|
||||
INITIALIZE_INPUT = FIRST_CALL_TRANSACTION,
|
||||
SET_CLIENT_STATE,
|
||||
START_INPUT,
|
||||
STOP_INPUT,
|
||||
SHOW_KEYBOARD,
|
||||
@@ -56,6 +57,7 @@ namespace MiscServices {
|
||||
virtual int32_t setKeyboardType(const KeyboardType& type) = 0;
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) = 0;
|
||||
virtual void SetClientState(bool state) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace MiscServices {
|
||||
bool stop_;
|
||||
int32_t KEYBOARD_HIDE = 1;
|
||||
int32_t KEYBOARD_SHOW = 2;
|
||||
bool isBindClient = false;
|
||||
|
||||
// communicating with IMSA
|
||||
sptr<IInputControlChannel> inputControlChannel;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace MiscServices {
|
||||
virtual int32_t setKeyboardType(const KeyboardType& type) override;
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
|
||||
|
||||
virtual void SetClientState(bool state) override;
|
||||
private:
|
||||
static inline BrokerDelegator<InputMethodCoreProxy> delegator_;
|
||||
};
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace MiscServices {
|
||||
virtual int32_t setKeyboardType(const KeyboardType& type) override;
|
||||
virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override;
|
||||
virtual int32_t InitInputControlChannel(sptr<IInputControlChannel> &inputControlChannel) override;
|
||||
virtual void SetClientState(bool state) override;
|
||||
void SetMessageHandler(MessageHandler *msgHandler);
|
||||
|
||||
private:
|
||||
|
||||
@@ -138,6 +138,11 @@ namespace MiscServices {
|
||||
OnInitInputControlChannel(msg);
|
||||
break;
|
||||
}
|
||||
case MSG_ID_SET_CLIENT_STATE: {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
isBindClient = data->ReadBool();
|
||||
break;
|
||||
}
|
||||
case MSG_ID_START_INPUT: {
|
||||
OnStartInput(msg);
|
||||
break;
|
||||
@@ -252,6 +257,10 @@ namespace MiscServices {
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent");
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent: key = %{public}d, status = %{public}d", keyCode, keyStatus);
|
||||
if (!isBindClient) {
|
||||
IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent abort. no client");
|
||||
return false;
|
||||
}
|
||||
return imeListener_->OnKeyEvent(keyCode, keyStatus);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,25 @@ namespace MiscServices {
|
||||
return code;
|
||||
}
|
||||
|
||||
void InputMethodCoreProxy::SetClientState(bool state)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreProxy::SetClientState");
|
||||
MessageParcel data;
|
||||
if (!(data.WriteInterfaceToken(GetDescriptor())
|
||||
&& data.WriteBool(state))) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::SetClientState write error");
|
||||
return;
|
||||
}
|
||||
MessageParcel reply;
|
||||
MessageOption option {
|
||||
MessageOption::TF_SYNC
|
||||
};
|
||||
|
||||
int32_t status = Remote()->SendRequest(SET_CLIENT_STATE, data, reply, option);
|
||||
if (status != ErrorCode::NO_ERROR) {
|
||||
IMSA_HILOGI("InputMethodCoreProxy::SetClientState status = %{public}d", status);
|
||||
}
|
||||
}
|
||||
bool InputMethodCoreProxy::startInput(const sptr<IInputDataChannel> &inputDataChannel,
|
||||
const InputAttribute& editorAttribute, bool supportPhysicalKbd)
|
||||
{
|
||||
|
||||
@@ -94,6 +94,11 @@ namespace MiscServices {
|
||||
reply.WriteNoException();
|
||||
break;
|
||||
}
|
||||
case SET_CLIENT_STATE: {
|
||||
bool state = data.ReadBool();
|
||||
SetClientState(state);
|
||||
break;
|
||||
}
|
||||
case STOP_INPUT: {
|
||||
stopInput();
|
||||
reply.WriteNoException();
|
||||
@@ -201,6 +206,18 @@ namespace MiscServices {
|
||||
return ErrorCode::NO_ERROR;
|
||||
}
|
||||
|
||||
void InputMethodCoreStub::SetClientState(bool state)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::SetClientState");
|
||||
if (msgHandler_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
MessageParcel *data = new MessageParcel();
|
||||
|
||||
Message *msg = new Message(MessageID::MSG_ID_SET_CLIENT_STATE, data);
|
||||
msgHandler_->SendMessage(msg);
|
||||
}
|
||||
|
||||
bool InputMethodCoreStub::showKeyboard(const sptr<IInputDataChannel>& inputDataChannel)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodCoreStub::showKeyboard");
|
||||
|
||||
@@ -1218,6 +1218,7 @@ namespace MiscServices {
|
||||
sptr<InputClientProxy> client = new InputClientProxy(clientObject);
|
||||
sptr<IInputClient> interface = client;
|
||||
int remainClientNum = 0;
|
||||
imsCore[0]->SetClientState(false);
|
||||
HideKeyboard(client);
|
||||
int ret = RemoveClient(client, remainClientNum);
|
||||
if (ret != ErrorCode::NO_ERROR) {
|
||||
@@ -1237,6 +1238,7 @@ namespace MiscServices {
|
||||
MessageParcel *data = msg->msgContent_;
|
||||
sptr<IRemoteObject> clientObject = data->ReadRemoteObject();
|
||||
sptr<InputClientProxy> client = new InputClientProxy(clientObject);
|
||||
imsCore[0]->SetClientState(true);
|
||||
ShowKeyboard(client);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user