Make closing system dialogs in A11y CTS test setup more robust.

The test activity needs to be active for proper test behavior, but
system dialogs from previous unrelated tests can prevent the test
activity from becoming active.

This commit makes two changes:
1. Ensure that the home screen is active+focused in A11y CTS tests.
   If it is not, then the system dialog will be closed before the test
   activity is launched.
2. If the launched activity is not visible+active+focused then attempt
   again to close any new system dialogs that appeared in between the
   home screen launching and the test activity launching.

Bug: 294403610
Test: atest AccessibilityImeTest --iterations 100;
Test: Repeat the above while manually triggering screenshots and swiping
      down the notification tray. Observe that the test closes the
      floating screenshot popup and the notification tray.
Change-Id: I3c4156f539974199ee773c42b629cbad7904ebe8
1 file changed