diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 0d439bd..5003cc1 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 (channalProxy != nullptr) { + inputDataChannel = channalProxy; + IMSA_HILOGI("InputMethodAbility::OnShowKeyboard inputDataChannel is not nullptr"); } ShowInputWindow(); } @@ -339,9 +340,12 @@ namespace MiscServices { } imeListener_->OnInputStart(); imeListener_->OnKeyboardStatus(true); - if (inputDataChannel) { - inputDataChannel->SendKeyboardStatus(KEYBOARD_SHOW); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::ShowInputWindow channel is nullptr"); + return; } + channel->SendKeyboardStatus(KEYBOARD_SHOW); } void InputMethodAbility::DissmissInputWindow() @@ -352,124 +356,135 @@ namespace MiscServices { return; } imeListener_->OnKeyboardStatus(false); - if (inputDataChannel) { - inputDataChannel->SendKeyboardStatus(KEYBOARD_HIDE); + sptr channel = inputDataChannel; + if (channel == nullptr) { + IMSA_HILOGI("InputMethodAbility::DissmissInputWindow channel is nullptr"); + return; } + channel->SendKeyboardStatus(KEYBOARD_HIDE); } bool InputMethodAbility::InsertText(const std::string text) { IMSA_HILOGI("InputMethodAbility::InsertText"); - if (!inputDataChannel) { - IMSA_HILOGI("InputMethodAbility::InsertText inputDataChanel 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"); - 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"); - 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"); - 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"); - inputControlChannel->hideKeyboardSelf(1); + sptr controlChannel = inputControlChannel; + if (controlChannel == nullptr) { + IMSA_HILOGI("InputMethodAbility::HideKeyboardSelf controlChannel is nullptr"); + return; + } + controlChannel->hideKeyboardSelf(1); } std::u16string InputMethodAbility::GetTextBeforeCursor(int32_t number) { IMSA_HILOGI("InputMethodAbility::GetTextBeforeCursor"); - - 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"); - - 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"); - - 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"); - - 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"); - - 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"); - - 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