feature:inputmethod get editing bundle name

Signed-off-by: wuchengwen <wuchengwen4@huawei.com>
This commit is contained in:
wuchengwen 2024-10-31 16:22:04 +08:00
parent d00da730fb
commit 3fa5a56d0d
7 changed files with 83 additions and 5 deletions

View File

@ -161,7 +161,8 @@ bool ITypesUtil::Unmarshalling(SubProperty &output, MessageParcel &data)
bool ITypesUtil::Marshalling(const InputAttribute &input, MessageParcel &data)
{
if (!Marshal(data, input.inputPattern, input.enterKeyType, input.inputOption, input.isTextPreviewSupported)) {
if (!Marshal(data, input.inputPattern, input.enterKeyType, input.inputOption, input.isTextPreviewSupported,
input.bundleName)) {
IMSA_HILOGE("write InputAttribute to message parcel failed.");
return false;
}
@ -170,7 +171,8 @@ bool ITypesUtil::Marshalling(const InputAttribute &input, MessageParcel &data)
bool ITypesUtil::Unmarshalling(InputAttribute &output, MessageParcel &data)
{
if (!Unmarshal(data, output.inputPattern, output.enterKeyType, output.inputOption, output.isTextPreviewSupported)) {
if (!Unmarshal(data, output.inputPattern, output.enterKeyType, output.inputOption, output.isTextPreviewSupported,
output.bundleName)) {
IMSA_HILOGE("read InputAttribute from message parcel failed.");
return false;
}

View File

@ -963,6 +963,8 @@ napi_value JsInputAttribute::Write(napi_env env, const InputAttribute &nativeObj
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "enterKeyType", nativeObject.enterKeyType);
ret = ret &&
JsUtil::Object::WriteProperty(env, jsObject, "isTextPreviewSupported", nativeObject.isTextPreviewSupported);
// not care write bundleName fail
JsUtil::Object::WriteProperty(env, jsObject, "bundleName", nativeObject.bundleName);
return ret ? jsObject : JsUtil::Const::Null(env);
}
@ -972,6 +974,8 @@ bool JsInputAttribute::Read(napi_env env, napi_value jsObject, InputAttribute &n
ret = ret && JsUtil::Object::ReadProperty(env, jsObject, "enterKeyType", nativeObject.enterKeyType);
ret = ret &&
JsUtil::Object::ReadProperty(env, jsObject, "isTextPreviewSupported", nativeObject.isTextPreviewSupported);
// not care read bundleName fail
JsUtil::Object::ReadProperty(env, jsObject, "bundleName", nativeObject.bundleName);
return ret;
}
} // namespace MiscServices

View File

@ -216,6 +216,10 @@ int32_t InputMethodAbility::StartInput(const InputClientInfo &clientInfo, bool i
panel->HidePanel();
}
}
{
std::lock_guard<std::mutex> lock(inputAttrLock_);
inputAttribute_.bundleName = clientInfo.config.inputAttribute.bundleName;
}
int32_t ret = isBindFromClient ? InvokeStartInputCallback(clientInfo.config, clientInfo.isNotifyInputStart)
: InvokeStartInputCallback(clientInfo.isNotifyInputStart);
if (ret != ErrorCode::NO_ERROR) {
@ -355,6 +359,7 @@ void InputMethodAbility::OnAttributeChange(InputAttribute attribute)
}
IMSA_HILOGD("enterKeyType: %{public}d, inputPattern: %{public}d.", attribute.enterKeyType,
attribute.inputPattern);
attribute.bundleName = GetInputAttribute().bundleName;
SetInputAttribute(attribute);
// add for mod inputPattern when panel show
auto panel = GetSoftKeyboardPanel();
@ -457,6 +462,7 @@ int32_t InputMethodAbility::InvokeStartInputCallback(bool isNotifyInputStart)
TextTotalConfig textConfig = {};
int32_t ret = GetTextConfig(textConfig);
if (ret == ErrorCode::NO_ERROR) {
textConfig.inputAttribute.bundleName = GetInputAttribute().bundleName;
return InvokeStartInputCallback(textConfig, isNotifyInputStart);
}
IMSA_HILOGW("failed to get text config, ret: %{public}d.", ret);
@ -689,7 +695,11 @@ int32_t InputMethodAbility::GetTextConfig(TextTotalConfig &textConfig)
IMSA_HILOGE("channel is nullptr!");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
return channel->GetTextConfig(textConfig);
auto ret = channel->GetTextConfig(textConfig);
if (ret == ErrorCode::NO_ERROR) {
textConfig.inputAttribute.bundleName = GetInputAttribute().bundleName;
}
return ret;
}
void InputMethodAbility::SetInputDataChannel(const sptr<IRemoteObject> &object)

View File

@ -32,15 +32,18 @@ struct InputAttribute {
int32_t enterKeyType = 0;
int32_t inputOption = 0;
bool isTextPreviewSupported{ false };
std::string bundleName { "" };
static bool Marshalling(const InputAttribute &in, MessageParcel &data)
{
return data.WriteInt32(in.inputPattern) && data.WriteInt32(in.enterKeyType) && data.WriteInt32(in.inputOption);
return data.WriteInt32(in.inputPattern) && data.WriteInt32(in.enterKeyType) &&
data.WriteInt32(in.inputOption) && data.WriteString(in.bundleName);
}
static bool Unmarshalling(InputAttribute &out, MessageParcel &data)
{
return data.ReadInt32(out.inputPattern) && data.ReadInt32(out.enterKeyType) && data.ReadInt32(out.inputOption);
return data.ReadInt32(out.inputPattern) && data.ReadInt32(out.enterKeyType) &&
data.ReadInt32(out.inputOption) && data.ReadString(out.bundleName);
}
bool GetSecurityFlag() const

View File

@ -294,6 +294,7 @@ int32_t InputMethodSystemAbility::StartInput(InputClientInfo &inputClientInfo, s
return ret;
}
}
inputClientInfo.config.inputAttribute.bundleName = identityChecker_->GetBundleNameByToken(tokenId);
int32_t ret = PrepareInput(userId, inputClientInfo);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to PrepareInput!");

View File

@ -261,6 +261,22 @@ HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
EXPECT_TRUE(outAttribute.GetSecurityFlag());
}
/**
* @tc.name: testSerializedInputAttribute
* @tc.desc: Checkout the serialization of InputAttribute.
* @tc.type: FUNC
*/
HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute_WithSpecificBundleName, TestSize.Level0)
{
InputAttribute inAttribute;
inAttribute.bundleName = "com.example.inputmethod";
MessageParcel data;
EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data));
InputAttribute outAttribute;
EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data));
EXPECT_EQ(inAttribute.bundleName, outAttribute.bundleName);
}
/**
* @tc.name: testShowKeyboardInputMethodCoreProxy
* @tc.desc: Test InputMethodCoreProxy ShowKeyboard

View File

@ -160,6 +160,48 @@ HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttribute, TestSize.Level
EXPECT_TRUE(ret);
}
/**
* @tc.name: testMarshallAndUnMarshallInputAttributeSuccess
* @tc.desc: IMA
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttributeSuccess_WithBundleName, TestSize.Level0)
{
IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputAttributeSuccess Test START");
MessageParcel data;
InputAttribute attrIn { .bundleName = "MyBundleName" };
auto ret = ITypesUtil::Marshalling(attrIn, data);
EXPECT_TRUE(ret);
InputAttribute attrOut;
ret = ITypesUtil::Unmarshalling(attrOut, data);
EXPECT_TRUE(ret);
EXPECT_EQ(attrIn, attrOut);
EXPECT_EQ(attrIn.bundleName, attrOut.bundleName);
}
/**
* @tc.name: testMarshallAndUnMarshallInputAttributeSuccess
* @tc.desc: IMA
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttribute_WithEmptyBundleName, TestSize.Level0)
{
IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputAttributeSuccess Test START");
MessageParcel data;
InputAttribute attrIn { .bundleName = "" };
auto ret = ITypesUtil::Marshalling(attrIn, data);
EXPECT_TRUE(ret);
InputAttribute attrOut;
ret = ITypesUtil::Unmarshalling(attrOut, data);
EXPECT_TRUE(ret);
EXPECT_EQ(attrIn, attrOut);
EXPECT_EQ(attrIn.bundleName, attrOut.bundleName);
}
/**
* @tc.name: testMarshallAndUnMarshallTextTotalConfig
* @tc.desc: IMA