Merge "Using focused windows from dumpsys to verify assistant started. Test: manual - run each test case for verification. Bug: 248342160"
diff --git a/resources/device_config.common.ascii_proto b/resources/device_config.common.ascii_proto
index 305acae..54d9835 100644
--- a/resources/device_config.common.ascii_proto
+++ b/resources/device_config.common.ascii_proto
@@ -35,6 +35,7 @@
   source: "LOGCAT"
   name: "vis_software_hotword"
   regex: "GsaVoiceInteractionSrv: onHotwordDetected"
+  regex: "SodaTriggeringFrontend: #onHotwordDetected"
 }
 
 event {
@@ -60,6 +61,10 @@
   source: "LOGCAT"
   name: "assistant_started"
   regex: "START.*com\.google\.android\.googlequicksearchbox.*opa\.OpaActivity.*|NGA starts FULL_LISTENING*"
+  regex: ".*mCurrentFocus=Window{.*VoiceInteractionSession}"
+  regex: ".*mCurrentFocus=Window{.*com\.google\.android\.googlequicksearchbox\/com\.google\.android\.apps\.search\.assistant\.surfaces\.voice\.ui\.host\.activity\.transientactivity\.FragmentHostTransientActivity}"
+  regex: ".*mCurrentFocus=Window{.*com\.google\.android\.googlequicksearchbox\/com\.google\.android\.apps\.search\.assistant\.surfaces\.voice\.ui\.host\.activity\.fullscreenactivity\.FragmentHostFullScreenActivity}"
+  regex: ".*mCurrentFocus=Window{.*com\.google\.android\.googlequicksearchbox\/com\.google\.android\.apps\.search\.assistant\.surfaces\.voice\.ui\.host\.activity\.defaultactivity\.FragmentHostDefaultActivity}"
 }
 
 event {
diff --git a/resources/stress_test.dsp_monitoring_on_idle.ascii_proto b/resources/stress_test.dsp_monitoring_on_idle.ascii_proto
index a1d490f..8ca2f04 100644
--- a/resources/stress_test.dsp_monitoring_on_idle.ascii_proto
+++ b/resources/stress_test.dsp_monitoring_on_idle.ascii_proto
@@ -6,6 +6,10 @@
   delay_after: 1
 }
 step {
+  command: "shell 'dumpsys window | grep mCurrentFocus'"
+  delay_after: 3
+}
+step {
   command: "shell dumpsys deviceidle force-idle"
   delay_after: 59
 }
diff --git a/resources/stress_test.dsp_trigger_and_screen_off.ascii_proto b/resources/stress_test.dsp_trigger_and_screen_off.ascii_proto
index 567446b..ae99fe9 100644
--- a/resources/stress_test.dsp_trigger_and_screen_off.ascii_proto
+++ b/resources/stress_test.dsp_trigger_and_screen_off.ascii_proto
@@ -8,6 +8,10 @@
   delay_after : 3
 }
 step {
+  command: "shell 'dumpsys window | grep mCurrentFocus'"
+  delay_after: 3
+}
+step {
   command: "shell input keyevent 3"
   delay_after: 1
 }
diff --git a/resources/stress_test.dsp_trigger_on_homescreen.ascii_proto b/resources/stress_test.dsp_trigger_on_homescreen.ascii_proto
index b796215..bb529ef 100644
--- a/resources/stress_test.dsp_trigger_on_homescreen.ascii_proto
+++ b/resources/stress_test.dsp_trigger_on_homescreen.ascii_proto
@@ -6,7 +6,10 @@
   audio_file_sample_rate : 24000
   delay_after : 3
 }
-
+step {
+  command: "shell 'dumpsys window | grep mCurrentFocus'"
+  delay_after: 3
+}
 step {
   command: "shell input keyevent 3"
   delay_after : 3
diff --git a/resources/stress_test.dsp_trigger_sw_rejection.ascii_proto b/resources/stress_test.dsp_trigger_sw_rejection.ascii_proto
index 81d2e5f..71a4559 100644
--- a/resources/stress_test.dsp_trigger_sw_rejection.ascii_proto
+++ b/resources/stress_test.dsp_trigger_sw_rejection.ascii_proto
@@ -6,6 +6,10 @@
   delay_after : 3
 }
 step {
+  command: "shell 'dumpsys window | grep mCurrentFocus'"
+  delay_after: 3
+}
+step {
   command: "shell input keyevent 3"
   delay_after: 1
 }
@@ -27,6 +31,10 @@
   delay_after : 3
 }
 step {
+  command: "shell 'dumpsys window | grep mCurrentFocus'"
+  delay_after: 3
+}
+step {
   command: "shell input keyevent 3"
   delay_after: 1
 }
@@ -52,7 +60,10 @@
 }
 
 event {
-  name: "sync_word_not_present"
-  condition: "sync_word_not_present == 1 and iterations_since_sync_word_not_present == 0"
+  name: "device_crashed"
+  condition: "iterations_since_aohd_hotword_detected >= 30 "
+             "or iterations_since_assistant_started >= 30"
+  action: "BUGREPORT"
   action: "NOTIFY"
+  action: "REMOVE_DEVICE"
 }
diff --git a/stress_test.py b/stress_test.py
index c77ae83..4f5cbe0 100644
--- a/stress_test.py
+++ b/stress_test.py
@@ -515,7 +515,7 @@
           if count > expected_count * number_of_iterations:
             logging.info(
                 "[STRESS_TEST] In iteration %d, got duplicated %s : %d",
-                self.iteration, self.name, count)
+                self.iteration, event, count)
             logging.info("[STRESS_TEST] Will count only : %d",
                          expected_count * number_of_iterations)
             count = expected_count * number_of_iterations
@@ -637,6 +637,9 @@
   def __AsyncCommand(self, command, log_output=False):
     result = self.Command(command).strip()
     if result and log_output:
+      # log both logcat and stress testing log
+      # some test will depend on adb command output (ex: dumpsys)
+      self.Command(['shell', 'log', '-t', 'STRESS_TEST', result])
       for line in result.splitlines():
         logging.info(line.decode("utf-8"))