Merge changes I507b7827,Ie7eea383,I7e53e4fd

* changes:
  Delete config variables for vnc vsock internals
  Dynamically choose the VNC vsock ports in run_cvd
  Simplify vm_manager_helpers_ with function pointers
diff --git a/common/libs/utils/subprocess.cpp b/common/libs/utils/subprocess.cpp
index e83b487..aed28de 100644
--- a/common/libs/utils/subprocess.cpp
+++ b/common/libs/utils/subprocess.cpp
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <unistd.h>
@@ -69,7 +70,8 @@
     const char* const* command, const char* const* envp,
     const std::map<cvd::Subprocess::StdIOChannel, int>& redirects,
     const std::map<cvd::SharedFD, int>& inherited_fds, bool with_control_socket,
-    cvd::SubprocessStopper stopper, bool in_group = false, bool verbose = false) {
+    cvd::SubprocessStopper stopper, bool in_group = false, bool verbose = false,
+    bool exit_with_parent = true) {
   // The parent socket will get closed on the child on the call to exec, the
   // child socket will be closed on the parent when this function returns and no
   // references to the fd are left
@@ -91,6 +93,10 @@
 
   pid_t pid = fork();
   if (!pid) {
+    if (exit_with_parent) {
+      prctl(PR_SET_PDEATHSIG, SIGHUP); // Die when parent dies
+    }
+
     do_redirects(redirects);
     if (in_group) {
       // This call should never fail (see SETPGID(2))
@@ -293,26 +299,34 @@
   verbose_ = verbose;
 }
 
-Subprocess Command::StartHelper(bool with_control_socket, bool in_group) const {
+void Command::SetExitWithParent(bool exit_with_parent) {
+  exit_with_parent_ = exit_with_parent;
+}
+
+void Command::SetWithControlSocket(bool with_control_socket) {
+  with_control_socket_ = with_control_socket;
+}
+
+Subprocess Command::StartHelper(bool in_group) const {
   auto cmd = ToCharPointers(command_);
   if (use_parent_env_) {
     return subprocess_impl(cmd.data(), nullptr, redirects_, inherited_fds_,
-                           with_control_socket, subprocess_stopper_, in_group,
-                           verbose_);
+                           with_control_socket_, subprocess_stopper_, in_group,
+                           verbose_, exit_with_parent_);
   } else {
     auto envp = ToCharPointers(env_);
     return subprocess_impl(cmd.data(), envp.data(), redirects_, inherited_fds_,
-                           with_control_socket, subprocess_stopper_, in_group,
-                           verbose_);
+                           with_control_socket_, subprocess_stopper_, in_group,
+                           verbose_, exit_with_parent_);
   }
 }
 
-Subprocess Command::Start(bool with_control_socket) const {
-  return StartHelper(with_control_socket, false);
+Subprocess Command::Start() const {
+  return StartHelper(false);
 }
 
-Subprocess Command::StartInGroup(bool with_control_socket) const {
-  return StartHelper(with_control_socket, true);
+Subprocess Command::StartInGroup() const {
+  return StartHelper(true);
 }
 
 // A class that waits for threads to exit in its destructor.
diff --git a/common/libs/utils/subprocess.h b/common/libs/utils/subprocess.h
index 44976f9..67e5ae2 100644
--- a/common/libs/utils/subprocess.h
+++ b/common/libs/utils/subprocess.h
@@ -118,8 +118,10 @@
   // optional subprocess stopper. When not provided, stopper defaults to sending
   // SIGKILL to the subprocess.
   Command(const std::string& executable,
-          SubprocessStopper stopper = KillSubprocess)
-      : subprocess_stopper_(stopper), verbose_(true) {
+          SubprocessStopper stopper = KillSubprocess,
+          bool exit_with_parent = true)
+      : subprocess_stopper_(stopper), verbose_(true),
+        exit_with_parent_(exit_with_parent), with_control_socket_(false) {
     command_.push_back(executable);
   }
   Command(Command&&) = default;
@@ -159,15 +161,16 @@
                      Subprocess::StdIOChannel parent_channel);
 
   void SetVerbose(bool verbose);
+  void SetExitWithParent(bool exit_with_parent);
+  // If with_control_socket is true the returned Subprocess instance will have a
+  // sharedFD that enables communication with the child process.
+  void SetWithControlSocket(bool with_control_socket);
 
   // Starts execution of the command. This method can be called multiple times,
-  // effectively staring multiple (possibly concurrent) instances. If
-  // with_control_socket is true the returned Subprocess instance will have a
-  // sharedFD that enables communication with the child process.
-  Subprocess Start(bool with_control_socket = false) const;
-  // Same as Start(bool), but the subprocess runs as head of its own process
-  // group.
-  Subprocess StartInGroup(bool with_control_socket = false) const;
+  // effectively staring multiple (possibly concurrent) instances.
+  Subprocess Start() const;
+  // Same as Start(), but the subprocess runs as head of its own process group.
+  Subprocess StartInGroup() const;
 
   std::string GetShortName() const {
     // This is safe because the constructor guarantees the name of the binary to
@@ -176,7 +179,7 @@
   }
 
  private:
-  Subprocess StartHelper(bool with_control_socket, bool in_group) const;
+  Subprocess StartHelper(bool in_group) const;
 
   std::vector<std::string> command_;
   std::map<cvd::SharedFD, int> inherited_fds_{};
@@ -185,6 +188,8 @@
   std::vector<std::string> env_{};
   SubprocessStopper subprocess_stopper_;
   bool verbose_;
+  bool exit_with_parent_;
+  bool with_control_socket_;
 };
 
 /*
diff --git a/guest/hals/audio/audio_hw.c b/guest/hals/audio/audio_hw.c
index f0979a9..40396d7 100644
--- a/guest/hals/audio/audio_hw.c
+++ b/guest/hals/audio/audio_hw.c
@@ -377,7 +377,7 @@
     }
 
     if (get) {
-        str = strdup(str_parms_to_str(reply));
+        str = str_parms_to_str(reply);
     }
     else {
         ALOGD("%s Unsupported paramter: %s", __FUNCTION__, keys);
@@ -906,7 +906,7 @@
     }
 
     if (get) {
-        str = strdup(str_parms_to_str(reply));
+        str = str_parms_to_str(reply);
     }
     else {
         ALOGD("%s Unsupported paramter: %s", __FUNCTION__, keys);
diff --git a/guest/hals/ril/cuttlefish_ril.cpp b/guest/hals/ril/cuttlefish_ril.cpp
index 47cb5c5..e5a120f 100644
--- a/guest/hals/ril/cuttlefish_ril.cpp
+++ b/guest/hals/ril/cuttlefish_ril.cpp
@@ -1241,13 +1241,6 @@
   gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, &areUiccApplicationsEnabled, sizeof(bool));
 }
 
-static void request_can_toggle_uicc_applications_enablement(int /*request*/, void* /*data*/,
-                                                             size_t /*datalen*/, RIL_Token t) {
-  ALOGV("Getting can toggle uicc applications enablement.");
-
-  gce_ril_env->OnRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
-}
-
 static void request_cdma_set_subscription_source(int /*request*/, void* data,
                                                  size_t /*datalen*/,
                                                  RIL_Token t) {
@@ -2589,9 +2582,6 @@
     case RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED:
       request_are_uicc_applications_enabled(request, data, datalen, t);
       break;
-    case RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT:
-      request_can_toggle_uicc_applications_enablement(request, data, datalen, t);
-      break;
     case RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5:
       request_set_system_selection_channels_1_5(request, t);
       break;
diff --git a/guest/hals/ril/libril/ril.h b/guest/hals/ril/libril/ril.h
index 80394ea..fd8553c 100644
--- a/guest/hals/ril/libril/ril.h
+++ b/guest/hals/ril/libril/ril.h
@@ -96,7 +96,6 @@
  *                    RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS
  *                    RIL_REQUEST_ENABLE_UICC_APPLICATIONS
  *                    RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED
- *                    RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT
  */
 #define RIL_VERSION 12
 #define LAST_IMPRECISE_RIL_VERSION 12 // Better self-documented name
@@ -6671,20 +6670,6 @@
 #define RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED 157
 
 /**
- * RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT
- *
- * Whether disabling / enabling uicc applications is supported
- *
- * Response: a boolean of whether it's supported.
- *
- * Valid errors:
- *  SUCCESS
- *  RADIO_NOT_AVAILABLE
- *  INTERNAL_ERR
- */
-#define RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT 158
-
-/**
  * Specify which bands modem's background scan must act on.
  * If specifyChannels is true, it only scans bands specified in specifiers.
  * If specifyChannels is false, it scans all bands.
@@ -6699,7 +6684,7 @@
  *  INVALID_ARGUMENTS
  *
  */
-#define RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5 159
+#define RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5 158
 
 /**
  * RIL_REQUEST_START_NETWORK_SCAN5
@@ -6721,7 +6706,7 @@
  *  INVALID_ARGUMENTS
  *
  */
-#define RIL_REQUEST_START_NETWORK_SCAN_1_5 160
+#define RIL_REQUEST_START_NETWORK_SCAN_1_5 159
 
 /***********************************************************************/
 
diff --git a/guest/hals/ril/libril/ril_commands.h b/guest/hals/ril/libril/ril_commands.h
index 17cb594..aa5df50 100644
--- a/guest/hals/ril/libril/ril_commands.h
+++ b/guest/hals/ril/libril/ril_commands.h
@@ -172,6 +172,5 @@
     {RIL_REQUEST_SET_SIGNAL_STRENGTH_REPORTING_CRITERIA_1_5, radio_1_5::setSignalStrengthReportingCriteriaResponse_1_5},
     {RIL_REQUEST_ENABLE_UICC_APPLICATIONS, radio_1_5::enableUiccApplicationsResponse},
     {RIL_REQUEST_ARE_UICC_APPLICATIONS_ENABLED, radio_1_5::areUiccApplicationsEnabledResponse},
-    {RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT, radio_1_5::canToggleUiccApplicationsEnablementResponse},
     {RIL_REQUEST_SET_SYSTEM_SELECTION_CHANNELS_1_5, radio_1_5::setSystemSelectionChannelsResponse_1_5},
     {RIL_REQUEST_START_NETWORK_SCAN_1_5, radio_1_5::startNetworkScanResponse_1_5},
diff --git a/guest/hals/ril/libril/ril_service.cpp b/guest/hals/ril/libril/ril_service.cpp
index b7b02a6..ae46c3f 100755
--- a/guest/hals/ril/libril/ril_service.cpp
+++ b/guest/hals/ril/libril/ril_service.cpp
@@ -537,7 +537,6 @@
             const ::android::hardware::radio::V1_5::AccessNetwork accessNetwork);
     Return<void> enableUiccApplications(int32_t serial, bool detach);
     Return<void> areUiccApplicationsEnabled(int32_t serial);
-    Return<void> canToggleUiccApplicationsEnablement(int32_t serial);
     Return<void> setSystemSelectionChannels_1_5(int32_t serial, bool specifyChannels,
             const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& specifiers);
     Return<void> startNetworkScan_1_5(int32_t serial,
@@ -3607,14 +3606,6 @@
     return Void();
 }
 
-Return<void> RadioImpl_1_5::canToggleUiccApplicationsEnablement(int32_t serial) {
-#if VDBG
-    RLOGD("canToggleUiccApplicationsEnablement: serial %d.", serial);
-#endif
-    dispatchVoid(serial, mSlotId, RIL_REQUEST_CAN_TOGGLE_UICC_APPLICATIONS_ENABLEMENT);
-    return Void();
-}
-
 Return<void> RadioImpl_1_5::setSystemSelectionChannels_1_5(int32_t serial, bool /* specifyChannels */,
         const hidl_vec<::android::hardware::radio::V1_5::RadioAccessSpecifier>& /* specifiers */) {
 #if VDBG
@@ -7902,28 +7893,6 @@
     return 0;
 }
 
-int radio_1_5::canToggleUiccApplicationsEnablementResponse(int slotId, int responseType,
-                                                       int serial, RIL_Errno e,
-                                                       void *response, size_t responseLen) {
-#if VDBG
-    RLOGD("%s(): %d", __FUNCTION__, serial);
-#endif
-    RadioResponseInfo responseInfo = {};
-    populateResponseInfo(responseInfo, serial, responseType, e);
-
-    // If we don't have a radio service, there's nothing we can do
-    if (radioService[slotId]->mRadioResponseV1_5 == NULL) {
-        RLOGE("%s: radioService[%d]->mRadioResponseV1_5 == NULL", __FUNCTION__, slotId);
-        return 0;
-    }
-
-    Return<void> retStatus =
-            radioService[slotId]->mRadioResponseV1_5->canToggleUiccApplicationsEnablementResponse(
-            responseInfo, true);
-    radioService[slotId]->checkReturnStatus(retStatus);
-    return 0;
-}
-
 int radio_1_5::setSystemSelectionChannelsResponse_1_5(int slotId, int responseType, int serial,
                                         RIL_Errno e, void* /* response */, size_t responseLen) {
 #if VDBG
diff --git a/guest/hals/ril/libril/ril_service.h b/guest/hals/ril/libril/ril_service.h
index 814768c..8c3fd71 100644
--- a/guest/hals/ril/libril/ril_service.h
+++ b/guest/hals/ril/libril/ril_service.h
@@ -798,10 +798,6 @@
                                      int responseType, int serial, RIL_Errno e,
                                      void *response, size_t responselen);
 
-int canToggleUiccApplicationsEnablementResponse(int slotId,
-                                            int responseType, int serial, RIL_Errno e,
-                                            void *response, size_t responselen);
-
 pthread_rwlock_t * getRadioServiceRwlock(int slotId);
 
 void setNitzTimeReceived(int slotId, long timeReceived);
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 627199d..21781bf 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -508,7 +508,7 @@
     return false;
   }
   decomp_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut, output_file);
-  auto decomp_proc = decomp_cmd.Start(false);
+  auto decomp_proc = decomp_cmd.Start();
   return decomp_proc.Started() && decomp_proc.Wait() == 0;
 }
 
diff --git a/host/commands/run_cvd/process_monitor.cc b/host/commands/run_cvd/process_monitor.cc
index 8243306..f497ddb 100644
--- a/host/commands/run_cvd/process_monitor.cc
+++ b/host/commands/run_cvd/process_monitor.cc
@@ -68,7 +68,8 @@
 }
 
 void ProcessMonitor::StartSubprocess(Command cmd, OnSocketReadyCb callback) {
-  auto proc = cmd.StartInGroup(true);
+  cmd.SetWithControlSocket(true);
+  auto proc = cmd.StartInGroup();
   if (!proc.Started()) {
     LOG(ERROR) << "Failed to start process";
     return;
@@ -151,7 +152,7 @@
     LOG(INFO) << "subprocess " << entry->cmd->GetShortName() << " (" << wait_ret
               << ") has exited for unknown reasons";
   }
-  entry->proc.reset(new Subprocess(entry->cmd->Start(true)));
+  entry->proc.reset(new Subprocess(entry->cmd->Start()));
   return true;
 }