Merge cherrypicks of [15800877, 15799943, 15800878, 15799944, 15800879, 15800987, 15800365, 15799765] into security-aosp-pi-release

Change-Id: I09591f7a6b91afcb080294e5d68e914b01bab716
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index be3bbf7..af34c1d 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -148,7 +148,8 @@
 
         const bool isVendorService =
             strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0;
-        const long timeout = uptimeMillis() + 5000;
+        const long timeout = 5000;
+        int64_t startTime = uptimeMillis();
         if (!gSystemBootCompleted) {
             char bootCompleted[PROPERTY_VALUE_MAX];
             property_get("sys.boot_completed", bootCompleted, "0");
@@ -158,7 +159,7 @@
         const long sleepTime = gSystemBootCompleted ? 1000 : 100;
 
         int n = 0;
-        while (uptimeMillis() < timeout) {
+        while (uptimeMillis() - startTime < timeout) {
             n++;
             if (isVendorService) {
                 ALOGI("Waiting for vendor service %s...", String8(name).string());