Only log excessive timeouts if those appear accidental

Do not generate a log message even when timeout would cause us to wake
up past the end of Linux time, if the timeout specification looks like
it was meant to wait forever.  Avoids log spam.

Bug: 27723547
Change-Id: I98d0fc1b1813a10ad906282957675b85bd933472
diff --git a/runtime/base/time_utils.cc b/runtime/base/time_utils.cc
index b7cf207..3e5bac8 100644
--- a/runtime/base/time_utils.cc
+++ b/runtime/base/time_utils.cc
@@ -15,6 +15,7 @@
  */
 
 #include <inttypes.h>
+#include <limits>
 #include <sstream>
 
 #include "time_utils.h"
@@ -190,9 +191,16 @@
   }
 
   int64_t end_sec = ts->tv_sec + ms / 1000;
-  if (UNLIKELY(end_sec >= 0x7fffffff)) {
-    LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
-    end_sec = 0x7ffffffe;
+  constexpr int32_t int32_max = std::numeric_limits<int32_t>::max();
+  if (UNLIKELY(end_sec >= int32_max)) {
+    // Either ms was intended to denote an infinite timeout, or we have a
+    // problem. The former generally uses the largest possible millisecond
+    // or nanosecond value.  Log only in the latter case.
+    constexpr int64_t int64_max = std::numeric_limits<int64_t>::max();
+    if (ms != int64_max && ms != int64_max / (1000 * 1000)) {
+      LOG(INFO) << "Note: end time exceeds INT32_MAX: " << end_sec;
+    }
+    end_sec = int32_max - 1;  // Allow for increment below.
   }
   ts->tv_sec = end_sec;
   ts->tv_nsec = (ts->tv_nsec + (ms % 1000) * 1000000) + ns;