More logging and better retry logic.

Bug: 183551663
Test: atest PackageManagerShellCommandTest PackageManagerShellCommandIncrementalTest IncrementalServiceTest PackageManagerServiceTest ChecksumsTest
Change-Id: I1b6da82cd4472cc5671b0b60fb12222b4ed08e17
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index 94f8e59..6695ba8 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -2523,7 +2523,8 @@
         now - mCurrentStatusTs <= Constants::bindingTimeout) {
         LOG(INFO) << "Binding still in progress. "
                   << (healthy ? "The DL is healthy/freshly bound, ok to retry for a few times."
-                              : "Already unhealthy, don't do anything.");
+                              : "Already unhealthy, don't do anything.")
+                  << " for storage " << mId;
         // Binding still in progress.
         if (!healthy) {
             // Already unhealthy, don't do anything.
@@ -2546,7 +2547,8 @@
     const auto previousBindTs = mPreviousBindTs;
     mPreviousBindTs = now;
 
-    const auto nonCrashingInterval = std::max(castToMs(now - previousBindTs), 100ms);
+    const auto nonCrashingInterval =
+            std::max(castToMs(now - previousBindTs - mPreviousBindDelay), 100ms);
     if (previousBindTs.time_since_epoch() == Clock::duration::zero() ||
         nonCrashingInterval > Constants::healthyDataLoaderUptime) {
         mPreviousBindDelay = 0ms;
@@ -2575,7 +2577,8 @@
     const auto bindDelay = *maybeBindDelay;
     if (bindDelay > 1s) {
         LOG(INFO) << "Delaying bind to " << mParams.packageName << " by "
-                  << bindDelay.count() / 1000 << "s";
+                  << bindDelay.count() / 1000 << "s"
+                  << " for storage " << mId;
     }
 
     bool result = false;