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

Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
cy7717 2024-07-22 08:08:57 +00:00
commit 5a6f2d13ae
74 changed files with 1484 additions and 174 deletions

View File

@ -16,11 +16,12 @@
"ohos.permission.GET_BUNDLE_INFO",
"ohos.permission.REPORT_RESOURCE_SCHEDULE_EVENT",
"ohos.permission.CONNECT_INPUT_METHOD_EXTENSION",
"ohos.permission.MANAGE_LOCAL_ACCOUNTS"
"ohos.permission.MANAGE_LOCAL_ACCOUNTS",
"ohos.permission.INPUT_PANEL_STATUS_PUBLISHER"
],
"permission_acls" : ["ohos.permission.INPUT_MONITORING"],
"caps" : [],
"secon" : "u:r:inputmethod_service:s0"
}
]
}
}

View File

@ -85,7 +85,7 @@ ohos_shared_library("inputmethodengine") {
"ffrt:libffrt",
"hilog:libhilog",
"input:libmmi-client",
"input:libmmi-util",
"input:libmmi-napi",
"ipc:ipc_core",
"napi:ace_napi",
"window_manager:libwm_lite",

View File

@ -874,7 +874,7 @@ napi_value JsTextInputClientEngine::SetPreviewText(napi_env env, napi_callback_i
int32_t code = InputMethodAbility::GetInstance()->SetPreviewText(ctxt->text, ctxt->range);
editorQueue_.Pop();
if (code == ErrorCode::NO_ERROR) {
IMSA_HILOGI("exec setPreviewText success");
IMSA_HILOGD("exec setPreviewText success");
ctxt->SetState(napi_ok);
} else if (code == ErrorCode::ERROR_INVALID_RANGE) {
ctxt->SetErrorCode(code);

View File

@ -42,6 +42,7 @@ napi_value JsKeyboardPanelManager::Init(napi_env env, napi_value info)
DECLARE_NAPI_FUNCTION("on", Subscribe),
DECLARE_NAPI_FUNCTION("off", UnSubscribe),
DECLARE_NAPI_FUNCTION("getDefaultInputMethod", GetDefaultInputMethod),
DECLARE_NAPI_FUNCTION("connectSystemCmd", ConnectSystemCmd),
};
NAPI_CALL(env,
napi_define_properties(env, info, sizeof(descriptor) / sizeof(napi_property_descriptor), descriptor));
@ -59,6 +60,33 @@ sptr<JsKeyboardPanelManager> JsKeyboardPanelManager::GetInstance()
return keyboardPanelManager_;
}
struct PanelManagerContext : public AsyncCall::Context {
PanelManagerContext() : Context(nullptr, nullptr){};
napi_status operator()(napi_env env, napi_value *result) override
{
if (status_ != napi_ok) {
output_ = nullptr;
return status_;
}
return Context::operator()(env, result);
}
};
napi_value JsKeyboardPanelManager::ConnectSystemCmd(napi_env env, napi_callback_info info)
{
auto ctxt = std::make_shared<PanelManagerContext>();
auto manager = JsKeyboardPanelManager::GetInstance();
auto exec = [ctxt, env, manager](AsyncCall::Context *ctx) {
auto ret = ImeSystemCmdChannel::GetInstance()->ConnectSystemCmd(manager);
ctxt->SetErrorCode(ret);
CHECK_RETURN_VOID(ret == ErrorCode::NO_ERROR, "ConnectSystemCmd return error!");
ctxt->SetState(napi_ok);
};
// 0 means JsAPI:ConnectSystemCmd has 0 params at most.
AsyncCall asyncCall(env, info, ctxt, 0);
return asyncCall.Call(env, exec, "ConnectSystemCmd");
}
napi_value JsKeyboardPanelManager::Subscribe(napi_env env, napi_callback_info info)
{
size_t argc = 2; // has 2 param
@ -75,11 +103,6 @@ napi_value JsKeyboardPanelManager::Subscribe(napi_env env, napi_callback_info in
return nullptr;
}
auto manager = JsKeyboardPanelManager::GetInstance();
auto ret = ImeSystemCmdChannel::GetInstance()->ConnectSystemCmd(manager);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("subscribe failed, type: %{public}s!", type.c_str());
return nullptr;
}
IMSA_HILOGD("subscribe type: %{public}s.", type.c_str());
std::shared_ptr<JSCallbackObject> callback =
std::make_shared<JSCallbackObject>(env, argv[1], std::this_thread::get_id());
@ -102,11 +125,6 @@ napi_value JsKeyboardPanelManager::UnSubscribe(napi_env env, napi_callback_info
return nullptr;
}
auto manager = JsKeyboardPanelManager::GetInstance();
auto ret = ImeSystemCmdChannel::GetInstance()->ConnectSystemCmd(manager);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("unsubscribe failed, type: %{public}s!", type.c_str());
return nullptr;
}
// if the second param is not napi_function/napi_null/napi_undefined, return
auto paramType = JsUtil::GetType(env, argv[1]);
if (paramType != napi_function && paramType != napi_null && paramType != napi_undefined) {

View File

@ -75,6 +75,7 @@ public:
static sptr<JsKeyboardPanelManager> GetInstance();
static napi_value SendPrivateCommand(napi_env env, napi_callback_info info);
static napi_value GetSmartMenuCfg(napi_env env, napi_callback_info info);
static napi_value ConnectSystemCmd(napi_env env, napi_callback_info info);
static napi_value Subscribe(napi_env env, napi_callback_info info);
static napi_value UnSubscribe(napi_env env, napi_callback_info info);
static napi_value GetDefaultInputMethod(napi_env env, napi_callback_info info);

View File

@ -51,6 +51,10 @@ public:
private:
MessageHandler *msgHandler_;
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
{
return ERR_UNKNOWN_TRANSACTION;
};
int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t StopInputOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply);
@ -66,19 +70,20 @@ private:
using ParcelHandler = std::function<bool(MessageParcel &)>;
int32_t SendMessage(int code, ParcelHandler input = nullptr);
using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(SHOW_KEYBOARD), &InputMethodCoreStub::ShowKeyboardOnRemote },
{ static_cast<uint32_t>(STOP_INPUT_SERVICE), &InputMethodCoreStub::StopInputServiceOnRemote },
{ static_cast<uint32_t>(HIDE_KEYBOARD), &InputMethodCoreStub::HideKeyboardOnRemote },
{ static_cast<uint32_t>(INIT_INPUT_CONTROL_CHANNEL), &InputMethodCoreStub::InitInputControlChannelOnRemote },
{ static_cast<uint32_t>(SET_SUBTYPE), &InputMethodCoreStub::SetSubtypeOnRemote },
{ static_cast<uint32_t>(START_INPUT), &InputMethodCoreStub::StartInputOnRemote },
{ static_cast<uint32_t>(STOP_INPUT), &InputMethodCoreStub::StopInputOnRemote },
{ static_cast<uint32_t>(IS_ENABLE), &InputMethodCoreStub::IsEnableOnRemote },
{ static_cast<uint32_t>(IS_PANEL_SHOWN), &InputMethodCoreStub::IsPanelShownOnRemote },
{ static_cast<uint32_t>(SECURITY_CHANGE), &InputMethodCoreStub::SecurityChangeOnRemote },
{ static_cast<uint32_t>(ON_CLIENT_INACTIVE), &InputMethodCoreStub::OnClientInactiveOnRemote },
{ static_cast<uint32_t>(ON_CONNECT_SYSTEM_CMD), &InputMethodCoreStub::OnConnectSystemCmdOnRemote },
const RequestHandler HANDLERS[CORE_CMD_LAST] = {
&InputMethodCoreStub::InvalidRequest,
&InputMethodCoreStub::ShowKeyboardOnRemote,
&InputMethodCoreStub::StopInputServiceOnRemote,
&InputMethodCoreStub::HideKeyboardOnRemote,
&InputMethodCoreStub::InitInputControlChannelOnRemote,
&InputMethodCoreStub::SetSubtypeOnRemote,
&InputMethodCoreStub::StartInputOnRemote,
&InputMethodCoreStub::StopInputOnRemote,
&InputMethodCoreStub::IsEnableOnRemote,
&InputMethodCoreStub::IsPanelShownOnRemote,
&InputMethodCoreStub::SecurityChangeOnRemote,
&InputMethodCoreStub::OnClientInactiveOnRemote,
&InputMethodCoreStub::OnConnectSystemCmdOnRemote,
};
};
} // namespace MiscServices

View File

@ -162,7 +162,7 @@ void InputMethodAbility::Initialize()
agentStub->SetMessageHandler(msgHandler_);
agentStub_ = agentStub;
coreStub_ = coreStub;
workThreadHandler = std::thread([this] { WorkThread(); });
workThreadHandler = std::thread([this] { this->WorkThread(); });
}
void InputMethodAbility::SetImeListener(std::shared_ptr<InputMethodEngineListener> imeListener)

View File

@ -49,7 +49,7 @@ int32_t InputMethodCoreStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
}
if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(CORE_CMD_LAST)) {
return (this->*HANDLERS.at(code))(data, reply);
return (this->*HANDLERS[code])(data, reply);
} else {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}

View File

@ -23,7 +23,6 @@
#include "inputmethod_trace.h"
#include "input_method_ability.h"
#include "input_method_ability_utils.h"
#include "inputmethod_trace.h"
#include "scene_board_judgement.h"
#include "sys_cfg_parser.h"
#include "ui/rs_surface_node.h"
@ -340,7 +339,7 @@ int32_t InputMethodPanel::CalculatePanelRect(const PanelFlag panelFlag, PanelAdj
}
auto densityDpi = displayInfo->GetDensityInCurResolution();
IMSA_HILOGI("densityDpi: %{public}f", densityDpi);
if (densityDpi < 0) {
if (densityDpi <= 0) {
return ErrorCode::ERROR_WINDOW_MANAGER;
}
if (panelFlag == PanelFlag::FLG_FIXED) {

View File

@ -59,6 +59,10 @@ public:
int32_t FinishTextPreview() override;
private:
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
{
return ERR_UNKNOWN_TRANSACTION;
};
int32_t InsertTextOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t DeleteForwardOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t DeleteBackwardOnRemote(MessageParcel &data, MessageParcel &reply);
@ -80,27 +84,28 @@ private:
int32_t SetPreviewTextOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t FinishTextPreviewOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (InputDataChannelStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(INSERT_TEXT), &InputDataChannelStub::InsertTextOnRemote },
{ static_cast<uint32_t>(DELETE_FORWARD), &InputDataChannelStub::DeleteForwardOnRemote },
{ static_cast<uint32_t>(DELETE_BACKWARD), &InputDataChannelStub::DeleteBackwardOnRemote },
{ static_cast<uint32_t>(GET_TEXT_BEFORE_CURSOR), &InputDataChannelStub::GetTextBeforeCursorOnRemote },
{ static_cast<uint32_t>(GET_TEXT_AFTER_CURSOR), &InputDataChannelStub::GetTextAfterCursorOnRemote },
{ static_cast<uint32_t>(GET_ENTER_KEY_TYPE), &InputDataChannelStub::GetEnterKeyTypeOnRemote },
{ static_cast<uint32_t>(GET_INPUT_PATTERN), &InputDataChannelStub::GetInputPatternOnRemote },
{ static_cast<uint32_t>(SEND_KEYBOARD_STATUS), &InputDataChannelStub::SendKeyboardStatusOnRemote },
{ static_cast<uint32_t>(SEND_FUNCTION_KEY), &InputDataChannelStub::SendFunctionKeyOnRemote },
{ static_cast<uint32_t>(MOVE_CURSOR), &InputDataChannelStub::MoveCursorOnRemote },
{ static_cast<uint32_t>(SELECT_BY_RANGE), &InputDataChannelStub::SelectByRangeOnRemote },
{ static_cast<uint32_t>(SELECT_BY_MOVEMENT), &InputDataChannelStub::SelectByMovementOnRemote },
{ static_cast<uint32_t>(HANDLE_EXTEND_ACTION), &InputDataChannelStub::HandleExtendActionOnRemote },
{ static_cast<uint32_t>(GET_TEXT_INDEX_AT_CURSOR), &InputDataChannelStub::GetTextIndexAtCursorOnRemote },
{ static_cast<uint32_t>(GET_TEXT_CONFIG), &InputDataChannelStub::GetTextConfigOnRemote },
{ static_cast<uint32_t>(NOTIFY_PANEL_STATUS_INFO), &InputDataChannelStub::NotifyPanelStatusInfoOnRemote },
{ static_cast<uint32_t>(NOTIFY_KEYBOARD_HEIGHT), &InputDataChannelStub::NotifyKeyboardHeightOnRemote },
{ static_cast<uint32_t>(SEND_PRIVATE_COMMAND), &InputDataChannelStub::SendPrivateCommandOnRemote },
{ static_cast<uint32_t>(SET_PREVIEW_TEXT), &InputDataChannelStub::SetPreviewTextOnRemote },
{ static_cast<uint32_t>(FINISH_TEXT_PREVIEW), &InputDataChannelStub::FinishTextPreviewOnRemote },
const RequestHandler HANDLERS[DATA_CHANNEL_CMD_LAST] = {
&InputDataChannelStub::InvalidRequest,
&InputDataChannelStub::InsertTextOnRemote,
&InputDataChannelStub::DeleteForwardOnRemote,
&InputDataChannelStub::DeleteBackwardOnRemote,
&InputDataChannelStub::GetTextBeforeCursorOnRemote,
&InputDataChannelStub::GetTextAfterCursorOnRemote,
&InputDataChannelStub::GetEnterKeyTypeOnRemote,
&InputDataChannelStub::GetInputPatternOnRemote,
&InputDataChannelStub::SendKeyboardStatusOnRemote,
&InputDataChannelStub::SendFunctionKeyOnRemote,
&InputDataChannelStub::MoveCursorOnRemote,
&InputDataChannelStub::SelectByRangeOnRemote,
&InputDataChannelStub::SelectByMovementOnRemote,
&InputDataChannelStub::HandleExtendActionOnRemote,
&InputDataChannelStub::GetTextIndexAtCursorOnRemote,
&InputDataChannelStub::GetTextConfigOnRemote,
&InputDataChannelStub::NotifyPanelStatusInfoOnRemote,
&InputDataChannelStub::NotifyKeyboardHeightOnRemote,
&InputDataChannelStub::SendPrivateCommandOnRemote,
&InputDataChannelStub::SetPreviewTextOnRemote,
&InputDataChannelStub::FinishTextPreviewOnRemote,
};
};
} // namespace MiscServices

View File

@ -43,7 +43,8 @@ public:
private:
static inline BrokerDelegator<KeyEventConsumerProxy> delegator_;
using ParcelHandler = std::function<bool(MessageParcel &)>;
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr);
int32_t SendRequest(int code, ParcelHandler input = nullptr, ParcelHandler output = nullptr,
MessageOption option = MessageOption::TF_SYNC);
bool keyEventConsume_ = false;
bool keyCodeConsume_ = false;
bool keyEventResult_ = false;

View File

@ -40,10 +40,15 @@ public:
int32_t OnKeyEventResult(bool isConsumed) override;
private:
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
{
return ERR_UNKNOWN_TRANSACTION;
};
int32_t OnKeyEventResultOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (KeyEventConsumerStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(KEY_EVENT_RESULT), &KeyEventConsumerStub::OnKeyEventResultOnRemote },
const RequestHandler HANDLERS[KEY_EVENT_CONSUMER_CMD_LAST] = {
&KeyEventConsumerStub::InvalidRequest,
&KeyEventConsumerStub::OnKeyEventResultOnRemote,
};
KeyEventCallback callback_;
std::shared_ptr<MMI::KeyEvent> keyEvent_;

View File

@ -39,12 +39,17 @@ public:
int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) override;
private:
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
{
return ERR_UNKNOWN_TRANSACTION;
};
int32_t NotifyPanelStatusOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t SendPrivateCommandOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (SystemCmdChannelStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(SEND_PRIVATE_COMMAND), &SystemCmdChannelStub::SendPrivateCommandOnRemote },
{ static_cast<uint32_t>(SHOULD_SYSTEM_PANEL_SHOW), &SystemCmdChannelStub::NotifyPanelStatusOnRemote },
const RequestHandler HANDLERS[SYSTEM_CMD_LAST] = {
&SystemCmdChannelStub::InvalidRequest,
&SystemCmdChannelStub::SendPrivateCommandOnRemote,
&SystemCmdChannelStub::NotifyPanelStatusOnRemote,
};
};
} // namespace MiscServices

View File

@ -43,7 +43,7 @@ int32_t InputDataChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
}
if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(DATA_CHANNEL_CMD_LAST)) {
return (this->*HANDLERS.at(code))(data, reply);
return (this->*HANDLERS[code])(data, reply);
} else {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}

View File

@ -621,7 +621,7 @@ int32_t InputMethodController::OnSelectionChange(std::u16string text, int start,
std::lock_guard<std::mutex> lock(textConfigLock_);
textConfig_.range = { start, end };
}
if (textString_ == text && selectNewBegin_ == start && selectNewEnd_ == end) {
if (isTextNotified_.exchange(true) && textString_ == text && selectNewBegin_ == start && selectNewEnd_ == end) {
IMSA_HILOGD("same to last update.");
return ErrorCode::NO_ERROR;
}
@ -934,9 +934,10 @@ void InputMethodController::ClearEditorCache(bool isNewEditor)
IMSA_HILOGD("isNewEditor: %{public}d.", isNewEditor);
{
std::lock_guard<std::mutex> lock(editorContentLock_);
textString_ = Str8ToStr16("");
// reset old range when editor changes or first attach
if (isNewEditor || !isBound_.load()) {
isTextNotified_.store(false);
textString_ = Str8ToStr16("");
selectOldBegin_ = INVALID_VALUE;
selectOldEnd_ = INVALID_VALUE;
selectNewBegin_ = INVALID_VALUE;
@ -1190,7 +1191,7 @@ int32_t InputMethodController::IsPanelShown(const PanelInfo &panelInfo, bool &is
IMSA_HILOGE("proxy is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
}
IMSA_HILOGI("type: %{public}d, flag: %{public}d.", static_cast<int32_t>(panelInfo.panelType),
IMSA_HILOGD("type: %{public}d, flag: %{public}d.", static_cast<int32_t>(panelInfo.panelType),
static_cast<int32_t>(panelInfo.panelFlag));
return proxy->IsPanelShown(panelInfo, isShown);
}

View File

@ -30,8 +30,9 @@ KeyEventConsumerProxy::KeyEventConsumerProxy(const sptr<IRemoteObject> &object)
int32_t KeyEventConsumerProxy::OnKeyEventResult(bool isConsumed)
{
return SendRequest(KEY_EVENT_RESULT,
[isConsumed](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, isConsumed); });
return SendRequest(
KEY_EVENT_RESULT, [isConsumed](MessageParcel &parcel) { return ITypesUtil::Marshal(parcel, isConsumed); },
nullptr, MessageOption::TF_ASYNC);
}
void KeyEventConsumerProxy::OnKeyEventConsumeResult(bool isConsumed)
@ -54,12 +55,11 @@ void KeyEventConsumerProxy::OnKeyCodeConsumeResult(bool isConsumed)
}
}
int32_t KeyEventConsumerProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output)
int32_t KeyEventConsumerProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output, MessageOption option)
{
IMSA_HILOGD("KeyEventConsumerProxy run in, code = %{public}d.", code);
MessageParcel data;
MessageParcel reply;
MessageOption option = MessageOption::TF_SYNC;
if (!data.WriteInterfaceToken(GetDescriptor())) {
IMSA_HILOGE("write interface token failed!");

View File

@ -44,7 +44,7 @@ int32_t KeyEventConsumerStub::OnRemoteRequest(uint32_t code, MessageParcel &data
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
}
if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(KEY_EVENT_CONSUMER_CMD_LAST)) {
return (this->*HANDLERS.at(code))(data, reply);
return (this->*HANDLERS[code])(data, reply);
} else {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}

View File

@ -76,7 +76,7 @@ int32_t SystemCmdChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data
return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION;
}
if (code >= FIRST_CALL_TRANSACTION && code < static_cast<uint32_t>(SYSTEM_CMD_LAST)) {
return (this->*HANDLERS.at(code))(data, reply);
return (this->*HANDLERS[code])(data, reply);
} else {
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
}

View File

@ -42,11 +42,6 @@ config("inputmethod_client_native_public_config") {
ohos_shared_library("inputmethod_client") {
branch_protector_ret = "pac_ret"
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
sources = [
"${inputmethod_path}/frameworks/native/inputmethod_ability/src/input_method_agent_proxy.cpp",
"${inputmethod_path}/frameworks/native/inputmethod_controller/src/ime_event_monitor_manager.cpp",

View File

@ -803,6 +803,7 @@ private:
std::mutex cursorInfoMutex_;
CursorInfo cursorInfo_;
std::atomic_bool isTextNotified_{ false };
std::mutex editorContentLock_;
std::u16string textString_;
int selectOldBegin_ = 0;

16
publicity.xml Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2024 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.
-->
<packageInfo package="com.ohos.inputmethodchoosedialog" label="输入法框架系统弹窗" feature="提供输入法框架系统弹窗功能。" author="华为终端有限公司"></packageInfo>

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import("//base/inputmethod/imf/inputmethod.gni")
import("//build/ohos.gni")
group("input_method_choose_dialog") {
@ -29,6 +30,7 @@ ohos_hap("input_method_choose_hap") {
hap_name = "input_method_choose_dialog"
subsystem_name = "applications"
part_name = "prebuilt_hap"
publicity_file = "${inputmethod_path}/publicity.xml"
module_install_dir = "app/com.ohos.inputmethodchoosedialog"
}

View File

@ -60,7 +60,7 @@ public:
void HandleBootCompleted(const EventFwk::CommonEventData &data);
private:
using EventListenerFunc = void (EventSubscriber::*)(const EventFwk::CommonEventData &data);
using EventListenerFunc = std::function<void(EventSubscriber *that, const EventFwk::CommonEventData &data)>;
std::map<std::string, EventListenerFunc> EventManagerFunc_;
void HandlePackageEvent(int32_t messageId, const EventFwk::CommonEventData &data);
};

View File

@ -31,6 +31,11 @@ public:
int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
private:
int32_t InvalidRequest(MessageParcel &data, MessageParcel &reply)
{
return ERR_UNKNOWN_TRANSACTION;
};
int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t ShowCurrentInputOnRemote(MessageParcel &data, MessageParcel &reply);
@ -97,71 +102,40 @@ private:
int32_t ConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &);
static inline const std::unordered_map<int32_t, RequestHandler> HANDLERS = {
{ static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT),
&InputMethodSystemAbilityStub::StartInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT),
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT),
&InputMethodSystemAbilityStub::HideCurrentInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_INPUT),
&InputMethodSystemAbilityStub::ShowInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_INPUT),
&InputMethodSystemAbilityStub::HideInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::RELEASE_INPUT),
&InputMethodSystemAbilityStub::ReleaseInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::REQUEST_SHOW_INPUT),
&InputMethodSystemAbilityStub::RequestShowInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::REQUEST_HIDE_INPUT),
&InputMethodSystemAbilityStub::RequestHideInputOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD),
&InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::GET_CURRENT_INPUT_METHOD_SUBTYPE),
&InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD),
&InputMethodSystemAbilityStub::ListInputMethodOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::LIST_INPUT_METHOD_SUBTYPE),
&InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::LIST_CURRENT_INPUT_METHOD_SUBTYPE),
&InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::SWITCH_INPUT_METHOD),
&InputMethodSystemAbilityStub::SwitchInputMethodOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD),
&InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::SET_CORE_AND_AGENT),
&InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::SHOW_CURRENT_INPUT_DEPRECATED),
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated },
{ static_cast<uint32_t>(InputMethodInterfaceCode::HIDE_CURRENT_INPUT_DEPRECATED),
&InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated },
{ static_cast<uint32_t>(InputMethodInterfaceCode::STOP_INPUT_SESSION),
&InputMethodSystemAbilityStub::StopInputSessionOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::PANEL_STATUS_CHANGE),
&InputMethodSystemAbilityStub::PanelStatusChangeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::UPDATE_LISTEN_EVENT_FLAG),
&InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::IS_CURRENT_IME),
&InputMethodSystemAbilityStub::IsCurrentImeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::UNREGISTERED_PROXY_IME),
&InputMethodSystemAbilityStub::UnRegisteredProxyImeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::IS_INPUT_TYPE_SUPPORTED),
&InputMethodSystemAbilityStub::IsInputTypeSupportedOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::START_INPUT_TYPE),
&InputMethodSystemAbilityStub::StartInputTypeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::EXIT_CURRENT_INPUT_TYPE),
&InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::GET_DEFAULT_INPUT_METHOD),
&InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::GET_INPUT_METHOD_SETTINGS),
&InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::IS_PANEL_SHOWN),
&InputMethodSystemAbilityStub::IsPanelShownOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::GET_SECURITY_MODE),
&InputMethodSystemAbilityStub::GetSecurityModeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::IS_DEFAULT_IME),
&InputMethodSystemAbilityStub::IsDefaultImeOnRemote },
{ static_cast<uint32_t>(InputMethodInterfaceCode::CONNECT_SYSTEM_CMD),
&InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote },
const RequestHandler HANDLERS[static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_LAST)] = {
&InputMethodSystemAbilityStub::InvalidRequest,
&InputMethodSystemAbilityStub::StartInputOnRemote,
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemote,
&InputMethodSystemAbilityStub::HideCurrentInputOnRemote,
&InputMethodSystemAbilityStub::ShowInputOnRemote,
&InputMethodSystemAbilityStub::HideInputOnRemote,
&InputMethodSystemAbilityStub::StopInputSessionOnRemote,
&InputMethodSystemAbilityStub::ReleaseInputOnRemote,
&InputMethodSystemAbilityStub::RequestShowInputOnRemote,
&InputMethodSystemAbilityStub::RequestHideInputOnRemote,
&InputMethodSystemAbilityStub::GetCurrentInputMethodOnRemote,
&InputMethodSystemAbilityStub::GetCurrentInputMethodSubtypeOnRemote,
&InputMethodSystemAbilityStub::ListInputMethodOnRemote,
&InputMethodSystemAbilityStub::ListInputMethodSubtypeOnRemote,
&InputMethodSystemAbilityStub::ListCurrentInputMethodSubtypeOnRemote,
&InputMethodSystemAbilityStub::SwitchInputMethodOnRemote,
&InputMethodSystemAbilityStub::DisplayOptionalInputMethodOnRemote,
&InputMethodSystemAbilityStub::SetCoreAndAgentOnRemote,
&InputMethodSystemAbilityStub::ShowCurrentInputOnRemoteDeprecated,
&InputMethodSystemAbilityStub::HideCurrentInputOnRemoteDeprecated,
&InputMethodSystemAbilityStub::PanelStatusChangeOnRemote,
&InputMethodSystemAbilityStub::UpdateListenEventFlagOnRemote,
&InputMethodSystemAbilityStub::IsCurrentImeOnRemote,
&InputMethodSystemAbilityStub::UnRegisteredProxyImeOnRemote,
&InputMethodSystemAbilityStub::IsInputTypeSupportedOnRemote,
&InputMethodSystemAbilityStub::StartInputTypeOnRemote,
&InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote,
&InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote,
&InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote,
&InputMethodSystemAbilityStub::IsPanelShownOnRemote,
&InputMethodSystemAbilityStub::GetSecurityModeOnRemote,
&InputMethodSystemAbilityStub::IsDefaultImeOnRemote,
&InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote,
};
};
} // namespace OHOS::MiscServices

View File

@ -40,6 +40,7 @@
#include "input_death_recipient.h"
#include "input_method_info.h"
#include "input_method_property.h"
#include "input_type_manager.h"
#include "input_window_info.h"
#include "inputmethod_sysevent.h"
#include "iremote_object.h"
@ -92,6 +93,7 @@ public:
void OnFocused(int32_t pid, int32_t uid);
void OnUnfocused(int32_t pid, int32_t uid);
int64_t GetCurrentClientPid();
int64_t GetInactiveClientPid();
int32_t OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info);
int32_t OnUpdateListenEventFlag(const InputClientInfo &clientInfo);
int32_t OnRegisterProxyIme(const sptr<IInputMethodCore> &core, const sptr<IRemoteObject> &agent);
@ -186,6 +188,7 @@ private:
bool WaitForCurrentImeStop();
void NotifyImeStopFinished();
bool GetCurrentUsingImeId(ImeIdentification &imeId);
BlockData<bool> isImeStarted_{ MAX_IME_START_TIME, false };
std::mutex imeDataLock_;

View File

@ -207,13 +207,34 @@ bool ImCommonEventManager::UnsubscribeEvent()
ImCommonEventManager::EventSubscriber::EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscribeInfo)
: EventFwk::CommonEventSubscriber(subscribeInfo)
{
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_SWITCHED] = &EventSubscriber::StartUser;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_REMOVED] = &EventSubscriber::RemoveUser;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] = &EventSubscriber::RemovePackage;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED] = &EventSubscriber::OnBundleScanFinished;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] = &EventSubscriber::AddPackage;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED] = &EventSubscriber::ChangePackage;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED] = &EventSubscriber::HandleBootCompleted;
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_SWITCHED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->StartUser(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_USER_REMOVED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->RemoveUser(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->RemovePackage(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->OnBundleScanFinished(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->AddPackage(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->ChangePackage(data);
};
EventManagerFunc_[CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED] =
[] (EventSubscriber *that, const EventFwk::CommonEventData &data) {
return that->HandleBootCompleted(data);
};
}
void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data)
@ -222,12 +243,8 @@ void ImCommonEventManager::EventSubscriber::OnReceiveEvent(const EventFwk::Commo
std::string action = want.GetAction();
IMSA_HILOGI("ImCommonEventManager::action: %{public}s!", action.c_str());
auto iter = EventManagerFunc_.find(action);
if (iter == EventManagerFunc_.end()) {
return;
}
auto EventListenerFunc = iter->second;
if (EventListenerFunc != nullptr) {
(this->*EventListenerFunc)(data);
if (iter != EventManagerFunc_.end()) {
EventManagerFunc_[action] (this, data);
}
}

View File

@ -275,7 +275,7 @@ void InputMethodSystemAbility::Initialize()
{
IMSA_HILOGI("InputMethodSystemAbility::Initialize.");
// init work thread to handle the messages
workThreadHandler = std::thread([this] { WorkThread(); });
workThreadHandler = std::thread([this] { this->WorkThread(); });
identityChecker_ = std::make_shared<IdentityCheckerImpl>();
userId_ = MAIN_USER_ID;
userSession_ = std::make_shared<PerUserSession>(userId_);
@ -349,17 +349,17 @@ int32_t InputMethodSystemAbility::ReleaseInput(sptr<IInputClient> client)
int32_t InputMethodSystemAbility::StartInput(InputClientInfo &inputClientInfo, sptr<IRemoteObject> &agent)
{
if (userSession_->GetCurrentClientPid() != IPCSkeleton::GetCallingPid()) {
//进程变化时需要通知inputstart
inputClientInfo.isNotifyInputStart = true;
}
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
if (!identityChecker_->IsBroker(tokenId)) {
if (!identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId)) {
return ErrorCode::ERROR_CLIENT_NOT_FOCUSED;
}
}
if (userSession_->GetCurrentClientPid() != IPCSkeleton::GetCallingPid()
&& userSession_->GetInactiveClientPid() != IPCSkeleton::GetCallingPid()) {
// notify inputStart when caller pid different from both current client and inactive client
inputClientInfo.isNotifyInputStart = true;
}
if (!userSession_->IsProxyImeEnable()) {
CheckInputTypeOption(inputClientInfo);
}
@ -724,7 +724,17 @@ bool InputMethodSystemAbility::IsNeedSwitch(const std::string &bundleName, const
int32_t InputMethodSystemAbility::Switch(const std::string &bundleName, const std::shared_ptr<ImeInfo> &info)
{
auto currentImeBundleName = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_)->bundleName;
return bundleName != currentImeBundleName ? SwitchExtension(info) : SwitchSubType(info);
if (bundleName != currentImeBundleName) {
IMSA_HILOGI("switch input method to: %{public}s", bundleName.c_str());
return SwitchExtension(info);
}
auto currentInputType = InputTypeManager::GetInstance().GetCurrentIme();
auto isInputTypeStarted = InputTypeManager::GetInstance().IsStarted();
if (isInputTypeStarted && bundleName != currentInputType.bundleName) {
IMSA_HILOGI("right click on state, switch input method to: %{public}s", bundleName.c_str());
return SwitchExtension(info);
}
return SwitchSubType(info);
}
// Switch the current InputMethodExtension to the new InputMethodExtension

View File

@ -51,7 +51,7 @@ int32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParc
auto id = XCollie::GetInstance().SetTimer("IMSA_API[" + std::to_string(code) + "]", FATAL_TIMEOUT, nullptr,
nullptr, XCOLLIE_FLAG_DEFAULT);
int64_t startPoint = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
auto ret = (this->*HANDLERS.at(code))(data, reply);
auto ret = (this->*HANDLERS[code])(data, reply);
int64_t costTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() - startPoint;
// log warning when timeout 5s
if (costTime > WARNING_TIMEOUT) {

View File

@ -995,13 +995,14 @@ int32_t PerUserSession::ForceStopCurrentIme()
StopClientInput(clientInfo);
}
// stop current inputmethod extension
auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
if (currentImeCfg == nullptr) {
ImeIdentification imeId;
if (!GetCurrentUsingImeId(imeId)) {
IMSA_HILOGE("currentImeCfg is nullptr");
RemoveImeData(ImeType::IME, true);
return ErrorCode::ERROR_NULL_POINTER;
}
AAFwk::Want want;
want.SetElementName(currentImeCfg->bundleName, currentImeCfg->extName);
want.SetElementName(imeId.bundleName, imeId.subName);
auto ret = AAFwk::AbilityManagerClient::GetInstance()->StopExtensionAbility(want, nullptr, userId_,
AppExecFwk::ExtensionAbilityType::INPUTMETHOD);
if (ret != ErrorCode::NO_ERROR) {
@ -1010,6 +1011,24 @@ int32_t PerUserSession::ForceStopCurrentIme()
return ret;
}
bool PerUserSession::GetCurrentUsingImeId(ImeIdentification &imeId)
{
if (InputTypeManager::GetInstance().IsStarted()) {
IMSA_HILOGI("get right click on state current ime.");
auto currentIme = InputTypeManager::GetInstance().GetCurrentIme();
imeId = currentIme;
return true;
}
auto currentImeCfg = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
if (currentImeCfg == nullptr) {
IMSA_HILOGE("currentImeCfg is nullptr");
return false;
}
imeId.bundleName = currentImeCfg->bundleName;
imeId.subName = currentImeCfg->extName;
return true;
}
bool PerUserSession::StartInputService(const std::shared_ptr<ImeNativeCfg> &ime)
{
SecurityMode mode;
@ -1065,6 +1084,19 @@ int64_t PerUserSession::GetCurrentClientPid()
return clientInfo->pid;
}
int64_t PerUserSession::GetInactiveClientPid()
{
auto client = GetInactiveClient();
if (client == nullptr) {
return INVALID_PID;
}
auto clientInfo = GetClientInfo(client->AsObject());
if (clientInfo == nullptr) {
return INVALID_PID;
}
return clientInfo->pid;
}
int32_t PerUserSession::OnPanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info)
{
auto clientMap = GetClientMap();
@ -1199,7 +1231,7 @@ int32_t PerUserSession::ExitCurrentInputType()
int32_t PerUserSession::IsPanelShown(const PanelInfo &panelInfo, bool &isShown)
{
if (GetCurrentClient() == nullptr) {
IMSA_HILOGI("not in bound state.");
IMSA_HILOGD("not in bound state.");
isShown = false;
return ErrorCode::NO_ERROR;
}

View File

@ -21,11 +21,13 @@ group("fuzztest") {
"controlchannelstub_fuzzer:fuzztest",
"corestub_fuzzer:fuzztest",
"datachannelstub_fuzzer:fuzztest",
"enableimedataparse_fuzzer:fuzztest",
"imeeventmonitormanager_fuzzer:fuzztest",
"inputclientstub_fuzzer:fuzztest",
"inputmethodability_fuzzer:fuzztest",
"inputmethodcontroller_fuzzer:fuzztest",
"perusersession_fuzzer:fuzztest",
"securitymodeparser_fuzzer:fuzztest",
"systemabilitystub_fuzzer:fuzztest",
"systemabilitystubfuzztest:system_ability_stub_fuzztest",
]

View File

@ -0,0 +1,75 @@
# Copyright (c) 2022 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.
import("//base/inputmethod/imf/inputmethod.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
##############################fuzztest##########################################
ohos_fuzztest("EnableImeDataParseFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file =
"${inputmethod_path}/test/fuzztest/enableimedataparse_fuzzer"
include_dirs = [
"${inputmethod_path}/services/adapter/settings_data_provider/include",
"${inputmethod_path}/services/adapter/ime_connection_manager/include",
"${inputmethod_path}/services/include",
"${inputmethod_path}/test/common",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"${inputmethod_path}/services/adapter/settings_data_provider/src/enable_ime_data_parser.cpp",
"enableimedataparse_fuzzer.cpp",
]
deps = [
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static",
"${inputmethod_path}/services:inputmethod_service_static",
"${inputmethod_path}/test/common:inputmethod_test_common",
]
external_deps = [
"ability_base:zuri",
"ability_runtime:dataobs_manager",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"data_share:datashare_common",
"data_share:datashare_consumer",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":EnableImeDataParseFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,84 @@
/*
* Copyright (c) 2024 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.
*/
#define private public
#define protected public
#include "enable_ime_data_parser.h"
#undef private
#include "enableimedataparse_fuzzer.h"
using namespace OHOS::MiscServices;
namespace OHOS {
constexpr size_t THRESHOLD = 10;
void FuzzInitialize(const int32_t userId)
{
EnableImeDataParser::GetInstance()->Initialize(userId);
}
void FuzzOnUserChanged(const int32_t userId)
{
EnableImeDataParser::GetInstance()->OnUserChanged(userId);
}
void FuzzCheckNeedSwitch(const std::string &key, SwitchInfo &switchInfo, const int32_t userId)
{
EnableImeDataParser::GetInstance()->CheckNeedSwitch(key, switchInfo, userId);
EnableImeDataParser::GetInstance()->CheckNeedSwitch(switchInfo, userId);
}
void FuzzGetEnableData(const std::string &key, std::vector<std::string> &enableVec, const int32_t userId)
{
EnableImeDataParser::GetInstance()->GetEnableData(key, enableVec, userId);
}
void FuzzParseEnableIme(const std::string &valueStr, int32_t userId, std::vector<std::string> &enableVec)
{
EnableImeDataParser::GetInstance()->ParseEnableIme(valueStr, userId, enableVec);
}
void FuzzParseEnableKeyboard(const std::string &valueStr, int32_t userId, std::vector<std::string> &enableVec)
{
EnableImeDataParser::GetInstance()->ParseEnableKeyboard(valueStr, userId, enableVec);
}
void FuzzCheckTargetEnableName(const std::string &key, const std::string &targetName, std::string &nextIme,
const int32_t userId)
{
EnableImeDataParser::GetInstance()->CheckTargetEnableName(key, targetName, nextIme, userId);
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if (size < OHOS::THRESHOLD) {
return 0;
}
/* Run your code on data */
const int32_t userId = static_cast<int32_t>(size);
std::string fuzzedString(reinterpret_cast<const char *>(data), size);
SwitchInfo switchInfo;
std::vector<std::string> enableVec;
OHOS::FuzzInitialize(userId);
OHOS::FuzzOnUserChanged(userId);
OHOS::FuzzCheckNeedSwitch(fuzzedString, switchInfo, userId);
OHOS::FuzzGetEnableData(fuzzedString, enableVec, userId);
OHOS::FuzzParseEnableIme(fuzzedString, userId, enableVec);
OHOS::FuzzParseEnableKeyboard(fuzzedString, userId, enableVec);
OHOS::FuzzCheckTargetEnableName(fuzzedString, fuzzedString, fuzzedString, userId);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_ENABLE_IME_DATA_PARSE_FUZZER_H
#define TEST_FUZZTEST_ENABLE_IME_DATA_PARSE_FUZZER_H
#define FUZZ_PROJECT_NAME "enableimedataparse_fuzzer"
#endif // TEST_FUZZTEST_ENABLE_IME_DATA_PARSE_FUZZER_H

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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

@ -0,0 +1,74 @@
# Copyright (c) 2022-2002 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.
import("//base/inputmethod/imf/inputmethod.gni")
#####################hydra-fuzz###################
import("//build/config/features.gni")
import("//build/ohos.gni")
import("//build/test.gni")
##############################fuzztest##########################################
ohos_fuzztest("SecurityModeParserFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file =
"${inputmethod_path}/test/fuzztest/securitymodeparser_fuzzer"
include_dirs = [
"${inputmethod_path}/services/adapter/settings_data_provider/include",
"${inputmethod_path}/services/adapter/ime_connection_manager/include",
"${inputmethod_path}/services/include",
"${inputmethod_path}/test/common",
]
cflags = [
"-g",
"-O0",
"-Wno-unused-variable",
"-fno-omit-frame-pointer",
]
sources = [
"${inputmethod_path}/services/adapter/settings_data_provider/src/security_mode_parser.cpp",
"securitymodeparser_fuzzer.cpp",
]
deps = [
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static",
"${inputmethod_path}/services:inputmethod_service_static",
"${inputmethod_path}/test/common:inputmethod_test_common",
]
external_deps = [
"ability_runtime:ability_manager",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"data_share:datashare_common",
"data_share:datashare_consumer",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",
]
}
###############################################################################
group("fuzztest") {
testonly = true
deps = []
deps += [
# deps file
":SecurityModeParserFuzzTest",
]
}
###############################################################################

View File

@ -0,0 +1,14 @@
# Copyright (c) 2022 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

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2022 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

@ -0,0 +1,66 @@
/*
* Copyright (c) 2022-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.
*/
#define private public
#define protected public
#include "security_mode_parser.h"
#undef private
#include "securitymodeparser_fuzzer.h"
using namespace OHOS::MiscServices;
namespace OHOS {
void FuzzInitialize(const int32_t userId)
{
SecurityModeParser::GetInstance()->Initialize(userId);
}
void FuzzGetSecurityMode(const std::string &bundleName, const int32_t userId)
{
SecurityModeParser::GetInstance()->GetSecurityMode(bundleName, userId);
}
void FuzzUpdateFullModeList(const int32_t userId)
{
SecurityModeParser::GetInstance()->UpdateFullModeList(userId);
}
void FuzzParseSecurityMode(const std::string &bundleName, const int32_t userId)
{
SecurityModeParser::GetInstance()->ParseSecurityMode(bundleName, userId);
}
void FuzzIsFullMode(const std::string &bundleName)
{
SecurityModeParser::GetInstance()->IsFullMode(bundleName);
}
} // namespace OHOS
/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
if (data == nullptr) {
return 0;
}
/* Run your code on data */
const int32_t userId = static_cast<int32_t>(size);
std::string fuzzedString(reinterpret_cast<const char *>(data), size);
OHOS::FuzzInitialize(userId);
OHOS::FuzzGetSecurityMode(fuzzedString, userId);
OHOS::FuzzUpdateFullModeList(userId);
OHOS::FuzzParseSecurityMode(fuzzedString, userId);
OHOS::FuzzIsFullMode(fuzzedString);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 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_SYSTEMABILITYSTUB_FUZZER_SYSTEMABILITYSTUB_FUZZER_H
#define TEST_FUZZTEST_SYSTEMABILITYSTUB_FUZZER_SYSTEMABILITYSTUB_FUZZER_H
#define FUZZ_PROJECT_NAME "securitymodeparser_fuzzer"
#endif // TEST_FUZZTEST_SYSTEMABILITYSTUB_FUZZER_SYSTEMABILITYSTUB_FUZZER_H

View File

@ -20,15 +20,20 @@ import("//build/test.gni")
group("system_ability_stub_fuzztest") {
testonly = true
deps = [
":ConnectSystemCmdFuzzTest",
":DisplayOptionalInputMethodFuzzTest",
":ExitCurrentInputTypeFuzzTest",
":GetCurrentInputmethodFuzzTest",
":GetCurrentInputmethodSubtypeFuzzTest",
":GetDefaultInputmethodFuzzTest",
":GetInputMethodConfigFuzzTest",
":GetSecurityModeFuzzTest",
":HideCurrentInputDeprecatedFuzzTest",
":HideCurrentInputFuzzTest",
":HideInputFuzzTest",
":ImsCmdLastFuzzTest",
":IsCurrentImeFuzzTest",
":IsDefaultImeFuzzTest",
":IsInputTypeSupportedFuzzTest",
":IsPanelShownFuzzTest",
":ListCurrentInputmethodSubtypeFuzzTest",
@ -36,12 +41,14 @@ group("system_ability_stub_fuzztest") {
":ListInputmethodSubtypeFuzzTest",
":PanelStatusChangeFuzzTest",
":ReleaseInputFuzzTest",
":RequestHideInputFuzzTest",
":RequestShowInputFuzzTest",
":SetCoreAndAgentFuzzTest",
":ShowCurrentInputDeprecatedFuzzTest",
":ShowCurrentInputFuzzTest",
":ShowInputFuzzTest",
":StartInputFuzzTest",
":StartInputTypeFuzzTest",
":StopInputFuzzTest",
":StopInputSessionFuzzTest",
":SwitchInputMethodFuzzTest",
":UnRegisteredProxyImeFuzzTest",
@ -292,17 +299,17 @@ ohos_fuzztest("StartInputFuzzTest") {
external_deps = common_external_deps
}
ohos_fuzztest("StopInputFuzzTest") {
ohos_fuzztest("ImsCmdLastFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/stopinput_fuzzer"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/imscmdlast_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/stopinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/imscmdlast_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "stopinput_fuzzer/stopinput_fuzzer.cpp" ]
sources = [ "imscmdlast_fuzzer/imscmdlast_fuzzer.cpp" ]
deps = common_deps
@ -514,3 +521,122 @@ ohos_fuzztest("GetInputMethodConfigFuzzTest") {
external_deps = common_external_deps
}
ohos_fuzztest("HideInputFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/hideinput_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/hideinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "hideinput_fuzzer/hideinput_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("ShowInputFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/showinput_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/showinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "showinput_fuzzer/showinput_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("RequestShowInputFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/requestshowinput_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/requestshowinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "requestshowinput_fuzzer/requestshowinput_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("RequestHideInputFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/requesthideinput_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/requesthideinput_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "requesthideinput_fuzzer/requesthideinput_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("GetSecurityModeFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/getsecuritymode_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/getsecuritymode_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "getsecuritymode_fuzzer/getsecuritymode_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("IsDefaultImeFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/isdefaultime_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/isdefaultime_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "isdefaultime_fuzzer/isdefaultime_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}
ohos_fuzztest("ConnectSystemCmdFuzzTest") {
module_out_path = "imf/imf"
fuzz_config_file = "${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/connectsystemcmd_fuzzer"
include_dirs = [
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/connectsystemcmd_fuzzer",
"${inputmethod_path}/test/fuzztest/systemabilitystubfuzztest/common",
]
sources = [ "connectsystemcmd_fuzzer/connectsystemcmd_fuzzer.cpp" ]
deps = common_deps
external_deps = common_external_deps
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "connectsystemcmd_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::CONNECT_SYSTEM_CMD);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_CONNECTSYSTEMCMD_FUZZER_H
#define TEST_FUZZTEST_CONNECTSYSTEMCMD_FUZZER_H
#define FUZZ_PROJECT_NAME "connectsystemcmd_fuzzer"
#endif // TEST_FUZZTEST_CONNECTSYSTEMCMD_FUZZER_H

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "getsecuritymode_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::GET_SECURITY_MODE);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_GETSECURITYMODE_FUZZER_H
#define TEST_FUZZTEST_GETSECURITYMODE_FUZZER_H
#define FUZZ_PROJECT_NAME "getsecuritymode_fuzzer"
#endif // TEST_FUZZTEST_GETSECURITYMODE_FUZZER_H

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -13,7 +13,7 @@
* limitations under the License.
*/
#include "stopinput_fuzzer.h"
#include "hideinput_fuzzer.h"
#include "imf_sa_stub_fuzz_util.h"
#include "inputmethod_service_ipc_interface_code.h"

View File

@ -13,9 +13,9 @@
* limitations under the License.
*/
#ifndef TEST_FUZZTEST_STOPINPUT_FUZZER_H
#define TEST_FUZZTEST_STOPINPUT_FUZZER_H
#ifndef TEST_FUZZTEST_HIDEINPUT_FUZZER_H
#define TEST_FUZZTEST_HIDEINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "stopinput_fuzzer"
#define FUZZ_PROJECT_NAME "hideinput_fuzzer"
#endif // TEST_FUZZTEST_STOPINPUT_FUZZER_H
#endif // TEST_FUZZTEST_HIDEINPUT_FUZZER_H

View File

@ -0,0 +1,14 @@
# 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

@ -0,0 +1,30 @@
/*
* 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 "imscmdlast_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::IMS_CMD_LAST);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* 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_STARTINPUT_FUZZER_H
#define TEST_FUZZTEST_STARTINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "imscmdlast_fuzzer"
#endif // TEST_FUZZTEST_STARTINPUT_FUZZER_H

View File

@ -0,0 +1,25 @@
<?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

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "isdefaultime_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::IS_DEFAULT_IME);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_ISDEFAULTIME_FUZZER_H
#define TEST_FUZZTEST_ISDEFAULTIME_FUZZER_H
#define FUZZ_PROJECT_NAME "isdefaultime_fuzzer"
#endif // TEST_FUZZTEST_ISDEFAULTIME_FUZZER_H

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "requesthideinput_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::REQUEST_HIDE_INPUT);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_REQUESTHIDEINPUT_FUZZER_H
#define TEST_FUZZTEST_REQUESTHIDEINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "requesthideinput_fuzzer"
#endif // TEST_FUZZTEST_REQUESTHIDEINPUT_FUZZER_H

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "requestshowinput_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::REQUEST_SHOW_INPUT);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_REQUESTSHOWINPUT_FUZZER_H
#define TEST_FUZZTEST_REQUESTSHOWINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "requestshowinput_fuzzer"
#endif // TEST_FUZZTEST_REQUESTSHOWINPUT_FUZZER_H

View File

@ -0,0 +1,14 @@
# Copyright (c) 2024 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

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2024 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

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 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 "showinput_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::SHOW_INPUT);
return 0;
}

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 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_SHOWINPUT_FUZZER_H
#define TEST_FUZZTEST_SHOWINPUT_FUZZER_H
#define FUZZ_PROJECT_NAME "showinput_fuzzer"
#endif // TEST_FUZZTEST_SHOWINPUT_FUZZER_H

View File

@ -931,6 +931,30 @@ HWTEST_F(InputMethodControllerTest, testIMCOnSelectionChange08, TestSize.Level0)
EXPECT_EQ(InputMethodControllerTest::newEnd_, 4);
}
/**
* @tc.name: testIMCOnSelectionChange09
* @tc.desc: Attach with range(0, 0) -> OnSelectionChange("", 0, 0) -> Get 'textChange' and 'selectionChange' Callback
* @tc.type: FUNC
* @tc.require:
* @tc.author: Zhaolinglan
*/
HWTEST_F(InputMethodControllerTest, testIMCOnSelectionChange09, TestSize.Level0)
{
IMSA_HILOGI("IMC testIMCOnSelectionChange09 Test START");
InputMethodControllerTest::inputMethodController_->Close();
TextConfig textConfig;
textConfig.range = { 0, 0 };
auto ret = inputMethodController_->Attach(textListener_, false, textConfig);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodControllerTest::ResetKeyboardListenerTextConfig();
InputMethodControllerTest::text_ = "test";
std::u16string text = Str8ToStr16("");
InputMethodControllerTest::TriggerSelectionChangeCallback(text, 0, 0);
EXPECT_EQ(InputMethodControllerTest::text_, "");
EXPECT_EQ(InputMethodControllerTest::newBegin_, 0);
EXPECT_EQ(InputMethodControllerTest::newEnd_, 0);
}
/**
* @tc.name: testShowTextInput
* @tc.desc: IMC ShowTextInput
@ -1540,5 +1564,23 @@ HWTEST_F(InputMethodControllerTest, testFinishTextPreviewAfterDetach_002, TestSi
inputMethodController_->DeactivateClient();
EXPECT_TRUE(TextListener::isFinishTextPreviewCalled_);
}
/**
* @tc.name: testOnInputReady
* @tc.desc: IMC testOnInputReady
* @tc.type: IMC
* @tc.require:
*/
HWTEST_F(InputMethodControllerTest, testOnInputReady, TestSize.Level0)
{
IMSA_HILOGI("IMC OnInputReady Test START");
InputAttribute inputAttribute = { .isTextPreviewSupported = true };
inputMethodController_->Attach(textListener_, false, inputAttribute);
sptr<IRemoteObject> agentObject = nullptr;
inputMethodController_->OnInputReady(agentObject);
TextListener::ResetParam();
inputMethodController_->DeactivateClient();
EXPECT_TRUE(TextListener::isFinishTextPreviewCalled_);
}
} // namespace MiscServices
} // namespace OHOS