Rearrange steps for core devices to help debug issues

Bug: https://github.com/flutter/flutter/issues/141383, https://github.com/flutter/flutter/issues/141624
Change-Id: I31209c422b3a00ecd0da60ac71ff07c2d2d6ce39
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/54108
Reviewed-by: Keyong Han <keyonghan@google.com>
Commit-Queue: Victoria Ashworth <vashworth@google.com>
diff --git a/recipe_modules/os_utils/api.py b/recipe_modules/os_utils/api.py
index 8abfeda..be69ce9 100644
--- a/recipe_modules/os_utils/api.py
+++ b/recipe_modules/os_utils/api.py
@@ -331,6 +331,22 @@
     """
     if self.is_devicelab() and self.is_ios() and self.m.platform.is_mac:
       with self.m.step.nest('Dismiss dialogs'):
+        # Get list of wired CoreDevices.
+        # Allow any return code and ignore failure since this command will only
+        # work with Xcode 15 and therefore may not work for all machines.
+        self.m.step(
+            'List CoreDevices',
+            [
+                'xcrun',
+                'devicectl',
+                'list',
+                'devices',
+                '-v',
+            ],
+            raise_on_failure=False,
+            ok_ret='any',
+        )
+
         with self.m.step.nest('Dismiss iOS dialogs'):
           cocoon_path = self._checkout_cocoon()
           resource_name = self.resource('dismiss_dialogs.sh')
@@ -363,22 +379,6 @@
       device_id(string): A string of the selected device's UDID.
     """
 
-    # Get list of wired CoreDevices.
-    # Allow any return code and ignore failure since this command will only
-    # work with Xcode 15 and therefore may not work for all machines.
-    self.m.step(
-        'List CoreDevices',
-        [
-            'xcrun',
-            'devicectl',
-            'list',
-            'devices',
-            '-v',
-        ],
-        raise_on_failure=False,
-        ok_ret='any',
-    )
-
     device_list = self.m.step(
         'Find wired CoreDevices',
         [
@@ -390,7 +390,7 @@
             "connectionProperties.transportType CONTAINS 'wired'",
             '-v',
         ],
-        stdout=self.m.raw_io.output_text(),
+        stdout=self.m.raw_io.output_text(add_output_log=True),
         raise_on_failure=False,
         ok_ret='any',
     ).stdout.rstrip()
@@ -434,7 +434,7 @@
       )
 
     self.m.retry.basic_wrap(
-        lambda timeout: self._trigger_automation_permission(
+        lambda timeout: self._create_tcc_entry(
             db_path,
             timeout=timeout,
         ),
@@ -460,6 +460,12 @@
     # Print contents of db for potential debugging purposes.
     self._query_automation_db_step_with_retry(db_path)
 
+    # Try and trigger Xcode automation. If fails or times out, permission was
+    # not successfully granted.
+    self._trigger_and_dismiss_automation_permission(
+        timeout=5 * 60, raise_on_failure=True
+    )
+
     # Xcode was opened by Applescript, so kill it.
     self.m.step(
         'Kill Xcode',
@@ -467,19 +473,34 @@
         ok_ret='any',
     )
 
-  def _trigger_automation_permission(self, db_path, timeout=2):
+  def _dismiss_automation_permission(self):
+    """Kill the Xcode automation dialog. After killing the dialog, an entry for
+    the app requesting control of Xcode should automatically be added to the db.
+    """
+
+    self.m.step(
+        'Dismiss dialog',
+        ['killall', '-9', 'UserNotificationCenter'],
+        ok_ret='any',
+    )
+
+  def _trigger_and_dismiss_automation_permission(
+      self,
+      timeout=2,
+      raise_on_failure=False,
+  ):
     """Trigger Xcode automation dialog to appear and then kill the dialog.
-    Killing the dialog will add an entry for the permission to the TCC.db.
-    Raises an error if dialog fails to add entry to db.
 
     Args:
-      db_path(string): A string of the path to the sqlite database.
+      timeout (int or float): How many seconds to wait before timing out the
+              "Trigger dialog" step.
+      raise_on_failure (bool): Raise InfraFailure or StepFailure on failure.
     """
 
     # Run an arbitrary AppleScript Xcode command to trigger permissions dialog.
     # The AppleScript counts how many Xcode windows are open.
     # The script will hang if permission has not been given, so timeout after
-    # a few seconds. For each attempt, use a longer timeout.
+    # a few seconds.
     self.m.step(
         'Trigger dialog',
         [
@@ -493,18 +514,22 @@
             '-e',
             'end tell',
         ],
-        raise_on_failure=False,
-        ok_ret='any',
+        raise_on_failure=raise_on_failure,
+        ok_ret=(0,) if raise_on_failure else 'any',
         timeout=timeout,
     )
+    self._dismiss_automation_permission()
 
-    # Kill the dialog. After killing the dialog, an entry for the app requesting
-    # control of Xcode should automatically be added to the db.
-    self.m.step(
-        'Dismiss dialog',
-        ['killall', '-9', 'UserNotificationCenter'],
-        ok_ret='any',
-    )
+  def _create_tcc_entry(self, db_path, timeout=2):
+    """Trigger Xcode automation dialog to appear and then kill the dialog.
+    Killing the dialog will add an entry for the permission to the TCC.db.
+    Raises an error if dialog fails to add entry to db.
+
+    Args:
+      db_path(string): A string of the path to the sqlite database.
+    """
+
+    self._trigger_and_dismiss_automation_permission(timeout=timeout)
 
     if 'Xcode' not in self._query_automation_db_step_with_retry(db_path):
       raise self.m.step.InfraFailure('Xcode entry not found in TCC.db')
@@ -586,6 +611,11 @@
       with self.m.step.nest('Reset Xcode automation dialogs'):
         tcc_directory_path, db_path, backup_db_path = self._get_tcc_path()
 
+        self._dismiss_automation_permission()
+
+        # Print contents of db for potential debugging purposes.
+        self._query_automation_db_step_with_retry(db_path)
+
         files = self.m.step(
             'Find TCC directory',
             ['ls', tcc_directory_path],
diff --git a/recipe_modules/os_utils/examples/full.expected/clean_derived_data.json b/recipe_modules/os_utils/examples/full.expected/clean_derived_data.json
index 3592f1e..d5fdddd 100644
--- a/recipe_modules/os_utils/examples/full.expected/clean_derived_data.json
+++ b/recipe_modules/os_utils/examples/full.expected/clean_derived_data.json
@@ -315,6 +315,19 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -484,20 +497,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -505,7 +504,8 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -625,6 +625,37 @@
   },
   {
     "cmd": [
+      "osascript",
+      "-e",
+      "tell app \"Xcode\"",
+      "-e",
+      "launch",
+      "-e",
+      "count window",
+      "-e",
+      "end tell"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Trigger dialog (2)",
+    "timeout": 300,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Dismiss dialog (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
       "killall",
       "-9",
       "Xcode"
@@ -641,6 +672,29 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],
diff --git a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_find_db.json b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_find_db.json
index d1a8025..be7f6b2 100644
--- a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_find_db.json
+++ b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_find_db.json
@@ -318,6 +318,19 @@
     ]
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -488,20 +501,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -509,7 +508,8 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
diff --git a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_update_db.json b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_update_db.json
index e6975c1..ffb6d83 100644
--- a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_update_db.json
+++ b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_fails_update_db.json
@@ -318,6 +318,19 @@
     ]
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -488,20 +501,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -509,7 +508,8 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
diff --git a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_skip_if_not_core_device.json b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_skip_if_not_core_device.json
index 33763af..5f796e1 100644
--- a/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_skip_if_not_core_device.json
+++ b/recipe_modules/os_utils/examples/full.expected/dimiss_dialog_xcode_automation_skip_if_not_core_device.json
@@ -315,6 +315,19 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -484,20 +497,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -505,7 +504,9 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_LINE@raw_io.output_text@No devices found.@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -522,6 +523,29 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],
diff --git a/recipe_modules/os_utils/examples/full.expected/ios_debug_symbol_doctor_fails_then_succeeds.json b/recipe_modules/os_utils/examples/full.expected/ios_debug_symbol_doctor_fails_then_succeeds.json
index 72c0fb3..625f1fb 100644
--- a/recipe_modules/os_utils/examples/full.expected/ios_debug_symbol_doctor_fails_then_succeeds.json
+++ b/recipe_modules/os_utils/examples/full.expected/ios_debug_symbol_doctor_fails_then_succeeds.json
@@ -349,6 +349,19 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -518,20 +531,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -539,7 +538,8 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -659,6 +659,37 @@
   },
   {
     "cmd": [
+      "osascript",
+      "-e",
+      "tell app \"Xcode\"",
+      "-e",
+      "launch",
+      "-e",
+      "count window",
+      "-e",
+      "end tell"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Trigger dialog (2)",
+    "timeout": 300,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Dismiss dialog (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
       "killall",
       "-9",
       "Xcode"
@@ -675,6 +706,29 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],
diff --git a/recipe_modules/os_utils/examples/full.expected/reset_dialog_xcode_automation_finds_db.json b/recipe_modules/os_utils/examples/full.expected/reset_dialog_xcode_automation_finds_db.json
index 6535857..b4ad30b 100644
--- a/recipe_modules/os_utils/examples/full.expected/reset_dialog_xcode_automation_finds_db.json
+++ b/recipe_modules/os_utils/examples/full.expected/reset_dialog_xcode_automation_finds_db.json
@@ -315,6 +315,19 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -484,20 +497,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "infra_step": true,
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -505,7 +504,8 @@
     "infra_step": true,
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -625,6 +625,37 @@
   },
   {
     "cmd": [
+      "osascript",
+      "-e",
+      "tell app \"Xcode\"",
+      "-e",
+      "launch",
+      "-e",
+      "count window",
+      "-e",
+      "end tell"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Trigger dialog (2)",
+    "timeout": 300,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "infra_step": true,
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Dismiss dialog (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
       "killall",
       "-9",
       "Xcode"
@@ -641,6 +672,29 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],
@@ -677,7 +731,7 @@
       "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
       "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
     ],
-    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "name": "Reset Xcode automation dialogs.Query TCC db (2)",
     "~followup_annotations": [
       "@@@STEP_NEST_LEVEL@1@@@",
       "@@@STEP_LOG_END@raw_io.output_text@@@"
diff --git a/recipes/devicelab/devicelab_drone.expected/xcode-devicelab-timeout.json b/recipes/devicelab/devicelab_drone.expected/xcode-devicelab-timeout.json
index fd01b8b..10501e0 100644
--- a/recipes/devicelab/devicelab_drone.expected/xcode-devicelab-timeout.json
+++ b/recipes/devicelab/devicelab_drone.expected/xcode-devicelab-timeout.json
@@ -629,6 +629,53 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -1128,54 +1175,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
-    "env": {
-      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
-      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
-      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
-      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
-      "GIT_BRANCH": "master",
-      "LUCI_BRANCH": "",
-      "LUCI_CI": "True",
-      "LUCI_PR": "",
-      "OS": "darwin",
-      "PUB_CACHE": "[START_DIR]/.pub-cache",
-      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
-      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
-      "USE_EMULATOR": "False"
-    },
-    "env_prefixes": {
-      "PATH": [
-        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
-        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
-      ]
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "project:ci"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -1217,7 +1216,8 @@
     },
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -1610,6 +1610,105 @@
   },
   {
     "cmd": [
+      "osascript",
+      "-e",
+      "tell app \"Xcode\"",
+      "-e",
+      "launch",
+      "-e",
+      "count window",
+      "-e",
+      "end tell"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Trigger dialog (2)",
+    "timeout": 300,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Dismiss dialog (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
       "killall",
       "-9",
       "Xcode"
@@ -2794,6 +2893,97 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],
diff --git a/recipes/devicelab/devicelab_drone.expected/xcode-devicelab.json b/recipes/devicelab/devicelab_drone.expected/xcode-devicelab.json
index 0555933..0451b8c 100644
--- a/recipes/devicelab/devicelab_drone.expected/xcode-devicelab.json
+++ b/recipes/devicelab/devicelab_drone.expected/xcode-devicelab.json
@@ -629,6 +629,53 @@
     "name": "Dismiss dialogs"
   },
   {
+    "cmd": [
+      "xcrun",
+      "devicectl",
+      "list",
+      "devices",
+      "-v"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.List CoreDevices",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
     "cmd": [],
     "name": "Dismiss dialogs.Dismiss iOS dialogs",
     "~followup_annotations": [
@@ -1128,54 +1175,6 @@
       "devicectl",
       "list",
       "devices",
-      "-v"
-    ],
-    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
-    "env": {
-      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
-      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
-      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
-      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
-      "GIT_BRANCH": "master",
-      "LUCI_BRANCH": "",
-      "LUCI_CI": "True",
-      "LUCI_PR": "",
-      "OS": "darwin",
-      "PUB_CACHE": "[START_DIR]/.pub-cache",
-      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
-      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
-      "USE_EMULATOR": "False"
-    },
-    "env_prefixes": {
-      "PATH": [
-        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
-        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
-      ]
-    },
-    "infra_step": true,
-    "luci_context": {
-      "realm": {
-        "name": "project:ci"
-      },
-      "resultdb": {
-        "current_invocation": {
-          "name": "invocations/build:8945511751514863184",
-          "update_token": "token"
-        },
-        "hostname": "rdbhost"
-      }
-    },
-    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.List CoreDevices",
-    "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
-    ]
-  },
-  {
-    "cmd": [
-      "xcrun",
-      "devicectl",
-      "list",
-      "devices",
       "--filter",
       "connectionProperties.transportType CONTAINS 'wired'",
       "-v"
@@ -1217,7 +1216,8 @@
     },
     "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Find wired CoreDevices",
     "~followup_annotations": [
-      "@@@STEP_NEST_LEVEL@2@@@"
+      "@@@STEP_NEST_LEVEL@2@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
     ]
   },
   {
@@ -1610,6 +1610,105 @@
   },
   {
     "cmd": [
+      "osascript",
+      "-e",
+      "tell app \"Xcode\"",
+      "-e",
+      "launch",
+      "-e",
+      "count window",
+      "-e",
+      "end tell"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Trigger dialog (2)",
+    "timeout": 300,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "infra_step": true,
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Dismiss dialogs.Dismiss Xcode automation dialogs.Dismiss dialog (2)",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@2@@@"
+    ]
+  },
+  {
+    "cmd": [
       "killall",
       "-9",
       "Xcode"
@@ -2796,6 +2895,97 @@
   },
   {
     "cmd": [
+      "killall",
+      "-9",
+      "UserNotificationCenter"
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Reset Xcode automation dialogs.Dismiss dialog",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "sqlite3",
+      "Users/fakeuser/Library/Application Support/com.apple.TCC/TCC.db",
+      "SELECT service, client, client_type, auth_value, auth_reason, indirect_object_identifier_type, indirect_object_identifier, flags, last_modified FROM access WHERE service = \"kTCCServiceAppleEvents\""
+    ],
+    "cwd": "[CLEANUP]/tmp_tmp_1/flutter sdk/dev/devicelab",
+    "env": {
+      "ARTIFACT_HUB_REPOSITORY": "artifactregistry://us-maven.pkg.dev/artifact-foundry-prod/maven-3p",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "FLUTTER_LOGS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "FLUTTER_TEST_OUTPUTS_DIR": "[CLEANUP]/flutter_logs_dir",
+      "GIT_BRANCH": "master",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "OS": "darwin",
+      "PUB_CACHE": "[START_DIR]/.pub-cache",
+      "REVISION": "12345abcde12345abcde12345abcde12345abcde",
+      "SDK_CHECKOUT_PATH": "[CLEANUP]/tmp_tmp_1/flutter sdk",
+      "USE_EMULATOR": "False"
+    },
+    "env_prefixes": {
+      "PATH": [
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin",
+        "[CLEANUP]/tmp_tmp_1/flutter sdk/bin/cache/dart-sdk/bin"
+      ]
+    },
+    "luci_context": {
+      "realm": {
+        "name": "project:ci"
+      },
+      "resultdb": {
+        "current_invocation": {
+          "name": "invocations/build:8945511751514863184",
+          "update_token": "token"
+        },
+        "hostname": "rdbhost"
+      }
+    },
+    "name": "Reset Xcode automation dialogs.Query TCC db",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_END@raw_io.output_text@@@"
+    ]
+  },
+  {
+    "cmd": [
       "ls",
       "Users/fakeuser/Library/Application Support/com.apple.TCC"
     ],