Insert new startup descriptors at point of execution

When generating a startup list using generate_startup_descriptors.py, the app is launched multiple times until the set of startup descriptors no longer change.

Prior to this CL, newly identified startup descriptors from launching the app were simply appended to the existing startup list.

For a new startup descriptor from a newly generated startup list, this CL finds the closest startup descriptor that is already in the complete startup list, and then inserts the new startup descriptor immediately after that in the existing trace (instead of appending it to the end).

Change-Id: Iee38a80e5c2b15ddc207a704204e1ef4e942c0c6
diff --git a/tools/startup/adb_utils.py b/tools/startup/adb_utils.py
index 56ad643..3df82d5 100755
--- a/tools/startup/adb_utils.py
+++ b/tools/startup/adb_utils.py
@@ -254,9 +254,12 @@
     args.append('-W')
   cmd = create_adb_cmd(args, device_id)
   stdout = subprocess.check_output(cmd).decode('utf-8').strip()
-  expected_stdout = (
-      'Starting: Intent { cmp=%s/.%s }' % (app_id, activity[len(app_id)+1:]))
-  assert stdout.startswith(expected_stdout), 'was %s' % stdout
+  if activity.startswith(app_id):
+    expected_stdout = (
+        'Starting: Intent { cmp=%s/.%s }' % (app_id, activity[len(app_id)+1:]))
+  else:
+    expected_stdout = 'Starting: Intent { cmp=%s/%s }' % (app_id, activity)
+  assert stdout.startswith(expected_stdout), 'was %s, expected %s' % (stdout, expected_stdout)
   lines = stdout.splitlines()
   result = {}
   for line in lines:
@@ -341,7 +344,8 @@
     expected_error = (
         'java.lang.IllegalArgumentException: Unknown package: %s' % app_id)
     assert 'Failure [DELETE_FAILED_INTERNAL_ERROR]' in stdout \
-        or expected_error in stderr
+        or expected_error in stderr, \
+        'stdout: %s, stderr: %s' % (stdout, stderr)
 
 def unlock(device_id=None, device_pin=None):
   ensure_screen_on(device_id)