Deprecate IMM#showSoftInputUnchecked() part 1
One of non-intuitive behaviors of InputMethodManager#showSoftInput() is
that it always fails if you pass a view that does not window focus. For
example, the following code does not show the software keyboard because
the target window is not yet focused during Activity#onCreate().
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
final EditText editText = new EditText(this);
layout.addView(editText);
final InputMethodManager imm =
getSystemService(InputMethodManager.class);
editText.requestFocus();
// This will be ignored because the target window has not gained
// focus yet.
imm.showSoftInput(editText, 0);
setContentView(layout);
}
Some platform components, however, have worked around by this limitation
by relying on IMM#showSoftInputUnchecked(), which just bypasses internal
IME focus handling flows.
Bypassing standard event handlign flow is indeed problematic, and has
actually contributed to issues such as Bug
35903813 and Bug
31915865
directly or indirectly. In order to make IME focus handling more
deterministic and reliable, IMM#showSoftInputUnchecked() really needs to
be deprecated.
As the initial step to deprecate IMM#showSoftInputUnchecked(), this CL
removes the dependency on it from SearchView. Instead of immediatelly
issuing delayed tasks that call IMM#showSoftInputUnchecked(), this CL
uses View#onCreateInputConnection() as a signal that SearchAutoComplete
now owns IME focus.
Test: Open System Settings and tap the search icon to make sure that
the software keyboard will be shown automatically.
Test: cts-tradefed run cts -m CtsWidgetTestCases --test android.widget.cts.SearchViewTest
Bug: r.android.com/223701
Bug:
36015425
Bug:
31756425
Fixes:
35903813
Change-Id: I20983e4ce1d625e098a8c2335ce75994cfa43235