diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp index 5a6c0abf3f05656d6b6fdb78e2f78e9d127d8ff5..561e0f332b4ec4419e39e5a371788191344dd508 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.cpp @@ -62,6 +62,7 @@ napi_value JsGetInputMethodSetting::Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getAllInputMethodsSync", GetAllInputMethodsSync), DECLARE_NAPI_FUNCTION("displayOptionalInputMethod", DisplayOptionalInputMethod), DECLARE_NAPI_FUNCTION("showOptionalInputMethods", ShowOptionalInputMethods), + DECLARE_NAPI_FUNCTION("isPanelShown", IsPanelShown), DECLARE_NAPI_FUNCTION("on", Subscribe), DECLARE_NAPI_FUNCTION("off", UnSubscribe), }; @@ -413,6 +414,33 @@ napi_value JsGetInputMethodSetting::ListCurrentInputMethodSubtype(napi_env env, return asyncCall.Call(env, exec, "listCurrentInputMethodSubtype"); } +napi_value JsGetInputMethodSetting::IsPanelShown(napi_env env, napi_callback_info info) +{ + IMSA_HILOGI("run in JsGetInputMethodSetting"); + // 1 means required param num + size_t argc = 1; + napi_value argv[1] = { nullptr }; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr)); + // 1 means least param num + PARAM_CHECK_RETURN(env, argc >= 1, "should has 1 parameters!", TYPE_NONE, JsUtil::Const::Null(env)); + // 0 means parameter of info + napi_valuetype valueType = napi_undefined; + napi_typeof(env, argv[0], &valueType); + PARAM_CHECK_RETURN(env, valueType == napi_object, " panelInfo: ", TYPE_OBJECT, JsUtil::Const::Null(env)); + + PanelInfo panelInfo; + napi_status status = JsUtils::GetValue(env, argv[0], panelInfo); + PARAM_CHECK_RETURN(env, status == napi_ok, " panelInfo: ", TYPE_OBJECT, JsUtil::Const::Null(env)); + + bool isShown = false; + int32_t errorCode = InputMethodController::GetInstance()->IsPanelShown(panelInfo, isShown); + if (errorCode != ErrorCode::NO_ERROR) { + JsUtils::ThrowException(env, JsUtils::Convert(errorCode), "failed to query is panel shown", TYPE_NONE); + return JsUtil::Const::Null(env); + } + return JsUtil::GetValue(env, isShown); +} + int32_t JsGetInputMethodSetting::RegisterListener( napi_value callback, std::string type, std::shared_ptr callbackObj) { diff --git a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h index bae7f3419337d9b06b60657b842efb554978b031..5660e4efeb38acc3596f5f5ecc547df37eba559a 100644 --- a/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h +++ b/frameworks/js/napi/inputmethodclient/js_get_input_method_setting.h @@ -109,6 +109,7 @@ public: static napi_value GetAllInputMethodsSync(napi_env env, napi_callback_info info); static napi_value DisplayOptionalInputMethod(napi_env env, napi_callback_info info); static napi_value ShowOptionalInputMethods(napi_env env, napi_callback_info info); + static napi_value IsPanelShown(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 std::shared_ptr GetInputMethodSettingInstance(); diff --git a/frameworks/native/inputmethod_ability/include/i_input_method_core.h b/frameworks/native/inputmethod_ability/include/i_input_method_core.h index 18ff0841c21469ac079defb20d7eeda1d8dcc7c8..77c4e79bb1ebda23ddc292200924d7026fcc0f6e 100644 --- a/frameworks/native/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/native/inputmethod_ability/include/i_input_method_core.h @@ -25,6 +25,7 @@ #include "input_method_property.h" #include "ipc_types.h" #include "iremote_broker.h" +#include "panel_info.h" /** * brief Definition of interface IInputMethodCore @@ -43,11 +44,13 @@ public: START_INPUT, STOP_INPUT, IS_ENABLE, + IS_PANEL_SHOWN, + CORE_CMD_LAST, }; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodCore"); - virtual int32_t StartInput(const std::shared_ptr &clientInfo, bool isBindFromClient) = 0; + virtual int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) = 0; virtual int32_t StopInput(const sptr &channel) = 0; virtual int32_t ShowKeyboard() = 0; virtual int32_t HideKeyboard() = 0; @@ -55,6 +58,7 @@ public: virtual void StopInputService() = 0; virtual int32_t SetSubtype(const SubProperty &property) = 0; virtual bool IsEnable() = 0; + virtual int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index 3cfffe0e1593e177258097c43f095ba471c413d7..5eb2c0981bfe9206eba8b977c98a214bc34fa625 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -55,7 +55,7 @@ public: int32_t DeleteForward(int32_t length); int32_t DeleteBackward(int32_t length); int32_t HideKeyboardSelf(); - int32_t StartInput(InputClientInfo &clientInfo, bool isBindFromClient); + int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient); int32_t StopInput(const sptr &channelObject); int32_t ShowKeyboard(); int32_t HideKeyboard(); @@ -78,6 +78,7 @@ public: bool IsCurrentIme(); bool IsEnable(); int32_t ExitCurrentInputType(); + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); private: std::thread workThreadHandler; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h index 68aa3ffb826d5a7127921a230498a714e2ae6474..02c1f3f10abfa55c6cf0370c246562da3dffca18 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h @@ -35,7 +35,7 @@ public: DISALLOW_COPY_AND_MOVE(InputMethodCoreProxy); - int32_t StartInput(const std::shared_ptr &clientInfo, bool isBindFromClient) override; + int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) override; int32_t StopInput(const sptr &channel) override; int32_t ShowKeyboard() override; int32_t HideKeyboard() override; @@ -43,6 +43,7 @@ public: void StopInputService() override; int32_t SetSubtype(const SubProperty &property) override; bool IsEnable() override; + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h index e4ea9edc41b4d8c3154824952489337e18cc129f..c11de0e5cb882a9d92ea444f74819910c5198426 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h @@ -39,7 +39,7 @@ public: InputMethodCoreStub(); virtual ~InputMethodCoreStub(); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int32_t StartInput(const std::shared_ptr &clientInfo, bool isBindFromClient) override; + int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) override; int32_t StopInput(const sptr &channel) override; int32_t ShowKeyboard() override; int32_t HideKeyboard() override; @@ -47,18 +47,34 @@ public: void StopInputService() override; int32_t SetSubtype(const SubProperty &property) override; bool IsEnable() override; + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; void SetMessageHandler(MessageHandler *msgHandler); private: MessageHandler *msgHandler_; - void InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply); - void SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply); int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply); int32_t StopInputOnRemote(MessageParcel &data, MessageParcel &reply); - int32_t IsEnableOnRemote(MessageParcel &data, MessageParcel &reply); int32_t ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t HideKeyboardOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t IsEnableOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply); using ParcelHandler = std::function; int32_t SendMessage(int code, ParcelHandler input = nullptr); + using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &); + static inline const std::unordered_map HANDLERS = { + { static_cast(SHOW_KEYBOARD), &InputMethodCoreStub::ShowKeyboardOnRemote }, + { static_cast(STOP_INPUT_SERVICE), &InputMethodCoreStub::StopInputServiceOnRemote }, + { static_cast(HIDE_KEYBOARD), &InputMethodCoreStub::HideKeyboardOnRemote }, + { static_cast(INIT_INPUT_CONTROL_CHANNEL), &InputMethodCoreStub::InitInputControlChannelOnRemote }, + { static_cast(SET_SUBTYPE), &InputMethodCoreStub::SetSubtypeOnRemote }, + { static_cast(START_INPUT), &InputMethodCoreStub::StartInputOnRemote }, + { static_cast(STOP_INPUT), &InputMethodCoreStub::StopInputOnRemote }, + { static_cast(IS_ENABLE), &InputMethodCoreStub::IsEnableOnRemote }, + { static_cast(IS_PANEL_SHOWN), &InputMethodCoreStub::IsPanelShownOnRemote }, + }; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/include/input_method_panel.h b/frameworks/native/inputmethod_ability/include/input_method_panel.h index 3ba264d5397bc287258cf3e894b78d258a564b1a..0f3cc1afef7a7c8253d14f6fb455a824bffdaa73 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_panel.h +++ b/frameworks/native/inputmethod_ability/include/input_method_panel.h @@ -22,27 +22,12 @@ #include "input_window_info.h" #include "js_runtime_utils.h" +#include "panel_info.h" #include "panel_status_listener.h" #include "window.h" namespace OHOS { namespace MiscServices { -enum PanelType { - SOFT_KEYBOARD = 0, - STATUS_BAR, -}; - -enum PanelFlag { - FLG_FIXED = 0, - FLG_FLOATING, - FLG_CANDIDATE_COLUMN, -}; - -struct PanelInfo { - PanelType panelType = SOFT_KEYBOARD; - PanelFlag panelFlag = FLG_FIXED; -}; - class InputMethodPanel { public: InputMethodPanel() = default; @@ -61,10 +46,10 @@ public: void SetPanelStatusListener(std::shared_ptr statusListener, const std::string &type); void ClearPanelListener(const std::string &type); int32_t SetCallingWindow(uint32_t windowId); + bool IsShowing(); uint32_t windowId_ = 0; private: - bool IsShowing(); bool IsHidden(); int32_t SetPanelProperties(); std::string GeneratePanelName(); diff --git a/frameworks/native/inputmethod_ability/include/panel_info.h b/frameworks/native/inputmethod_ability/include/panel_info.h new file mode 100644 index 0000000000000000000000000000000000000000..7ac622ff6b777b8a9cf644fc4b130894c34a2590 --- /dev/null +++ b/frameworks/native/inputmethod_ability/include/panel_info.h @@ -0,0 +1,39 @@ +/* + * 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 INPUTMETHOD_IMF_PANEL_INFO_H +#define INPUTMETHOD_IMF_PANEL_INFO_H + +namespace OHOS { +namespace MiscServices { +enum PanelType { + SOFT_KEYBOARD = 0, + STATUS_BAR, +}; + +enum PanelFlag { + FLG_FIXED = 0, + FLG_FLOATING, + FLG_CANDIDATE_COLUMN, +}; + +struct PanelInfo { + PanelType panelType = SOFT_KEYBOARD; + PanelFlag panelFlag = FLG_FIXED; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif // INPUTMETHOD_IMF_PANEL_INFO_H diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index 66964cc3d277bb7721e7a052632625e341df25eb..5971f184e490caaaec6f9b93375b632816c8b256 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -233,7 +233,7 @@ void InputMethodAbility::OnInitInputControlChannel(Message *msg) SetInputControlChannel(channelObject); } -int32_t InputMethodAbility::StartInput(InputClientInfo &clientInfo, bool isBindFromClient) +int32_t InputMethodAbility::StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) { IMSA_HILOGI("InputMethodAbility::isShowKeyboard: %{public}d", clientInfo.isShowKeyboard); if (clientInfo.channel->AsObject() == nullptr) { @@ -799,5 +799,23 @@ int32_t InputMethodAbility::ExitCurrentInputType() } return proxy->ExitCurrentInputType(); } + +int32_t InputMethodAbility::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + IMSA_HILOGI("InputMethodAbility, type: %{public}d, flag: %{public}d", panelInfo.panelType, panelInfo.panelFlag); + isShown = false; + auto result = panels_.Find(panelInfo.panelType); + if (!result.first) { + IMSA_HILOGD("panel not found"); + return ErrorCode::NO_ERROR; + } + auto panel = result.second; + if (panel->GetPanelType() == PanelType::SOFT_KEYBOARD && panel->GetPanelFlag() != panelInfo.panelFlag) { + IMSA_HILOGD("panel not found"); + return ErrorCode::NO_ERROR; + } + isShown = panel->IsShowing(); + return ErrorCode::NO_ERROR; +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp index 04f928dd8bf06ae462d0eb79be9ff3a4696fd5e0..df4ebcf3f9acb1d924f0596cf4c840fbc4358159 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp @@ -38,12 +38,11 @@ int32_t InputMethodCoreProxy::InitInputControlChannel(const sptr &clientInfo, bool isBindFromClient) +int32_t InputMethodCoreProxy::StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) { IMSA_HILOGD("InputMethodCoreProxy::StartInput"); return SendRequest(START_INPUT, [&clientInfo, isBindFromClient](MessageParcel &data) { - return ITypesUtil::Marshal(data, isBindFromClient, *clientInfo); + return ITypesUtil::Marshal(data, isBindFromClient, clientInfo); }); } @@ -81,6 +80,13 @@ bool InputMethodCoreProxy::IsEnable() return isEnable; } +int32_t InputMethodCoreProxy::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + return SendRequest( + IS_PANEL_SHOWN, [&panelInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, panelInfo); }, + [&isShown](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isShown); }); +} + int32_t InputMethodCoreProxy::SendRequest(int code, ParcelHandler input, ParcelHandler output) { IMSA_HILOGI("InputMethodCoreProxy, run in, code = %{public}d", code); diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp index b8e8b92ef260c4049a216ceee6e43c143d4b6fa4..393686f241b6900fb5bf4f7f0e9903816629c530 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp @@ -14,9 +14,10 @@ */ #include "input_method_core_stub.h" -#include #include +#include + #include "i_input_data_channel.h" #include "input_channel.h" #include "input_control_channel_proxy.h" @@ -40,64 +41,26 @@ InputMethodCoreStub::~InputMethodCoreStub() int32_t InputMethodCoreStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - IMSA_HILOGI("InputMethodCoreStub, code = %{public}u, callingPid: %{public}d, callingUid: %{public}d", code, + IMSA_HILOGI("InputMethodCoreStub, code: %{public}u, callingPid: %{public}d, callingUid: %{public}d", code, IPCSkeleton::GetCallingPid(), IPCSkeleton::GetCallingUid()); auto descriptorToken = data.ReadInterfaceToken(); - if (descriptorToken != GetDescriptor()) { - IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest descriptorToken is invalid"); + if (descriptorToken != IInputMethodCore::GetDescriptor()) { + IMSA_HILOGE("InputMethodCoreStub descriptor error"); return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; } - switch (code) { - case INIT_INPUT_CONTROL_CHANNEL: { - InitInputControlChannelOnRemote(data, reply); - break; - } - case START_INPUT: { - return StartInputOnRemote(data, reply); - } - case HIDE_KEYBOARD: { - reply.WriteInt32(HideKeyboard()); - break; - } - case STOP_INPUT_SERVICE: { - StopInputService(); - reply.WriteInt32(ErrorCode::NO_ERROR); - break; - } - case SET_SUBTYPE: { - SetSubtypeOnRemote(data, reply); - break; - } - case STOP_INPUT: { - return StopInputOnRemote(data, reply); - } - case SHOW_KEYBOARD: { - return ShowKeyboardOnRemote(data, reply); - } - case IS_ENABLE: { - return IsEnableOnRemote(data, reply); - } - default: { - return IRemoteStub::OnRemoteRequest(code, data, reply, option); - } + if (code >= 0 && code < static_cast(CORE_CMD_LAST)) { + return (this->*HANDLERS.at(code))(data, reply); + } else { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - return NO_ERROR; } int32_t InputMethodCoreStub::InitInputControlChannel(const sptr &inputControlChannel) { IMSA_HILOGD("InputMethodCoreStub::InitInputControlChannel"); - if (msgHandler_ == nullptr) { - return ErrorCode::ERROR_NULL_POINTER; - } - MessageParcel *data = new MessageParcel(); - if (inputControlChannel != nullptr) { - IMSA_HILOGD("InputMethodCoreStub, inputControlChannel is not nullptr"); - data->WriteRemoteObject(inputControlChannel->AsObject()); - } - Message *msg = new Message(MessageID::MSG_ID_INIT_INPUT_CONTROL_CHANNEL, data); - msgHandler_->SendMessage(msg); - return ErrorCode::NO_ERROR; + return SendMessage(MessageID::MSG_ID_INIT_INPUT_CONTROL_CHANNEL, [inputControlChannel](MessageParcel &data) { + return ITypesUtil::Marshal(data, inputControlChannel->AsObject()); + }); } int32_t InputMethodCoreStub::ShowKeyboard() @@ -115,12 +78,7 @@ int32_t InputMethodCoreStub::HideKeyboard() void InputMethodCoreStub::StopInputService() { IMSA_HILOGD("InputMethodCoreStub::StopInputService"); - if (msgHandler_ == nullptr) { - return; - } - MessageParcel *data = new MessageParcel(); - Message *msg = new Message(MessageID::MSG_ID_STOP_INPUT_SERVICE, data); - msgHandler_->SendMessage(msg); + SendMessage(MessageID::MSG_ID_STOP_INPUT_SERVICE); } void InputMethodCoreStub::SetMessageHandler(MessageHandler *msgHandler) @@ -128,22 +86,20 @@ void InputMethodCoreStub::SetMessageHandler(MessageHandler *msgHandler) msgHandler_ = msgHandler; } -void InputMethodCoreStub::InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply) +int32_t InputMethodCoreStub::InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply) { sptr channelObject = data.ReadRemoteObject(); if (channelObject == nullptr) { IMSA_HILOGE("channelObject is nullptr"); - reply.WriteInt32(ErrorCode::ERROR_EX_PARCELABLE); - return; + return reply.WriteInt32(ErrorCode::ERROR_EX_PARCELABLE) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } - sptr inputControlChannel = new InputControlChannelProxy(channelObject); + sptr inputControlChannel = new (std::nothrow) InputControlChannelProxy(channelObject); if (inputControlChannel == nullptr) { IMSA_HILOGE("failed to new inputControlChannel"); - reply.WriteInt32(ErrorCode::ERROR_NULL_POINTER); - return; + return reply.WriteInt32(ErrorCode::ERROR_NULL_POINTER) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } auto ret = InitInputControlChannel(inputControlChannel); - reply.WriteInt32(ret); + return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } int32_t InputMethodCoreStub::StartInputOnRemote(MessageParcel &data, MessageParcel &reply) @@ -155,18 +111,18 @@ int32_t InputMethodCoreStub::StartInputOnRemote(MessageParcel &data, MessageParc IMSA_HILOGE("Unmarshal failed."); return ErrorCode::ERROR_EX_PARCELABLE; } - auto ret = InputMethodAbility::GetInstance()->StartInput(clientInfo, isBindFromClient); + auto ret = StartInput(clientInfo, isBindFromClient); return ITypesUtil::Marshal(reply, ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } -void InputMethodCoreStub::SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply) +int32_t InputMethodCoreStub::SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply) { IMSA_HILOGD("InputMethodCoreStub::SetSubtypeOnRemote"); SubProperty property; int32_t ret = SendMessage(MessageID::MSG_ID_SET_SUBTYPE, [&data, &property](MessageParcel &parcel) { return ITypesUtil::Unmarshal(data, property) && ITypesUtil::Marshal(parcel, property); }); - reply.WriteInt32(ret); + return reply.WriteInt32(ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } int32_t InputMethodCoreStub::StopInputOnRemote(MessageParcel &data, MessageParcel &reply) @@ -195,9 +151,35 @@ int32_t InputMethodCoreStub::ShowKeyboardOnRemote(MessageParcel &data, MessagePa return ITypesUtil::Marshal(reply, ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } -int32_t InputMethodCoreStub::StartInput(const std::shared_ptr &clientInfo, bool isBindFromClient) +int32_t InputMethodCoreStub::HideKeyboardOnRemote(MessageParcel &data, MessageParcel &reply) { - return ErrorCode::NO_ERROR; + IMSA_HILOGD("run in"); + auto ret = HideKeyboard(); + return ITypesUtil::Marshal(reply, ret) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} + +int32_t InputMethodCoreStub::StopInputServiceOnRemote(MessageParcel &data, MessageParcel &reply) +{ + IMSA_HILOGD("run in"); + StopInputService(); + return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} + +int32_t InputMethodCoreStub::IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply) +{ + PanelInfo info; + if (!ITypesUtil::Unmarshal(data, info)) { + IMSA_HILOGE("unmarshal failed"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + bool isShown = false; + int32_t ret = IsPanelShown(info, isShown); + return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} + +int32_t InputMethodCoreStub::StartInput(const InputClientInfo &clientInfo, bool isBindFromClient) +{ + return InputMethodAbility::GetInstance()->StartInput(clientInfo, isBindFromClient); } int32_t InputMethodCoreStub::SetSubtype(const SubProperty &property) @@ -215,6 +197,11 @@ bool InputMethodCoreStub::IsEnable() return InputMethodAbility::GetInstance()->IsEnable(); } +int32_t InputMethodCoreStub::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + return InputMethodAbility::GetInstance()->IsPanelShown(panelInfo, isShown); +} + int32_t InputMethodCoreStub::SendMessage(int code, ParcelHandler input) { IMSA_HILOGD("InputMethodCoreStub::SendMessage"); diff --git a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h index 779c2f3be163d29e6dc72fc2e366f577d56e3a08..080633e4947c570229558d0aeac12bee6d847de9 100644 --- a/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/native/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -68,6 +68,7 @@ public: bool IsInputTypeSupported(InputType type) override; int32_t StartInputType(InputType type) override; int32_t ExitCurrentInputType() override; + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; // Deprecated because of no permission check, kept for compatibility int32_t HideCurrentInputDeprecated() override; diff --git a/frameworks/native/inputmethod_controller/include/itypes_util.h b/frameworks/native/inputmethod_controller/include/itypes_util.h index 38891ff725160b0349fe09e5185df24874a61817..1389942a5fa1a7b64e182c3394e6017727f107c3 100644 --- a/frameworks/native/inputmethod_controller/include/itypes_util.h +++ b/frameworks/native/inputmethod_controller/include/itypes_util.h @@ -26,6 +26,7 @@ #include "input_client_info.h" #include "input_window_info.h" #include "message_parcel.h" +#include "panel_info.h" namespace OHOS { namespace MiscServices { @@ -88,6 +89,9 @@ public: static bool Marshalling(const OHOS::AppExecFwk::ElementName &input, MessageParcel &data); static bool Unmarshalling(OHOS::AppExecFwk::ElementName &output, MessageParcel &data); + static bool Marshalling(const PanelInfo &input, MessageParcel &data); + static bool Unmarshalling(PanelInfo &output, MessageParcel &data); + template static bool Marshalling(const std::vector &val, MessageParcel &parcel); template diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 2aa881c3fc3846cfa0c4357291ce79b119af41f9..aa5a9a2efba6d159a6df8d8d70f1e4565eddac48 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1049,5 +1049,15 @@ int32_t InputMethodController::StartInputType(InputType type) } return proxy->StartInputType(type); } + +int32_t InputMethodController::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + auto proxy = GetSystemAbilityProxy(); + if (proxy == nullptr) { + IMSA_HILOGE("proxy is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; + } + return proxy->IsPanelShown(panelInfo, isShown); +} } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp index f063951fe6f5b01aacd82bf3867dd7aea88efae7..0845bf50a63d04fa640b75e7e30df1a9a2d2c4e7 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -223,6 +223,14 @@ int32_t InputMethodSystemAbilityProxy::ExitCurrentInputType() return SendRequest(static_cast(InputMethodInterfaceCode::EXIT_CURRENT_INPUT_TYPE)); } +int32_t InputMethodSystemAbilityProxy::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + return SendRequest( + static_cast(InputMethodInterfaceCode::IS_PANEL_SHOWN), + [&panelInfo](MessageParcel &data) { return ITypesUtil::Marshal(data, panelInfo); }, + [&isShown](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isShown); }); +} + void InputMethodSystemAbilityProxy::GetMessageOption(int32_t code, MessageOption &option) { switch (code) { diff --git a/frameworks/native/inputmethod_controller/src/itypes_util.cpp b/frameworks/native/inputmethod_controller/src/itypes_util.cpp index 2d2e7dd1bb6f61cbc1f250179f4af7e1f1a54d4d..f20dbad9fd2b9958b7b93b4e584ad342d9a0ecdb 100644 --- a/frameworks/native/inputmethod_controller/src/itypes_util.cpp +++ b/frameworks/native/inputmethod_controller/src/itypes_util.cpp @@ -316,5 +316,23 @@ bool ITypesUtil::Unmarshalling(InputType &output, MessageParcel &data) output = static_cast(ret); return true; } + +bool ITypesUtil::Marshalling(const PanelInfo &input, MessageParcel &data) +{ + return data.WriteInt32(static_cast(input.panelType)) + && data.WriteInt32(static_cast(input.panelFlag)); +} + +bool ITypesUtil::Unmarshalling(PanelInfo &output, MessageParcel &data) +{ + int32_t panelType = 0; + int32_t panelFlag = 0; + if (!data.ReadInt32(panelType) || !data.ReadInt32(panelFlag)) { + return false; + } + output.panelFlag = static_cast(panelFlag); + output.panelType = static_cast(panelType); + return true; +} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index edab3660a4a0b1f1003bd957db5cb2facd7774b1..e1a55e9965761f90b6ff34b4cb6c97c5243124af 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -37,6 +37,7 @@ #include "iremote_object.h" #include "key_event.h" #include "message_handler.h" +#include "panel_info.h" #include "visibility.h" namespace OHOS { @@ -626,7 +627,7 @@ public: * * @param type Indicates the input type being queried. * @return Returns true for supported, false for not supported. - * @since 10 + * @since 11 */ IMF_API bool IsInputTypeSupported(InputType type); @@ -637,10 +638,22 @@ public: * * @param type Indicates the input type being specified. * @return Returns 0 for success, others for failure. - * @since 10 + * @since 11 */ IMF_API int32_t StartInputType(InputType type); + /** + * @brief Query whether the specific type panel is shown. + * + * This function is used to query whether the specific type panel is shown. + * + * @param panelInfo Indicates the info of the panel. + * @param isShown Indicates the state of the specific panel. + * @return Returns 0 for success, others for failure. + * @since 11 + */ + IMF_API int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); + private: InputMethodController(); ~InputMethodController(); diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index 81e25ca2ca0a2c72a6c544c293c5ecae4e946191..4c7545c65bd434ef204e945feb906ad2b23cf963 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -34,6 +34,7 @@ #include "input_window_info.h" #include "iremote_broker.h" #include "message_parcel.h" +#include "panel_info.h" #include "unRegistered_type.h" namespace OHOS { @@ -66,6 +67,7 @@ public: virtual bool IsInputTypeSupported(InputType type) = 0; virtual int32_t StartInputType(InputType type) = 0; virtual int32_t ExitCurrentInputType() = 0; + virtual int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) = 0; // Deprecated because of no permission check, and keep for compatibility virtual int32_t HideCurrentInputDeprecated() = 0; diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 5e5c16dde54736025aa0ad4309efc7714d3f16f1..c176446854f4e597d382bf9361d4d85a318d66b7 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -75,6 +75,7 @@ public: bool IsInputTypeSupported(InputType type) override; int32_t StartInputType(InputType type) override; int32_t ExitCurrentInputType() override; + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override; // Deprecated because of no permission check, kept for compatibility int32_t HideCurrentInputDeprecated() override; diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index 188bc4360c73ddfea9dd03f937a57766f874133e..0894c24aa430ed459733e493b2ea1004b665c6e7 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -86,6 +86,8 @@ private: int32_t GetInputMethodConfigOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply); + using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &); static constexpr RequestHandler HANDLERS[static_cast(InputMethodInterfaceCode::IMS_CMD_LAST)] = { [static_cast(InputMethodInterfaceCode::START_INPUT)] = @@ -142,6 +144,8 @@ private: &InputMethodSystemAbilityStub::GetDefaultInputMethodOnRemote, [static_cast(InputMethodInterfaceCode::GET_INPUT_METHOD_SETTINGS)] = &InputMethodSystemAbilityStub::GetInputMethodConfigOnRemote, + [static_cast(InputMethodInterfaceCode::IS_PANEL_SHOWN)] = + &InputMethodSystemAbilityStub::IsPanelShownOnRemote, }; }; } // namespace OHOS::MiscServices diff --git a/services/include/inputmethod_service_ipc_interface_code.h b/services/include/inputmethod_service_ipc_interface_code.h index 83058b531aea51eb64d38b8edaaf6e4ce84827f5..fcfe3f731c19adb75e9ab74928076cd29770f72a 100644 --- a/services/include/inputmethod_service_ipc_interface_code.h +++ b/services/include/inputmethod_service_ipc_interface_code.h @@ -47,6 +47,7 @@ enum class InputMethodInterfaceCode { EXIT_CURRENT_INPUT_TYPE, GET_DEFAULT_INPUT_METHOD, GET_INPUT_METHOD_SETTINGS, + IS_PANEL_SHOWN, IMS_CMD_LAST, }; } // namespace MiscServices diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 9aa7970482276f03e2df881f4b96d1d82e4342b2..1186434514f587cb7f7dab3c948af9279581a82e 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -43,6 +43,7 @@ #include "iremote_object.h" #include "message.h" #include "message_handler.h" +#include "panel_info.h" #include "unRegistered_type.h" namespace OHOS { namespace MiscServices { @@ -89,6 +90,7 @@ public: bool IsProxyImeEnable(); bool IsBoundToClient(); int32_t ExitCurrentInputType(); + int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); private: struct ResetManager { diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 46d8755a8ae552ac31e52f380a6cb06af37fc9ab..31adc065cd5516841a17ca28111cc6b30681fb4e 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -407,6 +407,15 @@ int32_t InputMethodSystemAbility::ExitCurrentInputType() return userSession_->ExitCurrentInputType(); } +int32_t InputMethodSystemAbility::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + if (!identityChecker_->IsSystemApp(IPCSkeleton::GetCallingFullTokenID())) { + IMSA_HILOGE("not system application"); + return ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION; + } + return userSession_->IsPanelShown(panelInfo, isShown); +} + int32_t InputMethodSystemAbility::DisplayOptionalInputMethod() { IMSA_HILOGD("InputMethodSystemAbility run in"); diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index d9502d05fbe905bf10da1153572e16f8a9392ec8..a3894f13a0a8ace901a83cbeda8fde158fe97b9d 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -317,5 +317,17 @@ int32_t InputMethodSystemAbilityStub::ExitCurrentInputTypeOnRemote(MessageParcel { return ITypesUtil::Marshal(reply, ExitCurrentInputType()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; } + +int32_t InputMethodSystemAbilityStub::IsPanelShownOnRemote(MessageParcel &data, MessageParcel &reply) +{ + PanelInfo info; + if (!ITypesUtil::Unmarshal(data, info)) { + IMSA_HILOGE("unmarshal failed"); + return ErrorCode::ERROR_EX_PARCELABLE; + } + bool isShown = false; + int32_t ret = IsPanelShown(info, isShown); + return ITypesUtil::Marshal(reply, ret, isShown) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE; +} } // namespace MiscServices } // namespace OHOS diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 014b030da1d92706fab07621ce695323b8dedc59..121d449e3d5c3c407ac22d7d5098fe0272057e2b 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -406,7 +406,7 @@ int32_t PerUserSession::BindClientWithIme( IMSA_HILOGE("ime: %{public}d is abnormal", type); return ErrorCode::ERROR_IME_NOT_STARTED; } - auto ret = data->core->StartInput(clientInfo, isBindFromClient); + 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; @@ -883,5 +883,15 @@ int32_t PerUserSession::ExitCurrentInputType() } return ErrorCode::NO_ERROR; } + +int32_t PerUserSession::IsPanelShown(const PanelInfo &panelInfo, bool &isShown) +{ + auto ime = GetImeData(ImeType::IME); + if (ime == nullptr) { + IMSA_HILOGE("ime not started"); + return ErrorCode::ERROR_IME_NOT_STARTED; + } + return ime->core->IsPanelShown(panelInfo, isShown); +} } // namespace MiscServices } // namespace OHOS diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index b7bc28d79f8de92ac3be608c574eb95337e57ec2..14318d36f9f838bff9c43edb4c7fe82b6db802e9 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -217,7 +217,9 @@ ohos_unittest("InputMethodPanelTest") { ] external_deps = [ + "ability_base:want", "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", "access_token:libaccesstoken_sdk", "c_utils:utils", "eventhandler:libeventhandler", diff --git a/test/unittest/cpp_test/src/input_method_panel_test.cpp b/test/unittest/cpp_test/src/input_method_panel_test.cpp index 6658c76efb01863e8698a9ad1d1fa0acc048030b..2474081546085e1c33197a2a4e9f60834eb36df7 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -24,6 +24,7 @@ #include "display_manager.h" #include "global.h" +#include "input_method_ability.h" #include "input_method_controller.h" #include "panel_status_listener.h" #include "tdd_util.h" @@ -72,6 +73,7 @@ public: static InputWindowStatus status_; static std::vector windowInfo_; static sptr imc_; + static sptr ima_; static uint32_t windowWidth_; static uint32_t windowHeight_; static bool showPanel_; @@ -111,6 +113,7 @@ std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_; InputWindowStatus InputMethodPanelTest::status_{ InputWindowStatus::HIDE }; std::vector InputMethodPanelTest::windowInfo_; sptr InputMethodPanelTest::imc_; +sptr InputMethodPanelTest::ima_; uint32_t InputMethodPanelTest::windowWidth_ = 0; uint32_t InputMethodPanelTest::windowHeight_ = 0; uint64_t InputMethodPanelTest::tokenId_ = 0; @@ -119,6 +122,7 @@ void InputMethodPanelTest::SetUpTestCase(void) IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase"); TddUtil::StorageSelfTokenID(); + ima_ = InputMethodAbility::GetInstance(); auto listener = std::make_shared(); imc_ = InputMethodController::GetInstance(); imc_->SetSettingListener(listener); @@ -438,6 +442,110 @@ HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0) EXPECT_EQ(ret, ErrorCode::NO_ERROR); } +/** + * @tc.name: testIsPanelShown_001 + * @tc.desc: Test is panel shown. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start."); + TddUtil::SetTestTokenID(tokenId_); + int32_t ret = ima_->SetCoreAndAgent(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + bool isShown = false; + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED }; + ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + // query when fixed soft keyboard is showing + ret = inputMethodPanel->ShowPanel(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(isShown); + + // query when fixed soft keyboard is hidden + ret = inputMethodPanel->HidePanel(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(isShown); + + ret = ima_->DestroyPanel(inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** + * @tc.name: testIsPanelShown_002 + * @tc.desc: Test is panel shown. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start."); + TddUtil::SetTestTokenID(tokenId_); + int32_t ret = ima_->SetCoreAndAgent(); + bool isShown = false; + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED }; + ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = inputMethodPanel->ShowPanel(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + // query panel with old info when panel changes its flag. + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(isShown); + // query panel with updated shown one's info when panel changes its flag. + panelInfo.panelFlag = PanelFlag::FLG_FLOATING; + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(isShown); + + ret = ima_->DestroyPanel(inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + +/** + * @tc.name: testIsPanelShown_003 + * @tc.desc: Test is panel shown. + * @tc.type: FUNC + */ +HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start."); + TddUtil::SetTestTokenID(tokenId_); + int32_t ret = ima_->SetCoreAndAgent(); + bool isShown = false; + auto inputMethodPanel = std::make_shared(); + PanelInfo panelInfo = { .panelType = STATUS_BAR }; + ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + + // query status bar's status when it is showing + ret = inputMethodPanel->ShowPanel(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_TRUE(isShown); + + // query status bar's status when it is hidden + ret = inputMethodPanel->HidePanel(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = imc_->IsPanelShown(panelInfo, isShown); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + EXPECT_FALSE(isShown); + + ret = ima_->DestroyPanel(inputMethodPanel); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + /** * @tc.name: testSetPanelStatusListener * @tc.desc: Test SetPanelStatusListener.