minadbd sends heartbeat to rescue service for getprop command.

We start minadbd and rescue services in two processes. In particular,
minadbd handles the requests from host, then communicates with rescue
service to do install/wipe works. When resuce service doesn't see any
request in a pre-defined timeout (currently 300s), rescue service will
exit to avoid endless waiting.

This CL changes minadbd to additionally send a no-op command to rescue
service as a heartbeat signal, so that host side can finish
time-consuming operations (e.g. downloading over network) while keeping
rescue service alive.

Bug: 136457446
Test: Enter resuce mode on blueline. Send `adb rescue getprop
      ro.build.fingerprint` and check that rescue service doesn't exit.
Test: Stop sending the getprop command. Check that rescue service exits
      after 300s.
Change-Id: Ib9d5ed710cfa94ecfe6cf393a71a0b67b2539531
Merged-In: Ib9d5ed710cfa94ecfe6cf393a71a0b67b2539531
(cherry picked from commit 2223e6a9f8bf24b023e8ae3103b50c37def3147e)
(cherry picked from commit 0bbb2ed53eb4dc4ae8d447062482f9eda5ef9a91)
diff --git a/install/adb_install.cpp b/install/adb_install.cpp
index 4dd1f1b..9497df5 100644
--- a/install/adb_install.cpp
+++ b/install/adb_install.cpp
@@ -363,11 +363,13 @@
         "\n\nNow send the package you want to apply\n"
         "to the device with \"adb sideload <filename>\"...\n");
   } else {
-    ui->Print("\n\nWaiting for rescue commands...\n");
     command_map.emplace(MinadbdCommand::kWipeData, [&device]() {
       bool result = WipeData(device, false);
       return std::make_pair(result, true);
     });
+    command_map.emplace(MinadbdCommand::kNoOp, []() { return std::make_pair(true, true); });
+
+    ui->Print("\n\nWaiting for rescue commands...\n");
   }
 
   CreateMinadbdServiceAndExecuteCommands(ui, command_map, rescue_mode);
diff --git a/minadbd/minadbd_services.cpp b/minadbd/minadbd_services.cpp
index 1c4c0f4..6c10274 100644
--- a/minadbd/minadbd_services.cpp
+++ b/minadbd/minadbd_services.cpp
@@ -173,6 +173,14 @@
   if (!android::base::WriteFully(sfd, result.data(), result.size())) {
     exit(kMinadbdHostSocketIOError);
   }
+
+  // Send heartbeat signal to keep the rescue service alive.
+  if (!WriteCommandToFd(MinadbdCommand::kNoOp, minadbd_socket)) {
+    exit(kMinadbdSocketIOError);
+  }
+  if (MinadbdCommandStatus status; !WaitForCommandStatus(minadbd_socket, &status)) {
+    exit(kMinadbdMessageFormatError);
+  }
 }
 
 // Reboots into the given target. We don't reboot directly from minadbd, but going through recovery
diff --git a/minadbd/minadbd_types.h b/minadbd/minadbd_types.h
index 99fd45e..002523f 100644
--- a/minadbd/minadbd_types.h
+++ b/minadbd/minadbd_types.h
@@ -53,6 +53,7 @@
   kRebootRescue = 6,
   kWipeCache = 7,
   kWipeData = 8,
+  kNoOp = 9,
 
   // Last but invalid command.
   kError,