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

Signed-off-by: ht <hutao105@huawei.com>
This commit is contained in:
ht 2024-08-29 08:32:12 +00:00 committed by Gitee
commit 6f9440ee57
16 changed files with 148 additions and 6 deletions

View File

@ -255,7 +255,7 @@ void JsInputMethodExtension::OnStart(const AAFwk::Want &want)
{
auto task = std::make_shared<TaskAmsInit>();
TaskManager::GetInstance().PostTask(task);
InputMethodAbility::GetInstance()->InitConnect();
StartAsync("OnStart", static_cast<int32_t>(TraceTaskId::ONSTART_EXTENSION));
StartAsync("Extension::OnStart", static_cast<int32_t>(TraceTaskId::ONSTART_MIDDLE_EXTENSION));
Extension::OnStart(want);

View File

@ -46,6 +46,7 @@ public:
~InputMethodAbility();
static sptr<InputMethodAbility> GetInstance();
int32_t SetCoreAndAgent();
int32_t InitConnect();
int32_t UnRegisteredProxyIme(UnRegisteredType type);
int32_t InsertText(const std::string text);
void SetImeListener(std::shared_ptr<InputMethodEngineListener> imeListener);

View File

@ -127,6 +127,22 @@ int32_t InputMethodAbility::SetCoreAndAgent()
return ErrorCode::NO_ERROR;
}
int32_t InputMethodAbility::InitConnect()
{
IMSA_HILOGD("InputMethodAbility, init connect.");
auto proxy = GetImsaProxy();
if (proxy == nullptr) {
IMSA_HILOGE("imsa proxy is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
}
int32_t ret = proxy->InitConnect();
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("set failed, ret: %{public}d!", ret);
return ret;
}
return ErrorCode::NO_ERROR;
}
int32_t InputMethodAbility::UnRegisteredProxyIme(UnRegisteredType type)
{
isBound_.store(false);
@ -421,10 +437,6 @@ void InputMethodAbility::NotifyPanelStatusInfo(const PanelStatusInfo &info)
}
auto channel = GetInputDataChannelProxy();
if (channel != nullptr) {
if (info.panelInfo.panelType == PanelType::SOFT_KEYBOARD) {
info.visible ? channel->SendKeyboardStatus(KeyboardStatus::SHOW)
: channel->SendKeyboardStatus(KeyboardStatus::HIDE);
}
channel->NotifyPanelStatusInfo(info);
}

View File

@ -61,6 +61,7 @@ public:
int32_t SwitchInputMethod(const std::string &name, const std::string &subName, SwitchTrigger trigger) override;
int32_t DisplayOptionalInputMethod() override;
int32_t SetCoreAndAgent(const sptr<IInputMethodCore> &core, const sptr<IRemoteObject> &agent) override;
int32_t InitConnect() override;
int32_t UnRegisteredProxyIme(UnRegisteredType type, const sptr<IInputMethodCore> &core) override;
int32_t ListCurrentInputMethodSubtype(std::vector<SubProperty> &subProps) override;
int32_t ListInputMethodSubtype(const std::string &name, std::vector<SubProperty> &subProps) override;
@ -68,6 +69,7 @@ public:
int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) override;
bool IsCurrentIme() override;
bool IsInputTypeSupported(InputType type) override;
bool IsCurrentImeByPid(int32_t pid) override;
int32_t StartInputType(InputType type) override;
int32_t ExitCurrentInputType() override;
int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override;

View File

@ -156,6 +156,7 @@ void InputDataChannelProxy::GetMessageOption(int32_t code, MessageOption &option
switch (code) {
case SEND_KEYBOARD_STATUS:
case NOTIFY_KEYBOARD_HEIGHT:
case NOTIFY_PANEL_STATUS_INFO:
IMSA_HILOGD("Async IPC.");
option.SetFlags(MessageOption::TF_ASYNC);
break;

View File

@ -1201,6 +1201,10 @@ void InputMethodController::NotifyPanelStatusInfo(const PanelStatusInfo &info)
IMSA_HILOGE("listener is nullptr!");
return;
}
if (info.panelInfo.panelType == PanelType::SOFT_KEYBOARD) {
info.visible ? SendKeyboardStatus(KeyboardStatus::SHOW)
: SendKeyboardStatus(KeyboardStatus::HIDE);
}
listener->NotifyPanelStatusInfo(info);
if (info.panelInfo.panelType == PanelType::SOFT_KEYBOARD &&
info.panelInfo.panelFlag != PanelFlag::FLG_CANDIDATE_COLUMN && !info.visible) {
@ -1245,6 +1249,16 @@ bool InputMethodController::IsInputTypeSupported(InputType type)
return proxy->IsInputTypeSupported(type);
}
bool InputMethodController::IsCurrentImeByPid(int32_t pid)
{
auto proxy = GetSystemAbilityProxy();
if (proxy == nullptr) {
IMSA_HILOGE("proxy is nullptr!");
return false;
}
return proxy->IsCurrentImeByPid(pid);
}
int32_t InputMethodController::StartInputType(InputType type)
{
auto proxy = GetSystemAbilityProxy();

View File

@ -95,6 +95,11 @@ int32_t InputMethodSystemAbilityProxy::RequestHideInput()
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::REQUEST_HIDE_INPUT));
}
int32_t InputMethodSystemAbilityProxy::InitConnect()
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::INIT_CONNECT));
}
int32_t InputMethodSystemAbilityProxy::DisplayOptionalInputMethod()
{
return SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::DISPLAY_OPTIONAL_INPUT_METHOD));
@ -225,6 +230,15 @@ bool InputMethodSystemAbilityProxy::IsCurrentIme()
return isCurrentIme;
}
bool InputMethodSystemAbilityProxy::IsCurrentImeByPid(int32_t pid)
{
bool isCurrentIme = false;
SendRequest(static_cast<uint32_t>(InputMethodInterfaceCode::IS_CURRENT_IME_BY_PID),
[&pid](MessageParcel &data) { return ITypesUtil::Marshal(data, pid); },
[&isCurrentIme](MessageParcel &reply) { return ITypesUtil::Unmarshal(reply, isCurrentIme); });
return isCurrentIme;
}
bool InputMethodSystemAbilityProxy::IsInputTypeSupported(InputType type)
{
bool isSupported = false;

View File

@ -767,6 +767,19 @@ public:
*/
int32_t FinishTextPreview();
* @brief Query whether an process id current inputmethod.
*
* This function is used to query whether an process id is inputmethod.
* This interface only supports querying whether PID is the current input method application for process startup
* and initialization completion. If the current input method is in the initialization process, this interface can
* also return a failure.
*
* @param type Indicates current process id.
* @return Returns true for current ime process id, false for not current ime process id.
* @since 12
*/
IMF_API bool IsCurrentImeByPid(int32_t pid);
/**
* @brief Release resource.
*
@ -774,7 +787,7 @@ public:
*
* @since 12
*/
void Release();
IMF_API void Release();
private:
InputMethodController();

View File

@ -58,6 +58,7 @@ public:
virtual int32_t ListInputMethod(InputMethodStatus status, std::vector<Property> &props) = 0;
virtual int32_t DisplayOptionalInputMethod() = 0;
virtual int32_t SetCoreAndAgent(const sptr<IInputMethodCore> &core, const sptr<IRemoteObject> &agent) = 0;
virtual int32_t InitConnect() = 0;
virtual int32_t UnRegisteredProxyIme(UnRegisteredType type, const sptr<IInputMethodCore> &core) = 0;
virtual int32_t ListCurrentInputMethodSubtype(std::vector<SubProperty> &subProps) = 0;
virtual int32_t ListInputMethodSubtype(const std::string &name, std::vector<SubProperty> &subProps) = 0;
@ -67,6 +68,7 @@ public:
virtual int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) = 0;
virtual bool IsCurrentIme() = 0;
virtual bool IsInputTypeSupported(InputType type) = 0;
virtual bool IsCurrentImeByPid(int32_t pid) = 0;
virtual int32_t StartInputType(InputType type) = 0;
virtual int32_t ExitCurrentInputType() = 0;
virtual int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) = 0;

View File

@ -70,11 +70,13 @@ public:
const std::string &bundleName, const std::string &subName, SwitchTrigger trigger) override;
int32_t DisplayOptionalInputMethod() override;
int32_t SetCoreAndAgent(const sptr<IInputMethodCore> &core, const sptr<IRemoteObject> &agent) override;
int32_t InitConnect() override;
int32_t UnRegisteredProxyIme(UnRegisteredType type, const sptr<IInputMethodCore> &core) override;
int32_t PanelStatusChange(const InputWindowStatus &status, const ImeWindowInfo &info) override;
int32_t UpdateListenEventFlag(InputClientInfo &clientInfo, uint32_t eventFlag) override;
bool IsCurrentIme() override;
bool IsInputTypeSupported(InputType type) override;
bool IsCurrentImeByPid(int32_t pid) override;
int32_t StartInputType(InputType type) override;
int32_t ExitCurrentInputType() override;
int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown) override;

View File

@ -101,6 +101,10 @@ private:
int32_t ConnectSystemCmdOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t IsCurrentImeByPidOnRemote(MessageParcel &data, MessageParcel &reply);
int32_t InitConnectOnRemote(MessageParcel &data, MessageParcel &reply);
using RequestHandler = int32_t (InputMethodSystemAbilityStub::*)(MessageParcel &, MessageParcel &);
static inline constexpr RequestHandler HANDLERS[static_cast<uint32_t>(InputMethodInterfaceCode::IMS_CMD_END)] = {
&InputMethodSystemAbilityStub::InvalidRequest,
@ -168,6 +172,10 @@ private:
&InputMethodSystemAbilityStub::IsDefaultImeOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::CONNECT_SYSTEM_CMD)] =
&InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::IS_CURRENT_IME_BY_PID)] =
&InputMethodSystemAbilityStub::IsCurrentImeByPidOnRemote,
[static_cast<uint32_t>(InputMethodInterfaceCode::INIT_CONNECT)] =
&InputMethodSystemAbilityStub::InitConnectOnRemote,
};
};
} // namespace OHOS::MiscServices

View File

@ -53,6 +53,8 @@ enum class InputMethodInterfaceCode {
GET_SECURITY_MODE,
IS_DEFAULT_IME,
CONNECT_SYSTEM_CMD,
IS_CURRENT_IME_BY_PID,
INIT_CONNECT,
IMS_CMD_END,
};
} // namespace MiscServices

View File

@ -122,6 +122,7 @@ public:
int32_t OnUpdateListenEventFlag(const InputClientInfo &clientInfo);
int32_t OnRegisterProxyIme(const sptr<IInputMethodCore> &core, const sptr<IRemoteObject> &agent);
int32_t OnUnRegisteredProxyIme(UnRegisteredType type, const sptr<IInputMethodCore> &core);
int32_t InitConnect(pid_t pid);
bool StartCurrentIme(bool isStopCurrentIme = false);
bool StartIme(const std::shared_ptr<ImeNativeCfg> &ime, bool isStopCurrentIme = false);
@ -131,6 +132,7 @@ public:
bool IsProxyImeEnable();
bool IsBoundToClient();
bool IsCurrentImeByPid(int32_t pid);
int32_t RestoreCurrentImeSubType();
int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown);
bool CheckSecurityMode();

View File

@ -452,6 +452,21 @@ int32_t InputMethodSystemAbility::SetCoreAndAgent(const sptr<IInputMethodCore> &
return session->OnSetCoreAndAgent(core, agent);
}
int32_t InputMethodSystemAbility::InitConnect()
{
IMSA_HILOGD("InputMethodSystemAbility init connect.");
auto userId = GetCallingUserId();
auto session = UserSessionManager::GetInstance().GetUserSession(userId);
if (session == nullptr) {
IMSA_HILOGE("%{public}d session is nullptr", userId);
return ErrorCode::ERROR_NULL_POINTER;
}
if (!IsCurrentIme(userId)) {
return ErrorCode::ERROR_NOT_CURRENT_IME;
}
return session->InitConnect(IPCSkeleton::GetCallingPid());
}
int32_t InputMethodSystemAbility::HideCurrentInput()
{
AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID();
@ -589,6 +604,22 @@ int32_t InputMethodSystemAbility::IsDefaultImeFromTokenId(int32_t userId, uint32
return ErrorCode::NO_ERROR;
}
bool InputMethodSystemAbility::IsCurrentImeByPid(int32_t pid)
{
if (!identityChecker_->IsSystemApp(IPCSkeleton::GetCallingFullTokenID()) &&
!identityChecker_->IsNativeSa(IPCSkeleton::GetCallingTokenID())) {
IMSA_HILOGE("not system application or system ability!");
return false;
}
auto userId = GetCallingUserId();
auto session = UserSessionManager::GetInstance().GetUserSession(userId);
if (session == nullptr) {
IMSA_HILOGE("%{public}d session is nullptr", userId);
return false;
}
return session->IsCurrentImeByPid(pid);
}
int32_t InputMethodSystemAbility::IsPanelShown(const PanelInfo &panelInfo, bool &isShown)
{
if (!identityChecker_->IsSystemApp(IPCSkeleton::GetCallingFullTokenID())) {

View File

@ -396,5 +396,21 @@ int32_t InputMethodSystemAbilityStub::ConnectSystemCmdOnRemote(MessageParcel &da
return reply.WriteInt32(ret) && reply.WriteRemoteObject(agent) ? ErrorCode::NO_ERROR
: ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodSystemAbilityStub::IsCurrentImeByPidOnRemote(MessageParcel &data, MessageParcel &reply)
{
int32_t pid = -1;
if (!ITypesUtil::Unmarshal(data, pid)) {
IMSA_HILOGE("unmarshal failed!");
return ErrorCode::ERROR_EX_PARCELABLE;
}
return ITypesUtil::Marshal(reply, ErrorCode::NO_ERROR, IsCurrentImeByPid(pid)) ? ErrorCode::NO_ERROR
: ErrorCode::ERROR_EX_PARCELABLE;
}
int32_t InputMethodSystemAbilityStub::InitConnectOnRemote(MessageParcel &data, MessageParcel &reply)
{
return reply.WriteInt32(InitConnect()) ? ErrorCode::NO_ERROR : ErrorCode::ERROR_EX_PARCELABLE;
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -1218,6 +1218,17 @@ int32_t PerUserSession::RestoreCurrentImeSubType()
return SwitchSubtype(subProp);
}
bool PerUserSession::IsCurrentImeByPid(int32_t pid)
{
auto imeDate = GetReadyImeData(ImeType::IME);
if (imeDate == nullptr) {
IMSA_HILOGE("ime not started!");
return false;
}
IMSA_HILOGD("userId: %{public}d, pid: %{public}d, current pid: %{public}d.", userId_, pid, imeDate->pid);
return imeDate->pid == pid;
}
int32_t PerUserSession::IsPanelShown(const PanelInfo &panelInfo, bool &isShown)
{
if (GetCurrentClient() == nullptr) {
@ -1425,6 +1436,17 @@ int32_t PerUserSession::UpdateImeData(sptr<IInputMethodCore> core, sptr<IRemoteO
return ErrorCode::NO_ERROR;
}
int32_t PerUserSession::InitConnect(pid_t pid)
{
std::lock_guard<std::mutex> lock(imeDataLock_);
auto it = imeData_.find(ImeType::IME);
if (it == imeData_.end()) {
return ErrorCode::ERROR_NULL_POINTER;
}
it->second->pid = pid;
return ErrorCode::NO_ERROR;
}
std::shared_ptr<ImeData> PerUserSession::GetImeData(ImeType type)
{
std::lock_guard<std::mutex> lock(imeDataLock_);