修改方案

Signed-off-by: cy7717 <chenyu301@huawei.com>
This commit is contained in:
cy7717 2022-12-22 10:50:15 +08:00
parent d257092e96
commit 8b39768e36
6 changed files with 56 additions and 18 deletions

View File

@ -37,8 +37,8 @@
namespace OHOS {
namespace MiscServices {
struct IMAReadyHandleInfo {
bool isNeedProcessed{ false };
struct StartInputImeNotifier {
bool isNotifier{ false };
bool isShowKeyboard{};
SubProperty subProperty{};
};
@ -62,7 +62,7 @@ public:
void SetCallingWindow(uint32_t windowId);
int32_t GetEnterKeyType(int32_t &keyType);
int32_t GetInputPattern(int32_t &inputPattern);
void IMAReadyHandle();
void ImeReadyHandle();
private:
std::thread workThreadHandler;
@ -110,7 +110,8 @@ private:
void OnSelectionChange(Message *msg);
void ShowInputWindow(bool isShowKeyboard, const SubProperty &subProperty);
void DismissInputWindow();
IMAReadyHandleInfo info_;
bool isImeReady_{ false };
StartInputImeNotifier imeNotifier_;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -132,15 +132,15 @@ void InputMethodAbility::setImeListener(std::shared_ptr<InputMethodEngineListene
}
}
void InputMethodAbility::IMAReadyHandle()
void InputMethodAbility::ImeReadyHandle()
{
if (!info_.isNeedProcessed) {
IMSA_HILOGI("InputMethodAbility::IMA Ready, don't need to deal");
isImeReady_ = true;
if (!imeNotifier_.isNotifier) {
IMSA_HILOGI("InputMethodAbility::Ime Ready, don't need to notify");
return;
}
IMSA_HILOGI("InputMethodAbility::IMA Ready");
ShowInputWindow(info_.isShowKeyboard, info_.subProperty);
info_.isNeedProcessed = false;
IMSA_HILOGI("InputMethodAbility::IMA Ready, notify StartInput");
ShowInputWindow(imeNotifier_.isShowKeyboard, imeNotifier_.subProperty);
}
void InputMethodAbility::setKdListener(std::shared_ptr<KeyboardListener> kdListener)
@ -308,13 +308,18 @@ void InputMethodAbility::OnSelectionChange(Message *msg)
void InputMethodAbility::ShowInputWindow(bool isShowKeyboard, const SubProperty &subProperty)
{
IMSA_HILOGI("InputMethodAbility::ShowInputWindow");
if (imeListener_ == nullptr || !imeListener_->OnInputStart()) {
IMSA_HILOGI("InputMethodAbility::IMA not ready");
info_.isNeedProcessed = true;
info_.isShowKeyboard = isShowKeyboard;
info_.subProperty = subProperty;
if (!isImeReady_) {
IMSA_HILOGI("InputMethodAbility::ime is unready, stores imeNotifier_");
imeNotifier_.isNotifier = true;
imeNotifier_.isShowKeyboard = isShowKeyboard;
imeNotifier_.subProperty = subProperty;
return;
}
if (imeListener_ == nullptr) {
IMSA_HILOGI("InputMethodAbility::ShowInputWindow imeListener_ is nullptr");
return;
}
imeListener_->OnInputStart();
imeListener_->OnSetSubtype(subProperty);
if (!isShowKeyboard) {
IMSA_HILOGI("InputMethodAbility::ShowInputWindow will not show keyboard");

View File

@ -85,6 +85,7 @@ config("ability_public_config") {
ohos_shared_library("inputmethod_extension") {
include_dirs = [
"${inputmethod_path}/frameworks/kits/extension/include",
"${inputmethod_path}/frameworks/inputmethod_controller/include",
"//base/global/i18n/frameworks/intl/include",
"${inputmethod_path}/services/include",
"${inputmethod_path}/services/dfx/include",
@ -105,7 +106,6 @@ ohos_shared_library("inputmethod_extension") {
deps = [
"${ability_runtime_path}/frameworks/native/appkit:app_context",
"${inputmethod_path}/frameworks/inputmethod_ability:inputmethod_ability",
"${inputmethod_path}/frameworks/inputmethod_controller:inputmethod_client",
"${inputmethod_path}/services/dfx:inputmethod_dfx_static",
]

View File

@ -162,7 +162,7 @@ void JsInputMethodExtension::OnStart(const AAFwk::Want &want)
NativeValue *argv[] = { nativeWant };
StartAsync(HITRACE_TAG_MISC, "onCreate", static_cast<int32_t>(TraceTaskId::ONCREATE_EXTENSION));
CallObjectMethod("onCreate", argv, ARGC_ONE);
InputMethodAbility::GetInstance()->IMAReadyHandle();
InputMethodAbility::GetInstance()->ImeReadyHandle();
FinishAsync(HITRACE_TAG_MISC, "onCreate", static_cast<int32_t>(TraceTaskId::ONSTART_EXTENSION));
}

View File

@ -453,7 +453,7 @@ int32_t PerUserSession::OnSetCoreAndAgent(sptr<IInputMethodCore> core, sptr<IInp
if (client != nullptr) {
auto it = mapClients.find(client->AsObject());
if (it != mapClients.end()) {
IMSA_HILOGI("PerUserSession::Bind IMC to IMA");
IMSA_HILOGI("PerUserSession::Bind IMC to IMA, and notify StartInput to IME");
OnStartInput(it->second->client, it->second->isShowKeyBoard);
}
}

View File

@ -226,6 +226,38 @@ HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
EXPECT_TRUE(outAttribute.GetSecurityFlag());
}
/**
* @tc.name: testShowKeyboardInputMethodCoreProxy
* @tc.desc: Test InputMethodCoreProxy ShowKeyboard
* @tc.type: FUNC
* @tc.require: issueI5NXHK
*/
HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0)
{
sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub(0);
sptr<IInputMethodCore> core = coreStub;
auto msgHandler = new (std::nothrow) MessageHandler();
coreStub->SetMessageHandler(msgHandler);
sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
MessageParcel data;
data.WriteRemoteObject(core->AsObject());
data.WriteRemoteObject(channelStub->AsObject());
sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
sptr<InputDataChannelProxy> channelProxy = new InputDataChannelProxy(channelObject);
SubProperty subProperty;
auto ret = coreProxy->showKeyboard(channelProxy, false, subProperty);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
auto cvStatus = InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME));
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(cvStatus, std::cv_status::timeout);
EXPECT_TRUE(InputMethodAbilityTest::showKeyboard_);
delete msgHandler;
}
/**
* @tc.name: testHideKeyboardSelfWithoutImeListener
* @tc.desc: InputMethodAbility HideKeyboardSelf Without ImeListener