From 7fad45c3b11cb06b82c41abb8ce2df4cb7f648e9 Mon Sep 17 00:00:00 2001
From: Yuwei Huang <yuweih@chromium.org>
Date: Tue, 6 May 2025 15:31:29 -0700
Subject: [PATCH] [crd host][mac] Explicitly enable broker service before
 bootstrapping

It seems if the user has explicitly disabled the broker service with
`sudo launchctl disable system/org.chromium.chromoting.broker`, then the
bootstrap command will fail. Our code never tries to disable it, but
explicitly enabling it could make the installer more robust.

Bug: 411490453
Change-Id: Ie2bc8970b5d686c0d1bc541a844b75e5f678ef21
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6517192
Auto-Submit: Yuwei Huang <yuweih@chromium.org>
Reviewed-by: Joe Downing <joedow@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1456646}
---
 remoting/host/installer/mac/Scripts/remoting_postflight.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/remoting/host/installer/mac/Scripts/remoting_postflight.sh b/remoting/host/installer/mac/Scripts/remoting_postflight.sh
index 202a2d3e35850..76b3d9e036554 100755
--- a/remoting/host/installer/mac/Scripts/remoting_postflight.sh
+++ b/remoting/host/installer/mac/Scripts/remoting_postflight.sh
@@ -22,6 +22,7 @@ NATIVE_MESSAGING_HOST_BUNDLE_NAME=@@NATIVE_MESSAGING_HOST_BUNDLE_NAME@@
 REMOTE_ASSISTANCE_HOST_BUNDLE_NAME=@@REMOTE_ASSISTANCE_HOST_BUNDLE_NAME@@
 HOST_EXE="$HELPERTOOLS/$HOST_BUNDLE_NAME/Contents/MacOS/remoting_me2me_host"
 USERS_TMP_FILE="$HOST_SERVICE_BINARY.users"
+BROKER_SERVICE_TARGET="system/org.chromium.chromoting.broker"
 
 # ksadmin moved from MacOS to Helpers in Keystone 1.2.13.112, 2019-11-12. A
 # symbolic link from the old location was left in place, but may not remain
@@ -138,6 +139,8 @@ ln -s "$HELPERTOOLS/$HOST_BUNDLE_NAME/Contents/Resources/icudtl.dat" \
 # started until a host process connects to
 # chromoting.agent_process_broker_mojo_ipc.
 logger Loading broker service
+logger launchctl enable $BROKER_SERVICE_TARGET
+launchctl enable $BROKER_SERVICE_TARGET
 logger launchctl bootstrap system $BROKER_PLIST
 launchctl bootstrap system $BROKER_PLIST