!213 新增显示隐藏键盘功能

Merge pull request !213 from 赵凌岚/master
This commit is contained in:
openharmony_ci 2022-08-15 16:31:38 +00:00 committed by Gitee
commit 6cfac70b84
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
25 changed files with 291 additions and 74 deletions

View File

@ -24,7 +24,7 @@ group("imf_packages") {
"frameworks/inputmethod_ability:inputmethod_ability",
"frameworks/inputmethod_controller:inputmethod_client",
"interfaces/kits/js/declaration:inputmethod",
"interfaces/kits/js/napi/inputmethod:inputmethod",
"interfaces/kits/js/napi/inputmethodclient:inputmethod",
"interfaces/kits/js/napi/inputmethodengine:inputmethodengine",
"profile:inputmethod_inputmethod_sa_profiles",
"services:inputmethod_service",

View File

@ -57,7 +57,7 @@
"//base/inputmethod/imf/frameworks/kits/extension:inputmethod_extension",
"//base/inputmethod/imf/frameworks/kits/extension:inputmethod_extension_module",
"//base/inputmethod/imf/interfaces/kits/js/declaration:inputmethod",
"//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod:inputmethod",
"//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodclient:inputmethod",
"//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine:inputmethodengine",
"//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod_extension_ability:inputmethodextensionability_napi",
"//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod_extension_context:inputmethodextensioncontext_napi",
@ -103,33 +103,6 @@
],
"header_base": "//base/inputmethod/imf/frameworks/inputmethod_ability/include"
}
},
{
"name": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod:inputmethod",
"header": {
"header_files": [
"js_input_method_registry.h",
"js_input_method_utils.h",
"js_input_method_setting.h",
"js_input_method_controller.h"
],
"header_base": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethod/include"
}
},
{
"name": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine:inputmethodengine",
"header": {
"header_files": [
"js_input_method_engine_registry.h",
"js_input_method_engine_listener.h",
"js_input_method_engine.h",
"js_input_method_engine_utils.h",
"js_keyboard_controller.h",
"js_text_input_client.h",
"js_keyboard_delegate.h"
],
"header_base": "//base/inputmethod/imf/interfaces/kits/js/napi/inputmethodengine/include"
}
}
],
"test": [

View File

@ -53,7 +53,7 @@ namespace MiscServices {
const InputAttribute& editorAttribute,
bool supportPhysicalKbd) = 0;
virtual int32_t stopInput() = 0;
virtual bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel) = 0;
virtual bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel, bool isShowKeyboard) = 0;
virtual bool hideKeyboard(int32_t flags) = 0;
virtual int32_t setKeyboardType(const KeyboardType& type) = 0;
virtual int32_t getKeyboardWindowHeight(int32_t &retHeight) = 0;

View File

@ -107,7 +107,7 @@ namespace MiscServices {
void OnSelectionChange(Message *msg);
void InitialInputWindow();
void ShowInputWindow();
void ShowInputWindow(bool isShowKeyboard);
void DissmissInputWindow();
};
} // namespace MiscServices

View File

@ -40,7 +40,7 @@ namespace MiscServices {
const InputAttribute& editorAttribute,
bool supportPhysicalKbd) override;
int32_t stopInput() override;
bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel) override;
bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel, bool isShowKeyboard) override;
bool hideKeyboard(int32_t flags) override;
int32_t setKeyboardType(const KeyboardType& type) override;
int32_t getKeyboardWindowHeight(int32_t &retHeight) override;

View File

@ -49,7 +49,7 @@ namespace MiscServices {
const InputAttribute& editorAttribute,
bool supportPhysicalKbd) override;
int32_t stopInput() override;
bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel) override;
bool showKeyboard(const sptr<IInputDataChannel>& inputDataChannel, bool isShowKeyboard) override;
bool hideKeyboard(int32_t flags)override;
int32_t setKeyboardType(const KeyboardType& type) override;
int32_t getKeyboardWindowHeight(int32_t &retHeight) override;

View File

@ -243,7 +243,8 @@ namespace MiscServices {
return;
}
SetInputDataChannel(channelObject);
ShowInputWindow();
bool isShowKeyboard = data->ReadBool();
ShowInputWindow(isShowKeyboard);
}
void InputMethodAbility::OnHideKeyboard(Message *msg)
@ -321,7 +322,7 @@ namespace MiscServices {
kdListener_->OnSelectionChange(oldBegin, oldEnd, newBegin, newEnd);
}
void InputMethodAbility::ShowInputWindow()
void InputMethodAbility::ShowInputWindow(bool isShowKeyboard)
{
IMSA_HILOGI("InputMethodAbility::ShowInputWindow");
if (!imeListener_) {
@ -329,6 +330,10 @@ namespace MiscServices {
return;
}
imeListener_->OnInputStart();
if (!isShowKeyboard) {
IMSA_HILOGI("InputMethodAbility::ShowInputWindow will not show keyboard");
return;
}
imeListener_->OnKeyboardStatus(true);
std::shared_ptr<InputDataChannelProxy> channel = GetInputDataChannel();
if (channel == nullptr) {

View File

@ -193,7 +193,7 @@ namespace MiscServices {
return reply.ReadInt32();
}
bool InputMethodCoreProxy::showKeyboard(const sptr<IInputDataChannel> &inputDataChannel)
bool InputMethodCoreProxy::showKeyboard(const sptr<IInputDataChannel> &inputDataChannel, bool isShowKeyboard)
{
IMSA_HILOGI("InputMethodCoreProxy::showKeyboard");
auto remote = Remote();
@ -203,14 +203,12 @@ namespace MiscServices {
}
MessageParcel data;
if (!(data.WriteInterfaceToken(GetDescriptor())
&& data.WriteRemoteObject(inputDataChannel->AsObject()))) {
if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteRemoteObject(inputDataChannel->AsObject())
&& data.WriteBool(isShowKeyboard))) {
return false;
}
MessageParcel reply;
MessageOption option {
MessageOption::TF_SYNC
};
MessageOption option { MessageOption::TF_SYNC };
int32_t res = remote->SendRequest(SHOW_KEYBOARD, data, reply, option);
if (res != ErrorCode::NO_ERROR) {

View File

@ -110,7 +110,8 @@ namespace MiscServices {
}
case SHOW_KEYBOARD: {
sptr<IInputDataChannel> inputDataChannel = iface_cast<IInputDataChannel>(data.ReadRemoteObject());
showKeyboard(inputDataChannel);
bool isShowKeyboard = data.ReadBool();
showKeyboard(inputDataChannel, isShowKeyboard);
reply.WriteNoException();
break;
}
@ -230,19 +231,27 @@ namespace MiscServices {
msgHandler_->SendMessage(msg);
}
bool InputMethodCoreStub::showKeyboard(const sptr<IInputDataChannel>& inputDataChannel)
bool InputMethodCoreStub::showKeyboard(const sptr<IInputDataChannel>& inputDataChannel, bool isShowKeyboard)
{
IMSA_HILOGI("InputMethodCoreStub::showKeyboard");
if (!msgHandler_) {
return false;
}
MessageParcel *data = new MessageParcel();
auto *data = new (std::nothrow) MessageParcel();
if (data == nullptr) {
return false;
}
IMSA_HILOGI("InputMethodCoreStub::showKeyboard isShowKeyboard %{public}s", isShowKeyboard ? "true" : "false");
if (inputDataChannel) {
IMSA_HILOGI("InputMethodCoreStub::showKeyboard inputDataChannel is not nullptr");
data->WriteRemoteObject(inputDataChannel->AsObject());
data->WriteBool(isShowKeyboard);
}
Message *msg = new Message(MessageID::MSG_ID_SHOW_KEYBOARD, data);
Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_SHOW_KEYBOARD, data);
if (msg == nullptr) {
return false;
}
msgHandler_->SendMessage(msg);
return true;
}

View File

@ -59,6 +59,7 @@ namespace MiscServices {
public:
static sptr<InputMethodController> GetInstance();
void Attach(sptr<OnTextChangedListener> &listener);
void Attach(sptr<OnTextChangedListener> &listener, bool isShowKeyboard);
std::u16string GetTextBeforeCursor(int32_t number);
std::u16string GetTextAfterCursor(int32_t number);
void ShowTextInput();
@ -74,6 +75,7 @@ namespace MiscServices {
int32_t GetEnterKeyType();
int32_t GetInputPattern();
int32_t HideCurrentInput();
int32_t ShowCurrentInput();
void SetCallingWindow(uint32_t windowId);
int32_t SwitchInputMethod(const InputMethodProperty &target);
@ -85,7 +87,7 @@ namespace MiscServices {
sptr<InputMethodSystemAbilityProxy> GetImsaProxy();
void PrepareInput(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel,
InputAttribute &attribute);
void StartInput(sptr<InputClientStub> &client);
void StartInput(sptr<InputClientStub> &client, bool isShowKeyboard);
void StopInput(sptr<InputClientStub> &client);
void ReleaseInput(sptr<InputClientStub> &client);
void SetInputMethodAgent(sptr<IRemoteObject> &object);

View File

@ -50,6 +50,7 @@ namespace MiscServices {
void stopInput(MessageParcel& data) override;
void SetCoreAndAgent(MessageParcel& data) override;
int32_t HideCurrentInput(MessageParcel& data) override;
int32_t ShowCurrentInput(MessageParcel& data) override;
int32_t Prepare(int32_t displayId, sptr<InputClientStub> &client, sptr<InputDataChannelStub> &channel,
InputAttribute &attribute);

View File

@ -200,18 +200,24 @@ using namespace MessageID;
}
void InputMethodController::Attach(sptr<OnTextChangedListener> &listener)
{
Attach(listener, true);
}
void InputMethodController::Attach(sptr<OnTextChangedListener> &listener, bool isShowKeyboard)
{
textListener = listener;
IMSA_HILOGI("InputMethodController::Attach");
InputmethodTrace tracer("InputMethodController Attach trace.");
StartInput(mClient);
IMSA_HILOGI("InputMethodController::Attach isShowKeyboard %{public}s", isShowKeyboard ? "true" : "false");
StartInput(mClient, isShowKeyboard);
PrepareInput(0, mClient, mInputDataChannel, mAttribute);
}
void InputMethodController::ShowTextInput()
{
IMSA_HILOGI("InputMethodController::ShowTextInput");
StartInput(mClient);
StartInput(mClient, true);
}
void InputMethodController::HideTextInput()
@ -233,6 +239,19 @@ using namespace MessageID;
return mImms->HideCurrentInput(data);
}
int32_t InputMethodController::ShowCurrentInput()
{
IMSA_HILOGI("InputMethodController::ShowCurrentInput");
if (!mImms) {
return ErrorCode::ERROR_KBD_SHOW_FAILED;
}
MessageParcel data;
if (!(data.WriteInterfaceToken(mImms->GetDescriptor()))) {
return ErrorCode::ERROR_KBD_SHOW_FAILED;
}
return mImms->ShowCurrentInput(data);
}
void InputMethodController::Close()
{
ReleaseInput(mClient);
@ -283,15 +302,15 @@ using namespace MessageID;
return properties;
}
void InputMethodController::StartInput(sptr<InputClientStub> &client)
void InputMethodController::StartInput(sptr<InputClientStub> &client, bool isShowKeyboard)
{
IMSA_HILOGI("InputMethodController::StartInput");
if (!mImms) {
return;
}
MessageParcel data;
if (!(data.WriteInterfaceToken(mImms->GetDescriptor())
&& data.WriteRemoteObject(client->AsObject()))) {
if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) && data.WriteRemoteObject(client->AsObject())
&& data.WriteBool(isShowKeyboard))) {
return;
}
isStopInput = false;

View File

@ -81,7 +81,7 @@ namespace MiscServices {
}
}
void InputMethodSystemAbilityProxy::startInput(MessageParcel& data)
void InputMethodSystemAbilityProxy::startInput(MessageParcel &data)
{
IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput");
MessageParcel reply;
@ -155,6 +155,26 @@ namespace MiscServices {
return ErrorCode::NO_ERROR;
}
int32_t InputMethodSystemAbilityProxy::ShowCurrentInput(MessageParcel &data)
{
IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput");
MessageParcel reply;
MessageOption option;
auto ret = Remote()->SendRequest(SHOW_CURRENT_INPUT, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput SendRequest failed");
return ErrorCode::ERROR_KBD_SHOW_FAILED;
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGI("InputMethodSystemAbilityProxy::ShowCurrentInput reply failed");
return ErrorCode::ERROR_KBD_SHOW_FAILED;
}
return ErrorCode::NO_ERROR;
}
int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr<InputClientStub> &client,
sptr<InputDataChannelStub> &channel, InputAttribute &attribute)
{

View File

@ -117,6 +117,48 @@ declare namespace inputMethod {
stopInput(callback: AsyncCallback<boolean>): void;
stopInput(): Promise<boolean>;
/**
* Show soft keyboard
* @since 9
* @param callback
* @return :
* if true, success.
* if false, fail.
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
showSoftKeyboard(callback: AsyncCallback<boolean>): void;
/**
* Show soft keyboard
* @since 9
* @return :
* if true, success.
* if false, fail.
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
showSoftKeyboard():Promise<boolean>;
/**
* Hide soft keyboard
* @since 9
* @param callback
* @return :
* if true, success.
* if false, fail.
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
hideSoftKeyboard(callback: AsyncCallback<boolean>): void;
/**
* Hide soft keyboard
* @since 9
* @return :
* if true, success.
* if false, fail.
* @syscap SystemCapability.MiscServices.InputMethodFramework
*/
hideSoftKeyboard():Promise<boolean>;
}
/**

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")
import("//build/ohos.gni")
config("imf_config") {
visibility = [ ":*" ]
include_dirs = [ "include" ]
}
config("imf_public_config") {
visibility = []
include_dirs = [
"include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
"${inputmethod_path}/services/dfx/include",
]
}
ohos_shared_library("inputmethod") {
sources = [
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_client_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp",
"${inputmethod_path}/frameworks/inputmethod_controller/src/input_method_controller.cpp",
"async_call.cpp",
"input_method_module.cpp",
"js_get_input_method_controller.cpp",
"js_get_input_method_setting.cpp",
"js_input_method.cpp",
]
configs = [ ":imf_config" ]
deps = [
"${ability_runtime_inner_api_path}/ability_manager:ability_manager",
"${ability_runtime_inner_api_path}/app_manager:app_manager",
"${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native",
"${inputmethod_path}/services/dfx:inputmethod_dfx_static",
"//base/global/resource_management/frameworks/resmgr:global_resmgr",
"//base/inputmethod/imf/frameworks/inputmethod_ability:inputmethod_ability",
"//foundation/arkui/napi/:ace_napi",
"//foundation/communication/ipc/interfaces/innerkits/ipc_core:ipc_core",
"//foundation/communication/ipc/interfaces/innerkits/ipc_single:ipc_single",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
]
external_deps = [
"ability_base:want",
"ability_runtime:runtime",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
public_configs = [ ":imf_public_config" ]
relative_install_dir = "module"
subsystem_name = "inputmethod"
part_name = "imf"
}

View File

@ -32,6 +32,8 @@ napi_value JsGetInputMethodController::Init(napi_env env, napi_value info)
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("stopInput", StopInput),
DECLARE_NAPI_FUNCTION("hideSoftKeyboard", HideSoftKeyboard),
DECLARE_NAPI_FUNCTION("showSoftKeyboard", ShowSoftKeyboard),
};
napi_value cons = nullptr;
NAPI_CALL(env, napi_define_class(env, IMC_CLASS_NAME.c_str(), IMC_CLASS_NAME.size(),
@ -81,30 +83,46 @@ napi_value JsGetInputMethodController::GetInputMethodController(napi_env env, na
return instance;
}
napi_value JsGetInputMethodController::StopInput(napi_env env, napi_callback_info info)
napi_value JsGetInputMethodController::HandleSoftKeyboard(
napi_env env, napi_callback_info info, std::function<int32_t()> callback)
{
auto ctxt = std::make_shared<StopInputContext>();
auto ctxt = std::make_shared<HandleContext>();
auto input = [ctxt](napi_env env, size_t argc, napi_value *argv, napi_value self) -> napi_status {
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, " should null or 1 parameters!", napi_invalid_arg);
return napi_ok;
};
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
napi_status status = napi_get_boolean(env, ctxt->isStopInput, result);
napi_status status = napi_get_boolean(env, ctxt->isHandle, result);
IMSA_HILOGE("output napi_get_boolean != nullptr[%{public}d]", result != nullptr);
return status;
};
auto exec = [ctxt](AsyncCall::Context *ctx) {
int32_t errCode = InputMethodController::GetInstance()->HideCurrentInput();
IMSA_HILOGE("exec HideCurrentInput %{public}d", errCode);
auto exec = [ctxt, callback](AsyncCall::Context *ctx) {
int errCode = callback();
IMSA_HILOGI("exec %{public}d", errCode);
if (errCode == ErrorCode::NO_ERROR) {
IMSA_HILOGE("exec HideCurrentInput success");
IMSA_HILOGI("exec success");
ctxt->status = napi_ok;
ctxt->isStopInput = true;
ctxt->isHandle = true;
}
};
ctxt->SetAction(std::move(input), std::move(output));
AsyncCall asyncCall(env, info, std::dynamic_pointer_cast<AsyncCall::Context>(ctxt), 0);
return asyncCall.Call(env, exec);
}
napi_value JsGetInputMethodController::ShowSoftKeyboard(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->ShowCurrentInput(); });
}
napi_value JsGetInputMethodController::HideSoftKeyboard(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); });
}
napi_value JsGetInputMethodController::StopInput(napi_env env, napi_callback_info info)
{
return HandleSoftKeyboard(env, info, [] { return InputMethodController::GetInstance()->HideCurrentInput(); });
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -15,17 +15,17 @@
#ifndef INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H
#define INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H
#include "global.h"
#include "async_call.h"
#include "global.h"
#include "js_input_method.h"
namespace OHOS {
namespace MiscServices {
struct StopInputContext : public AsyncCall::Context {
bool isStopInput = false;
struct HandleContext : public AsyncCall::Context {
bool isHandle = false;
napi_status status = napi_generic_failure;
StopInputContext() : Context(nullptr, nullptr) { };
StopInputContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
HandleContext() : Context(nullptr, nullptr) { };
HandleContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)) { };
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
@ -47,12 +47,16 @@ public:
~JsGetInputMethodController() = default;
static napi_value Init(napi_env env, napi_value info);
static napi_value GetInputMethodController(napi_env env, napi_callback_info info);
static napi_value StopInput(napi_env env, napi_callback_info Info);
static napi_value HandleSoftKeyboard(napi_env env, napi_callback_info info, std::function<int32_t()> callback);
static napi_value HideSoftKeyboard(napi_env env, napi_callback_info info);
static napi_value ShowSoftKeyboard(napi_env env, napi_callback_info info);
static napi_value StopInput(napi_env env, napi_callback_info info);
private:
static napi_value JsConstructor(napi_env env, napi_callback_info cbinfo);
static const std::string IMC_CLASS_NAME;
static thread_local napi_ref IMCRef_;
};
}
}
} // namespace MiscServices
} // namespace OHOS
#endif // INTERFACE_KITS_JS_GETINPUT_METHOD_CCONTROLLER_H

View File

@ -38,6 +38,7 @@ namespace MiscServices {
START_INPUT,
STOP_INPUT,
HIDE_CURRENT_INPUT,
SHOW_CURRENT_INPUT,
SET_INPUT_METHOD_CORE,
GET_DISPLAY_MODE,
GET_KEYBOARD_WINDOW_HEIGHT,
@ -58,6 +59,7 @@ namespace MiscServices {
virtual void stopInput(MessageParcel& data) = 0;
virtual void SetCoreAndAgent(MessageParcel& data) = 0;
virtual int32_t HideCurrentInput(MessageParcel& data) = 0;
virtual int32_t ShowCurrentInput(MessageParcel& data) = 0;
virtual int32_t displayOptionalInputMethod(MessageParcel& data) = 0;
virtual int32_t getDisplayMode(int32_t &retMode) = 0;

View File

@ -35,6 +35,7 @@ namespace MiscServices {
void stopInput(MessageParcel& data) override;
void SetCoreAndAgent(MessageParcel& data) override;
int32_t HideCurrentInput(MessageParcel& data) override;
int32_t ShowCurrentInput(MessageParcel& data) override;
int32_t displayOptionalInputMethod(MessageParcel& data) override;
virtual int32_t listInputMethodByUserId(int32_t userId, std::vector<InputMethodProperty*> *properties) = 0;
int32_t SwitchInputMethod(MessageParcel &data);

View File

@ -46,6 +46,7 @@ namespace MessageID {
MSG_ID_RELEASE_INPUT, // release input
MSG_ID_SET_CORE_AND_AGENT,
MSG_HIDE_CURRENT_INPUT,
MSG_SHOW_CURRENT_INPUT,
MSG_ID_SWITCH_INPUT_METHOD, // switch input method
// the request to handle the condition that the remote object died

View File

@ -171,6 +171,7 @@ namespace MiscServices {
void OnClientDied(const wptr<IRemoteObject>& who);
void OnImsDied(const wptr<IRemoteObject>& who);
void OnHideKeyboardSelf(int flags);
void OnShowKeyboardSelf();
void OnAdvanceToNext();
void OnSetDisplayMode(int mode);
void OnRestartIms(int index, const std::u16string& imeId);
@ -181,7 +182,7 @@ namespace MiscServices {
int RemoveClient(const sptr<IInputClient>& inputClient, int retClientNum);
int StartInputMethod(int index);
int StopInputMethod(int index);
int ShowKeyboard(const sptr<IInputClient>& inputClient);
int ShowKeyboard(const sptr<IInputClient>& inputClient, bool isShowKeyboard);
int HideKeyboard(const sptr<IInputClient>& inputClient);
void SetDisplayId(int displayId);
int GetImeIndex(const sptr<IInputClient>& inputClient);

View File

@ -603,6 +603,7 @@ namespace MiscServices {
case MSG_ID_START_INPUT:
case MSG_ID_STOP_INPUT:
case MSG_HIDE_CURRENT_INPUT:
case MSG_SHOW_CURRENT_INPUT:
case MSG_ID_SET_CORE_AND_AGENT:
case MSG_ID_HIDE_KEYBOARD_SELF:
case MSG_ID_SET_DISPLAY_MODE:

View File

@ -170,6 +170,11 @@ namespace MiscServices {
reply.WriteInt32(NO_ERROR);
break;
}
case SHOW_CURRENT_INPUT: {
int32_t ret = ShowCurrentInput(data);
reply.WriteInt32(ret);
break;
}
case SWITCH_INPUT_METHOD: {
int32_t ret = SwitchInputMethod(data);
reply.WriteInt32(ret);
@ -255,6 +260,7 @@ namespace MiscServices {
MessageParcel *parcel = new MessageParcel();
parcel->WriteInt32(userId);
parcel->WriteRemoteObject(data.ReadRemoteObject());
parcel->WriteBool(data.ReadBool());
Message *msg = new Message(MSG_ID_START_INPUT, parcel);
MessageHandler::Instance()->SendMessage(msg);
@ -311,6 +317,26 @@ namespace MiscServices {
return ErrorCode::NO_ERROR;
}
int32_t InputMethodSystemAbilityStub::ShowCurrentInput(MessageParcel &data)
{
IMSA_HILOGI("InputMethodSystemAbilityStub::ShowCurrentInput");
int32_t uid = IPCSkeleton::GetCallingUid();
int32_t userId = getUserId(uid);
auto *parcel = new (std::nothrow) MessageParcel();
if (parcel == nullptr) {
return ErrorCode::ERROR_EX_NULL_POINTER;
}
parcel->WriteInt32(userId);
auto *msg = new (std::nothrow) Message(MSG_SHOW_CURRENT_INPUT, parcel);
if (msg == nullptr) {
return ErrorCode::ERROR_EX_NULL_POINTER;
}
MessageHandler::Instance()->SendMessage(msg);
return ErrorCode::NO_ERROR;
}
int32_t InputMethodSystemAbilityStub::SwitchInputMethod(MessageParcel &data)
{
IMSA_HILOGI("InputMethodSystemAbilityStub::switchInputMethod");

View File

@ -186,6 +186,10 @@ namespace MiscServices {
OnHideKeyboardSelf(0);
break;
}
case MSG_SHOW_CURRENT_INPUT: {
OnShowKeyboardSelf();
break;
}
default: {
break;
}
@ -271,7 +275,7 @@ namespace MiscServices {
break;
}
if (needReshowClient && GetImeIndex(needReshowClient) == i) {
ShowKeyboard(needReshowClient);
ShowKeyboard(needReshowClient, true);
needReshowClient = nullptr;
}
}
@ -478,7 +482,7 @@ namespace MiscServices {
\return ErrorCode::ERROR_KBD_SHOW_FAILED failed to show keyboard
\return other errors returned by binder driver
*/
int PerUserSession::ShowKeyboard(const sptr<IInputClient>& inputClient)
int PerUserSession::ShowKeyboard(const sptr<IInputClient>& inputClient, bool isShowKeyboard)
{
IMSA_HILOGI("PerUserSession::ShowKeyboard");
ClientInfo *clientInfo = GetClientInfo(inputClient);
@ -493,7 +497,7 @@ namespace MiscServices {
return ErrorCode::ERROR_NULL_POINTER;
}
imsCore[0]->showKeyboard(clientInfo->channel);
imsCore[0]->showKeyboard(clientInfo->channel, isShowKeyboard);
currentClient = inputClient;
return ErrorCode::NO_ERROR;
@ -799,6 +803,12 @@ namespace MiscServices {
HideKeyboard(currentClient);
}
void PerUserSession::OnShowKeyboardSelf()
{
IMSA_HILOGI("PerUserSession::OnShowKeyboardSelf");
ShowKeyboard(currentClient, true);
}
/*! Switch to next keyboard type
*/
void PerUserSession::OnAdvanceToNext()
@ -875,7 +885,7 @@ namespace MiscServices {
int ret = StartInputMethod(index);
if (needReshowClient && GetImeIndex(needReshowClient) == index) {
if (ret == ErrorCode::NO_ERROR) {
ShowKeyboard(needReshowClient);
ShowKeyboard(needReshowClient, true);
}
needReshowClient = nullptr;
}
@ -1253,7 +1263,8 @@ namespace MiscServices {
if (imsCore[0]) {
imsCore[0]->SetClientState(true);
}
ShowKeyboard(client);
bool isShowKeyboard = data->ReadBool();
ShowKeyboard(client, isShowKeyboard);
}
void PerUserSession::SetCoreAndAgent(Message *msg)

View File

@ -218,6 +218,14 @@ namespace MiscServices {
int waitForStatusOk = 2;
sleep(waitForStatusOk);
IMSA_HILOGI("IMC Attach isShowKeyboard true START");
imc->Attach(textListener, true);
sleep(waitForStatusOk);
IMSA_HILOGI("IMC Attach isShowKeyboard false START");
imc->Attach(textListener, false);
sleep(waitForStatusOk);
IMSA_HILOGI("IMC ShowTextInput START");
imc->ShowTextInput();
sleep(10);