!1561 一致性修改

Merge pull request !1561 from wangdongqi/OpenHarmony-5.0.1-Release
This commit is contained in:
openharmony_ci 2024-11-01 16:50:38 +00:00 committed by Gitee
commit a85089250f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
22 changed files with 198 additions and 112 deletions

View File

@ -35,8 +35,8 @@ ErrCode InputMethodExtensionContext::StartAbility(const AAFwk::Want &want) const
return err;
}
ErrCode InputMethodExtensionContext::StartAbility(
const AAFwk::Want &want, const AAFwk::StartOptions &startOptions) const
ErrCode InputMethodExtensionContext::StartAbility(const AAFwk::Want &want,
const AAFwk::StartOptions &startOptions) const
{
IMSA_HILOGD("%{public}s start.", __func__);
ErrCode err =

View File

@ -290,7 +290,6 @@ int32_t InputMethodAbility::StartInput(const InputClientInfo &clientInfo, bool i
IMSA_HILOGE("failed to invoke callback, ret: %{public}d!", ret);
return ret;
}
isImeTerminating_.store(false);
isPendingShowKeyboard_ = clientInfo.isShowKeyboard;
if (clientInfo.isShowKeyboard) {
auto task = [this, cmdCount]() {
@ -300,6 +299,7 @@ int32_t InputMethodAbility::StartInput(const InputClientInfo &clientInfo, bool i
IMSA_HILOGE("imeListener_ is nullptr, or post task failed!");
ShowKeyboardImplWithoutLock(cmdCount);
}
isImeTerminating_.store(false);
}
return ErrorCode::NO_ERROR;
}
@ -518,13 +518,13 @@ int32_t InputMethodAbility::ShowKeyboardImplWithoutLock(int32_t cmdId)
void InputMethodAbility::NotifyPanelStatusInfo(const PanelStatusInfo &info)
{
// CANDIDATE_COLUMN not notify
auto channel = GetInputDataChannelProxy();
NotifyPanelStatusInfo(info, channel);
}
int32_t InputMethodAbility::InvokeStartInputCallback(bool isNotifyInputStart)
{
// CANDIDATE_COLUMN not notify
TextTotalConfig textConfig = {};
int32_t ret = GetTextConfig(textConfig);
if (ret == ErrorCode::NO_ERROR) {
@ -946,6 +946,7 @@ int32_t InputMethodAbility::HidePanel(const std::shared_ptr<InputMethodPanel> &i
if (inputMethodPanel == nullptr) {
return ErrorCode::ERROR_BAD_PARAMETERS;
}
// Current Ime is exiting, hide softkeyboard will cause the TextFiled to lose focus.
if (isImeTerminating_.load() && inputMethodPanel->GetPanelType() == PanelType::SOFT_KEYBOARD) {
IMSA_HILOGI("Current Ime is terminating, no need to hide keyboard.");
@ -989,10 +990,12 @@ int32_t InputMethodAbility::HidePanel(const std::shared_ptr<InputMethodPanel> &i
return ErrorCode::ERROR_BAD_PARAMETERS;
}
auto ret = inputMethodPanel->HidePanel();
if (ret == ErrorCode::NO_ERROR) {
NotifyPanelStatusInfo({ { inputMethodPanel->GetPanelType(), flag }, false, trigger });
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGD("failed, ret: %{public}d", ret);
return ret;
}
return ret;
NotifyPanelStatusInfo({ { inputMethodPanel->GetPanelType(), flag }, false, trigger });
return ErrorCode::NO_ERROR;
}
int32_t InputMethodAbility::NotifyPanelStatus(
@ -1180,6 +1183,10 @@ void InputMethodAbility::OnClientInactive(const sptr<IRemoteObject> &channel)
IMSA_HILOGE("failed to create channel proxy!");
return;
}
auto panel = GetSoftKeyboardPanel();
if (imeListener_ != nullptr && panel != nullptr && panel->GetPanelFlag() != PanelFlag::FLG_FIXED) {
imeListener_->OnKeyboardStatus(false);
}
panels_.ForEach([this, &channelProxy](const PanelType &panelType, const std::shared_ptr<InputMethodPanel> &panel) {
if (panelType != PanelType::SOFT_KEYBOARD || panel->GetPanelFlag() != PanelFlag::FLG_FIXED) {
auto ret = panel->HidePanel();

View File

@ -171,7 +171,7 @@ LayoutParams InputMethodPanel::GetResizeParams()
IMSA_HILOGI("is fold device and fold state or other");
return resizePanelFoldParams_;
}
void InputMethodPanel::SetResizeParams(uint32_t width, uint32_t height)
{
if (Rosen::DisplayManager::GetInstance().IsFoldable() &&
@ -285,8 +285,7 @@ int32_t InputMethodPanel::AdjustPanelRect(const PanelFlag panelFlag, const Layou
IMSA_HILOGE("posX_ and posY_ cannot be less than 0!");
return ErrorCode::ERROR_PARAMETER_CHECK_FAILED;
}
if (!CheckSize(panelFlag, layoutParams.portraitRect.width_,
layoutParams.portraitRect.height_, true)) {
if (!CheckSize(panelFlag, layoutParams.portraitRect.width_, layoutParams.portraitRect.height_, true)) {
IMSA_HILOGE("portrait invalid size!");
return ErrorCode::ERROR_PARAMETER_CHECK_FAILED;
}
@ -351,8 +350,8 @@ int32_t InputMethodPanel::CalculateNoConfigRect(const PanelFlag panelFlag, const
}
keyboardLayoutParams_.PortraitPanelRect_.width_ = portraitDisplaySize.width;
keyboardLayoutParams_.PortraitPanelRect_.height_ = layoutParams.portraitRect.height_;
keyboardLayoutParams_.PortraitPanelRect_.posY_ = static_cast<int32_t>(portraitDisplaySize.height -
keyboardLayoutParams_.PortraitPanelRect_.height_);
keyboardLayoutParams_.PortraitPanelRect_.posY_ =
static_cast<int32_t>(portraitDisplaySize.height - keyboardLayoutParams_.PortraitPanelRect_.height_);
keyboardLayoutParams_.PortraitPanelRect_.posX_ = NUMBER_ZERO;
//fixed Portraitkeyboard
keyboardLayoutParams_.PortraitKeyboardRect_.width_ = keyboardLayoutParams_.PortraitPanelRect_.width_;
@ -367,8 +366,8 @@ int32_t InputMethodPanel::CalculateNoConfigRect(const PanelFlag panelFlag, const
}
keyboardLayoutParams_.LandscapePanelRect_.width_ = landscapeDisplaySize.width;
keyboardLayoutParams_.LandscapePanelRect_.height_ = layoutParams.landscapeRect.height_;
keyboardLayoutParams_.LandscapePanelRect_.posY_ = static_cast<int32_t>(landscapeDisplaySize.height -
keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posY_ =
static_cast<int32_t>(landscapeDisplaySize.height - keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO;
//Landscapekeyboard
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_;
@ -500,6 +499,7 @@ int32_t InputMethodPanel::CalculateFloatRect(const LayoutParams &layoutParams, P
keyboardLayoutParams_.PortraitKeyboardRect_.posY_ - static_cast<int32_t>(porIterValue.top * densityDpi);
keyboardLayoutParams_.PortraitPanelRect_.posX_ =
keyboardLayoutParams_.PortraitKeyboardRect_.posX_ - static_cast<int32_t>(porIterValue.left * densityDpi);
//landscape floating keyboard
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = layoutParams.landscapeRect.width_;
keyboardLayoutParams_.LandscapeKeyboardRect_.height_ = layoutParams.landscapeRect.height_;
@ -530,12 +530,12 @@ int32_t InputMethodPanel::CalculateLandscapeRect(sptr<OHOS::Rosen::Display> &def
keyboardLayoutParams_.LandscapePanelRect_.height_ = layoutParams.landscapeRect.height_ +
static_cast<uint32_t>((lanIterValue.top + lanIterValue.bottom) * densityDpi);
if (keyboardLayoutParams_.LandscapePanelRect_.height_ >
landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) {
landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO) {
keyboardLayoutParams_.LandscapePanelRect_.height_ =
landscapeDisplaySize.height * FIXED_SOFT_KEYBOARD_PANEL_RATIO;
}
keyboardLayoutParams_.LandscapePanelRect_.posY_ = static_cast<int32_t>(landscapeDisplaySize.height -
keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posY_ =
static_cast<int32_t>(landscapeDisplaySize.height - keyboardLayoutParams_.LandscapePanelRect_.height_);
keyboardLayoutParams_.LandscapePanelRect_.posX_ = NUMBER_ZERO;
//Landscapekeyboard
keyboardLayoutParams_.LandscapeKeyboardRect_.width_ = keyboardLayoutParams_.LandscapePanelRect_.width_ -
@ -779,7 +779,7 @@ void InputMethodPanel::PanelStatusChangeToImc(const InputWindowStatus &status, c
bool InputMethodPanel::IsShowing()
{
WindowState windowState = window_->GetWindowState();
auto windowState = window_->GetWindowState();
if (windowState == WindowState::STATE_SHOWN) {
return true;
}
@ -801,7 +801,7 @@ int32_t InputMethodPanel::SetUiContent(const std::string &contentInfo, napi_env
std::shared_ptr<NativeReference> storage)
{
if (window_ == nullptr) {
IMSA_HILOGE("window_ is nullptr, can not SetUiContent!");
IMSA_HILOGE("window_ is nullptr, can not SetUiContent.");
return ErrorCode::ERROR_NULL_POINTER;
}
WMError ret = WMError::WM_OK;
@ -840,8 +840,8 @@ bool InputMethodPanel::SetPanelStatusListener(std::shared_ptr<PanelStatusListene
}
}
}
if (panelType_ == PanelType::SOFT_KEYBOARD && (panelFlag_ == PanelFlag::FLG_FIXED ||
panelFlag_ == PanelFlag::FLG_FLOATING) && type == "sizeChange") {
if (panelType_ == PanelType::SOFT_KEYBOARD &&
(panelFlag_ == PanelFlag::FLG_FIXED || panelFlag_ == PanelFlag::FLG_FLOATING) && type == "sizeChange") {
if (panelStatusListener_ == nullptr && statusListener != nullptr) {
panelStatusListener_ = std::move(statusListener);
}
@ -850,9 +850,8 @@ bool InputMethodPanel::SetPanelStatusListener(std::shared_ptr<PanelStatusListene
IMSA_HILOGD("windowChangedListener already registered.");
return true;
}
windowChangedListener_ = new (std::nothrow) WindowChangeListenerImpl([this](WindowSize windowSize) {
SizeChange(windowSize);
});
windowChangedListener_ = new (std::nothrow)
WindowChangeListenerImpl([this](WindowSize windowSize) { SizeChange(windowSize); });
if (windowChangedListener_ == nullptr || window_ == nullptr) {
IMSA_HILOGE("observer or window_ is nullptr!");
return false;
@ -896,7 +895,7 @@ bool InputMethodPanel::MarkListener(const std::string &type, bool isRegister)
} else if (type == "sizeChange") {
sizeChangeRegistered_ = isRegister;
} else {
IMSA_HILOGE("type error!");
IMSA_HILOGE("type error.");
return false;
}
return true;
@ -919,7 +918,7 @@ bool InputMethodPanel::IsSizeValid(uint32_t width, uint32_t height)
}
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
if (defaultDisplay == nullptr) {
IMSA_HILOGE("GetDefaultDisplay failed!");
IMSA_HILOGE("GetDefaultDisplay failed.");
return false;
}
float ratio = panelType_ == PanelType::SOFT_KEYBOARD && panelFlag_ == PanelFlag::FLG_FIXED
@ -1035,8 +1034,8 @@ bool InputMethodPanel::CheckSize(PanelFlag panelFlag, uint32_t width, uint32_t h
return IsSizeValid(panelFlag, width, height, displaySize.width, displaySize.height);
}
bool InputMethodPanel::IsSizeValid(PanelFlag panelFlag, uint32_t width, uint32_t height,
int32_t displayWidth, int32_t displayHeight)
bool InputMethodPanel::IsSizeValid(PanelFlag panelFlag, uint32_t width, uint32_t height, int32_t displayWidth,
int32_t displayHeight)
{
if (width > INT32_MAX || height > INT32_MAX) {
IMSA_HILOGE("width or height over maximum");
@ -1046,13 +1045,13 @@ bool InputMethodPanel::IsSizeValid(PanelFlag panelFlag, uint32_t width, uint32_t
? FIXED_SOFT_KEYBOARD_PANEL_RATIO
: NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO;
if (static_cast<float>(height) > displayHeight * ratio) {
IMSA_HILOGE("height invalid, defaultDisplay height = %{public}d, target height = %{public}u",
displayHeight, height);
IMSA_HILOGE("height is invalid, defaultDisplay height: %{public}d, target height: %{public}u!", displayHeight,
height);
return false;
}
if (static_cast<int32_t>(width) > displayWidth) {
IMSA_HILOGE("width invalid, defaultDisplay width = %{public}d, target width = %{public}u",
displayWidth, width);
IMSA_HILOGE("width is invalid, defaultDisplay width: %{public}d, target width: %{public}u!", displayWidth,
width);
return false;
}
return true;
@ -1063,4 +1062,4 @@ void InputMethodPanel::SetPanelHeightCallback(CallbackFunc heightCallback)
panelHeightCallback_ = std::move(heightCallback);
}
} // namespace MiscServices
} // namespace OHOS
} // namespace OHOS

View File

@ -81,7 +81,7 @@ int32_t InputClientProxy::SendRequest(int code, ParcelHandler input, ParcelHandl
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGE("reply error, ret: %{public}d.", ret);
IMSA_HILOGE("reply error, ret: %{public}d", ret);
return ret;
}
if (output != nullptr && (!output(reply))) {

View File

@ -119,7 +119,7 @@ int32_t InputMethodController::Initialize()
{
sptr<IInputClient> client = new (std::nothrow) InputClientStub();
if (client == nullptr) {
IMSA_HILOGE("failed to create client!");
IMSA_HILOGE("failed to create client");
return ErrorCode::ERROR_NULL_POINTER;
}
sptr<IInputDataChannel> channel = new (std::nothrow) InputDataChannelStub();
@ -247,7 +247,7 @@ int32_t InputMethodController::Attach(sptr<OnTextChangedListener> listener, bool
sptr<IRemoteObject> agent = nullptr;
int32_t ret = StartInput(clientInfo_, agent);
if (ret != ErrorCode::NO_ERROR) {
IMSA_HILOGE("failed to start input, ret:%{public}d", ret);
IMSA_HILOGE("failed to start input, ret: %{public}d", ret);
return ret;
}
clientInfo_.state = ClientState::ACTIVE;
@ -263,7 +263,7 @@ int32_t InputMethodController::ShowTextInput()
{
InputMethodSyncTrace tracer("IMC_ShowTextInput");
if (!IsBound()) {
IMSA_HILOGE("not bound!");
IMSA_HILOGE("not bound.");
return ErrorCode::ERROR_CLIENT_NOT_BOUND;
}
IMSA_HILOGI("start.");
@ -305,14 +305,13 @@ int32_t InputMethodController::HideCurrentInput()
}
auto proxy = GetSystemAbilityProxy();
if (proxy == nullptr) {
IMSA_HILOGE("proxy is nullptr!");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
{
std::lock_guard<std::recursive_mutex> lock(clientInfoLock_);
clientInfo_.isShowKeyboard = false;
}
return ErrorCode::ERROR_EX_NULL_POINTER;
}
clientInfo_.isShowKeyboard = false;
InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_NORMAL);
return proxy->HideCurrentInputDeprecated();
}
@ -343,7 +342,6 @@ int32_t InputMethodController::Close()
if (IsBound()) {
IMSA_HILOGI("start.");
}
auto listener = GetTextListener();
if (listener != nullptr) {
listener->OnDetach();
@ -598,7 +596,7 @@ void InputMethodController::RestoreAttachInfoInSaDied()
isShowKeyboard = clientInfo_.isShowKeyboard;
}
auto errCode = Attach(listener, isShowKeyboard, tempConfig);
IMSA_HILOGI("attach end, errCode = %{public}d", errCode);
IMSA_HILOGI("attach end, errCode: %{public}d", errCode);
return errCode == ErrorCode::NO_ERROR;
};
if (attach()) {
@ -663,7 +661,7 @@ int32_t InputMethodController::OnSelectionChange(std::u16string text, int start,
std::lock_guard<std::mutex> lock(textConfigLock_);
textConfig_.range = { start, end };
}
if (isTextNotified_.exchange(true) && textString_ == text && selectNewBegin_ == start && selectNewEnd_ == end) {
if (textString_ == text && selectNewBegin_ == start && selectNewEnd_ == end) {
IMSA_HILOGD("same to last update.");
return ErrorCode::NO_ERROR;
}
@ -896,7 +894,10 @@ int32_t InputMethodController::HideSoftKeyboard()
return ErrorCode::ERROR_EX_NULL_POINTER;
}
IMSA_HILOGI("start.");
clientInfo_.isShowKeyboard = false;
{
std::lock_guard<std::recursive_mutex> lock(clientInfoLock_);
clientInfo_.isShowKeyboard = false;
}
InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_NORMAL);
return proxy->HideCurrentInput();
}
@ -1277,7 +1278,7 @@ int32_t InputMethodController::IsPanelShown(const PanelInfo &panelInfo, bool &is
IMSA_HILOGE("proxy is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
}
IMSA_HILOGD("type: %{public}d, flag: %{public}d.", static_cast<int32_t>(panelInfo.panelType),
IMSA_HILOGI("type: %{public}d, flag: %{public}d.", static_cast<int32_t>(panelInfo.panelType),
static_cast<int32_t>(panelInfo.panelFlag));
return proxy->IsPanelShown(panelInfo, isShown);
}
@ -1312,7 +1313,7 @@ int32_t InputMethodController::ReceivePrivateCommand(
{
auto listener = GetTextListener();
if (listener == nullptr) {
IMSA_HILOGE("listener is nullptr!");
IMSA_HILOGE("listener is nullptr.");
return ErrorCode::ERROR_EX_NULL_POINTER;
}
IMSA_HILOGD("IMC in.");
@ -1395,4 +1396,4 @@ int32_t InputMethodController::FinishTextPreview()
return ErrorCode::NO_ERROR;
}
} // namespace MiscServices
} // namespace OHOS
} // namespace OHOS

View File

@ -316,7 +316,7 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input
}
auto ret = remote->SendRequest(code, data, reply, option);
if (ret != NO_ERROR) {
IMSA_HILOGE("failed to send request to IMSA, code: %{public}d, ret: %{public}d!", code, ret);
IMSA_HILOGE("failed to send request, code: %{public}d, ret %{public}d!", code, ret);
return ret;
}
if (option.GetFlags() == MessageOption::TF_ASYNC) {
@ -324,7 +324,7 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input
}
ret = reply.ReadInt32();
if (ret != NO_ERROR) {
IMSA_HILOGE("dispose failed in IMSA, code: %{public}d, ret: %{public}d!", code, ret);
IMSA_HILOGE("dispose failed in service, code: %{public}d, ret: %{public}d!", code, ret);
return ret;
}
if (output != nullptr && (!output(reply))) {
@ -334,4 +334,4 @@ int32_t InputMethodSystemAbilityProxy::SendRequest(int code, ParcelHandler input
return ErrorCode::NO_ERROR;
}
} // namespace MiscServices
} // namespace OHOS
} // namespace OHOS

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef INPUTMETHOD_INPUT_METHOD_TYPES_H
#define INPUTMETHOD_INPUT_METHOD_TYPES_H
#ifndef INPUTMETHOD_IMF_PROXY_IME_UNREGISTERED_TYPE_H
#define INPUTMETHOD_IMF_PROXY_IME_UNREGISTERED_TYPE_H
#include "input_attribute.h"
#include "key_event.h"
@ -23,4 +23,4 @@ namespace MiscServices {
enum class UnRegisteredType : int32_t { REMOVE_PROXY_IME, SWITCH_PROXY_IME_TO_IME, NONE };
} // namespace MiscServices
} // namespace OHOS
#endif // INPUTMETHOD_INPUT_METHOD_TYPES_H
#endif // INPUTMETHOD_IMF_PROXY_IME_UNREGISTERED_TYPE_H

View File

@ -37,12 +37,12 @@ int32_t KeyboardEvent::AddKeyEventMonitor(KeyHandle handle)
IMSA_HILOGI("KeyboardEvent::AddKeyEventMonitor start.");
std::shared_ptr<InputEventCallback> callback = std::make_shared<InputEventCallback>();
callback->SetKeyHandle(handle);
int32_t monitorId =
InputManager::GetInstance()->AddMonitor([callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
if (callback == nullptr) {
int32_t monitorId = InputManager::GetInstance()->AddMonitor([callback](std::shared_ptr<MMI::KeyEvent> keyEvent) {
if (callback == nullptr) {
IMSA_HILOGE("callback is nullptr!");
return;
}
return;
}
callback->OnInputEvent(keyEvent);
callback->OnInputEvent(keyEvent);
});
if (monitorId < 0) {
@ -79,4 +79,4 @@ void KeyboardEvent::SubscribeCombinationKey(int32_t preKey, int32_t finalKey, Co
}
}
} // namespace MiscServices
} // namespace OHOS
} // namespace OHOS

View File

@ -14,7 +14,7 @@
},
{
"name": "dialogTitle",
"value": "Select Ime"
"value": "Select keyboard"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string":[
{
"name": "dialogTitle",
"value": "ནང་འཇུག་ཐབས་འདེམས་པ།"
}
]
}

View File

@ -1,20 +0,0 @@
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "ServiceExtAbility_desc",
"value": "InputMethodChoose Dialog"
},
{
"name": "ServiceExtAbility_label",
"value": "InputMethodChooseDialog"
},
{
"name": "dialogTitle",
"value": "Select Input Method"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "dialogTitle",
"value": "كىرگۈزگۈچ تاللاش"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string":[
{
"name": "dialogTitle",
"value": "選擇輸入法"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string":[
{
"name": "dialogTitle",
"value": "選取輸入法"
}
]
}

View File

@ -0,0 +1,8 @@
{
"string": [
{
"name": "dialogTitle",
"value": "[TS_952980]_Select keyboard"
}
]
}

View File

@ -15,12 +15,12 @@
#include "file_operator.h"
#include <cstring>
#include <fstream>
#include <sys/stat.h>
#include <unistd.h>
#include <climits>
#include <fstream>
#include "global.h"
namespace OHOS {
namespace MiscServices {
@ -129,4 +129,4 @@ std::string FileOperator::GetRealPath(const char *path)
return std::string(realPath);
}
} // namespace MiscServices
} // namespace OHOS
} // namespace OHOS

View File

@ -123,6 +123,7 @@ private:
int32_t SwitchExtension(int32_t userId, const std::shared_ptr<ImeInfo> &info);
int32_t SwitchSubType(int32_t userId, const std::shared_ptr<ImeInfo> &info);
int32_t SwitchInputType(int32_t userId, const SwitchInfo &switchInfo);
void GetValidSubtype(const std::string &subName, const std::shared_ptr<ImeInfo> &info);
ServiceRunningState state_;
void InitServiceHandler();
void UpdateUserInfo(int32_t userId);

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,8 @@ public:
bool IsWmsReady();
bool CheckPwdInputPatternConv(InputClientInfo &clientInfo);
int32_t RestoreCurrentIme();
std::shared_ptr<ImeNativeCfg> GetImeNativeCfg(int32_t userId, const std::string &bundleName,
const std::string &subName);
private:
struct ResetManager {
@ -238,6 +240,7 @@ private:
bool StopExitingCurrentIme();
bool HandleFirstStart(const std::shared_ptr<ImeNativeCfg> &ime, bool isStopCurrentIme);
bool HandleStartImeTimeout(const std::shared_ptr<ImeNativeCfg> &ime);
bool CheckInputTypeToStart(std::shared_ptr<ImeNativeCfg> &imeToStart);
std::mutex imeStartLock_;
BlockData<bool> isImeStarted_{ MAX_IME_START_TIME, false };

View File

@ -57,6 +57,7 @@ using namespace AppExecFwk;
using namespace Security::AccessToken;
REGISTER_SYSTEM_ABILITY_BY_ID(InputMethodSystemAbility, INPUT_METHOD_SYSTEM_ABILITY_ID, true);
constexpr std::int32_t INIT_INTERVAL = 10000L;
constexpr const char *UNDEFINED = "undefined";
static const std::string PERMISSION_CONNECT_IME_ABILITY = "ohos.permission.CONNECT_IME_ABILITY";
std::shared_ptr<AppExecFwk::EventHandler> InputMethodSystemAbility::serviceHandler_;
@ -705,14 +706,15 @@ int32_t InputMethodSystemAbility::OnSwitchInputMethod(int32_t userId, const Swit
InputMethodSyncTrace tracer("InputMethodSystemAbility_OnSwitchInputMethod");
std::string targetImeName = info->prop.name + "/" + info->prop.id;
ImeCfgManager::GetInstance().ModifyImeCfg({ userId, targetImeName, info->subProp.id });
auto targetIme = std::make_shared<ImeNativeCfg>(
ImeNativeCfg{ targetImeName, info->prop.name, info->subProp.id, info->prop.id });
auto targetIme = std::make_shared<ImeNativeCfg>(ImeNativeCfg {
targetImeName, info->prop.name, switchInfo.subName.empty() ? "" : info->subProp.id, info->prop.id });
if (!session->StartIme(targetIme)) {
InputMethodSysEvent::GetInstance().InputmethodFaultReporter(ret, switchInfo.bundleName,
"switch input method failed!");
session->GetSwitchQueue().Pop();
return ErrorCode::ERROR_IME_START_FAILED;
}
GetValidSubtype(switchInfo.subName, info);
session->NotifyImeChangeToClients(info->prop, info->subProp);
ret = session->SwitchSubtype(info->subProp);
}
@ -725,6 +727,16 @@ int32_t InputMethodSystemAbility::OnSwitchInputMethod(int32_t userId, const Swit
return ret;
}
void InputMethodSystemAbility::GetValidSubtype(const std::string &subName, const std::shared_ptr<ImeInfo> &info)
{
if (subName.empty()) {
IMSA_HILOGW("undefined subtype");
info->subProp.id = UNDEFINED;
info->subProp.name = UNDEFINED;
}
}
int32_t InputMethodSystemAbility::OnStartInputType(int32_t userId, const SwitchInfo &switchInfo,
bool isCheckPermission)
{
@ -804,6 +816,8 @@ int32_t InputMethodSystemAbility::SwitchExtension(int32_t userId, const std::sha
return ErrorCode::ERROR_IME_START_FAILED;
}
session->NotifyImeChangeToClients(info->prop, info->subProp);
GetValidSubtype("", info);
session->SwitchSubtype(info->subProp);
return ErrorCode::NO_ERROR;
}
@ -833,19 +847,16 @@ int32_t InputMethodSystemAbility::SwitchInputType(int32_t userId, const SwitchIn
IMSA_HILOGE("%{public}d session is nullptr!", userId);
return ErrorCode::ERROR_NULL_POINTER;
}
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeProperty(userId, switchInfo.bundleName);
if (targetImeProperty == nullptr) {
IMSA_HILOGE("GetImeProperty [%{public}d, %{public}s] failed", userId, switchInfo.bundleName.c_str());
auto targetIme = session->GetImeNativeCfg(userId, switchInfo.bundleName, switchInfo.subName);
if (targetIme == nullptr) {
IMSA_HILOGE("targetIme is nullptr!");
return ErrorCode::ERROR_NULL_POINTER;
}
std::string targetName = switchInfo.bundleName + "/" + targetImeProperty->id;
ImeNativeCfg targetIme = { targetName, switchInfo.bundleName, switchInfo.subName, targetImeProperty->id };
InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName });
if (!session->StartIme(std::make_shared<ImeNativeCfg>(targetIme))) {
if (!session->StartIme(targetIme)) {
IMSA_HILOGE("start input method failed!");
InputTypeManager::GetInstance().Set(false);
return ErrorCode::ERROR_IME_START_FAILED;
}
InputTypeManager::GetInstance().Set(true, { switchInfo.bundleName, switchInfo.subName });
int32_t ret = session->SwitchSubtype({ .name = switchInfo.bundleName, .id = switchInfo.subName });
if (ret != ErrorCode::NO_ERROR) {
InputTypeManager::GetInstance().Set(false);

View File

@ -119,6 +119,30 @@ ImeIdentification InputTypeManager::GetCurrentIme()
return currentTypeIme_;
}
bool InputTypeManager::IsVoiceImeStarted()
{
if (!IsStarted()) {
return false;
}
std::lock_guard<std::mutex> lock(typesLock_);
return 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;
}
bool InputTypeManager::Init()
{
IMSA_HILOGD("start.");

View File

@ -260,13 +260,12 @@ void PerUserSession::OnImeDied(const sptr<IInputMethodCore> &remote, ImeType typ
auto imeData = GetImeData(type);
if (imeData != nullptr && imeData->imeStatus == ImeStatus::EXITING) {
RemoveImeData(type, true);
NotifyImeStopFinished();
InputTypeManager::GetInstance().Set(false);
NotifyImeStopFinished();
IMSA_HILOGI("%{public}d not current imeData.", type);
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;
@ -984,10 +983,13 @@ bool PerUserSession::IsSameClient(sptr<IInputClient> source, sptr<IInputClient>
bool PerUserSession::StartCurrentIme(bool isStopCurrentIme)
{
auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
auto imeToStart = ImeInfoInquirer::GetInstance().GetImeToStart(userId_);
IMSA_HILOGD("currentIme: %{public}s, imeToStart: %{public}s.", currentIme->imeId.c_str(),
imeToStart->imeId.c_str());
std::shared_ptr<ImeNativeCfg> imeToStart = nullptr;
if (!CheckInputTypeToStart(imeToStart)) {
auto currentIme = ImeCfgManager::GetInstance().GetCurrentImeCfg(userId_);
imeToStart = ImeInfoInquirer::GetInstance().GetImeToStart(userId_);
IMSA_HILOGD("currentIme: %{public}s, imeToStart: %{public}s.", currentIme->imeId.c_str(),
imeToStart->imeId.c_str());
}
if (!StartIme(imeToStart, isStopCurrentIme)) {
IMSA_HILOGE("failed to start ime!");
InputMethodSysEvent::GetInstance().InputmethodFaultReporter(ErrorCode::ERROR_IME_START_FAILED,
@ -999,6 +1001,7 @@ bool PerUserSession::StartCurrentIme(bool isStopCurrentIme)
ImeInfoInquirer::GetInstance().GetImeInfo(userId_, imeToStart->bundleName, imeToStart->subName);
if (currentImeInfo != nullptr) {
NotifyImeChangeToClients(currentImeInfo->prop, currentImeInfo->subProp);
SwitchSubtype(currentImeInfo->subProp);
}
return true;
}
@ -1068,18 +1071,6 @@ bool PerUserSession::StartInputService(const std::shared_ptr<ImeNativeCfg> &ime)
}
IMSA_HILOGI("%{public}s started successfully.", ime->imeId.c_str());
InputMethodSysEvent::GetInstance().RecordEvent(IMEBehaviour::START_IME);
auto info = ImeInfoInquirer::GetInstance().GetImeInfo(userId_, ime->bundleName, ime->subName);
if (info == nullptr) {
IMSA_HILOGW("ime doesn't exist!");
return true;
}
auto subProp = info->subProp;
auto data = GetReadyImeData(ImeType::IME);
if (data == nullptr) {
IMSA_HILOGW("ime doesn't exist!");
return true;
}
RequestIme(data, RequestType::NORMAL, [&data, &subProp] { return data->core->SetSubtype(subProp); });
return true;
}
@ -1708,5 +1699,32 @@ bool PerUserSession::CheckPwdInputPatternConv(InputClientInfo &newClientInfo)
IMSA_HILOGI("new input pattern is normal.");
return exClientInfo->config.inputAttribute.GetSecurityFlag();
}
std::shared_ptr<ImeNativeCfg> PerUserSession::GetImeNativeCfg(int32_t userId, const std::string &bundleName,
const std::string &subName)
{
auto targetImeProperty = ImeInfoInquirer::GetInstance().GetImeProperty(userId, bundleName);
if (targetImeProperty == nullptr) {
IMSA_HILOGE("GetImeProperty [%{public}d, %{public}s] failed!", userId, bundleName.c_str());
return nullptr;
}
std::string targetName = bundleName + "/" + targetImeProperty->id;
ImeNativeCfg targetIme = { targetName, bundleName, subName, targetImeProperty->id };
return std::make_shared<ImeNativeCfg>(targetIme);
}
bool PerUserSession::CheckInputTypeToStart(std::shared_ptr<ImeNativeCfg> &imeToStart)
{
if (!InputTypeManager::GetInstance().IsStarted()) {
return false;
}
auto currentInputTypeIme = InputTypeManager::GetInstance().GetCurrentIme();
if (currentInputTypeIme.bundleName.empty()) {
auto currentInputType = InputTypeManager::GetInstance().GetCurrentInputType();
InputTypeManager::GetInstance().GetImeByInputType(currentInputType, currentInputTypeIme);
}
imeToStart = GetImeNativeCfg(userId_, currentInputTypeIme.bundleName, currentInputTypeIme.subName);
return true;
}
} // namespace MiscServices
} // namespace OHOS