LISA: Make System.set_property watch logcat for boot completion

The current method using System.wakeup is unreliable and can return
before the system reaches the lock screen. Watch for the "Boot is
finished" message in SurfaceFlinger instead

Test: Ran a workload that sets a property & confirmed that
set_property blocks until the system is ready
Signed-off-by: Connor O'Brien <connoro@google.com>

Change-Id: I10549c6fb0be3bb2aa74052b039b079db1ae4971
diff --git a/libs/utils/android/system.py b/libs/utils/android/system.py
index a461d0a..be7b0b3 100644
--- a/libs/utils/android/system.py
+++ b/libs/utils/android/system.py
@@ -20,6 +20,7 @@
 from devlib.utils.android import adb_command
 from devlib import TargetError
 import os
+import re
 import time
 import pexpect as pe
 
@@ -165,6 +166,9 @@
     def set_property(target, prop, value, restart=False):
         """
         Set a system property, then run adb shell stop && start if necessary
+
+        When restart=True, this function clears logcat to avoid detecting old
+        "Boot is finished" messages.
         """
         try:
             target.execute('setprop {} {}'.format(prop, value), as_root=True)
@@ -174,13 +178,14 @@
         if not restart:
             return
 
+        target.execute('logcat -c', check_exit_code=False)
+        BOOT_FINISHED_RE = re.compile(r'Boot is finished')
+        logcat = target.background('logcat SurfaceFlinger:* *:S')
         target.execute('stop && start', as_root=True)
         while True:
-            try:
-                System.wakeup(target)
-            except TargetError:
-                time.sleep(1)
-            else:
+            message = logcat.stdout.readline(1024)
+            match = BOOT_FINISHED_RE.search(message)
+            if match:
                 return
 
     @staticmethod