Commit ff451f4a authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting][mac] Delegate to old script if it exists and OS is Mojave

Mojave users might have already granted a11y permission to the old
helper script. In order not to unnecessarily break them, this CL
implements a fallback logic in the host service executable to always
delegate to the old script if the script exists and the user is on
macOS 10.14.

Bug: 10142116
Change-Id: I301585cf25ca3c37ac1ebedac8b4dee6c1251c0b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1861278Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706026}
parent e567bb9e
......@@ -23,6 +23,8 @@ const char kHostConfigFilePath[] = HELPER_TOOLS_DIR SERVICE_NAME ".json";
const char kHostHelperScriptPath[] =
HELPER_TOOLS_DIR HOST_BUNDLE_NAME "/Contents/MacOS/host_service";
const char kOldHostHelperScriptPath[] =
HELPER_TOOLS_DIR SERVICE_NAME ".me2me.sh";
const char kHostBinaryPath[] = HELPER_TOOLS_DIR HOST_BUNDLE_NAME;
const char kHostLegacyBinaryPath[] = HELPER_TOOLS_DIR HOST_LEGACY_BUNDLE_NAME;
const char kHostEnabledPath[] = HELPER_TOOLS_DIR SERVICE_NAME ".me2me_enabled";
......
......@@ -23,6 +23,10 @@ extern const char kHostConfigFilePath[];
// installed host components.
extern const char kHostHelperScriptPath[];
// Path to the old host helper script, which is still used after user updates
// their host on macOS 10.14.*.
extern const char kOldHostHelperScriptPath[];
// Path to the service binary (.app).
extern const char kHostBinaryPath[];
......
......@@ -14,6 +14,7 @@
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/process/launch.h"
......@@ -110,12 +111,16 @@ class HostService {
void PrintPid();
private:
int RunHostFromOldScript();
base::FilePath old_host_helper_file_;
base::FilePath enabled_file_;
base::FilePath config_file_;
base::FilePath host_exe_file_;
};
HostService::HostService() {
old_host_helper_file_ = base::FilePath(kOldHostHelperScriptPath);
enabled_file_ = base::FilePath(kHostEnabledPath);
config_file_ = base::FilePath(kHostConfigFilePath);
......@@ -127,6 +132,14 @@ HostService::HostService() {
HostService::~HostService() = default;
int HostService::RunHost() {
// Mojave users updating from an older host likely have already granted a11y
// permission to the old script. In this case we always delegate RunHost to
// the old script so that they don't need to grant permission to a new app.
if (base::mac::IsOS10_14() && base::PathExists(old_host_helper_file_)) {
HOST_LOG << "RunHost will be delegated to the old host script.";
return RunHostFromOldScript();
}
// Run the config-upgrade tool, but only if running as root, as normal users
// don't have permission to write the config file.
if (geteuid() == 0) {
......@@ -288,6 +301,24 @@ void HostService::PrintPid() {
fflush(stdout);
}
int HostService::RunHostFromOldScript() {
base::CommandLine cmdline(old_host_helper_file_);
cmdline.AppendSwitch(kSwitchHostRunFromLaunchd);
base::LaunchOptions options;
options.disclaim_responsibility = true;
base::Process process = base::LaunchProcess(cmdline, options);
if (!process.IsValid()) {
LOG(ERROR) << "Failed to launch the old host script for unknown reason.";
return 1;
}
g_host_pid = process.Pid();
int exit_code;
process.WaitForExit(&exit_code);
g_host_pid = 0;
return exit_code;
}
} // namespace
} // namespace remoting
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment