[arc] Add a function to wait for userspace to be ready

Tests can use this as way to make sure that all the basic services are
ready.

The new function launches Android settings, waiting for that to succeed.
It then closes the app.

TEST=cheets_SettingsBridge passes after using it to wait
BUG=b:110853374

Change-Id: I2cb30795412200c1d4e73effa30517fae2814c57
Reviewed-on: https://chromium-review.googlesource.com/1144527
Trybot-Ready: Lloyd Pique <lpique@google.com>
Tested-by: Lloyd Pique <lpique@google.com>
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Commit-Queue: Lloyd Pique <lpique@google.com>
diff --git a/client/common_lib/cros/arc.py b/client/common_lib/cros/arc.py
index 5a19bf2..ce8c584 100644
--- a/client/common_lib/cros/arc.py
+++ b/client/common_lib/cros/arc.py
@@ -591,6 +591,23 @@
     utils.run('inject_powerd_input_event', args=args)
 
 
+def wait_for_userspace_ready():
+    """Waits for userspace apps to be launchable.
+
+    Launches and then closes Android settings as a way to ensure all basic
+    services are ready. This goes a bit beyond waiting for boot-up to complete,
+    as being able to launch an activity requires more of the framework to have
+    started. The boot-complete signal happens fairly early, and the framework
+    system server is still starting services. By waiting for ActivityManager to
+    respond, we automatically wait on more services to be ready.
+    """
+    output = adb_shell('am start -W -a android.settings.SETTINGS')
+    if not output.endswith('Complete'):
+        logging.debug('Output was: %s', output)
+        raise error.TestError('Could not launch SETTINGS')
+    adb_shell('am force-stop com.android.settings')
+
+
 class Logcat(object):
     """Saves the output of logcat to a file."""