Android: fix potential null InputMethodManager object access
Ensure we don't end up calling methods from a null m_imm object inside runAction(), the code was guarded outside the call but not inside where it can still happen. Fixes: QTBUG-129684 Change-Id: I41d7e64a028f551bb53d177e16a77e7ae512a84e Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io> (cherry picked from commit 33ef9330f67dd3c6603fb222e1556c31591f1fd9) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
4a27d0fe0a
commit
07807794f7
@ -80,6 +80,8 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
void initInputMethodManager(Activity activity)
|
void initInputMethodManager(Activity activity)
|
||||||
{
|
{
|
||||||
m_imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
m_imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
if (m_imm == null)
|
||||||
|
Log.w(TAG, "getSystemService() returned a null InputMethodManager instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
// QtInputInterface implementation begin
|
// QtInputInterface implementation begin
|
||||||
@ -87,6 +89,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
public void updateSelection(final int selStart, final int selEnd,
|
public void updateSelection(final int selStart, final int selEnd,
|
||||||
final int candidatesStart, final int candidatesEnd)
|
final int candidatesStart, final int candidatesEnd)
|
||||||
{
|
{
|
||||||
|
if (m_imm != null) {
|
||||||
QtNative.runAction(() -> {
|
QtNative.runAction(() -> {
|
||||||
if (m_imm != null) {
|
if (m_imm != null) {
|
||||||
m_imm.updateSelection(m_currentEditText, selStart, selEnd,
|
m_imm.updateSelection(m_currentEditText, selStart, selEnd,
|
||||||
@ -94,12 +97,16 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showSoftwareKeyboard(Activity activity,
|
public void showSoftwareKeyboard(Activity activity,
|
||||||
final int x, final int y, final int width, final int height,
|
final int x, final int y, final int width, final int height,
|
||||||
final int inputHints, final int enterKeyType)
|
final int inputHints, final int enterKeyType)
|
||||||
{
|
{
|
||||||
|
if (m_imm == null)
|
||||||
|
return;
|
||||||
|
|
||||||
QtNative.runAction(() -> {
|
QtNative.runAction(() -> {
|
||||||
if (m_imm == null || m_currentEditText == null)
|
if (m_imm == null || m_currentEditText == null)
|
||||||
return;
|
return;
|
||||||
@ -174,6 +181,8 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
if (m_imm == null || m_currentEditText == null)
|
if (m_imm == null || m_currentEditText == null)
|
||||||
return;
|
return;
|
||||||
m_currentEditText.postDelayed(() -> {
|
m_currentEditText.postDelayed(() -> {
|
||||||
|
if (m_imm == null || m_currentEditText == null)
|
||||||
|
return;
|
||||||
m_imm.restartInput(m_currentEditText);
|
m_imm.restartInput(m_currentEditText);
|
||||||
m_currentEditText.m_optionsChanged = false;
|
m_currentEditText.m_optionsChanged = false;
|
||||||
}, 5);
|
}, 5);
|
||||||
@ -182,6 +191,9 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
@Override
|
@Override
|
||||||
public void hideSoftwareKeyboard()
|
public void hideSoftwareKeyboard()
|
||||||
{
|
{
|
||||||
|
if (m_imm == null || m_currentEditText == null)
|
||||||
|
return;
|
||||||
|
|
||||||
m_isKeyboardHidingAnimationOngoing = true;
|
m_isKeyboardHidingAnimationOngoing = true;
|
||||||
QtNative.runAction(() -> {
|
QtNative.runAction(() -> {
|
||||||
if (m_imm == null || m_currentEditText == null)
|
if (m_imm == null || m_currentEditText == null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user