!1480 获取输入类型并通知到面板测

Merge pull request !1480 from guojin31/master
This commit is contained in:
openharmony_ci 2024-10-12 06:15:52 +00:00 committed by Gitee
commit 7f5950cf5c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
21 changed files with 130 additions and 20 deletions

View File

@ -314,16 +314,20 @@ bool ITypesUtil::Unmarshalling(PanelStatusInfo &output, MessageParcel &data)
bool ITypesUtil::Marshalling(const SysPanelStatus &input, MessageParcel &data)
{
return data.WriteBool(input.isSecurity) && data.WriteInt32(input.flag) && data.WriteUint32(input.width) &&
data.WriteUint32(input.height);
return data.WriteInt32(static_cast<int32_t>(input.inputType)) &&
data.WriteInt32(input.flag) &&
data.WriteUint32(input.width) &&
data.WriteUint32(input.height);
}
bool ITypesUtil::Unmarshalling(SysPanelStatus &output, MessageParcel &data)
{
if (!data.ReadBool(output.isSecurity) || !data.ReadInt32(output.flag) || !data.ReadUint32(output.width) ||
int32_t inputType = 0;
if (!data.ReadInt32(inputType) || !data.ReadInt32(output.flag) || !data.ReadUint32(output.width) ||
!data.ReadUint32(output.height)) {
return false;
}
output.inputType = static_cast<InputType>(inputType);
return true;
}

View File

@ -179,7 +179,12 @@ napi_value JsPanel::Resize(napi_env env, napi_callback_info info)
jsQueue_.Pop();
return;
}
SysPanelStatus sysPanelStatus = { false, ctxt->inputMethodPanel->GetPanelFlag(), ctxt->width, ctxt->height };
SysPanelStatus sysPanelStatus = {
InputType::NONE,
ctxt->inputMethodPanel->GetPanelFlag(),
ctxt->width,
ctxt->height
};
InputMethodAbility::GetInstance()->NotifyPanelStatus(ctxt->inputMethodPanel, sysPanelStatus);
auto code = ctxt->inputMethodPanel->Resize(ctxt->width, ctxt->height);
jsQueue_.Pop();
@ -454,10 +459,10 @@ napi_value JsPanel::AdjustPanelRect(napi_env env, napi_callback_info info)
}
SysPanelStatus sysPanelStatus;
if (ctxt->inputMethodPanel->IsDisplayPortrait()) {
sysPanelStatus = { false, ctxt->panelFlag, ctxt->layoutParams.portraitRect.width_,
sysPanelStatus = { InputType::NONE, ctxt->panelFlag, ctxt->layoutParams.portraitRect.width_,
ctxt->layoutParams.portraitRect.height_ };
} else {
sysPanelStatus = { false, ctxt->panelFlag, ctxt->layoutParams.landscapeRect.width_,
sysPanelStatus = { InputType::NONE, ctxt->panelFlag, ctxt->layoutParams.landscapeRect.width_,
ctxt->layoutParams.landscapeRect.height_ };
}
InputMethodAbility::GetInstance()->NotifyPanelStatus(ctxt->inputMethodPanel, sysPanelStatus);

View File

@ -367,7 +367,7 @@ napi_value JsPanelStatus::Write(napi_env env, const SysPanelStatus &in)
{
napi_value jsObject = nullptr;
napi_create_object(env, &jsObject);
bool ret = JsUtil::Object::WriteProperty(env, jsObject, "isSecurity", in.isSecurity);
bool ret = JsUtil::Object::WriteProperty(env, jsObject, "inputType", static_cast<int32_t>(in.inputType));
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "flag", in.flag);
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "width", in.width);
ret = ret && JsUtil::Object::WriteProperty(env, jsObject, "height", in.height);

View File

@ -95,7 +95,11 @@ private:
std::string smartMenu;
std::unordered_map<std::string, PrivateDataValue> privateCommand;
explicit UvEntry(const std::vector<std::shared_ptr<JSCallbackObject>> &cbVec, const std::string &type)
: vecCopy(cbVec), type(type), sysPanelStatus({ false, 0, 0, 0 }), smartMenu(""), privateCommand({})
: vecCopy(cbVec),
type(type),
sysPanelStatus({ InputType::NONE, 0, 0, 0 }),
smartMenu(""),
privateCommand({})
{
}
};

View File

@ -47,6 +47,7 @@ public:
SECURITY_CHANGE,
ON_CLIENT_INACTIVE,
ON_CONNECT_SYSTEM_CMD,
ON_SET_INPUT_TYPE,
CORE_CMD_END,
};
@ -64,6 +65,7 @@ public:
virtual int32_t OnSecurityChange(int32_t security) = 0;
virtual int32_t OnConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent) = 0;
virtual void OnClientInactive(const sptr<IRemoteObject> &channel) = 0;
virtual int32_t OnSetInputType(InputType inputType) = 0;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -92,6 +92,7 @@ public:
int32_t NotifyPanelStatus(const std::shared_ptr<InputMethodPanel> &inputMethodPanel,
SysPanelStatus &sysPanelStatus);
InputAttribute GetInputAttribute();
void OnSetInputType(InputType inputType);
public:
/* called from TaskManager worker thread */
@ -158,6 +159,7 @@ private:
int32_t ShowKeyboardImplWithLock(int32_t cmdId);
int32_t ShowKeyboardImplWithoutLock(int32_t cmdId);
void NotifyPanelStatusInfo(const PanelStatusInfo &info, std::shared_ptr<InputDataChannelProxy> &channelProxy);
void ClearInputType();
ConcurrentMap<PanelType, std::shared_ptr<InputMethodPanel>> panels_{};
std::atomic_bool isBound_{ false };
@ -177,6 +179,9 @@ private:
InputAttribute inputAttribute_{};
std::recursive_mutex keyboardCmdLock_;
int32_t cmdId_ = 0;
std::mutex inputTypeLock_;
InputType inputType_ = InputType::NONE;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -45,6 +45,7 @@ public:
int32_t OnSecurityChange(int32_t security) override;
int32_t OnConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent) override;
void OnClientInactive(const sptr<IRemoteObject> &channel) override;
int32_t OnSetInputType(InputType inputType) override;
private:
static inline BrokerDelegator<InputMethodCoreProxy> delegator_;

View File

@ -46,6 +46,7 @@ public:
int32_t OnSecurityChange(int32_t security) override;
int32_t OnConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent) override;
void OnClientInactive(const sptr<IRemoteObject> &channel) override;
int32_t OnSetInputType(InputType inputType) override;
private:
int32_t StartInputOnRemote(MessageParcel &data, MessageParcel &reply);
@ -60,6 +61,7 @@ private:
int32_t SecurityChangeOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t OnClientInactiveOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t OnConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t OnSetInputTypeOnRemote(MessageParcel &data, MessageParcel &reply);
using ParcelHandler = std::function<bool(MessageParcel &)>;
int32_t SendMessage(int code, ParcelHandler input = nullptr);
using RequestHandler = int32_t (InputMethodCoreStub::*)(MessageParcel &, MessageParcel &);
@ -76,6 +78,7 @@ private:
[SECURITY_CHANGE] = &InputMethodCoreStub::SecurityChangeOnRemote,
[ON_CLIENT_INACTIVE] = &InputMethodCoreStub::OnClientInactiveOnRemote,
[ON_CONNECT_SYSTEM_CMD] = &InputMethodCoreStub::OnConnectSystemCmdOnRemote,
[ON_SET_INPUT_TYPE] = &InputMethodCoreStub::OnSetInputTypeOnRemote,
};
};
} // namespace MiscServices

View File

@ -250,6 +250,18 @@ void InputMethodAbility::OnSetSubtype(SubProperty subProperty)
imeListener_->OnSetSubtype(subProperty);
}
void InputMethodAbility::OnSetInputType(InputType inputType)
{
inputType_ = inputType;
IMSA_HILOGD("OnSetInputType, inputType = %{public}d", static_cast<int32_t>(inputType));
auto panel = GetSoftKeyboardPanel();
if (panel != nullptr) {
auto keyboardSize = panel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { inputType_, panel->GetPanelFlag(), keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(panel, sysPanelStatus);
}
}
void InputMethodAbility::ClearDataChannel(const sptr<IRemoteObject> &channel)
{
std::lock_guard<std::mutex> lock(dataChannelLock_);
@ -272,6 +284,7 @@ int32_t InputMethodAbility::StopInput(sptr<IRemoteObject> channelObject)
HideKeyboardImplWithoutLock(cmdCount, false);
ClearDataChannel(channelObject);
ClearInputAttribute();
ClearInputType();
if (imeListener_ != nullptr) {
imeListener_->OnInputFinish();
}
@ -346,7 +359,7 @@ void InputMethodAbility::OnAttributeChange(InputAttribute attribute)
auto panel = GetSoftKeyboardPanel();
if (panel != nullptr) {
auto keyboardSize = panel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { false, panel->GetPanelFlag(), keyboardSize.width, keyboardSize.height };
SysPanelStatus sysPanelStatus = { inputType_, panel->GetPanelFlag(), keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(panel, sysPanelStatus);
}
kdListener_->OnEditorAttributeChange(attribute);
@ -861,7 +874,7 @@ int32_t InputMethodAbility::ShowPanel(const std::shared_ptr<InputMethodPanel> &i
}
}
auto keyboardSize = inputMethodPanel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { false, flag, keyboardSize.width, keyboardSize.height };
SysPanelStatus sysPanelStatus = { inputType_, flag, keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(inputMethodPanel, sysPanelStatus);
auto ret = inputMethodPanel->ShowPanel();
if (ret == ErrorCode::NO_ERROR) {
@ -896,8 +909,7 @@ int32_t InputMethodAbility::NotifyPanelStatus(
if (channel == nullptr) {
return ErrorCode::NO_ERROR;
}
bool isSecurity = GetInputAttribute().GetSecurityFlag();
sysPanelStatus.isSecurity = isSecurity;
sysPanelStatus.inputType = inputType_;
auto systemChannel = GetSystemCmdChannelProxy();
if (systemChannel == nullptr) {
IMSA_HILOGE("channel is nullptr!");
@ -1031,6 +1043,13 @@ bool InputMethodAbility::IsEnable()
int32_t InputMethodAbility::ExitCurrentInputType()
{
IMSA_HILOGD("InputMethodAbility start.");
ClearInputType();
auto panel = GetSoftKeyboardPanel();
if (panel != nullptr) {
auto keyboardSize = panel->GetKeyboardSize();
SysPanelStatus sysPanelStatus = { inputType_, panel->GetPanelFlag(), keyboardSize.width, keyboardSize.height };
NotifyPanelStatus(panel, sysPanelStatus);
}
auto proxy = GetImsaProxy();
if (proxy == nullptr) {
IMSA_HILOGE("failed to get imsa proxy!");
@ -1039,6 +1058,12 @@ int32_t InputMethodAbility::ExitCurrentInputType()
return proxy->ExitCurrentInputType();
}
void InputMethodAbility::ClearInputType()
{
std::lock_guard<std::mutex> lock(inputTypeLock_);
inputType_ = InputType::NONE;
}
int32_t InputMethodAbility::IsPanelShown(const PanelInfo &panelInfo, bool &isShown)
{
isShown = false;

View File

@ -52,6 +52,13 @@ int32_t InputMethodCoreProxy::OnSecurityChange(int32_t security)
[security](MessageParcel &data) { return ITypesUtil::Marshal(data, security); });
}
int32_t InputMethodCoreProxy::OnSetInputType(InputType inputType)
{
return SendRequest(ON_SET_INPUT_TYPE,
[inputType](MessageParcel &data) { return ITypesUtil::Marshal(data, inputType); },
nullptr, MessageOption::TF_ASYNC);
}
int32_t InputMethodCoreProxy::OnConnectSystemCmd(const sptr<IRemoteObject> &channel, sptr<IRemoteObject> &agent)
{
return SendRequest(

View File

@ -157,6 +157,17 @@ int32_t InputMethodCoreStub::SetSubtypeOnRemote(MessageParcel &data, MessageParc
return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodCoreStub::OnSetInputTypeOnRemote(MessageParcel &data, MessageParcel &reply)
{
InputType inputType;
if (!ITypesUtil::Unmarshal(data, inputType)) {
IMSA_HILOGE("failed to read inputType parcel!");
return ErrorCode::ERROR_EX_PARCELABLE;
}
InputMethodAbility::GetInstance()->OnSetInputType(inputType);
return reply.WriteInt32(ErrorCode::NO_ERROR) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodCoreStub::StopInputOnRemote(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> channel = nullptr;
@ -247,6 +258,11 @@ int32_t InputMethodCoreStub::OnSecurityChange(int32_t security)
return ErrorCode::NO_ERROR;
}
int32_t InputMethodCoreStub::OnSetInputType(InputType inputType)
{
return ErrorCode::NO_ERROR;
}
int32_t InputMethodCoreStub::StopInput(const sptr<IRemoteObject> &channel)
{
return ErrorCode::NO_ERROR;

View File

@ -24,7 +24,7 @@
namespace OHOS {
namespace MiscServices {
struct SysPanelStatus {
bool isSecurity { false };
InputType inputType = InputType::NONE;
int32_t flag = FLG_FIXED;
uint32_t width = 0;
uint32_t height = 0;

View File

@ -49,6 +49,8 @@ public:
bool IsStarted();
bool IsSecurityImeStarted();
bool IsCameraImeStarted();
bool IsVoiceImeStarted();
InputType GetCurrentInputType();
void Set(bool isStarted, const ImeIdentification &currentIme = {});
ImeIdentification GetCurrentIme();
int32_t GetImeByInputType(InputType type, ImeIdentification &ime);

View File

@ -144,6 +144,7 @@ public:
bool IsWmsReady();
bool CheckPwdInputPatternConv(InputClientInfo &clientInfo);
int32_t RestoreCurrentIme();
int32_t SetInputType();
private:
struct ResetManager {

View File

@ -299,6 +299,7 @@ int32_t InputMethodSystemAbility::StartInput(InputClientInfo &inputClientInfo, s
IMSA_HILOGE("failed to PrepareInput!");
return ret;
}
session->SetInputType();
return session->OnStartInput(inputClientInfo, agent);
}

View File

@ -104,6 +104,27 @@ bool InputTypeManager::IsCameraImeStarted()
inputTypes_[InputType::CAMERA_INPUT] == currentTypeIme_;
}
bool InputTypeManager::IsVoiceImeStarted()
{
std::lock_guard<std::mutex> lock(stateLock_);
return isStarted_ && inputTypes_.find(InputType::VOICE_INPUT) != inputTypes_.end() &&
inputTypes_[InputType::VOICE_INPUT] == currentTypeIme_;
}
InputType InputTypeManager::GetCurrentInputType()
{
if (IsSecurityImeStarted()) {
return InputType::SECURITY_INPUT;
}
if (IsCameraImeStarted()) {
return InputType::CAMERA_INPUT;
}
if (IsVoiceImeStarted()) {
return InputType::VOICE_INPUT;
}
return InputType::NONE;
}
ImeIdentification InputTypeManager::GetCurrentIme()
{
std::lock_guard<std::mutex> lock(stateLock_);

View File

@ -258,6 +258,9 @@ void PerUserSession::OnImeDied(const sptr<IInputMethodCore> &remote, ImeType typ
}
IMSA_HILOGI("type: %{public}d.", type);
auto imeData = GetImeData(type);
auto ime = InputTypeManager::GetInstance().GetCurrentIme();
if (ime.bundleName == imeData->ime.first) {
}
if (imeData != nullptr && imeData->imeStatus == ImeStatus::EXITING) {
RemoveImeData(type, true);
NotifyImeStopFinished();
@ -266,7 +269,6 @@ void PerUserSession::OnImeDied(const sptr<IInputMethodCore> &remote, ImeType typ
return;
}
RemoveImeData(type, true);
InputTypeManager::GetInstance().Set(false);
if (!OsAccountAdapter::IsOsAccountForeground(userId_)) {
IMSA_HILOGW("userId:%{public}d in background, no need to restart ime.", userId_);
return;
@ -1180,6 +1182,17 @@ int32_t PerUserSession::SwitchSubtype(const SubProperty &subProperty)
return RequestIme(data, RequestType::NORMAL, [&data, &subProperty] { return data->core->SetSubtype(subProperty); });
}
int32_t PerUserSession::SetInputType()
{
InputType inputType = InputTypeManager::GetInstance().GetCurrentInputType();
auto data = GetValidIme(ImeType::IME);
if (data == nullptr) {
IMSA_HILOGE("ime: %{public}d is not exist!", ImeType::IME);
return ErrorCode::ERROR_IME_NOT_STARTED;
}
return RequestIme(data, RequestType::NORMAL, [&data, &inputType] { return data->core->OnSetInputType(inputType); });
}
bool PerUserSession::IsBoundToClient()
{
if (GetCurrentClient() == nullptr) {

View File

@ -83,7 +83,7 @@ void FuzzPrivateCommand(const uint8_t *data, size_t size)
void FuzzNotifyPanelStatus(const uint8_t *data, size_t size)
{
bool fuzzedBool = static_cast<bool>(data[0] % 2);
InputType fuzzedBool = static_cast<InputType>(data[0] % 2);
auto fuzzedUint32 = static_cast<uint32_t>(size);
SysPanelStatus sysPanelStatus = { fuzzedBool, 0, fuzzedUint32, fuzzedUint32 };

View File

@ -37,7 +37,7 @@ uint32_t ConvertToUint32(const uint8_t *ptr)
}
bool FuzzSystemCmdChannelStub(const uint8_t *rawData, size_t size)
{
bool fuzzedBool = static_cast<bool>(rawData[0] % 2);
InputType fuzzedBool = static_cast<InputType>(rawData[0] % 2);
auto fuzzedUint32 = static_cast<uint32_t>(size);
uint32_t code = ConvertToUint32(rawData);
@ -48,7 +48,7 @@ bool FuzzSystemCmdChannelStub(const uint8_t *rawData, size_t size)
std::unordered_map <std::string, PrivateDataValue> privateCommand;
PrivateDataValue privateDataValue1 = std::string("stringValue");
PrivateDataValue privateDataValue2 = fuzzedBool;
PrivateDataValue privateDataValue2 = static_cast<int32_t>(fuzzedBool);
PrivateDataValue privateDataValue3 = PRIVATEDATAVALUE;
privateCommand.emplace("value1", privateDataValue1);
privateCommand.emplace("value2", privateDataValue2);

View File

@ -133,7 +133,7 @@ HWTEST_F(ImeSystemChannelTest, testImeSystemChannel_nullptr, TestSize.Level0)
imeSystemChannel_->GetSmartMenuCfg();
int32_t ret = imeSystemChannel_->ReceivePrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::ERROR_EX_NULL_POINTER);
ret = imeSystemChannel_->NotifyPanelStatus({ false, 0, 0, 0 });
ret = imeSystemChannel_->NotifyPanelStatus({ InputType::NONE, 0, 0, 0 });
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
} // namespace MiscServices

View File

@ -264,12 +264,12 @@ HWTEST_F(VirtualListenerTest, testOnSystemCmdListener_001, TestSize.Level0)
SystemCmdChannelListenerImpl::ResetParam();
std::unordered_map<std::string, PrivateDataValue> privateCommand;
VirtualListenerTest::systemCmdListener_->ReceivePrivateCommand(privateCommand);
VirtualListenerTest::systemCmdListener_->NotifyPanelStatus({ false, 0, 0, 0 });
VirtualListenerTest::systemCmdListener_->NotifyPanelStatus({ InputType::NONE, 0, 0, 0 });
EXPECT_FALSE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_FALSE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
SystemCmdChannelListenerImpl::ResetParam();
listener->ReceivePrivateCommand(privateCommand);
listener->NotifyPanelStatus({ false, 0, 0, 0 });
listener->NotifyPanelStatus({ InputType::NONE, 0, 0, 0 });
EXPECT_TRUE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_TRUE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
}