blob: ada6dc6be2c8712aee27f8f78c929a4c8d689bde [file] [log] [blame]
Jorge E. Moreira577383b2018-05-24 14:17:51 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "host/libs/config/cuttlefish_config.h"
18
Cody Schuffelenefadb8d2018-08-10 16:10:35 -070019#include <algorithm>
Jorge E. Moreira577383b2018-05-24 14:17:51 -070020#include <climits>
21#include <cstdlib>
22#include <cstring>
23#include <fstream>
24#include <iomanip>
Cody Schuffelenefadb8d2018-08-10 16:10:35 -070025#include <iterator>
Jorge E. Moreira577383b2018-05-24 14:17:51 -070026#include <sstream>
27#include <string>
28
Jorge E. Moreira577383b2018-05-24 14:17:51 -070029#include <glog/logging.h>
30#include <json/json.h>
31
Jorge E. Moreira2a777f62018-06-13 17:28:10 -070032#include "common/libs/utils/environment.h"
Ryan Haining10e42312018-07-17 12:11:52 -070033#include "common/libs/utils/files.h"
Jorge E. Moreiraba626622019-01-28 17:47:50 -080034#include "host/libs/vm_manager/qemu_manager.h"
35
Jorge E. Moreira2a777f62018-06-13 17:28:10 -070036
Jorge E. Moreira577383b2018-05-24 14:17:51 -070037namespace {
38
Jorge E. Moreira577383b2018-05-24 14:17:51 -070039int InstanceFromEnvironment() {
40 static constexpr char kInstanceEnvironmentVariable[] = "CUTTLEFISH_INSTANCE";
Jorge E. Moreira577383b2018-05-24 14:17:51 -070041 static constexpr int kDefaultInstance = 1;
42
43 // CUTTLEFISH_INSTANCE environment variable
44 const char* instance_str = std::getenv(kInstanceEnvironmentVariable);
45 if (!instance_str) {
46 // Try to get it from the user instead
47 instance_str = std::getenv("USER");
Ryan Haining7338d352018-10-24 17:41:52 -070048
49 if (!instance_str || std::strncmp(instance_str, vsoc::kVsocUserPrefix,
50 sizeof(vsoc::kVsocUserPrefix) - 1)) {
Jorge E. Moreira577383b2018-05-24 14:17:51 -070051 // No user or we don't recognize this user
Ryan Haining7338d352018-10-24 17:41:52 -070052 LOG(WARNING) << "No user or non-vsoc user, returning default config";
Jorge E. Moreira577383b2018-05-24 14:17:51 -070053 return kDefaultInstance;
54 }
Ryan Haining7338d352018-10-24 17:41:52 -070055 instance_str += sizeof(vsoc::kVsocUserPrefix) - 1;
56
Jorge E. Moreira577383b2018-05-24 14:17:51 -070057 // Set the environment variable so that child processes see it
58 setenv(kInstanceEnvironmentVariable, instance_str, 0);
59 }
60
61 int instance = std::atoi(instance_str);
62 if (instance <= 0) {
63 instance = kDefaultInstance;
64 }
65
66 return instance;
67}
Ryan Haining10e42312018-07-17 12:11:52 -070068
Jorge E. Moreira577383b2018-05-24 14:17:51 -070069const char* kSerialNumber = "serial_number";
70const char* kInstanceDir = "instance_dir";
Jorge E. Moreira88322832018-07-22 16:41:01 -070071const char* kVmManager = "vm_manager";
Jorge E. Moreiraba626622019-01-28 17:47:50 -080072const char* kHardwareName = "hardware_name";
Ryan Haining6d821ec2018-07-27 11:39:09 -070073const char* kDeviceTitle = "device_title";
Jorge E. Moreira577383b2018-05-24 14:17:51 -070074
75const char* kCpus = "cpus";
76const char* kMemoryMb = "memory_mb";
77const char* kDpi = "dpi";
78const char* kXRes = "x_res";
79const char* kYRes = "y_res";
Cody Schuffelen5bc697c2019-01-28 21:05:29 -080080const char* kNumScreenBuffers = "num_screen_buffers";
Jorge E. Moreira577383b2018-05-24 14:17:51 -070081const char* kRefreshRateHz = "refresh_rate_hz";
82
83const char* kKernelImagePath = "kernel_image_path";
Cody Schuffelene13a78a2019-01-29 14:51:26 -080084const char* kUseUnpackedKernel = "use_unpacked_kernel";
Jorge E. Moreira80ddd7f2019-02-04 16:30:13 -080085const char* kDecompressedKernelImagePath = "decompressed_kernel_image_path";
86const char* kDecompressKernel = "decompress_kernel";
Greg Hartman91f81422018-07-09 16:04:49 -070087const char* kGdbFlag = "gdb_flag";
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -070088const char* kKernelCmdline = "kernel_cmdline";
Jorge E. Moreira577383b2018-05-24 14:17:51 -070089const char* kRamdiskImagePath = "ramdisk_image_path";
90
91const char* kSystemImagePath = "system_image_path";
92const char* kCacheImagePath = "cache_image_path";
93const char* kDataImagePath = "data_image_path";
94const char* kVendorImagePath = "vendor_image_path";
95const char* kUsbV1SocketName = "usb_v1_socket_name";
96const char* kVhciPort = "vhci_port";
97const char* kUsbIpSocketName = "usb_ip_socket_name";
98const char* kKernelLogSocketName = "kernel_log_socket_name";
Jorge E. Moreira81afca12018-07-26 16:48:49 -070099const char* kDeprecatedBootCompleted = "deprecated_boot_completed";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700100const char* kConsolePath = "console_path";
101const char* kLogcatPath = "logcat_path";
Jorge E. Moreira66f6ec82018-07-16 16:43:15 -0700102const char* kLauncherLogPath = "launcher_log_path";
Jorge E. Moreira50a07752018-07-18 18:49:04 -0700103const char* kLauncherMonitorPath = "launcher_monitor_socket";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700104const char* kDtbPath = "dtb_path";
Jorge E. Moreiraba626622019-01-28 17:47:50 -0800105const char* kGsiFstabPath = "gsi.fstab_path";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700106
107const char* kMempath = "mempath";
108const char* kIvshmemQemuSocketPath = "ivshmem_qemu_socket_path";
109const char* kIvshmemClientSocketPath = "ivshmem_client_socket_path";
110const char* kIvshmemVectorCount = "ivshmem_vector_count";
111
112const char* kMobileBridgeName = "mobile_bridge_name";
113const char* kMobileTapName = "mobile_tap_name";
Cody Schuffelen975175a2018-06-14 18:20:02 -0700114const char* kWifiBridgeName = "wifi_bridge_name";
115const char* kWifiTapName = "wifi_tap_name";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700116const char* kWifiGuestMacAddr = "wifi_guest_mac_addr";
117const char* kWifiHostMacAddr = "wifi_host_mac_addr";
118const char* kEntropySource = "entropy_source";
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800119const char* kVsockGuestCid = "vsock_guest_cid";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700120
121const char* kUuid = "uuid";
Greg Hartman6abdbb92018-05-24 09:49:00 -0700122const char* kCuttlefishEnvPath = "cuttlefish_env_path";
Ryan Haining4a1abea2018-07-10 16:20:19 -0700123
124const char* kAdbMode = "adb_mode";
Ryan Haining7338d352018-10-24 17:41:52 -0700125const char* kAdbIPAndPort = "adb_ip_and_port";
Greg Hartmanf1f28c52018-09-20 17:19:19 -0700126const char* kSetupWizardMode = "setupwizard_mode";
Cody Schuffelen58980032018-10-11 17:11:13 -0700127
Cody Schuffelen58980032018-10-11 17:11:13 -0700128const char* kQemuBinary = "qemu_binary";
Jorge E. Moreiraba626622019-01-28 17:47:50 -0800129const char* kCrosvmBinary = "crosvm_binary";
Cody Schuffelen5bc697c2019-01-28 21:05:29 -0800130const char* kIvServerBinary = "ivserver_binary";
Cody Schuffelen55676ca2019-01-28 22:00:05 -0800131const char* kKernelLogMonitorBinary = "kernel_log_monitor_binary";
Cody Schuffelen17b34722019-01-28 22:57:14 -0800132
133const char* kEnableVncServer = "enable_vnc_server";
134const char* kVncServerBinary = "vnc_server_binary";
135const char* kVncServerPort = "vnc_server_port";
136
137const char* kEnableStreamAudio = "enable_stream_audio";
138const char* kStreamAudioBinary = "stream_audio_binary";
139const char* kStreamAudioPort = "stream_audio_port";
Cody Schuffelend12e0c92019-01-29 15:44:45 -0800140
141const char* kRestartSubprocesses = "restart_subprocesses";
Cody Schuffelen1f08d972019-01-29 16:21:12 -0800142const char* kRunAdbConnector = "run_adb_connector";
143const char* kAdbConnectorBinary = "adb_connector_binary";
144const char* kVirtualUsbManagerBinary = "virtual_usb_manager_binary";
145const char* kSocketForwardProxyBinary = "socket_forward_proxy_binary";
146const char* kSocketVsockProxyBinary = "socket_vsock_proxy_binary";
Cody Schuffelen50249732019-01-29 16:42:55 -0800147
148const char* kRunAsDaemon = "run_as_daemon";
Cody Schuffelen3a640952019-01-29 17:14:41 -0800149const char* kRunE2eTest = "run_e2e_test";
150const char* kE2eTestBinary = "e2e_test_binary";
Cody Schuffelen2b51bab2019-01-29 18:14:48 -0800151
152const char* kDataPolicy = "data_policy";
153const char* kBlankDataImageMb = "blank_data_image_mb";
154const char* kBlankDataImageFmt = "blank_data_image_fmt";
Jorge E. Moreirafd10cae2019-02-19 15:35:42 -0800155
156const char* kLogcatMode = "logcat_mode";
157const char* kLogcatVsockPort = "logcat_vsock_mode";
158const char* kLogcatReceiverBinary = "logcat_receiver_binary";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700159} // namespace
160
161namespace vsoc {
162
163std::string CuttlefishConfig::instance_dir() const {
164 return (*dictionary_)[kInstanceDir].asString();
165}
166void CuttlefishConfig::set_instance_dir(const std::string& instance_dir) {
167 (*dictionary_)[kInstanceDir] = instance_dir;
168}
169
Jorge E. Moreira88322832018-07-22 16:41:01 -0700170std::string CuttlefishConfig::vm_manager() const {
171 return (*dictionary_)[kVmManager].asString();
172}
173void CuttlefishConfig::set_vm_manager(const std::string& name) {
Ryan Haining6d821ec2018-07-27 11:39:09 -0700174 (*dictionary_)[kVmManager] = name;
Jorge E. Moreira88322832018-07-22 16:41:01 -0700175}
176
Jorge E. Moreiraba626622019-01-28 17:47:50 -0800177std::string CuttlefishConfig::hardware_name() const {
178 return (*dictionary_)[kHardwareName].asString();
179}
180void CuttlefishConfig::set_hardware_name(const std::string& name) {
181 (*dictionary_)[kHardwareName] = name;
182}
183
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700184std::string CuttlefishConfig::serial_number() const {
185 return (*dictionary_)[kSerialNumber].asString();
186}
187void CuttlefishConfig::set_serial_number(const std::string& serial_number) {
188 (*dictionary_)[kSerialNumber] = serial_number;
189}
190
191int CuttlefishConfig::cpus() const { return (*dictionary_)[kCpus].asInt(); }
192void CuttlefishConfig::set_cpus(int cpus) { (*dictionary_)[kCpus] = cpus; }
193
194int CuttlefishConfig::memory_mb() const {
195 return (*dictionary_)[kMemoryMb].asInt();
196}
197void CuttlefishConfig::set_memory_mb(int memory_mb) {
198 (*dictionary_)[kMemoryMb] = memory_mb;
199}
200
201int CuttlefishConfig::dpi() const { return (*dictionary_)[kDpi].asInt(); }
202void CuttlefishConfig::set_dpi(int dpi) { (*dictionary_)[kDpi] = dpi; }
203
204int CuttlefishConfig::x_res() const { return (*dictionary_)[kXRes].asInt(); }
205void CuttlefishConfig::set_x_res(int x_res) { (*dictionary_)[kXRes] = x_res; }
206
207int CuttlefishConfig::y_res() const { return (*dictionary_)[kYRes].asInt(); }
208void CuttlefishConfig::set_y_res(int y_res) { (*dictionary_)[kYRes] = y_res; }
209
Cody Schuffelen5bc697c2019-01-28 21:05:29 -0800210int CuttlefishConfig::num_screen_buffers() const {
211 return (*dictionary_)[kNumScreenBuffers].asInt();
212}
213void CuttlefishConfig::set_num_screen_buffers(int num_screen_buffers) {
214 (*dictionary_)[kNumScreenBuffers] = num_screen_buffers;
215}
216
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700217int CuttlefishConfig::refresh_rate_hz() const {
218 return (*dictionary_)[kRefreshRateHz].asInt();
219}
220void CuttlefishConfig::set_refresh_rate_hz(int refresh_rate_hz) {
221 (*dictionary_)[kRefreshRateHz] = refresh_rate_hz;
222}
223
224std::string CuttlefishConfig::kernel_image_path() const {
225 return (*dictionary_)[kKernelImagePath].asString();
226}
Greg Hartman91f81422018-07-09 16:04:49 -0700227
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700228void CuttlefishConfig::SetPath(const std::string& key,
229 const std::string& path) {
230 if (!path.empty()) {
231 (*dictionary_)[key] = cvd::AbsolutePath(path);
232 }
233}
234
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700235void CuttlefishConfig::set_kernel_image_path(
236 const std::string& kernel_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700237 SetPath(kKernelImagePath, kernel_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700238}
239
Cody Schuffelene13a78a2019-01-29 14:51:26 -0800240bool CuttlefishConfig::use_unpacked_kernel() const {
241 return (*dictionary_)[kUseUnpackedKernel].asBool();
242}
243
244void CuttlefishConfig::set_use_unpacked_kernel(bool use_unpacked_kernel) {
245 (*dictionary_)[kUseUnpackedKernel] = use_unpacked_kernel;
246}
247
Jorge E. Moreira80ddd7f2019-02-04 16:30:13 -0800248bool CuttlefishConfig::decompress_kernel() const {
249 return (*dictionary_)[kDecompressKernel].asBool();
250}
251void CuttlefishConfig::set_decompress_kernel(bool decompress_kernel) {
252 (*dictionary_)[kDecompressKernel] = decompress_kernel;
253}
254
255std::string CuttlefishConfig::decompressed_kernel_image_path() const {
256 return (*dictionary_)[kDecompressedKernelImagePath].asString();
257}
258void CuttlefishConfig::set_decompressed_kernel_image_path(
259 const std::string& path) {
260 SetPath(kDecompressedKernelImagePath, path);
261}
262
Greg Hartman91f81422018-07-09 16:04:49 -0700263std::string CuttlefishConfig::gdb_flag() const {
264 return (*dictionary_)[kGdbFlag].asString();
265}
266
Ryan Haining6d821ec2018-07-27 11:39:09 -0700267void CuttlefishConfig::set_gdb_flag(const std::string& device) {
Matthias Maennichac14e1e2019-02-06 16:25:42 +0000268 (*dictionary_)[kGdbFlag] = device;
Greg Hartman91f81422018-07-09 16:04:49 -0700269}
270
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700271std::set<std::string> CuttlefishConfig::kernel_cmdline() const {
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700272 std::set<std::string> args_set;
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700273 auto args_json_obj = (*dictionary_)[kKernelCmdline];
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700274 std::transform(args_json_obj.begin(), args_json_obj.end(),
275 std::inserter(args_set, args_set.begin()),
276 [](const Json::Value& it) { return it.asString(); });
277 return args_set;
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700278}
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700279void CuttlefishConfig::set_kernel_cmdline(
280 const std::set<std::string>& kernel_cmdline) {
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700281 Json::Value args_json_obj(Json::arrayValue);
Chih-Hung Hsieh90c1dcc2018-12-12 13:43:34 -0800282 for (const auto& arg : kernel_cmdline) {
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700283 args_json_obj.append(arg);
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700284 }
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700285 (*dictionary_)[kKernelCmdline] = args_json_obj;
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700286}
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700287void CuttlefishConfig::add_kernel_cmdline(
288 const std::set<std::string>& extra_args) {
289 std::set<std::string> cmdline = kernel_cmdline();
Chih-Hung Hsieh90c1dcc2018-12-12 13:43:34 -0800290 for (const auto& arg : extra_args) {
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700291 if (cmdline.count(arg)) {
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700292 LOG(ERROR) << "Kernel argument " << arg << " is duplicated";
293 }
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700294 cmdline.insert(arg);
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700295 }
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700296 set_kernel_cmdline(cmdline);
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700297}
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700298void CuttlefishConfig::add_kernel_cmdline(const std::string& kernel_cmdline) {
299 std::stringstream args_stream(kernel_cmdline);
300 std::set<std::string> kernel_cmdline_set;
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700301 using is_iter = std::istream_iterator<std::string>;
302 std::copy(is_iter(args_stream), is_iter(),
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700303 std::inserter(kernel_cmdline_set, kernel_cmdline_set.begin()));
304 add_kernel_cmdline(kernel_cmdline_set);
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700305}
Jorge E. Moreirab2427ba2018-08-23 17:11:55 -0700306std::string CuttlefishConfig::kernel_cmdline_as_string() const {
307 auto args_set = kernel_cmdline();
Cody Schuffelenefadb8d2018-08-10 16:10:35 -0700308 std::stringstream output;
309 std::copy(args_set.begin(), args_set.end(),
310 std::ostream_iterator<std::string>(output, " "));
311 return output.str();
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700312}
313
314std::string CuttlefishConfig::ramdisk_image_path() const {
315 return (*dictionary_)[kRamdiskImagePath].asString();
316}
317void CuttlefishConfig::set_ramdisk_image_path(
318 const std::string& ramdisk_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700319 SetPath(kRamdiskImagePath, ramdisk_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700320}
321
322std::string CuttlefishConfig::system_image_path() const {
323 return (*dictionary_)[kSystemImagePath].asString();
324}
325void CuttlefishConfig::set_system_image_path(
326 const std::string& system_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700327 SetPath(kSystemImagePath, system_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700328}
329
330std::string CuttlefishConfig::cache_image_path() const {
331 return (*dictionary_)[kCacheImagePath].asString();
332}
333void CuttlefishConfig::set_cache_image_path(
334 const std::string& cache_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700335 SetPath(kCacheImagePath, cache_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700336}
337
338std::string CuttlefishConfig::data_image_path() const {
339 return (*dictionary_)[kDataImagePath].asString();
340}
341void CuttlefishConfig::set_data_image_path(const std::string& data_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700342 SetPath(kDataImagePath, data_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700343}
344
345std::string CuttlefishConfig::vendor_image_path() const {
346 return (*dictionary_)[kVendorImagePath].asString();
347}
348void CuttlefishConfig::set_vendor_image_path(
349 const std::string& vendor_image_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700350 SetPath(kVendorImagePath, vendor_image_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700351}
352
353std::string CuttlefishConfig::dtb_path() const {
354 return (*dictionary_)[kDtbPath].asString();
355}
356void CuttlefishConfig::set_dtb_path(const std::string& dtb_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700357 SetPath(kDtbPath, dtb_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700358}
359
Jorge E. Moreiraba626622019-01-28 17:47:50 -0800360std::string CuttlefishConfig::gsi_fstab_path() const {
361 return (*dictionary_)[kGsiFstabPath].asString();
362}
363void CuttlefishConfig::set_gsi_fstab_path(const std::string& path){
364 SetPath(kGsiFstabPath, path);
365}
366
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700367std::string CuttlefishConfig::mempath() const {
368 return (*dictionary_)[kMempath].asString();
369}
370void CuttlefishConfig::set_mempath(const std::string& mempath) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700371 SetPath(kMempath, mempath);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700372}
373
374std::string CuttlefishConfig::ivshmem_qemu_socket_path() const {
375 return (*dictionary_)[kIvshmemQemuSocketPath].asString();
376}
377void CuttlefishConfig::set_ivshmem_qemu_socket_path(
378 const std::string& ivshmem_qemu_socket_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700379 SetPath(kIvshmemQemuSocketPath, ivshmem_qemu_socket_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700380}
381
382std::string CuttlefishConfig::ivshmem_client_socket_path() const {
383 return (*dictionary_)[kIvshmemClientSocketPath].asString();
384}
385void CuttlefishConfig::set_ivshmem_client_socket_path(
386 const std::string& ivshmem_client_socket_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700387 SetPath(kIvshmemClientSocketPath, ivshmem_client_socket_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700388}
389
390int CuttlefishConfig::ivshmem_vector_count() const {
391 return (*dictionary_)[kIvshmemVectorCount].asInt();
392}
393void CuttlefishConfig::set_ivshmem_vector_count(int ivshmem_vector_count) {
394 (*dictionary_)[kIvshmemVectorCount] = ivshmem_vector_count;
395}
396
397std::string CuttlefishConfig::usb_v1_socket_name() const {
398 return (*dictionary_)[kUsbV1SocketName].asString();
399}
400void CuttlefishConfig::set_usb_v1_socket_name(
401 const std::string& usb_v1_socket_name) {
402 (*dictionary_)[kUsbV1SocketName] = usb_v1_socket_name;
403}
404
405int CuttlefishConfig::vhci_port() const {
406 return (*dictionary_)[kVhciPort].asInt();
407}
408void CuttlefishConfig::set_vhci_port(int vhci_port) {
409 (*dictionary_)[kVhciPort] = vhci_port;
410}
411
412std::string CuttlefishConfig::usb_ip_socket_name() const {
413 return (*dictionary_)[kUsbIpSocketName].asString();
414}
415void CuttlefishConfig::set_usb_ip_socket_name(
416 const std::string& usb_ip_socket_name) {
417 (*dictionary_)[kUsbIpSocketName] = usb_ip_socket_name;
418}
419
420std::string CuttlefishConfig::kernel_log_socket_name() const {
421 return (*dictionary_)[kKernelLogSocketName].asString();
422}
423void CuttlefishConfig::set_kernel_log_socket_name(
424 const std::string& kernel_log_socket_name) {
425 (*dictionary_)[kKernelLogSocketName] = kernel_log_socket_name;
426}
427
Jorge E. Moreira81afca12018-07-26 16:48:49 -0700428bool CuttlefishConfig::deprecated_boot_completed() const {
429 return (*dictionary_)[kDeprecatedBootCompleted].asBool();
430}
431void CuttlefishConfig::set_deprecated_boot_completed(
432 bool deprecated_boot_completed) {
433 (*dictionary_)[kDeprecatedBootCompleted] = deprecated_boot_completed;
434}
435
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700436std::string CuttlefishConfig::console_path() const {
437 return (*dictionary_)[kConsolePath].asString();
438}
439void CuttlefishConfig::set_console_path(const std::string& console_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700440 SetPath(kConsolePath, console_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700441}
442
443std::string CuttlefishConfig::logcat_path() const {
444 return (*dictionary_)[kLogcatPath].asString();
445}
446void CuttlefishConfig::set_logcat_path(const std::string& logcat_path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700447 SetPath(kLogcatPath, logcat_path);
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700448}
449
Jorge E. Moreira50a07752018-07-18 18:49:04 -0700450std::string CuttlefishConfig::launcher_monitor_socket_path() const {
451 return (*dictionary_)[kLauncherMonitorPath].asString();
452}
453void CuttlefishConfig::set_launcher_monitor_socket_path(
Jorge E. Moreirabe7049a2018-07-26 18:12:13 -0700454 const std::string& launcher_monitor_path) {
455 SetPath(kLauncherMonitorPath, launcher_monitor_path);
Jorge E. Moreira50a07752018-07-18 18:49:04 -0700456}
457
Jorge E. Moreira66f6ec82018-07-16 16:43:15 -0700458std::string CuttlefishConfig::launcher_log_path() const {
459 return (*dictionary_)[kLauncherLogPath].asString();
460}
461void CuttlefishConfig::set_launcher_log_path(
462 const std::string& launcher_log_path) {
463 (*dictionary_)[kLauncherLogPath] = launcher_log_path;
464}
465
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700466std::string CuttlefishConfig::mobile_bridge_name() const {
467 return (*dictionary_)[kMobileBridgeName].asString();
468}
469void CuttlefishConfig::set_mobile_bridge_name(
470 const std::string& mobile_bridge_name) {
471 (*dictionary_)[kMobileBridgeName] = mobile_bridge_name;
472}
473
Cody Schuffelen975175a2018-06-14 18:20:02 -0700474std::string CuttlefishConfig::wifi_bridge_name() const {
475 return (*dictionary_)[kWifiBridgeName].asString();
476}
477void CuttlefishConfig::set_wifi_bridge_name(
478 const std::string& wifi_bridge_name) {
479 (*dictionary_)[kWifiBridgeName] = wifi_bridge_name;
480}
481
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700482std::string CuttlefishConfig::wifi_guest_mac_addr() const {
483 return (*dictionary_)[kWifiGuestMacAddr].asString();
484}
485void CuttlefishConfig::set_wifi_guest_mac_addr(
486 const std::string& wifi_guest_mac_addr) {
487 (*dictionary_)[kWifiGuestMacAddr] = wifi_guest_mac_addr;
488}
489
490std::string CuttlefishConfig::wifi_host_mac_addr() const {
491 return (*dictionary_)[kWifiHostMacAddr].asString();
492}
493void CuttlefishConfig::set_wifi_host_mac_addr(
494 const std::string& wifi_host_mac_addr) {
495 (*dictionary_)[kWifiHostMacAddr] = wifi_host_mac_addr;
496}
497
498std::string CuttlefishConfig::mobile_tap_name() const {
499 return (*dictionary_)[kMobileTapName].asString();
500}
501void CuttlefishConfig::set_mobile_tap_name(const std::string& mobile_tap_name) {
502 (*dictionary_)[kMobileTapName] = mobile_tap_name;
503}
504
Cody Schuffelen975175a2018-06-14 18:20:02 -0700505std::string CuttlefishConfig::wifi_tap_name() const {
506 return (*dictionary_)[kWifiTapName].asString();
507}
508void CuttlefishConfig::set_wifi_tap_name(const std::string& wifi_tap_name) {
509 (*dictionary_)[kWifiTapName] = wifi_tap_name;
510}
511
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700512std::string CuttlefishConfig::entropy_source() const {
513 return (*dictionary_)[kEntropySource].asString();
514}
515void CuttlefishConfig::set_entropy_source(const std::string& entropy_source) {
516 (*dictionary_)[kEntropySource] = entropy_source;
517}
518
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800519int CuttlefishConfig::vsock_guest_cid() const {
520 return (*dictionary_)[kVsockGuestCid].asInt();
521}
522
523void CuttlefishConfig::set_vsock_guest_cid(int vsock_guest_cid) {
524 (*dictionary_)[kVsockGuestCid] = vsock_guest_cid;
525}
526
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700527std::string CuttlefishConfig::uuid() const {
528 return (*dictionary_)[kUuid].asString();
529}
530void CuttlefishConfig::set_uuid(const std::string& uuid) {
531 (*dictionary_)[kUuid] = uuid;
532}
533
Greg Hartman6abdbb92018-05-24 09:49:00 -0700534void CuttlefishConfig::set_cuttlefish_env_path(const std::string& path) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700535 SetPath(kCuttlefishEnvPath, path);
Greg Hartman6abdbb92018-05-24 09:49:00 -0700536}
537std::string CuttlefishConfig::cuttlefish_env_path() const {
538 return (*dictionary_)[kCuttlefishEnvPath].asString();
539}
540
Ryan Haining4a1abea2018-07-10 16:20:19 -0700541std::string CuttlefishConfig::adb_mode() const {
542 return (*dictionary_)[kAdbMode].asString();
543}
544
545void CuttlefishConfig::set_adb_mode(const std::string& mode) {
546 (*dictionary_)[kAdbMode] = mode;
547}
548
Ryan Haining7338d352018-10-24 17:41:52 -0700549std::string CuttlefishConfig::adb_ip_and_port() const {
550 return (*dictionary_)[kAdbIPAndPort].asString();
551}
552
553void CuttlefishConfig::set_adb_ip_and_port(const std::string& ip_port) {
554 (*dictionary_)[kAdbIPAndPort] = ip_port;
555}
556
557std::string CuttlefishConfig::adb_device_name() const {
558 if (adb_mode().find("tunnel") != std::string::npos) {
559 return adb_ip_and_port();
560 } else if (adb_mode().find("usb") != std::string::npos) {
561 return serial_number();
562 }
563 LOG(ERROR) << "no adb_mode found, returning bad device name";
564 return "NO_ADB_MODE_SET_NO_VALID_DEVICE_NAME";
565}
566
Ryan Haining6d821ec2018-07-27 11:39:09 -0700567std::string CuttlefishConfig::device_title() const {
568 return (*dictionary_)[kDeviceTitle].asString();
569}
570
571void CuttlefishConfig::set_device_title(const std::string& title) {
572 (*dictionary_)[kDeviceTitle] = title;
573}
574
Greg Hartmanf1f28c52018-09-20 17:19:19 -0700575std::string CuttlefishConfig::setupwizard_mode() const {
576 return (*dictionary_)[kSetupWizardMode].asString();
577}
578
579void CuttlefishConfig::set_setupwizard_mode(const std::string& mode) {
580 (*dictionary_)[kSetupWizardMode] = mode;
581}
582
Cody Schuffelen58980032018-10-11 17:11:13 -0700583std::string CuttlefishConfig::qemu_binary() const {
584 return (*dictionary_)[kQemuBinary].asString();
585}
586
587void CuttlefishConfig::set_qemu_binary(const std::string& qemu_binary) {
588 (*dictionary_)[kQemuBinary] = qemu_binary;
589}
590
Jorge E. Moreiraba626622019-01-28 17:47:50 -0800591std::string CuttlefishConfig::crosvm_binary() const {
592 return (*dictionary_)[kCrosvmBinary].asString();
593}
594
595void CuttlefishConfig::set_crosvm_binary(const std::string& crosvm_binary) {
596 (*dictionary_)[kCrosvmBinary] = crosvm_binary;
597}
598
Cody Schuffelen5bc697c2019-01-28 21:05:29 -0800599std::string CuttlefishConfig::ivserver_binary() const {
600 return (*dictionary_)[kIvServerBinary].asString();
601}
602
603void CuttlefishConfig::set_ivserver_binary(const std::string& ivserver_binary) {
604 (*dictionary_)[kIvServerBinary] = ivserver_binary;
605}
606
Cody Schuffelen55676ca2019-01-28 22:00:05 -0800607std::string CuttlefishConfig::kernel_log_monitor_binary() const {
608 return (*dictionary_)[kKernelLogMonitorBinary].asString();
609}
610
611void CuttlefishConfig::set_kernel_log_monitor_binary(
612 const std::string& kernel_log_monitor_binary) {
613 (*dictionary_)[kKernelLogMonitorBinary] = kernel_log_monitor_binary;
614}
615
Cody Schuffelen17b34722019-01-28 22:57:14 -0800616bool CuttlefishConfig::enable_vnc_server() const {
617 return (*dictionary_)[kEnableVncServer].asBool();
618}
619
620void CuttlefishConfig::set_enable_vnc_server(bool enable_vnc_server) {
621 (*dictionary_)[kEnableVncServer] = enable_vnc_server;
622}
623
624std::string CuttlefishConfig::vnc_server_binary() const {
625 return (*dictionary_)[kVncServerBinary].asString();
626}
627
628void CuttlefishConfig::set_vnc_server_binary(
629 const std::string& vnc_server_binary) {
630 (*dictionary_)[kVncServerBinary] = vnc_server_binary;
631}
632
633int CuttlefishConfig::vnc_server_port() const {
634 return (*dictionary_)[kVncServerPort].asInt();
635}
636
637void CuttlefishConfig::set_vnc_server_port(int vnc_server_port) {
638 (*dictionary_)[kVncServerPort] = vnc_server_port;
639}
640
641bool CuttlefishConfig::enable_stream_audio() const {
642 return (*dictionary_)[kEnableStreamAudio].asBool();
643}
644
645void CuttlefishConfig::set_enable_stream_audio(bool enable_stream_audio) {
646 (*dictionary_)[kEnableStreamAudio] = enable_stream_audio;
647}
648
649std::string CuttlefishConfig::stream_audio_binary() const {
650 return (*dictionary_)[kStreamAudioBinary].asString();
651}
652
653void CuttlefishConfig::set_stream_audio_binary(
654 const std::string& stream_audio_binary) {
655 (*dictionary_)[kStreamAudioBinary] = stream_audio_binary;
656}
657
658int CuttlefishConfig::stream_audio_port() const {
659 return (*dictionary_)[kStreamAudioPort].asInt();
660}
661
662void CuttlefishConfig::set_stream_audio_port(int stream_audio_port) {
663 (*dictionary_)[kStreamAudioPort] = stream_audio_port;
664}
665
Cody Schuffelend12e0c92019-01-29 15:44:45 -0800666bool CuttlefishConfig::restart_subprocesses() const {
667 return (*dictionary_)[kRestartSubprocesses].asBool();
668}
669
670void CuttlefishConfig::set_restart_subprocesses(bool restart_subprocesses) {
671 (*dictionary_)[kRestartSubprocesses] = restart_subprocesses;
672}
673
Cody Schuffelen1f08d972019-01-29 16:21:12 -0800674bool CuttlefishConfig::run_adb_connector() const {
Jorge E. Moreirab86922b2019-02-04 10:52:58 -0800675 return (*dictionary_)[kRunAdbConnector].asBool();
Cody Schuffelen1f08d972019-01-29 16:21:12 -0800676}
677
678void CuttlefishConfig::set_run_adb_connector(bool run_adb_connector) {
679 (*dictionary_)[kRunAdbConnector] = run_adb_connector;
680}
681
682std::string CuttlefishConfig::adb_connector_binary() const {
683 return (*dictionary_)[kAdbConnectorBinary].asString();
684}
685
686void CuttlefishConfig::set_adb_connector_binary(
687 const std::string& adb_connector_binary) {
688 (*dictionary_)[kAdbConnectorBinary] = adb_connector_binary;
689}
690
691std::string CuttlefishConfig::virtual_usb_manager_binary() const {
692 return (*dictionary_)[kVirtualUsbManagerBinary].asString();
693}
694
695void CuttlefishConfig::set_virtual_usb_manager_binary(
696 const std::string& virtual_usb_manager_binary) {
697 (*dictionary_)[kVirtualUsbManagerBinary] = virtual_usb_manager_binary;
698}
699
700std::string CuttlefishConfig::socket_forward_proxy_binary() const {
701 return (*dictionary_)[kSocketForwardProxyBinary].asString();
702}
703
704void CuttlefishConfig::set_socket_forward_proxy_binary(
705 const std::string& socket_forward_proxy_binary) {
706 (*dictionary_)[kSocketForwardProxyBinary] = socket_forward_proxy_binary;
707}
708
709std::string CuttlefishConfig::socket_vsock_proxy_binary() const {
710 return (*dictionary_)[kSocketVsockProxyBinary].asString();
711}
712
713void CuttlefishConfig::set_socket_vsock_proxy_binary(
714 const std::string& socket_vsock_proxy_binary) {
715 (*dictionary_)[kSocketVsockProxyBinary] = socket_vsock_proxy_binary;
716}
717
Cody Schuffelen50249732019-01-29 16:42:55 -0800718bool CuttlefishConfig::run_as_daemon() const {
719 return (*dictionary_)[kRunAsDaemon].asBool();
720}
721
722void CuttlefishConfig::set_run_as_daemon(bool run_as_daemon) {
723 (*dictionary_)[kRunAsDaemon] = run_as_daemon;
724}
725
Cody Schuffelen3a640952019-01-29 17:14:41 -0800726bool CuttlefishConfig::run_e2e_test() const {
727 return (*dictionary_)[kRunE2eTest].asBool();
728}
729
730void CuttlefishConfig::set_run_e2e_test(bool run_e2e_test) {
731 (*dictionary_)[kRunE2eTest] = run_e2e_test;
732}
733
734std::string CuttlefishConfig::e2e_test_binary() const {
735 return (*dictionary_)[kE2eTestBinary].asString();
736}
737
738void CuttlefishConfig::set_e2e_test_binary(const std::string& e2e_test_binary) {
739 (*dictionary_)[kE2eTestBinary] = e2e_test_binary;
740}
741
Cody Schuffelen2b51bab2019-01-29 18:14:48 -0800742std::string CuttlefishConfig::data_policy() const {
743 return (*dictionary_)[kDataPolicy].asString();
744}
745
746void CuttlefishConfig::set_data_policy(const std::string& data_policy) {
747 (*dictionary_)[kDataPolicy] = data_policy;
748}
749
750int CuttlefishConfig::blank_data_image_mb() const {
Cody Schuffelene3269ed2019-02-11 18:38:42 -0800751 return (*dictionary_)[kBlankDataImageMb].asInt();
Cody Schuffelen2b51bab2019-01-29 18:14:48 -0800752}
753
754void CuttlefishConfig::set_blank_data_image_mb(int blank_data_image_mb) {
755 (*dictionary_)[kBlankDataImageMb] = blank_data_image_mb;
756}
757
758std::string CuttlefishConfig::blank_data_image_fmt() const {
759 return (*dictionary_)[kBlankDataImageFmt].asString();
760}
761
762void CuttlefishConfig::set_blank_data_image_fmt(const std::string& blank_data_image_fmt) {
763 (*dictionary_)[kBlankDataImageFmt] = blank_data_image_fmt;
764}
765
Jorge E. Moreiraf4b202b2019-02-05 17:51:06 -0800766
Jorge E. Moreirafd10cae2019-02-19 15:35:42 -0800767void CuttlefishConfig::set_logcat_mode(const std::string& mode) {
768 (*dictionary_)[kLogcatMode] = mode;
769}
770
771std::string CuttlefishConfig::logcat_mode() const {
772 return (*dictionary_)[kLogcatMode].asString();
773}
774
775void CuttlefishConfig::set_logcat_vsock_port(int port) {
776 (*dictionary_)[kLogcatVsockPort] = port;
777}
778
779int CuttlefishConfig::logcat_vsock_port() const {
780 return (*dictionary_)[kLogcatVsockPort].asInt();
781}
782
783void CuttlefishConfig::set_logcat_receiver_binary(const std::string& binary) {
784 SetPath(kLogcatReceiverBinary, binary);
785}
786
787std::string CuttlefishConfig::logcat_receiver_binary() const {
788 return (*dictionary_)[kLogcatReceiverBinary].asString();
789}
790
791
Jorge E. Moreiraf4b202b2019-02-05 17:51:06 -0800792bool CuttlefishConfig::enable_ivserver() const {
Jorge E. Moreirafd1a6b02019-02-27 16:25:00 -0800793 return hardware_name() == "cutf_ivsh";
Jorge E. Moreiraf4b202b2019-02-05 17:51:06 -0800794}
795
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700796// Creates the (initially empty) config object and populates it with values from
Cody Schuffelenf219a162018-10-11 19:01:57 -0700797// the config file if the CUTTLEFISH_CONFIG_FILE env variable is present.
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700798// Returns nullptr if there was an error loading from file
799/*static*/ CuttlefishConfig* CuttlefishConfig::BuildConfigImpl() {
Jorge E. Moreiraa00584e2018-10-25 15:07:52 -0700800 auto config_file_path = cvd::StringFromEnv(kCuttlefishConfigEnvVarName,
801 vsoc::GetGlobalConfigFileLink());
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700802 auto ret = new CuttlefishConfig();
Jorge E. Moreiraa00584e2018-10-25 15:07:52 -0700803 if (ret) {
804 auto loaded = ret->LoadFromFile(config_file_path.c_str());
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700805 if (!loaded) {
Cody Schuffelenf219a162018-10-11 19:01:57 -0700806 delete ret;
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700807 return nullptr;
808 }
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700809 }
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700810 return ret;
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700811}
812
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700813/*static*/ CuttlefishConfig* CuttlefishConfig::Get() {
814 static std::shared_ptr<CuttlefishConfig> config(BuildConfigImpl());
815 return config.get();
816}
817
818CuttlefishConfig::CuttlefishConfig() : dictionary_(new Json::Value()) {}
819// Can't use '= default' on the header because the compiler complains of
820// Json::Value being an incomplete type
821CuttlefishConfig::~CuttlefishConfig() {}
822
823bool CuttlefishConfig::LoadFromFile(const char* file) {
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700824 auto real_file_path = cvd::AbsolutePath(file);
Ryan Haining10e42312018-07-17 12:11:52 -0700825 if (real_file_path.empty()) {
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700826 LOG(ERROR) << "Could not get real path for file " << file;
827 return false;
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700828 }
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700829 Json::Reader reader;
830 std::ifstream ifs(real_file_path);
831 if (!reader.parse(ifs, *dictionary_)) {
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700832 LOG(ERROR) << "Could not read config file " << file << ": "
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700833 << reader.getFormattedErrorMessages();
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700834 return false;
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700835 }
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700836 return true;
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700837}
838bool CuttlefishConfig::SaveToFile(const std::string& file) const {
839 std::ofstream ofs(file);
840 if (!ofs.is_open()) {
841 LOG(ERROR) << "Unable to write to file " << file;
842 return false;
843 }
844 ofs << *dictionary_;
845 return !ofs.fail();
846}
847
848std::string CuttlefishConfig::PerInstancePath(const char* file_name) const {
849 return (instance_dir() + "/") + file_name;
850}
851
852std::string CuttlefishConfig::instance_name() const {
853 return GetPerInstanceDefault("cvd-");
854}
855
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700856int GetInstance() {
857 static int instance_id = InstanceFromEnvironment();
858 return instance_id;
859}
860
Jorge E. Moreira015c0002018-07-19 11:01:16 -0700861std::string GetGlobalConfigFileLink() {
862 return cvd::StringFromEnv("HOME", ".") + "/.cuttlefish_config.json";
863}
864
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700865std::string GetDomain() {
866 return CuttlefishConfig::Get()->ivshmem_client_socket_path();
867}
868
869std::string GetPerInstanceDefault(const char* prefix) {
870 std::ostringstream stream;
871 stream << prefix << std::setfill('0') << std::setw(2) << GetInstance();
872 return stream.str();
873}
874int GetPerInstanceDefault(int base) { return base + GetInstance() - 1; }
875
876std::string GetDefaultPerInstanceDir() {
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700877 std::ostringstream stream;
Jorge E. Moreirad9668372019-01-28 22:40:42 -0800878 stream << std::getenv("HOME") << "/cuttlefish_runtime";
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700879 return stream.str();
880}
881
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700882std::string GetDefaultMempath() {
883 return GetPerInstanceDefault("/var/run/shm/cvd-");
884}
885
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800886int GetDefaultPerInstanceVsockCid() {
887 constexpr int kFirstGuestCid = 3;
888 return vsoc::HostSupportsVsock() ? GetPerInstanceDefault(kFirstGuestCid) : 0;
889}
890
Jorge E. Moreiraa8142f92018-06-13 17:33:55 -0700891std::string DefaultHostArtifactsPath(const std::string& file_name) {
892 return (cvd::StringFromEnv("ANDROID_HOST_OUT",
893 cvd::StringFromEnv("HOME", ".")) +
894 "/") +
895 file_name;
896}
897
898std::string DefaultGuestImagePath(const std::string& file_name) {
899 return (cvd::StringFromEnv("ANDROID_PRODUCT_OUT",
Ryan Haining6d821ec2018-07-27 11:39:09 -0700900 cvd::StringFromEnv("HOME", ".")) +
Jorge E. Moreiraa8142f92018-06-13 17:33:55 -0700901 "/") +
902 file_name;
903}
904
905bool HostSupportsQemuCli() {
906 static bool supported =
907 std::system(
908 "/usr/lib/cuttlefish-common/bin/capability_query.py qemu_cli") == 0;
909 return supported;
910}
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800911
912bool HostSupportsVsock() {
913 static bool supported =
914 std::system(
915 "/usr/lib/cuttlefish-common/bin/capability_query.py vsock") == 0;
916 return supported;
917}
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700918} // namespace vsoc