fix: OnConfigurationChange donot missing isPreviewTextSupported

Signed-off-by: zhaolinglan <zhaolinglan1@huawei.com>
This commit is contained in:
zhaolinglan 2024-06-04 22:31:50 +08:00
parent d706ab4ee7
commit 406a0c2280
11 changed files with 97 additions and 49 deletions

View File

@ -61,6 +61,7 @@ enum {
MSG_ID_ON_CURSOR_UPDATE,
MSG_ID_ON_SELECTION_CHANGE,
MSG_ID_ON_CONFIGURATION_CHANGE,
MSG_ID_ON_ATTRIBUTE_CHANGE,
MSG_ID_QUIT_WORKER_THREAD,
};
}

View File

@ -588,8 +588,8 @@ void JsKeyboardDelegateSetting::OnEditorAttributeChange(const InputAttribute &in
IMSA_HILOGE("eventHandler is nullptr!");
return;
}
IMSA_HILOGD("enterKeyType: %{public}d, inputPattern: %{public}d", inputAttribute.enterKeyType,
inputAttribute.inputPattern);
IMSA_HILOGD("enterKeyType: %{public}d, inputPattern: %{public}d, previewSupport: %{public}d",
inputAttribute.enterKeyType, inputAttribute.inputPattern, inputAttribute.isTextPreviewSupported);
auto task = [entry]() {
auto paramGetter = [entry](napi_env env, napi_value *args, uint8_t argc) -> bool {
if (argc == 0) {

View File

@ -36,7 +36,7 @@ public:
ON_SELECTION_CHANGE,
SET_CALLING_WINDOW_ID,
SEND_PRIVATE_COMMAND,
ON_CONFIGURATION_CHANGE,
ON_ATTRIBUTE_CHANGE,
};
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodAgent");
@ -47,7 +47,7 @@ public:
virtual void OnSelectionChange(
std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) = 0;
virtual void SetCallingWindow(uint32_t windowId) = 0;
virtual void OnConfigurationChange(const Configuration &config) = 0;
virtual void OnAttributeChange(const InputAttribute &attribute) = 0;
virtual int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) = 0;
};
} // namespace MiscServices

View File

@ -140,7 +140,7 @@ private:
int32_t InvokeStartInputCallback(const TextTotalConfig &textConfig, bool isNotifyInputStart);
void OnCursorUpdate(Message *msg);
void OnSelectionChange(Message *msg);
void OnConfigurationChange(Message *msg);
void OnAttributeChange(Message *msg);
void OnStopInputService(Message *msg);
int32_t HideKeyboard(Trigger trigger);

View File

@ -42,7 +42,7 @@ public:
void OnSelectionChange(
std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override;
void SetCallingWindow(uint32_t windowId) override;
void OnConfigurationChange(const Configuration &config) override;
void OnAttributeChange(const InputAttribute &attribute) override;
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
private:

View File

@ -35,13 +35,14 @@ public:
void OnSelectionChange(
std::u16string text, int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override;
void SetCallingWindow(uint32_t windowId) override;
void OnConfigurationChange(const Configuration &config) override;
void OnAttributeChange(const InputAttribute &attribute) override;
void SetMessageHandler(MessageHandler *msgHandler);
int32_t SendPrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
private:
int32_t DispatchKeyEventOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t SendPrivateCommandOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t OnAttributeChangeOnRemote(MessageParcel &data, MessageParcel &reply);
MessageHandler *msgHandler_;
};
} // namespace MiscServices

View File

@ -202,8 +202,8 @@ void InputMethodAbility::WorkThread()
OnSelectionChange(msg);
break;
}
case MSG_ID_ON_CONFIGURATION_CHANGE: {
OnConfigurationChange(msg);
case MSG_ID_ON_ATTRIBUTE_CHANGE: {
OnAttributeChange(msg);
break;
}
case MSG_ID_STOP_INPUT_SERVICE: {
@ -372,18 +372,20 @@ void InputMethodAbility::OnSelectionChange(Message *msg)
kdListener_->OnSelectionChange(oldBegin, oldEnd, newBegin, newEnd);
}
void InputMethodAbility::OnConfigurationChange(Message *msg)
void InputMethodAbility::OnAttributeChange(Message *msg)
{
if (kdListener_ == nullptr) {
IMSA_HILOGE("in, kdListener_ is nullptr");
if (kdListener_ == nullptr || msg == nullptr) {
IMSA_HILOGE("kdListener_ or msg is nullptr");
return;
}
MessageParcel *data = msg->msgContent_;
InputAttribute attribute;
attribute.enterKeyType = data->ReadInt32();
attribute.inputPattern = data->ReadInt32();
IMSA_HILOGD("InputMethodAbility, enterKeyType: %{public}d, inputPattern: %{public}d", attribute.enterKeyType,
attribute.inputPattern);
if (!ITypesUtil::Unmarshal(*data, attribute)) {
IMSA_HILOGE("failed to read attribute");
return;
}
IMSA_HILOGD(
"IMA, enterKeyType: %{public}d, inputPattern: %{public}d", attribute.enterKeyType, attribute.inputPattern);
SetInputAttribute(attribute);
// add for mod inputPattern when panel show
auto panel = GetSoftKeyboardPanel();

View File

@ -64,13 +64,11 @@ void InputMethodAgentProxy::SetCallingWindow(uint32_t windowId)
IMSA_HILOGD("InputMethodAgentProxy::SetCallingWindow ret = %{public}d", ret);
}
void InputMethodAgentProxy::OnConfigurationChange(const Configuration &config)
void InputMethodAgentProxy::OnAttributeChange(const InputAttribute &attribute)
{
auto ret = SendRequest(ON_CONFIGURATION_CHANGE, [&config](MessageParcel &data) {
return data.WriteInt32(static_cast<int32_t>(config.GetEnterKeyType()))
&& data.WriteInt32(static_cast<int32_t>(config.GetTextInputType()));
});
IMSA_HILOGD("InputMethodAgentProxy, ret = %{public}d", ret);
auto ret = SendRequest(
ON_ATTRIBUTE_CHANGE, [&attribute](MessageParcel &data) { return ITypesUtil::Marshal(data, attribute); });
IMSA_HILOGD("InputMethodAgentProxy, ret: %{public}d", ret);
}
int32_t InputMethodAgentProxy::SendPrivateCommand(

View File

@ -71,17 +71,12 @@ int32_t InputMethodAgentStub::OnRemoteRequest(
reply.WriteNoException();
return ErrorCode::NO_ERROR;
}
case ON_CONFIGURATION_CHANGE: {
Configuration configuration;
configuration.SetEnterKeyType(EnterKeyType(data.ReadInt32()));
configuration.SetTextInputType(TextInputType(data.ReadInt32()));
OnConfigurationChange(configuration);
reply.WriteNoException();
return ErrorCode::NO_ERROR;
}
case SEND_PRIVATE_COMMAND: {
return SendPrivateCommandOnRemote(data, reply);
}
case ON_ATTRIBUTE_CHANGE: {
return OnAttributeChangeOnRemote(data, reply);
}
default: {
return IRemoteStub::OnRemoteRequest(code, data, reply, option);
}
@ -117,6 +112,18 @@ int32_t InputMethodAgentStub::SendPrivateCommandOnRemote(MessageParcel &data, Me
return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodAgentStub::OnAttributeChangeOnRemote(MessageParcel &data, MessageParcel &reply)
{
InputAttribute attribute;
if (!ITypesUtil::Unmarshal(data, attribute)) {
IMSA_HILOGE("failed to read attribute from parcel");
return ErrorCode::ERROR_EX_PARCELABLE;
}
OnAttributeChange(attribute);
reply.WriteNoException();
return ErrorCode::NO_ERROR;
}
int32_t InputMethodAgentStub::DispatchKeyEvent(
const std::shared_ptr<MMI::KeyEvent> &keyEvent, sptr<IKeyEventConsumer> &consumer)
{
@ -157,24 +164,37 @@ void InputMethodAgentStub::OnSelectionChange(
msgHandler_->SendMessage(message);
}
void InputMethodAgentStub::OnConfigurationChange(const Configuration &config)
{
if (msgHandler_ == nullptr) {
return;
}
MessageParcel *data = new MessageParcel();
data->WriteInt32(static_cast<int32_t>(config.GetEnterKeyType()));
data->WriteInt32(static_cast<int32_t>(config.GetTextInputType()));
Message *message = new Message(MessageID::MSG_ID_ON_CONFIGURATION_CHANGE, data);
msgHandler_->SendMessage(message);
}
int32_t InputMethodAgentStub::SendPrivateCommand(
const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
{
return ErrorCode::NO_ERROR;
}
void InputMethodAgentStub::OnAttributeChange(const InputAttribute &attribute)
{
if (msgHandler_ == nullptr) {
IMSA_HILOGE("msgHandler_ is nullptr");
return;
}
auto data = new (std::nothrow) MessageParcel();
if (data == nullptr) {
IMSA_HILOGE("failed to create message parcel");
return;
}
if (!ITypesUtil::Marshal(*data, attribute)) {
IMSA_HILOGE("failed to write attribute");
delete data;
return;
}
auto message = new (std::nothrow) Message(MessageID::MSG_ID_ON_ATTRIBUTE_CHANGE, data);
if (message == nullptr) {
IMSA_HILOGE("failed to create Message");
delete data;
return;
}
msgHandler_->SendMessage(message);
}
void InputMethodAgentStub::SetMessageHandler(MessageHandler *msgHandler)
{
msgHandler_ = msgHandler;

View File

@ -643,23 +643,25 @@ int32_t InputMethodController::OnConfigurationChange(Configuration info)
IMSA_HILOGD("not bound");
return ErrorCode::ERROR_CLIENT_NOT_BOUND;
}
InputAttribute attribute;
{
std::lock_guard<std::mutex> lock(textConfigLock_);
textConfig_.inputAttribute.enterKeyType = static_cast<int32_t>(info.GetEnterKeyType());
textConfig_.inputAttribute.inputPattern = static_cast<int32_t>(info.GetTextInputType());
attribute = textConfig_.inputAttribute;
}
if (!IsEditable()) {
IMSA_HILOGD("not editable");
return ErrorCode::ERROR_CLIENT_NOT_EDITABLE;
}
IMSA_HILOGI("IMC enterKeyType: %{public}d, textInputType: %{public}d", textConfig_.inputAttribute.enterKeyType,
textConfig_.inputAttribute.inputPattern);
IMSA_HILOGI(
"IMC enterKeyType: %{public}d, textInputType: %{public}d", attribute.enterKeyType, attribute.inputPattern);
auto agent = GetAgent();
if (agent == nullptr) {
IMSA_HILOGE("agent is nullptr");
return ErrorCode::ERROR_IME_NOT_STARTED;
}
agent->OnConfigurationChange(info);
agent->OnAttributeChange(attribute);
return ErrorCode::NO_ERROR;
}

View File

@ -1007,14 +1007,14 @@ HWTEST_F(InputMethodControllerTest, testIMCGetInputPattern, TestSize.Level0)
}
/**
* @tc.name: testOnEditorAttributeChanged
* @tc.desc: IMC testOnEditorAttributeChanged.
* @tc.name: testOnEditorAttributeChanged01
* @tc.desc: IMC testOnEditorAttributeChanged01.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged, TestSize.Level0)
HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged01, TestSize.Level0)
{
IMSA_HILOGI("IMC testOnEditorAttributeChanged Test START");
IMSA_HILOGI("IMC testOnEditorAttributeChanged01 Test START");
auto ret = inputMethodController_->Attach(textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
Configuration info;
@ -1025,6 +1025,30 @@ HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged, TestSize.Level
EXPECT_EQ(InputMethodControllerTest::inputAttribute_.enterKeyType, static_cast<int32_t>(info.GetEnterKeyType()));
}
/**
* @tc.name: testOnEditorAttributeChanged02
* @tc.desc: Attach(isPreviewSupport) -> OnConfigurationChange -> editorChange callback (isPreviewSupport).
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InputMethodControllerTest, testOnEditorAttributeChanged02, TestSize.Level0)
{
IMSA_HILOGI("IMC testOnEditorAttributeChanged02 Test START");
InputAttribute attribute = { .inputPattern = static_cast<int32_t>(TextInputType::DATETIME),
.enterKeyType = static_cast<int32_t>(EnterKeyType::GO),
.isTextPreviewSupported = true };
auto ret = inputMethodController_->Attach(textListener_, false, attribute);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
Configuration info;
info.SetEnterKeyType(EnterKeyType::NEW_LINE);
info.SetTextInputType(TextInputType::NUMBER);
InputMethodControllerTest::ResetKeyboardListenerTextConfig();
InputMethodControllerTest::TriggerConfigurationChangeCallback(info);
EXPECT_EQ(InputMethodControllerTest::inputAttribute_.inputPattern, static_cast<int32_t>(info.GetTextInputType()));
EXPECT_EQ(InputMethodControllerTest::inputAttribute_.enterKeyType, static_cast<int32_t>(info.GetEnterKeyType()));
EXPECT_EQ(InputMethodControllerTest::inputAttribute_.isTextPreviewSupported, attribute.isTextPreviewSupported);
}
/**
* @tc.name: testHideSoftKeyboard
* @tc.desc: IMC HideSoftKeyboard