A way to wait until IME's layout becomes stable

This is a preparation CL for Bug 38298890 and and Bug 69002467.  There
should be no behavior change in existing CTS test in this CL.

In order to write stable CTS tests, it would be nice if the test case
can wait until the IME's layout becomes stable, because in some cases
the IME receives multiple relayout requests and the last one needs to
be compared with the expected result.  To do this, this CL introduces
ImeEventStreamTestUtils#waitForInputViewLayoutStable(), which enables
us to write test cases as follows:

  try(MockImeSession imeSession = MockImeSession.create(
          context, uiautomation, new ImeSettings.Builder()) {

      final ImeEventStream stream = imeSession.openEventStream();

      // Do something
      ......

      // Wait until MockIme's layout becomes stable.
      final ImeLayoutInfo lastLayout =
              waitForInputViewLayoutStable(stream, LAYOUT_STABLE_THRESHOLD);
      assertNotNull(lastLayout);

      // Check if the keyboard height (observed from the IME process) is
      // expected.
      assertEquals(EXPECTED_KEYBOARD_HEIGHT,
              lastLayout.getInputViewBoundsInScreen().height());

      // Do something
  }

Bug: 38298890
Bug: 69002467
Test: atest CtsInputMethodTestCases
Change-Id: Ia3c5a8dd92bc0dd4569848f3ff0ef9630323c2e0
3 files changed