From 518279ccfbfccf45c03d12beebea06b266af2112 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Fri, 15 Jul 2022 18:37:29 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../src/input_method_ability.cpp | 133 +++++++++--------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index eea5ef4..bcef293 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -202,12 +202,12 @@ namespace MiscServices { IMSA_HILOGI("InputMethodAbility::OnInitialInput channelObject is nullptr"); return; } - sptr channelProxy = new InputControlChannelProxy(channelObject); - inputControlChannel = channelProxy; - if (!inputControlChannel) { + sptr channelProxy = new (std::nothrow) InputControlChannelProxy(channelObject); + if (channelProxy == nullptr) { IMSA_HILOGI("InputMethodAbility::OnInitialInput inputControlChannel is nullptr"); return; } + inputControlChannel = channelProxy; } void InputMethodAbility::OnInitInputControlChannel(Message *msg) @@ -219,23 +219,24 @@ namespace MiscServices { IMSA_HILOGI("InputMethodAbility::OnInitInputControlChannel channelObject is nullptr"); return; } - sptr channelProxy = new InputControlChannelProxy(channelObject); - inputControlChannel = channelProxy; - if (!inputControlChannel) { + sptr channelProxy = new (std::nothrow) InputControlChannelProxy(channelObject); + if (channelProxy == nullptr) { IMSA_HILOGI("InputMethodAbility::OnInitInputControlChannel inputControlChannel is nullptr"); + return; } + inputControlChannel = channelProxy; } void InputMethodAbility::OnStartInput(Message *msg) { IMSA_HILOGI("InputMethodAbility::OnStartInput"); MessageParcel *data = msg->msgContent_; - sptr channalProxy = new InputDataChannelProxy(data->ReadRemoteObject()); - inputDataChannel = channalProxy; - if (!inputDataChannel) { + sptr channalProxy = new (std::nothrow) InputDataChannelProxy(data->ReadRemoteObject()); + if (channalProxy == nullptr) { IMSA_HILOGI("InputMethodAbility::OnStartInput inputDataChannel is nullptr"); return; } + inputDataChannel = channalProxy; editorAttribute = data->ReadParcelable(); if (!editorAttribute) { IMSA_HILOGI("InputMethodAbility::OnStartInput editorAttribute is nullptr"); @@ -247,10 +248,10 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodAbility::OnShowKeyboard"); MessageParcel *data = msg->msgContent_; - sptr channalProxy = new InputDataChannelProxy(data->ReadRemoteObject()); - inputDataChannel = channalProxy; - if (!inputDataChannel) { - IMSA_HILOGI("InputMethodAbility::OnShowKeyboard inputDataChannel is nullptr"); + sptr channalProxy = new (std::nothrow) InputDataChannelProxy(data->ReadRemoteObject()); + if (inputDataChannel) { + inputDataChannel = channalProxy; + IMSA_HILOGI("InputMethodAbility::OnShowKeyboard inputDataChannel is not nullptr"); } ShowInputWindow(); } @@ -339,11 +340,12 @@ namespace MiscServices { } imeListener_->OnInputStart(); imeListener_->OnKeyboardStatus(true); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::ShowInputWindow inputDataChannel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::ShowInputWindow channel is nullptr"); + return; } - inputDataChannel_->SendKeyboardStatus(KEYBOARD_SHOW); + channel->SendKeyboardStatus(KEYBOARD_SHOW); } void InputMethodAbility::DissmissInputWindow() @@ -354,134 +356,135 @@ namespace MiscServices { return; } imeListener_->OnKeyboardStatus(false); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::DissmissInputWindow inputDataChannel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::DissmissInputWindow channel is nullptr"); + return; } - inputDataChannel_->SendKeyboardStatus(KEYBOARD_HIDE); + channel->SendKeyboardStatus(KEYBOARD_HIDE); } bool InputMethodAbility::InsertText(const std::string text) { IMSA_HILOGI("InputMethodAbility::InsertText"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::InsertText inputDataChannel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::InsertText channel is nullptr"); return false; } - return inputDataChannel_->InsertText(Utils::to_utf16(text)); + return channel->InsertText(Utils::to_utf16(text)); } void InputMethodAbility::DeleteForward(int32_t length) { IMSA_HILOGI("InputMethodAbility::DeleteForward"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::DeleteForward inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::DeleteForward channel is nullptr"); return; } - inputDataChannel_->DeleteForward(length); + channel->DeleteForward(length); } void InputMethodAbility::DeleteBackward(int32_t length) { IMSA_HILOGI("InputMethodAbility::DeleteBackward"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::DeleteBackward inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::DeleteBackward channel is nullptr"); return; } - inputDataChannel_->DeleteBackward(length); + channel->DeleteBackward(length); } void InputMethodAbility::SendFunctionKey(int32_t funcKey) { IMSA_HILOGI("InputMethodAbility::SendFunctionKey"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::SendFunctionKey inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::SendFunctionKey channel is nullptr"); return; } - inputDataChannel_->SendFunctionKey(funcKey); + channel->SendFunctionKey(funcKey); } void InputMethodAbility::HideKeyboardSelf() { IMSA_HILOGI("InputMethodAbility::HideKeyboardSelf"); - sptr inputControlChannel_ = inputControlChannel; - if (!inputControlChannel_) { - IMSA_HILOGI("InputMethodAbility::HideKeyboardSelf inputControlChannel_ is nullptr"); + sptr controlChannel = inputControlChannel; + if(controlChannel == nullptr) { + IMSA_HILOGI("InputMethodAbility::HideKeyboardSelf controlChannel is nullptr"); return; } - inputControlChannel_->hideKeyboardSelf(1); + controlChannel->hideKeyboardSelf(1); } std::u16string InputMethodAbility::GetTextBeforeCursor(int32_t number) { IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor channel is nullptr"); return u""; } - return inputDataChannel_->GetTextBeforeCursor(number); + return channel->GetTextBeforeCursor(number); } std::u16string InputMethodAbility::GetTextAfterCursor(int32_t number) { IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::GetTextAfterCursor channel is nullptr"); return u""; } - return inputDataChannel_->GetTextAfterCursor(number); + return channel->GetTextAfterCursor(number); } void InputMethodAbility::MoveCursor(int32_t keyCode) { IMSA_HILOGI("InputMethodAbility::MoveCursor"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::MoveCursor inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::MoveCursor channel is nullptr"); return; } - inputDataChannel_->MoveCursor(keyCode); + channel->MoveCursor(keyCode); return; } int32_t InputMethodAbility::GetEnterKeyType() { IMSA_HILOGI("InputMethodAbility::GetEnterKeyType"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::GetEnterKeyType inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::GetEnterKeyType channel is nullptr"); return 0; } - return inputDataChannel_->GetEnterKeyType(); + return channel->GetEnterKeyType(); } int32_t InputMethodAbility::GetInputPattern() { IMSA_HILOGI("InputMethodAbility::GetInputPattern"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::GetInputPattern inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::GetInputPattern channel is nullptr"); return 0; } - return inputDataChannel_->GetInputPattern(); + return channel->GetInputPattern(); } void InputMethodAbility::StopInput() { IMSA_HILOGI("InputMethodAbility::StopInput"); - sptr inputDataChannel_ = inputDataChannel; - if (!inputDataChannel_) { - IMSA_HILOGI("InputMethodAbility::StopInput inputDataChanel_ is nullptr"); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::StopInput channel is nullptr"); return; } - inputDataChannel_->StopInput(); + channel->StopInput(); } } // namespace MiscServices } // namespace OHOS