修复ffi代码回调函数未注册时的行为

Signed-off-by: PipiSummer <xiatian44@huawei.com>
Change-Id: I1cf4da2d321c00423eae5b87d9da6611d42b5428
This commit is contained in:
PipiSummer 2024-08-15 09:41:26 +08:00
parent 68cdb32e83
commit 7b03e79976
3 changed files with 55 additions and 19 deletions

View File

@ -75,13 +75,6 @@ private:
std::function<int32_t(void)> getTextIndexAtCursor;
static std::mutex controllerMutex_;
static std::shared_ptr<CjInputMethodController> controller_;
static const std::string IMC_CLASS_NAME;
static std::mutex eventHandlerMutex_;
static std::shared_ptr<AppExecFwk::EventHandler> handler_;
static constexpr size_t PARAM_POS_ZERO = 0;
static constexpr size_t PARAM_POS_ONE = 1;
static constexpr size_t PARAM_POS_TWO = 2;
static constexpr size_t PARAM_POS_THREE = 3;
};
} // namespace MiscServices
} // namespace OHOS

View File

@ -27,22 +27,14 @@ public:
void InsertText(const std::u16string &text) override;
void DeleteForward(int32_t length) override;
void DeleteBackward(int32_t length) override;
void SendKeyEventFromInputMethod(const KeyEvent &event) override
{
}
void SendKeyEventFromInputMethod(const KeyEvent &event) override {}
void SendKeyboardStatus(const KeyboardStatus &status) override;
void SendFunctionKey(const FunctionKey &functionKey) override;
void SetKeyboardStatus(bool status) override
{
}
void SetKeyboardStatus(bool status) override {}
void MoveCursor(const Direction direction) override;
void HandleSetSelection(int32_t start, int32_t end) override
{
}
void HandleSetSelection(int32_t start, int32_t end) override {}
void HandleExtendAction(int32_t action) override;
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override
{
}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override {}
std::u16string GetLeftTextOfCursor(int32_t number) override;
std::u16string GetRightTextOfCursor(int32_t number) override;
int32_t GetTextIndexAtCursor() override;

View File

@ -276,6 +276,7 @@ void CjInputMethodController::RegisterListener(int8_t type, int64_t id)
}
}
}
void CjInputMethodController::UnRegisterListener(int8_t type)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
@ -341,11 +342,21 @@ int32_t CjInputMethodController::Unsubscribe(int8_t type)
void CjInputMethodController::OnSelectByRange(int32_t start, int32_t end)
{
if (onSelelctByRange == nullptr) {
IMSA_HILOGI("onSelelctByRange null");
return;
}
IMSA_HILOGI("onSelelctByRange runs");
return onSelectByRange(start, end);
}
void CjInputMethodController::OnSelectByMovement(int32_t direction)
{
if (onSelectByMovement == nullptr) {
IMSA_HILOGI("onSelectByMovement null");
return;
}
IMSA_HILOGI("onSelectByMovement runs");
return onSelectByMovement(direction);
}
@ -356,6 +367,10 @@ void CjInputMethodController::InsertText(const std::u16string &text)
IMSA_HILOGE("Failed to excute InsertText callback: out of memory.");
return;
}
if (insertText == nullptr) {
IMSA_HILOGI("insertText null");
return;
}
IMSA_HILOGI("insertText runs");
insertText(insertTxt);
free(insertTxt);
@ -364,6 +379,10 @@ void CjInputMethodController::InsertText(const std::u16string &text)
void CjInputMethodController::DeleteRight(int32_t length)
{
if (deleteRight == nullptr) {
IMSA_HILOGI("deleteRight null");
return;
}
IMSA_HILOGI("deleteRight runs");
deleteRight(length);
return;
@ -371,6 +390,10 @@ void CjInputMethodController::DeleteRight(int32_t length)
void CjInputMethodController::DeleteLeft(int32_t length)
{
if (deleteLeft == nullptr) {
IMSA_HILOGI("deleteLeft null");
return;
}
IMSA_HILOGI("deleteLeft runs");
deleteLeft(length);
return;
@ -378,6 +401,10 @@ void CjInputMethodController::DeleteLeft(int32_t length)
void CjInputMethodController::SendKeyboardStatus(const KeyboardStatus &status)
{
if (sendKeyboardStatus == nullptr) {
IMSA_HILOGI("sendKeyboardStatus null");
return;
}
IMSA_HILOGI("sendKeyboardStatus runs");
auto statusNum = static_cast<int64_t>(status);
sendKeyboardStatus(statusNum);
@ -386,6 +413,10 @@ void CjInputMethodController::SendKeyboardStatus(const KeyboardStatus &status)
void CjInputMethodController::SendFunctionKey(const FunctionKey &functionKey)
{
if (sendFunctionKey == nullptr) {
IMSA_HILOGI("sendFunctionKey null");
return;
}
IMSA_HILOGI("sendFunctionKey runs");
auto type = static_cast<int64_t>(functionKey.GetEnterKeyType());
sendFunctionKey(type);
@ -394,6 +425,10 @@ void CjInputMethodController::SendFunctionKey(const FunctionKey &functionKey)
void CjInputMethodController::MoveCursor(const Direction direction)
{
if (moveCursor == nullptr) {
IMSA_HILOGI("moveCursor null");
return;
}
IMSA_HILOGI("moveCursor runs");
auto dir = static_cast<int64_t>(direction);
moveCursor(dir);
@ -402,6 +437,10 @@ void CjInputMethodController::MoveCursor(const Direction direction)
void CjInputMethodController::HandleExtendAction(int32_t action)
{
if (handleExtendAction == nullptr) {
IMSA_HILOGI("handleExtendAction null");
return;
}
IMSA_HILOGI("handleExtendAction runs");
handleExtendAction(action);
return;
@ -409,6 +448,10 @@ void CjInputMethodController::HandleExtendAction(int32_t action)
std::u16string CjInputMethodController::GetLeftText(int32_t number)
{
if (getLeftText == nullptr) {
IMSA_HILOGI("getLeftText null");
return u"";
}
IMSA_HILOGI("getLeftText runs");
char *text = getLeftText(number);
auto ret = Str8ToStr16(std::string(text));
@ -418,6 +461,10 @@ std::u16string CjInputMethodController::GetLeftText(int32_t number)
std::u16string CjInputMethodController::GetRightText(int32_t number)
{
if (getRightText == nullptr) {
IMSA_HILOGI("getRightText null");
return u"";
}
IMSA_HILOGI("getRightText runs");
char *text = getRightText(number);
auto ret = Str8ToStr16(std::string(text));
@ -427,6 +474,10 @@ std::u16string CjInputMethodController::GetRightText(int32_t number)
int32_t CjInputMethodController::GetTextIndexAtCursor()
{
if (getTextIndexAtCursor == nullptr) {
IMSA_HILOGI("getTextIndexAtCursor null");
return -1;
}
IMSA_HILOGI("getTextIndexAtCursor runs");
return getTextIndexAtCursor();
}