Wait for home visible before resuming app switches

The part that sets the stop-app-switches time from pressHomeButton()
might race with resumeAppSwitches(), so waiting for home visible before
calling the latter. That *might* be the cause of the flakiness in the
bug. However, if it isn't I believe this change doesn't hurt.

Test: atest BackgroundActivityLaunchTest
Bug: 134733754
Change-Id: Ie128b658ee427e0931cfa2cb4bf2b1e7a071357b
diff --git a/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java b/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
index 09c8fc2..19ba5c0 100644
--- a/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
+++ b/tests/framework/base/windowmanager/backgroundactivity/src/android/server/wm/BackgroundActivityLaunchTest.java
@@ -454,10 +454,12 @@
         // Press home key to ensure stopAppSwitches is called because the last-stop-app-switch-time
         // is a criteria of allowing background start.
         pressHomeButton();
+        // Waiting for home visible before resuming app switches to make sure the part that sets the
+        // stop-app-switches time from pressHomeButton() doesn't race with resumeAppSwitches()
+        mWmState.waitForHomeActivityVisible();
         // Resume the stopped state (it won't affect last-stop-app-switch-time) so we don't need to
         // wait extra time to prevent the next launch from being delayed.
         resumeAppSwitches();
-        mWmState.waitForHomeActivityVisible();
     }
 
     private void assertTaskStack(ComponentName[] expectedComponents,