Merge branch 'master' of gitee.com:openharmony/inputmethod_imf into master

Signed-off-by: 赵凌岚 <zhaolinglan@huawei.com>
This commit is contained in:
赵凌岚 2023-10-25 01:44:56 +00:00 committed by Gitee
commit 6a9baf2e09
32 changed files with 184 additions and 339 deletions

View File

@ -21,6 +21,7 @@
#include "i_input_data_channel.h"
#include "input_attribute.h"
#include "input_channel.h"
#include "input_client_info.h"
#include "input_method_property.h"
#include "input_panel_info.h"
#include "ipc_types.h"
@ -48,8 +49,7 @@ public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodCore");
virtual int32_t StartInput(
const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard) = 0;
virtual int32_t StartInput(const std::shared_ptr<InputClientInfo> &clientInfo, bool isBindFromClient) = 0;
virtual int32_t StopInput(const sptr<IInputDataChannel> &channel) = 0;
virtual int32_t ShowKeyboard() = 0;
virtual int32_t HideKeyboard() = 0;

View File

@ -55,7 +55,7 @@ public:
int32_t DeleteForward(int32_t length);
int32_t DeleteBackward(int32_t length);
int32_t HideKeyboardSelf();
int32_t StartInput(const sptr<IRemoteObject> &channelObject, bool isShowKeyboard);
int32_t StartInput(InputClientInfo &clientInfo, bool isBindFromClient);
int32_t StopInput(const sptr<IRemoteObject> &channelObject);
int32_t ShowKeyboard();
int32_t HideKeyboard();

View File

@ -35,7 +35,7 @@ public:
DISALLOW_COPY_AND_MOVE(InputMethodCoreProxy);
int32_t StartInput(const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard) override;
int32_t StartInput(const std::shared_ptr<InputClientInfo> &clientInfo, bool isBindFromClient) override;
int32_t StopInput(const sptr<IInputDataChannel> &channel) override;
int32_t ShowKeyboard() override;
int32_t HideKeyboard() override;

View File

@ -39,7 +39,7 @@ public:
InputMethodCoreStub();
virtual ~InputMethodCoreStub();
int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
int32_t StartInput(const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard) override;
int32_t StartInput(const std::shared_ptr<InputClientInfo> &clientInfo, bool isBindFromClient) override;
int32_t StopInput(const sptr<IInputDataChannel> &channel) override;
int32_t ShowKeyboard() override;
int32_t HideKeyboard() override;

View File

@ -233,21 +233,21 @@ void InputMethodAbility::OnInitInputControlChannel(Message *msg)
SetInputControlChannel(channelObject);
}
int32_t InputMethodAbility::StartInput(const sptr<IRemoteObject> &channelObject, bool isShowKeyboard)
int32_t InputMethodAbility::StartInput(InputClientInfo &clientInfo, bool isBindFromClient)
{
IMSA_HILOGI("InputMethodAbility::isShowKeyboard: %{public}d", isShowKeyboard);
if (channelObject == nullptr) {
IMSA_HILOGI("InputMethodAbility::isShowKeyboard: %{public}d", clientInfo.isShowKeyboard);
if (clientInfo.channel->AsObject() == nullptr) {
IMSA_HILOGE("InputMethodAbility::channelObject is nullptr");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
SetInputDataChannel(channelObject);
NotifyAllTextConfig();
SetInputDataChannel(clientInfo.channel->AsObject());
isBindFromClient ? OnTextConfigChange(clientInfo.config) : NotifyAllTextConfig();
if (imeListener_ == nullptr) {
IMSA_HILOGE("InputMethodAbility, imeListener is nullptr");
return ErrorCode::ERROR_IME;
}
imeListener_->OnInputStart();
return isShowKeyboard ? ShowKeyboard() : ErrorCode::NO_ERROR;
return clientInfo.isShowKeyboard ? ShowKeyboard() : ErrorCode::NO_ERROR;
}
void InputMethodAbility::OnSetSubtype(Message *msg)

View File

@ -38,11 +38,12 @@ int32_t InputMethodCoreProxy::InitInputControlChannel(const sptr<IInputControlCh
});
}
int32_t InputMethodCoreProxy::StartInput(const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard)
int32_t InputMethodCoreProxy::StartInput(
const std::shared_ptr<InputClientInfo> &clientInfo, bool isBindFromClient)
{
IMSA_HILOGD("InputMethodCoreProxy::StartInput");
return SendRequest(START_INPUT, [&inputDataChannel, isShowKeyboard](MessageParcel &data) {
return ITypesUtil::Marshal(data, inputDataChannel->AsObject(), isShowKeyboard);
return SendRequest(START_INPUT, [&clientInfo, isBindFromClient](MessageParcel &data) {
return ITypesUtil::Marshal(data, isBindFromClient, *clientInfo);
});
}

View File

@ -153,13 +153,13 @@ void InputMethodCoreStub::InitInputControlChannelOnRemote(MessageParcel &data, M
int32_t InputMethodCoreStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
{
IMSA_HILOGD("InputMethodCoreStub::StartInputOnRemote");
sptr<IRemoteObject> channel;
bool isShowKeyboard = false;
if (!ITypesUtil::Unmarshal(data, channel, isShowKeyboard)) {
bool isBindFromClient = false;
InputClientInfo clientInfo = {};
if (!ITypesUtil::Unmarshal(data, isBindFromClient, clientInfo)) {
IMSA_HILOGE("Unmarshal failed.");
return ErrorCode::ERROR_EX_PARCELABLE;
}
auto ret = InputMethodAbility::GetInstance()->StartInput(channel, isShowKeyboard);
auto ret = InputMethodAbility::GetInstance()->StartInput(clientInfo, isBindFromClient);
return ITypesUtil::Marshal(reply, ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
@ -211,7 +211,8 @@ int32_t InputMethodCoreStub::IsPanelShownOnRemote(MessageParcel &data, MessagePa
return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodCoreStub::StartInput(const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard)
int32_t InputMethodCoreStub::StartInput(const std::shared_ptr<InputClientInfo> &clientInfo, bool isBindFromClient)
{
return ErrorCode::NO_ERROR;
}

View File

@ -32,6 +32,7 @@ struct InputClientInfo {
int32_t userID{ 0 }; // user id of input client
bool isShowKeyboard{ false }; // soft keyboard status
ImeType bindImeType{ ImeType::NONE }; // type of the ime client bind
TextTotalConfig config = {}; // text config
uint32_t eventFlag{ EventStatusManager::NO_EVENT_ON }; // the flag of the all listen event
InputAttribute attribute; // the input client attribute
sptr<IInputClient> client{ nullptr }; // the remote object handler for service to callback input client

View File

@ -55,6 +55,7 @@ private:
static inline BrokerDelegator<InputDataChannelProxy> delegator_;
using ParcelHandler = std::function<bool(MessageParcel &)>;
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr);
void GetMessageOption(int32_t code, MessageOption &option);
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -44,8 +44,7 @@ public:
~InputMethodSystemAbilityProxy() = default;
DISALLOW_COPY_AND_MOVE(InputMethodSystemAbilityProxy);
int32_t PrepareInput(InputClientInfo &inputClientInfo) override;
int32_t StartInput(sptr<IInputClient> client, bool isShowKeyboard) override;
int32_t StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent) override;
int32_t ShowCurrentInput() override;
int32_t HideCurrentInput() override;
int32_t StopInputSession() override;
@ -80,6 +79,7 @@ private:
static inline BrokerDelegator<InputMethodSystemAbilityProxy> delegator_;
using ParcelHandler = std::function<bool(MessageParcel &)>;
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr);
void GetMessageOption(int32_t code, MessageOption &option);
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -18,7 +18,6 @@
#include "global.h"
#include "ipc_types.h"
#include "itypes_util.h"
#include "itypes_util.h"
#include "message_option.h"
#include "message_parcel.h"
@ -31,14 +30,12 @@ InputDataChannelProxy::InputDataChannelProxy(const sptr<IRemoteObject> &object)
int32_t InputDataChannelProxy::InsertText(const std::u16string &text)
{
return SendRequest(
INSERT_TEXT, [&text](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, text); });
return SendRequest(INSERT_TEXT, [&text](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, text); });
}
int32_t InputDataChannelProxy::DeleteForward(int32_t length)
{
return SendRequest(
DELETE_FORWARD, [length](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, length); });
return SendRequest(DELETE_FORWARD, [length](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, length); });
}
int32_t InputDataChannelProxy::DeleteBackward(int32_t length)
@ -51,20 +48,19 @@ int32_t InputDataChannelProxy::GetTextBeforeCursor(int32_t number, std::u16strin
{
return SendRequest(
GET_TEXT_BEFORE_CURSOR, [number](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, number); },
[&text](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, text);});
[&text](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, text); });
}
int32_t InputDataChannelProxy::GetTextAfterCursor(int32_t number, std::u16string &text)
{
return SendRequest(
GET_TEXT_AFTER_CURSOR, [number](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, number); },
[&text](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, text);});
[&text](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, text); });
}
void InputDataChannelProxy::SendKeyboardStatus(int32_t status)
{
SendRequest(
SEND_KEYBOARD_STATUS, [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, status); });
SendRequest(SEND_KEYBOARD_STATUS, [status](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, status); });
}
int32_t InputDataChannelProxy::SendFunctionKey(int32_t funcKey)
@ -75,36 +71,31 @@ int32_t InputDataChannelProxy::SendFunctionKey(int32_t funcKey)
int32_t InputDataChannelProxy::MoveCursor(int32_t keyCode)
{
return SendRequest(
MOVE_CURSOR, [keyCode](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, keyCode); });
return SendRequest(MOVE_CURSOR, [keyCode](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, keyCode); });
}
int32_t InputDataChannelProxy::GetEnterKeyType(int32_t &keyType)
{
return SendRequest(
GET_ENTER_KEY_TYPE, nullptr,
[&keyType](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, keyType);});
return SendRequest(GET_ENTER_KEY_TYPE, nullptr,
[&keyType](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, keyType); });
}
int32_t InputDataChannelProxy::GetInputPattern(int32_t &inputPattern)
{
return SendRequest(
GET_INPUT_PATTERN, nullptr,
[&inputPattern](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, inputPattern);});
return SendRequest(GET_INPUT_PATTERN, nullptr,
[&inputPattern](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, inputPattern); });
}
int32_t InputDataChannelProxy::GetTextIndexAtCursor(int32_t &index)
{
return SendRequest(
GET_TEXT_INDEX_AT_CURSOR, nullptr,
[&index](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, index);});
return SendRequest(GET_TEXT_INDEX_AT_CURSOR, nullptr,
[&index](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, index); });
}
int32_t InputDataChannelProxy::GetTextConfig(TextTotalConfig &textConfig)
{
return SendRequest(GET_TEXT_CONFIG, nullptr, [&textConfig](MessageParcel &parcel) {
return ITypesUtil::Unmarshal(parcel, textConfig);
});
return SendRequest(GET_TEXT_CONFIG, nullptr,
[&textConfig](MessageParcel &parcel) { return ITypesUtil::Unmarshal(parcel, textConfig); });
}
int32_t InputDataChannelProxy::SelectByRange(int32_t start, int32_t end)
@ -126,12 +117,28 @@ int32_t InputDataChannelProxy::HandleExtendAction(int32_t action)
HANDLE_EXTEND_ACTION, [action](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, action); });
}
void InputDataChannelProxy::GetMessageOption(int32_t code, MessageOption &option)
{
switch (code) {
case SEND_KEYBOARD_STATUS:
IMSA_HILOGD("Async IPC.");
option.SetFlags(MessageOption::TF_ASYNC);
break;
default:
option.SetFlags(MessageOption::TF_SYNC);
break;
}
}
int32_t InputDataChannelProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)
{
IMSA_HILOGI("InputDataChannelProxy run in, code = %{public}d", code);
MessageParcel data;
MessageParcel reply;
MessageOption option{ MessageOption::TF_SYNC };
MessageOption option;
GetMessageOption(code, option);
if (!data.WriteInterfaceToken(GetDescriptor())) {
IMSA_HILOGE("write interface token failed");
return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
@ -145,6 +152,9 @@ int32_t InputDataChannelProxy::SendRequest(int code, ParcelHandler input, Parcel
IMSA_HILOGE("InputDataChannelProxy send request failed, code: %{public}d ret %{public}d", code, ret);
return ret;
}
if (option.GetFlags() == MessageOption::TF_ASYNC) {
return ErrorCode::NO_ERROR;
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGE("reply error, ret %{public}d", ret);

View File

@ -235,22 +235,19 @@ int32_t InputMethodController::Attach(
SetTextListener(listener);
clientInfo_.isShowKeyboard = isShowKeyboard;
SaveTextConfig(textConfig);
GetTextConfig(clientInfo_.config);
int32_t ret = PrepareInput(clientInfo_);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to prepare, ret: %{public}d", ret);
return ret;
}
ret = StartInput(clientInfo_.client, isShowKeyboard);
sptr<IRemoteObject> agent = nullptr;
int32_t ret = StartInput(clientInfo_, agent);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to start input, ret:%{public}d", ret);
return ret;
}
IMSA_HILOGI("bind imf successfully, enter editable state");
OnInputReady(agent);
if (isShowKeyboard) {
InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_SHOW_ATTACH);
}
IMSA_HILOGI("bind imf successfully, enter editable state");
return ErrorCode::NO_ERROR;
}
@ -329,17 +326,6 @@ int32_t InputMethodController::Close()
return ReleaseInput(clientInfo_.client);
}
int32_t InputMethodController::PrepareInput(InputClientInfo &inputClientInfo)
{
IMSA_HILOGI("InputMethodController::PrepareInput");
auto proxy = GetSystemAbilityProxy();
if (proxy == nullptr) {
IMSA_HILOGE("proxy is nullptr");
return ErrorCode::ERROR_SERVICE_START_FAILED;
}
return proxy->PrepareInput(inputClientInfo);
}
int32_t InputMethodController::DisplayOptionalInputMethod()
{
IMSA_HILOGI("InputMethodController::DisplayOptionalInputMethod");
@ -433,7 +419,7 @@ std::shared_ptr<SubProperty> InputMethodController::GetCurrentInputMethodSubtype
return property;
}
int32_t InputMethodController::StartInput(sptr<IInputClient> &client, bool isShowKeyboard)
int32_t InputMethodController::StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent)
{
IMSA_HILOGI("InputMethodController::StartInput");
auto proxy = GetSystemAbilityProxy();
@ -441,7 +427,7 @@ int32_t InputMethodController::StartInput(sptr<IInputClient> &client, bool isSho
IMSA_HILOGE("proxy is nullptr");
return ErrorCode::ERROR_SERVICE_START_FAILED;
}
return proxy->StartInput(client, isShowKeyboard);
return proxy->StartInput(inputClientInfo, agent);
}
int32_t InputMethodController::ReleaseInput(sptr<IInputClient> &client)
@ -452,7 +438,11 @@ int32_t InputMethodController::ReleaseInput(sptr<IInputClient> &client)
IMSA_HILOGE("proxy is nullptr");
return ErrorCode::ERROR_SERVICE_START_FAILED;
}
return proxy->ReleaseInput(client);
int32_t ret = proxy->ReleaseInput(client);
if (ret == ErrorCode::NO_ERROR) {
OnInputStop();
}
return ret;
}
int32_t InputMethodController::ShowInput(sptr<IInputClient> &client)

View File

@ -30,19 +30,14 @@ InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr<IRemoteO
{
}
int32_t InputMethodSystemAbilityProxy::PrepareInput(InputClientInfo &inputClientInfo)
int32_t InputMethodSystemAbilityProxy::StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent)
{
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT), [&inputClientInfo](MessageParcel &data) {
return ITypesUtil::Marshal(data, inputClientInfo);
});
}
int32_t InputMethodSystemAbilityProxy::StartInput(sptr<IInputClient> client, bool isShowKeyboard)
{
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT), [isShowKeyboard, client](MessageParcel &data) {
return data.WriteRemoteObject(client->AsObject()) && data.WriteBool(isShowKeyboard);
static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT),
[&inputClientInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, inputClientInfo); },
[&agent](MessageParcel &reply) {
agent = reply.ReadRemoteObject();
return true;
});
}
@ -75,9 +70,8 @@ int32_t InputMethodSystemAbilityProxy::HideInput(sptr<IInputClient> client)
int32_t InputMethodSystemAbilityProxy::ReleaseInput(sptr<IInputClient> client)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT), [client](MessageParcel &data) {
return data.WriteRemoteObject(client->AsObject());
});
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT),
[client](MessageParcel &data) { return data.WriteRemoteObject(client->AsObject()); });
}
int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethod()
@ -145,12 +139,8 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethod(InputMethodStatus status,
{
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD),
[status](MessageParcel &data) {
return ITypesUtil::Marshal(data, uint32_t(status));
},
[&props](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, props);
});
[status](MessageParcel &data) { return ITypesUtil::Marshal(data, uint32_t(status)); },
[&props](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, props); });
}
int32_t InputMethodSystemAbilityProxy::ShowCurrentInputDeprecated()
@ -173,46 +163,35 @@ int32_t InputMethodSystemAbilityProxy::ListInputMethodSubtype(
{
return SendRequest(
static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE),
[&name](MessageParcel &data) {
return ITypesUtil::Marshal(data, name);
},
[&subProps](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, subProps);
});
[&name](MessageParcel &data) { return ITypesUtil::Marshal(data, name); },
[&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); });
}
int32_t InputMethodSystemAbilityProxy::ListCurrentInputMethodSubtype(std::vector<SubProperty> &subProps)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE), nullptr,
[&subProps](MessageParcel &reply) {
return ITypesUtil::Unmarshal(reply, subProps);
});
[&subProps](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, subProps); });
}
int32_t InputMethodSystemAbilityProxy::SwitchInputMethod(const std::string& name,
const std::string& subName)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD),
[&name, &subName](MessageParcel& data) {
return ITypesUtil::Marshal(data, name, subName);
});
[&name, &subName](MessageParcel &data) { return ITypesUtil::Marshal(data, name, subName); });
}
int32_t InputMethodSystemAbilityProxy::PanelStatusChange(
const InputWindowStatus &status, const InputWindowInfo &windowInfo)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE),
[status, windowInfo](MessageParcel &data) {
return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), windowInfo);
});
[status, windowInfo](
MessageParcel &data) { return ITypesUtil::Marshal(data, static_cast<uint32_t>(status), windowInfo); });
}
int32_t InputMethodSystemAbilityProxy::UpdateListenEventFlag(InputClientInfo &clientInfo, EventType eventType)
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG),
[&clientInfo, eventType](MessageParcel &data) {
return ITypesUtil::Marshal(data, clientInfo, eventType);
});
[&clientInfo, eventType](MessageParcel &data) { return ITypesUtil::Marshal(data, clientInfo, eventType); });
}
bool InputMethodSystemAbilityProxy::IsCurrentIme()
@ -252,12 +231,28 @@ int32_t InputMethodSystemAbilityProxy::IsPanelShown(const PanelInfo &panelInfo,
[&isShown](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isShown); });
}
void InputMethodSystemAbilityProxy::GetMessageOption(int32_t code, MessageOption &option)
{
switch (code) {
case static_cast<int32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE): {
IMSA_HILOGD("Async IPC.");
option.SetFlags(MessageOption::TF_ASYNC);
break;
}
default:
option.SetFlags(MessageOption::TF_SYNC);
break;
}
}
int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)
{
IMSA_HILOGI("InputMethodSystemAbilityProxy run in, code = %{public}d", code);
MessageParcel data;
MessageParcel reply;
MessageOption option{ MessageOption::TF_SYNC };
MessageOption option;
GetMessageOption(code, option);
if (!data.WriteInterfaceToken(GetDescriptor())) {
IMSA_HILOGE("write interface token failed");
return ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT;
@ -271,6 +266,9 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input
IMSA_HILOGE("transport exceptions, code: %{public}d, ret %{public}d", code, ret);
return ret;
}
if (option.GetFlags() == MessageOption::TF_ASYNC) {
return ErrorCode::NO_ERROR;
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGE("dispose failed in service, code: %{public}d, ret: %{public}d", code, ret);

View File

@ -226,7 +226,7 @@ bool ITypesUtil::Unmarshalling(TextTotalConfig &output, MessageParcel &data)
bool ITypesUtil::Marshalling(const InputClientInfo &input, MessageParcel &data)
{
if (!Marshal(data, input.pid, input.uid, input.userID, input.isShowKeyboard, input.eventFlag,
if (!Marshal(data, input.pid, input.uid, input.userID, input.isShowKeyboard, input.eventFlag, input.config,
input.client->AsObject(), input.channel->AsObject())) {
IMSA_HILOGE("write InputClientInfo to message parcel failed");
return false;
@ -236,7 +236,8 @@ bool ITypesUtil::Marshalling(const InputClientInfo &input, MessageParcel &data)
bool ITypesUtil::Unmarshalling(InputClientInfo &output, MessageParcel &data)
{
if (!Unmarshal(data, output.pid, output.uid, output.userID, output.isShowKeyboard, output.eventFlag)) {
if (!Unmarshal(
data, output.pid, output.uid, output.userID, output.isShowKeyboard, output.eventFlag, output.config)) {
IMSA_HILOGE("read InputClientInfo from message parcel failed");
return false;
}

View File

@ -660,8 +660,7 @@ private:
int32_t Initialize();
sptr<IInputMethodSystemAbility> GetSystemAbilityProxy();
int32_t PrepareInput(InputClientInfo &inputClientInfo);
int32_t StartInput(sptr<IInputClient> &client, bool isShowKeyboard);
int32_t StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent);
int32_t ShowInput(sptr<IInputClient> &client);
int32_t HideInput(sptr<IInputClient> &client);
int32_t ReleaseInput(sptr<IInputClient> &client);

View File

@ -43,8 +43,7 @@ class IInputMethodSystemAbility : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility");
virtual int32_t PrepareInput(InputClientInfo &clientInfo) = 0;
virtual int32_t StartInput(sptr<IInputClient> client, bool isShowKeyboard) = 0;
virtual int32_t StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent) = 0;
virtual int32_t ShowCurrentInput() = 0;
virtual int32_t HideCurrentInput() = 0;
virtual int32_t StopInputSession() = 0;

View File

@ -33,8 +33,8 @@
#include "inputmethod_dump.h"
#include "inputmethod_trace.h"
#include "peruser_session.h"
#include "unRegistered_type.h"
#include "system_ability.h"
#include "unRegistered_type.h"
namespace OHOS {
namespace MiscServices {
@ -51,8 +51,7 @@ public:
InputMethodSystemAbility();
~InputMethodSystemAbility();
int32_t PrepareInput(InputClientInfo &clientInfo) override;
int32_t StartInput(sptr<IInputClient> client, bool isShowKeyboard) override;
int32_t StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent) override;
int32_t ShowCurrentInput() override;
int32_t HideCurrentInput() override;
int32_t ShowInput(sptr<IInputClient> client) override;
@ -96,6 +95,7 @@ private:
std::thread workThreadHandler; /*!< thread handler of the WorkThread */
std::shared_ptr<PerUserSession> userSession_ = nullptr;
std::shared_ptr<IdentityChecker> identityChecker_ = nullptr;
int32_t PrepareInput(InputClientInfo &clientInfo);
void WorkThread();
bool StartInputService(const std::string &imeId);
int32_t OnUserStarted(const Message *msg);

View File

@ -31,8 +31,6 @@ public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int32_t PrepareInputOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply);
@ -92,8 +90,6 @@ private:
using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &);
static constexpr RequestHandler HANDLERS[static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_LAST)] = {
[static_cast<uint32_t>(InputMethodInterfaceCode::PREPARE_INPUT)] =
&InputMethodSystemAbilityStub::PrepareInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT)] =
&InputMethodSystemAbilityStub::StartInputOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT)] =

View File

@ -20,8 +20,7 @@
namespace OHOS {
namespace MiscServices {
enum class InputMethodInterfaceCode {
PREPARE_INPUT = 0,
START_INPUT,
START_INPUT = 0,
SHOW_CURRENT_INPUT,
HIDE_CURRENT_INPUT,
SHOW_INPUT,

View File

@ -68,7 +68,7 @@ public:
~PerUserSession();
int32_t OnPrepareInput(const InputClientInfo &clientInfo);
int32_t OnStartInput(const sptr<IInputClient> &client, bool isShowKeyboard);
int32_t OnStartInput(const sptr<IInputClient> &client, bool isShowKeyboard, sptr<IRemoteObject> &agent);
int32_t OnReleaseInput(const sptr<IInputClient> &client);
int32_t OnSetCoreAndAgent(const sptr<IInputMethodCore> &core, const sptr<IInputMethodAgent> &agent);
int32_t OnHideCurrentInput();
@ -129,11 +129,13 @@ private:
std::shared_ptr<ImeData> GetImeData(ImeType type);
void RemoveImeData(ImeType type);
int32_t RemoveClient(const sptr<IInputClient> &client);
int32_t RemoveClient(const sptr<IInputClient> &client, bool isUnbindFromClient = false);
int32_t RemoveIme(const sptr<IInputMethodCore> &core, ImeType type);
int32_t BindClientWithIme(const std::shared_ptr<InputClientInfo> &clientInfo, ImeType type);
void UnBindClientWithIme(const std::shared_ptr<InputClientInfo> &currentClientInfo);
int32_t BindClientWithIme(
const std::shared_ptr<InputClientInfo> &clientInfo, ImeType type, bool isBindFromClient = false);
void UnBindClientWithIme(
const std::shared_ptr<InputClientInfo> &currentClientInfo, bool isUnbindFromClient = false);
void StopClientInput(const sptr<IInputClient> &currentClient);
void StopImeInput(ImeType currentType, const sptr<IInputDataChannel> &currentChannel);

View File

@ -204,12 +204,6 @@ bool InputMethodSystemAbility::StartInputService(const std::string &imeId)
int32_t InputMethodSystemAbility::PrepareInput(InputClientInfo &clientInfo)
{
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
if (!identityChecker_->IsBroker(tokenId)) {
if (!identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId)) {
return ErrorCode::ERROR_CLIENT_NOT_FOCUSED;
}
}
auto ret = GenerateClientInfo(clientInfo);
if (ret != ErrorCode::NO_ERROR) {
return ret;
@ -243,7 +237,7 @@ int32_t InputMethodSystemAbility::ReleaseInput(sptr<IInputClient> client)
return userSession_->OnReleaseInput(client);
};
int32_t InputMethodSystemAbility::StartInput(sptr<IInputClient> client, bool isShowKeyboard)
int32_t InputMethodSystemAbility::StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent)
{
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
if (!identityChecker_->IsBroker(tokenId)) {
@ -251,11 +245,13 @@ int32_t InputMethodSystemAbility::StartInput(sptr<IInputClient> client, bool isS
return ErrorCode::ERROR_CLIENT_NOT_FOCUSED;
}
}
if (client == nullptr) {
IMSA_HILOGE("InputMethodSystemAbility::client is nullptr");
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
int32_t ret = PrepareInput(inputClientInfo);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("PrepareInput failed");
return ret;
}
return userSession_->OnStartInput(client, isShowKeyboard);
return userSession_->OnStartInput(inputClientInfo.client, inputClientInfo.isShowKeyboard, agent);
};
int32_t InputMethodSystemAbility::ShowInput(sptr<IInputClient> client)
@ -947,7 +943,7 @@ int32_t InputMethodSystemAbility::UnRegisteredProxyIme(UnRegisteredType type, co
return userSession_->OnUnRegisteredProxyIme(type, core);
}
bool InputMethodSystemAbility::IsSwitchPermitted(const SwitchInfo& switchInfo)
bool InputMethodSystemAbility::IsSwitchPermitted(const SwitchInfo &switchInfo)
{
auto currentBundleName = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName;
// if currentIme is switching subtype, permission verification is not performed.
@ -956,8 +952,8 @@ bool InputMethodSystemAbility::IsSwitchPermitted(const SwitchInfo& switchInfo)
!switchInfo.subName.empty())) {
return true;
}
InputMethodSysEvent::GetInstance().InputmethodFaultReporter(ErrorCode::ERROR_STATUS_PERMISSION_DENIED,
switchInfo.bundleName, "switch inputmethod failed!");
InputMethodSysEvent::GetInstance().InputmethodFaultReporter(
ErrorCode::ERROR_STATUS_PERMISSION_DENIED, switchInfo.bundleName, "switch inputmethod failed!");
IMSA_HILOGE("not permitted");
return false;
}

View File

@ -45,27 +45,17 @@ int32_t InputMethodSystemAbilityStub::OnRemoteRequest(
}
}
int32_t InputMethodSystemAbilityStub::PrepareInputOnRemote(MessageParcel &data, MessageParcel &reply)
int32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
{
InputClientInfo clientInfo;
if (!ITypesUtil::Unmarshal(data, clientInfo)) {
IMSA_HILOGE("read clientInfo failed");
return ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t ret = PrepareInput(clientInfo);
return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodSystemAbilityStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply)
{
auto clientObject = data.ReadRemoteObject();
if (clientObject == nullptr) {
IMSA_HILOGE("clientObject is nullptr");
return ErrorCode::ERROR_EX_PARCELABLE;
}
bool isShowKeyboard = data.ReadBool();
int32_t ret = StartInput(iface_cast<IInputClient>(clientObject), isShowKeyboard);
return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
sptr<IRemoteObject> agent = nullptr;
int32_t ret = StartInput(clientInfo, agent);
return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
: ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodSystemAbilityStub::ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply)

View File

@ -328,17 +328,17 @@ int32_t PerUserSession::OnPrepareInput(const InputClientInfo &clientInfo)
int32_t PerUserSession::OnReleaseInput(const sptr<IInputClient> &client)
{
IMSA_HILOGI("PerUserSession::Start");
return RemoveClient(client);
return RemoveClient(client, true);
}
int32_t PerUserSession::RemoveClient(const sptr<IInputClient> &client)
int32_t PerUserSession::RemoveClient(const sptr<IInputClient> &client, bool isUnbindFromClient)
{
if (client == nullptr) {
return ErrorCode::ERROR_CLIENT_NULL_POINTER;
}
// if client is current client, unbind firstly
if (IsCurrentClient(client)) {
UnBindClientWithIme(GetClientInfo(client->AsObject()));
UnBindClientWithIme(GetClientInfo(client->AsObject()), isUnbindFromClient);
SetCurrentClient(nullptr);
ExitCurrentInputType();
}
@ -358,7 +358,7 @@ bool PerUserSession::IsProxyImeEnable()
return data != nullptr && data->core != nullptr && data->core->IsEnable();
}
int32_t PerUserSession::OnStartInput(const sptr<IInputClient> &client, bool isShowKeyboard)
int32_t PerUserSession::OnStartInput(const sptr<IInputClient> &client, bool isShowKeyboard, sptr<IRemoteObject> &agent)
{
IMSA_HILOGD("start input with keyboard[%{public}d]", isShowKeyboard);
if (client == nullptr) {
@ -377,10 +377,16 @@ int32_t PerUserSession::OnStartInput(const sptr<IInputClient> &client, bool isSh
}
InputClientInfo infoTemp = { .client = client, .channel = clientInfo->channel, .isShowKeyboard = isShowKeyboard };
auto imeType = IsProxyImeEnable() ? ImeType::PROXY_IME : ImeType::IME;
return BindClientWithIme(std::make_shared<InputClientInfo>(infoTemp), imeType);
int32_t ret = BindClientWithIme(std::make_shared<InputClientInfo>(infoTemp), imeType, true);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("start client input failed, ret: %{public}d", ret);
}
agent = GetImeData(imeType)->agent->AsObject();
return ret;
}
int32_t PerUserSession::BindClientWithIme(const std::shared_ptr<InputClientInfo> &clientInfo, ImeType type)
int32_t PerUserSession::BindClientWithIme(
const std::shared_ptr<InputClientInfo> &clientInfo, ImeType type, bool isBindFromClient)
{
if (clientInfo == nullptr) {
IMSA_HILOGE("clientInfo is nullptr");
@ -400,15 +406,14 @@ int32_t PerUserSession::BindClientWithIme(const std::shared_ptr<InputClientInfo>
IMSA_HILOGE("ime: %{public}d is abnormal", type);
return ErrorCode::ERROR_IME_NOT_STARTED;
}
auto ret = data->core->StartInput(clientInfo->channel, clientInfo->isShowKeyboard);
auto ret = data->core->StartInput(clientInfo, isBindFromClient);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("start client input failed, ret: %{public}d", ret);
return ErrorCode::ERROR_IME_START_INPUT_FAILED;
}
ret = clientInfo->client->OnInputReady(data->agent);
if (ret != ErrorCode::NO_ERROR) {
if (!isBindFromClient && clientInfo->client->OnInputReady(data->agent) != ErrorCode::NO_ERROR) {
IMSA_HILOGE("start client input failed, ret: %{public}d", ret);
return ret;
return ErrorCode::ERROR_EX_PARCELABLE;
}
UpdateClientInfo(clientInfo->client->AsObject(),
{ { UpdateFlag::BINDIMETYPE, type }, { UpdateFlag::ISSHOWKEYBOARD, clientInfo->isShowKeyboard } });
@ -416,12 +421,16 @@ int32_t PerUserSession::BindClientWithIme(const std::shared_ptr<InputClientInfo>
return ErrorCode::NO_ERROR;
}
void PerUserSession::UnBindClientWithIme(const std::shared_ptr<InputClientInfo> &currentClientInfo)
void PerUserSession::UnBindClientWithIme(
const std::shared_ptr<InputClientInfo> &currentClientInfo, bool isUnbindFromClient)
{
if (currentClientInfo == nullptr) {
return;
}
StopClientInput(currentClientInfo->client);
if (!isUnbindFromClient) {
IMSA_HILOGD("Unbind from service.");
StopClientInput(currentClientInfo->client);
}
StopImeInput(currentClientInfo->bindImeType, currentClientInfo->channel);
}

View File

@ -101,8 +101,9 @@ bool FuzzPerUserSession(const uint8_t *rawData, size_t size)
userSessions->OnPrepareInput(clientInfo);
userSessions->OnSetCoreAndAgent(core, agent);
userSessions->OnShowCurrentInput();
userSessions->OnStartInput(client, false);
userSessions->OnStartInput(client, true);
sptr<IRemoteObject> agentObject = nullptr;
userSessions->OnStartInput(client, false, agentObject);
userSessions->OnStartInput(client, true, agentObject);
userSessions->NotifyImeChangeToClients(property, subProperty);
userSessions->OnHideCurrentInput();
userSessions->OnHideInput(client);

View File

@ -30,7 +30,6 @@ group("system_ability_stub_fuzztest") {
":ListInputmethodFuzzTest",
":ListInputmethodSubtypeFuzzTest",
":PanelStatusChangeFuzzTest",
":PrepareInputFuzzTest",
":ReleaseInputFuzzTest",
":SetCoreAndAgentFuzzTest",
":ShowCurrentInputDeprecatedFuzzTest",
@ -215,23 +214,6 @@ ohos_fuzztest("PanelStatusChangeFuzzTest") {
external_deps = common_external_deps
}
ohos_fuzztest("PrepareInputFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/prepareinput_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/prepareinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "prepareinput_fuzzer/prepareinput_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("ReleaseInputFuzzTest") {
module_out_path = "imf/imf"

View File

@ -1,14 +0,0 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FUZZ

View File

@ -1,30 +0,0 @@
/*
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "prepareinput_fuzzer.h"
#include "imf_sa_stub_fuzz_util.h"
#include "inputmethod_service_ipc_interface_code.h"
using namespace OHOS::MiscServices;
namespace OHOS {
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
/* Run your code on data */
ImfSaStubFuzzUtil::FuzzInputMethodSystemAbility(data, size, InputMethodInterfaceCode::PREPARE_INPUT);
return 0;
}

View File

@ -1,21 +0,0 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_PREPAREINPUT_FUZZER_H
#define TEST_FUZZTEST_PREPAREINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "prepareinput_fuzzer"
#endif // TEST_FUZZTEST_PREPAREINPUT_FUZZER_H

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<fuzz_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>

View File

@ -110,57 +110,6 @@ HWTEST_F(IdentityCheckerTest, testPrepareInput_001, TestSize.Level0)
IMSA_HILOGI("service_ is nullptr");
}
int32_t ret = IdentityCheckerTest::service_->PrepareInput(clientInfo);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
}
/**
* @tc.name: testPrepareInput_002
* @tc.desc: is broker, not focused app
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(IdentityCheckerTest, testPrepareInput_002, TestSize.Level0)
{
IMSA_HILOGI("IdentityCheckerTest testPrepareInput_002 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(true));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).WillRepeatedly(Return(false));
InputClientInfo clientInfo{};
int32_t ret = IdentityCheckerTest::service_->PrepareInput(clientInfo);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
/**
* @tc.name: testPrepareInput_003
* @tc.desc: is broker, focused app
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(IdentityCheckerTest, testPrepareInput_003, TestSize.Level0)
{
IMSA_HILOGI("IdentityCheckerTest testPrepareInput_003 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(true));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).WillRepeatedly(Return(true));
InputClientInfo clientInfo{};
int32_t ret = IdentityCheckerTest::service_->PrepareInput(clientInfo);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
/**
* @tc.name: testPrepareInput_004
* @tc.desc: not broker, is focused app
* @tc.type: FUNC
* @tc.require:
* @tc.author:
*/
HWTEST_F(IdentityCheckerTest, testPrepareInput_004, TestSize.Level0)
{
IMSA_HILOGI("IdentityCheckerTest testPrepareInput_004 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(false));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).Times(1).WillRepeatedly(Return(true));
InputClientInfo clientInfo{};
int32_t ret = IdentityCheckerTest::service_->PrepareInput(clientInfo);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
@ -175,7 +124,9 @@ HWTEST_F(IdentityCheckerTest, testStartInput_001, TestSize.Level0)
{
IMSA_HILOGI("IdentityCheckerTest testStartInput_001 start");
service_->identityChecker_ = identityCheckerImpl_;
int32_t ret = IdentityCheckerTest::service_->StartInput(nullptr, false);
sptr<IRemoteObject> agent = nullptr;
InputClientInfo inputClientInfo;
int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
}
@ -191,8 +142,10 @@ HWTEST_F(IdentityCheckerTest, testStartInput_002, TestSize.Level0)
IMSA_HILOGI("IdentityCheckerTest testStartInput_002 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(true));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).WillRepeatedly(Return(false));
int32_t ret = IdentityCheckerTest::service_->StartInput(nullptr, false);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
sptr<IRemoteObject> agent = nullptr;
InputClientInfo inputClientInfo;
int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
/**
@ -207,9 +160,10 @@ HWTEST_F(IdentityCheckerTest, testStartInput_003, TestSize.Level0)
IMSA_HILOGI("IdentityCheckerTest testStartInput_003 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(true));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).WillRepeatedly(Return(true));
InputClientInfo clientInfo{};
int32_t ret = IdentityCheckerTest::service_->StartInput(nullptr, false);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
sptr<IRemoteObject> agent = nullptr;
InputClientInfo inputClientInfo;
int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
/**
@ -224,9 +178,10 @@ HWTEST_F(IdentityCheckerTest, testStartInput_004, TestSize.Level0)
IMSA_HILOGI("IdentityCheckerTest testStartInput_004 start");
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsBroker(_)).Times(1).WillRepeatedly(Return(false));
EXPECT_CALL(*IdentityCheckerTest::identityCheckerMock_, IsFocused(_, _, _)).Times(1).WillRepeatedly(Return(true));
InputClientInfo clientInfo{};
int32_t ret = IdentityCheckerTest::service_->StartInput(nullptr, false);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
sptr<IRemoteObject> agent = nullptr;
InputClientInfo inputClientInfo;
int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
/**

View File

@ -225,9 +225,12 @@ HWTEST_F(InputMethodAbilityTest, testStartInputWithoutPanel, TestSize.Level0)
IMSA_HILOGI("InputMethodAbilityTest testStartInputWithoutAttach start.");
inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
auto ret = inputMethodAbility_->StartInput(channelStub->AsObject(), false);
InputClientInfo clientInfo;
clientInfo.channel = channelStub;
auto ret = inputMethodAbility_->StartInput(clientInfo, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
ret = inputMethodAbility_->StartInput(channelStub->AsObject(), true);
clientInfo.isShowKeyboard = true;
ret = inputMethodAbility_->StartInput(clientInfo, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}

View File

@ -307,7 +307,8 @@ HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionParameterNullptr001, TestSi
{
IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr001 TEST START");
auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
int32_t ret = userSession->OnStartInput(nullptr, true);
sptr<IRemoteObject> agent = nullptr;
int32_t ret = userSession->OnStartInput(nullptr, true, agent);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
ret = userSession->OnReleaseInput(nullptr);
EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);