Merge "Include the error code if GetPipeProperties fails."
diff --git a/adb/device.py b/adb/device.py
index b6eaad6..a15675b 100644
--- a/adb/device.py
+++ b/adb/device.py
@@ -170,8 +170,12 @@
         out, _ = p.communicate()
         return self._parse_shell_output(out)
 
-    def install(self, filename):
-        return self._simple_call(['install', filename])
+    def install(self, filename, replace=False):
+        cmd = ['install']
+        if replace:
+            cmd.append('-r')
+        cmd.append(filename)
+        return self._simple_call(cmd)
 
     def push(self, local, remote):
         return self._simple_call(['push', local, remote])
diff --git a/include/utils/Errors.h b/include/utils/Errors.h
index 46173db..9402614 100644
--- a/include/utils/Errors.h
+++ b/include/utils/Errors.h
@@ -58,7 +58,6 @@
     ALREADY_EXISTS      = -EEXIST,
     DEAD_OBJECT         = -EPIPE,
     FAILED_TRANSACTION  = (UNKNOWN_ERROR + 2),
-    JPARKS_BROKE_IT     = -EPIPE,
 #if !defined(HAVE_MS_C_RUNTIME)
     BAD_INDEX           = -EOVERFLOW,
     NOT_ENOUGH_DATA     = -ENODATA,
diff --git a/init/perfboot.py b/init/perfboot.py
index 82f7e67..b0efb11 100755
--- a/init/perfboot.py
+++ b/init/perfboot.py
@@ -40,6 +40,7 @@
 import argparse
 import atexit
 import cStringIO
+import glob
 import inspect
 import logging
 import math
@@ -66,6 +67,8 @@
     'boot_progress_pms_ready',
     'boot_progress_ams_ready',
     'boot_progress_enable_screen',
+    'sf_stop_bootanim',
+    'wm_boot_animation_done',
 ]
 
 
@@ -139,6 +142,7 @@
         def notify_timeout():
             self._timedout = True
         self._timer = threading.Timer(timeout, notify_timeout)
+        self._timer.daemon = True
         self._timer.start()
 
     def is_timedout(self):
@@ -200,7 +204,7 @@
                 output_results(output, record_list, tags)
             if original_dropbox_max_files is not None:
                 restore_dropbox(device, original_dropbox_max_files)
-        except subprocess.CalledProcessError, RuntimeError:
+        except (subprocess.CalledProcessError, RuntimeError):
             pass
     atexit.register(cleanup)
 
@@ -405,9 +409,17 @@
                         'event tags are read. Every line contains one event '
                         'tag and the last event tag is used to detect that '
                         'the device has finished booting.')
+    parser.add_argument('--apk-dir', help='Specify the directory which contains '
+                        'APK files to be installed before measuring boot time.')
     return parser.parse_args()
 
 
+def install_apks(device, apk_dir):
+    for apk in glob.glob(os.path.join(apk_dir, '*.apk')):
+        print 'Installing: ' + apk
+        device.install(apk, replace=True)
+
+
 def main():
     args = parse_args()
     if args.verbose:
@@ -422,6 +434,9 @@
             device.get_prop('ro.build.version.incremental'))
     check_dm_verity_settings(device)
 
+    if args.apk_dir:
+        install_apks(device, args.apk_dir)
+
     record_list = []
     event_tags = filter_event_tags(read_event_tags(args.tags), device)
     init_perf(device, args.output, record_list, event_tags)
diff --git a/rootdir/Android.mk b/rootdir/Android.mk
index d6dad2d..30a2851 100644
--- a/rootdir/Android.mk
+++ b/rootdir/Android.mk
@@ -24,9 +24,18 @@
 # Put it here instead of in init.rc module definition,
 # because init.rc is conditionally included.
 #
-# create some directories (some are mount points)
-LOCAL_POST_INSTALL_CMD := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
-    sbin dev proc sys system data oem acct cache config storage mnt root)
+# create some directories (some are mount points) and symlinks
+local_post_install_cmd_base := mkdir -p $(addprefix $(TARGET_ROOT_OUT)/, \
+    sbin dev proc sys system data oem acct cache config storage mnt root); \
+    ln -sf /system/etc $(TARGET_ROOT_OUT)/etc; \
+    ln -sf /sys/kernel/debug $(TARGET_ROOT_OUT)/d; \
+    ln -sf /storage/self/primary $(TARGET_ROOT_OUT)/sdcard
+ifdef BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE
+  LOCAL_POST_INSTALL_CMD := $(local_post_install_cmd_base); mkdir -p $(TARGET_ROOT_OUT)/vendor
+else
+  LOCAL_POST_INSTALL_CMD := $(local_post_install_cmd_base)
+endif
+local_post_install_cmd_base :=
 
 include $(BUILD_SYSTEM)/base_rules.mk