Merge "win32: adb_test/libbase_test fixes"
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/adb/usb_osx.cpp b/adb/usb_osx.cpp
index af65130..939f319 100644
--- a/adb/usb_osx.cpp
+++ b/adb/usb_osx.cpp
@@ -34,6 +34,10 @@
 
 #define  DBG   D
 
+// There's no strerror equivalent for the errors returned by IOKit.
+// https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_Handling_Errors/AH_Handling_Errors.html
+// Search the web for "IOReturn.h" to find a complete up to date list.
+
 static IONotificationPortRef    notificationPort = 0;
 static io_iterator_t            notificationIterator;
 
@@ -362,7 +366,7 @@
 
             handle->zero_mask = maxPacketSize - 1;
         } else {
-            DBG("ERR: FindDeviceInterface - could not get pipe properties\n");
+            DBG("ERR: FindDeviceInterface - could not get pipe properties (%08x)\n", kr);
             goto err_get_pipe_props;
         }
     }
diff --git a/fastboot/usb_osx.cpp b/fastboot/usb_osx.cpp
index a959566..1c7eff0 100644
--- a/fastboot/usb_osx.cpp
+++ b/fastboot/usb_osx.cpp
@@ -210,7 +210,7 @@
                     handle->zero_mask = maxPacketSize - 1;
                 }
             } else {
-                ERR("could not get pipe properties\n");
+                ERR("could not get pipe properties (%08x)\n", kr);
             }
 
             if (handle->info.has_bulk_in && handle->info.has_bulk_out) {
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)