Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 1 | /* |
| 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 Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 19 | #include <algorithm> |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 20 | #include <climits> |
| 21 | #include <cstdlib> |
| 22 | #include <cstring> |
| 23 | #include <fstream> |
| 24 | #include <iomanip> |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 25 | #include <iterator> |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 26 | #include <sstream> |
| 27 | #include <string> |
| 28 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 29 | #include <glog/logging.h> |
| 30 | #include <json/json.h> |
| 31 | |
Jorge E. Moreira | 2a777f6 | 2018-06-13 17:28:10 -0700 | [diff] [blame] | 32 | #include "common/libs/utils/environment.h" |
Ryan Haining | 10e4231 | 2018-07-17 12:11:52 -0700 | [diff] [blame] | 33 | #include "common/libs/utils/files.h" |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 34 | #include "host/libs/vm_manager/qemu_manager.h" |
| 35 | |
Jorge E. Moreira | 2a777f6 | 2018-06-13 17:28:10 -0700 | [diff] [blame] | 36 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 37 | namespace { |
| 38 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 39 | int InstanceFromEnvironment() { |
| 40 | static constexpr char kInstanceEnvironmentVariable[] = "CUTTLEFISH_INSTANCE"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 41 | 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 Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 48 | |
| 49 | if (!instance_str || std::strncmp(instance_str, vsoc::kVsocUserPrefix, |
| 50 | sizeof(vsoc::kVsocUserPrefix) - 1)) { |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 51 | // No user or we don't recognize this user |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 52 | LOG(WARNING) << "No user or non-vsoc user, returning default config"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 53 | return kDefaultInstance; |
| 54 | } |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 55 | instance_str += sizeof(vsoc::kVsocUserPrefix) - 1; |
| 56 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 57 | // 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 Haining | 10e4231 | 2018-07-17 12:11:52 -0700 | [diff] [blame] | 68 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 69 | const char* kSerialNumber = "serial_number"; |
| 70 | const char* kInstanceDir = "instance_dir"; |
Jorge E. Moreira | 8832283 | 2018-07-22 16:41:01 -0700 | [diff] [blame] | 71 | const char* kVmManager = "vm_manager"; |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 72 | const char* kHardwareName = "hardware_name"; |
Ryan Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 73 | const char* kDeviceTitle = "device_title"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 74 | |
| 75 | const char* kCpus = "cpus"; |
| 76 | const char* kMemoryMb = "memory_mb"; |
| 77 | const char* kDpi = "dpi"; |
| 78 | const char* kXRes = "x_res"; |
| 79 | const char* kYRes = "y_res"; |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 80 | const char* kNumScreenBuffers = "num_screen_buffers"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 81 | const char* kRefreshRateHz = "refresh_rate_hz"; |
| 82 | |
| 83 | const char* kKernelImagePath = "kernel_image_path"; |
Cody Schuffelen | e13a78a | 2019-01-29 14:51:26 -0800 | [diff] [blame] | 84 | const char* kUseUnpackedKernel = "use_unpacked_kernel"; |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 85 | const char* kDecompressedKernelImagePath = "decompressed_kernel_image_path"; |
| 86 | const char* kDecompressKernel = "decompress_kernel"; |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 87 | const char* kGdbFlag = "gdb_flag"; |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 88 | const char* kKernelCmdline = "kernel_cmdline"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 89 | const char* kRamdiskImagePath = "ramdisk_image_path"; |
| 90 | |
| 91 | const char* kSystemImagePath = "system_image_path"; |
| 92 | const char* kCacheImagePath = "cache_image_path"; |
| 93 | const char* kDataImagePath = "data_image_path"; |
| 94 | const char* kVendorImagePath = "vendor_image_path"; |
| 95 | const char* kUsbV1SocketName = "usb_v1_socket_name"; |
| 96 | const char* kVhciPort = "vhci_port"; |
| 97 | const char* kUsbIpSocketName = "usb_ip_socket_name"; |
| 98 | const char* kKernelLogSocketName = "kernel_log_socket_name"; |
Jorge E. Moreira | 81afca1 | 2018-07-26 16:48:49 -0700 | [diff] [blame] | 99 | const char* kDeprecatedBootCompleted = "deprecated_boot_completed"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 100 | const char* kConsolePath = "console_path"; |
| 101 | const char* kLogcatPath = "logcat_path"; |
Jorge E. Moreira | 66f6ec8 | 2018-07-16 16:43:15 -0700 | [diff] [blame] | 102 | const char* kLauncherLogPath = "launcher_log_path"; |
Jorge E. Moreira | 50a0775 | 2018-07-18 18:49:04 -0700 | [diff] [blame] | 103 | const char* kLauncherMonitorPath = "launcher_monitor_socket"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 104 | const char* kDtbPath = "dtb_path"; |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 105 | const char* kGsiFstabPath = "gsi.fstab_path"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 106 | |
| 107 | const char* kMempath = "mempath"; |
| 108 | const char* kIvshmemQemuSocketPath = "ivshmem_qemu_socket_path"; |
| 109 | const char* kIvshmemClientSocketPath = "ivshmem_client_socket_path"; |
| 110 | const char* kIvshmemVectorCount = "ivshmem_vector_count"; |
| 111 | |
| 112 | const char* kMobileBridgeName = "mobile_bridge_name"; |
| 113 | const char* kMobileTapName = "mobile_tap_name"; |
Cody Schuffelen | 975175a | 2018-06-14 18:20:02 -0700 | [diff] [blame] | 114 | const char* kWifiBridgeName = "wifi_bridge_name"; |
| 115 | const char* kWifiTapName = "wifi_tap_name"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 116 | const char* kWifiGuestMacAddr = "wifi_guest_mac_addr"; |
| 117 | const char* kWifiHostMacAddr = "wifi_host_mac_addr"; |
| 118 | const char* kEntropySource = "entropy_source"; |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 119 | const char* kVsockGuestCid = "vsock_guest_cid"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 120 | |
| 121 | const char* kUuid = "uuid"; |
Greg Hartman | 6abdbb9 | 2018-05-24 09:49:00 -0700 | [diff] [blame] | 122 | const char* kCuttlefishEnvPath = "cuttlefish_env_path"; |
Ryan Haining | 4a1abea | 2018-07-10 16:20:19 -0700 | [diff] [blame] | 123 | |
| 124 | const char* kAdbMode = "adb_mode"; |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 125 | const char* kAdbIPAndPort = "adb_ip_and_port"; |
Greg Hartman | f1f28c5 | 2018-09-20 17:19:19 -0700 | [diff] [blame] | 126 | const char* kSetupWizardMode = "setupwizard_mode"; |
Cody Schuffelen | 5898003 | 2018-10-11 17:11:13 -0700 | [diff] [blame] | 127 | |
Cody Schuffelen | 5898003 | 2018-10-11 17:11:13 -0700 | [diff] [blame] | 128 | const char* kQemuBinary = "qemu_binary"; |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 129 | const char* kCrosvmBinary = "crosvm_binary"; |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 130 | const char* kIvServerBinary = "ivserver_binary"; |
Cody Schuffelen | 55676ca | 2019-01-28 22:00:05 -0800 | [diff] [blame] | 131 | const char* kKernelLogMonitorBinary = "kernel_log_monitor_binary"; |
Cody Schuffelen | 17b3472 | 2019-01-28 22:57:14 -0800 | [diff] [blame] | 132 | |
| 133 | const char* kEnableVncServer = "enable_vnc_server"; |
| 134 | const char* kVncServerBinary = "vnc_server_binary"; |
| 135 | const char* kVncServerPort = "vnc_server_port"; |
| 136 | |
| 137 | const char* kEnableStreamAudio = "enable_stream_audio"; |
| 138 | const char* kStreamAudioBinary = "stream_audio_binary"; |
| 139 | const char* kStreamAudioPort = "stream_audio_port"; |
Cody Schuffelen | d12e0c9 | 2019-01-29 15:44:45 -0800 | [diff] [blame] | 140 | |
| 141 | const char* kRestartSubprocesses = "restart_subprocesses"; |
Cody Schuffelen | 1f08d97 | 2019-01-29 16:21:12 -0800 | [diff] [blame] | 142 | const char* kRunAdbConnector = "run_adb_connector"; |
| 143 | const char* kAdbConnectorBinary = "adb_connector_binary"; |
| 144 | const char* kVirtualUsbManagerBinary = "virtual_usb_manager_binary"; |
| 145 | const char* kSocketForwardProxyBinary = "socket_forward_proxy_binary"; |
| 146 | const char* kSocketVsockProxyBinary = "socket_vsock_proxy_binary"; |
Cody Schuffelen | 5024973 | 2019-01-29 16:42:55 -0800 | [diff] [blame] | 147 | |
| 148 | const char* kRunAsDaemon = "run_as_daemon"; |
Cody Schuffelen | 3a64095 | 2019-01-29 17:14:41 -0800 | [diff] [blame] | 149 | const char* kRunE2eTest = "run_e2e_test"; |
| 150 | const char* kE2eTestBinary = "e2e_test_binary"; |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 151 | |
| 152 | const char* kDataPolicy = "data_policy"; |
| 153 | const char* kBlankDataImageMb = "blank_data_image_mb"; |
| 154 | const char* kBlankDataImageFmt = "blank_data_image_fmt"; |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 155 | |
| 156 | const char* kLogcatMode = "logcat_mode"; |
| 157 | const char* kLogcatVsockPort = "logcat_vsock_mode"; |
| 158 | const char* kLogcatReceiverBinary = "logcat_receiver_binary"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 159 | } // namespace |
| 160 | |
| 161 | namespace vsoc { |
| 162 | |
| 163 | std::string CuttlefishConfig::instance_dir() const { |
| 164 | return (*dictionary_)[kInstanceDir].asString(); |
| 165 | } |
| 166 | void CuttlefishConfig::set_instance_dir(const std::string& instance_dir) { |
| 167 | (*dictionary_)[kInstanceDir] = instance_dir; |
| 168 | } |
| 169 | |
Jorge E. Moreira | 8832283 | 2018-07-22 16:41:01 -0700 | [diff] [blame] | 170 | std::string CuttlefishConfig::vm_manager() const { |
| 171 | return (*dictionary_)[kVmManager].asString(); |
| 172 | } |
| 173 | void CuttlefishConfig::set_vm_manager(const std::string& name) { |
Ryan Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 174 | (*dictionary_)[kVmManager] = name; |
Jorge E. Moreira | 8832283 | 2018-07-22 16:41:01 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 177 | std::string CuttlefishConfig::hardware_name() const { |
| 178 | return (*dictionary_)[kHardwareName].asString(); |
| 179 | } |
| 180 | void CuttlefishConfig::set_hardware_name(const std::string& name) { |
| 181 | (*dictionary_)[kHardwareName] = name; |
| 182 | } |
| 183 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 184 | std::string CuttlefishConfig::serial_number() const { |
| 185 | return (*dictionary_)[kSerialNumber].asString(); |
| 186 | } |
| 187 | void CuttlefishConfig::set_serial_number(const std::string& serial_number) { |
| 188 | (*dictionary_)[kSerialNumber] = serial_number; |
| 189 | } |
| 190 | |
| 191 | int CuttlefishConfig::cpus() const { return (*dictionary_)[kCpus].asInt(); } |
| 192 | void CuttlefishConfig::set_cpus(int cpus) { (*dictionary_)[kCpus] = cpus; } |
| 193 | |
| 194 | int CuttlefishConfig::memory_mb() const { |
| 195 | return (*dictionary_)[kMemoryMb].asInt(); |
| 196 | } |
| 197 | void CuttlefishConfig::set_memory_mb(int memory_mb) { |
| 198 | (*dictionary_)[kMemoryMb] = memory_mb; |
| 199 | } |
| 200 | |
| 201 | int CuttlefishConfig::dpi() const { return (*dictionary_)[kDpi].asInt(); } |
| 202 | void CuttlefishConfig::set_dpi(int dpi) { (*dictionary_)[kDpi] = dpi; } |
| 203 | |
| 204 | int CuttlefishConfig::x_res() const { return (*dictionary_)[kXRes].asInt(); } |
| 205 | void CuttlefishConfig::set_x_res(int x_res) { (*dictionary_)[kXRes] = x_res; } |
| 206 | |
| 207 | int CuttlefishConfig::y_res() const { return (*dictionary_)[kYRes].asInt(); } |
| 208 | void CuttlefishConfig::set_y_res(int y_res) { (*dictionary_)[kYRes] = y_res; } |
| 209 | |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 210 | int CuttlefishConfig::num_screen_buffers() const { |
| 211 | return (*dictionary_)[kNumScreenBuffers].asInt(); |
| 212 | } |
| 213 | void CuttlefishConfig::set_num_screen_buffers(int num_screen_buffers) { |
| 214 | (*dictionary_)[kNumScreenBuffers] = num_screen_buffers; |
| 215 | } |
| 216 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 217 | int CuttlefishConfig::refresh_rate_hz() const { |
| 218 | return (*dictionary_)[kRefreshRateHz].asInt(); |
| 219 | } |
| 220 | void CuttlefishConfig::set_refresh_rate_hz(int refresh_rate_hz) { |
| 221 | (*dictionary_)[kRefreshRateHz] = refresh_rate_hz; |
| 222 | } |
| 223 | |
| 224 | std::string CuttlefishConfig::kernel_image_path() const { |
| 225 | return (*dictionary_)[kKernelImagePath].asString(); |
| 226 | } |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 227 | |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 228 | void 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. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 235 | void CuttlefishConfig::set_kernel_image_path( |
| 236 | const std::string& kernel_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 237 | SetPath(kKernelImagePath, kernel_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Cody Schuffelen | e13a78a | 2019-01-29 14:51:26 -0800 | [diff] [blame] | 240 | bool CuttlefishConfig::use_unpacked_kernel() const { |
| 241 | return (*dictionary_)[kUseUnpackedKernel].asBool(); |
| 242 | } |
| 243 | |
| 244 | void CuttlefishConfig::set_use_unpacked_kernel(bool use_unpacked_kernel) { |
| 245 | (*dictionary_)[kUseUnpackedKernel] = use_unpacked_kernel; |
| 246 | } |
| 247 | |
Jorge E. Moreira | 80ddd7f | 2019-02-04 16:30:13 -0800 | [diff] [blame] | 248 | bool CuttlefishConfig::decompress_kernel() const { |
| 249 | return (*dictionary_)[kDecompressKernel].asBool(); |
| 250 | } |
| 251 | void CuttlefishConfig::set_decompress_kernel(bool decompress_kernel) { |
| 252 | (*dictionary_)[kDecompressKernel] = decompress_kernel; |
| 253 | } |
| 254 | |
| 255 | std::string CuttlefishConfig::decompressed_kernel_image_path() const { |
| 256 | return (*dictionary_)[kDecompressedKernelImagePath].asString(); |
| 257 | } |
| 258 | void CuttlefishConfig::set_decompressed_kernel_image_path( |
| 259 | const std::string& path) { |
| 260 | SetPath(kDecompressedKernelImagePath, path); |
| 261 | } |
| 262 | |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 263 | std::string CuttlefishConfig::gdb_flag() const { |
| 264 | return (*dictionary_)[kGdbFlag].asString(); |
| 265 | } |
| 266 | |
Ryan Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 267 | void CuttlefishConfig::set_gdb_flag(const std::string& device) { |
Matthias Maennich | ac14e1e | 2019-02-06 16:25:42 +0000 | [diff] [blame] | 268 | (*dictionary_)[kGdbFlag] = device; |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 271 | std::set<std::string> CuttlefishConfig::kernel_cmdline() const { |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 272 | std::set<std::string> args_set; |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 273 | auto args_json_obj = (*dictionary_)[kKernelCmdline]; |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 274 | 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. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 278 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 279 | void CuttlefishConfig::set_kernel_cmdline( |
| 280 | const std::set<std::string>& kernel_cmdline) { |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 281 | Json::Value args_json_obj(Json::arrayValue); |
Chih-Hung Hsieh | 90c1dcc | 2018-12-12 13:43:34 -0800 | [diff] [blame] | 282 | for (const auto& arg : kernel_cmdline) { |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 283 | args_json_obj.append(arg); |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 284 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 285 | (*dictionary_)[kKernelCmdline] = args_json_obj; |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 286 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 287 | void CuttlefishConfig::add_kernel_cmdline( |
| 288 | const std::set<std::string>& extra_args) { |
| 289 | std::set<std::string> cmdline = kernel_cmdline(); |
Chih-Hung Hsieh | 90c1dcc | 2018-12-12 13:43:34 -0800 | [diff] [blame] | 290 | for (const auto& arg : extra_args) { |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 291 | if (cmdline.count(arg)) { |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 292 | LOG(ERROR) << "Kernel argument " << arg << " is duplicated"; |
| 293 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 294 | cmdline.insert(arg); |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 295 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 296 | set_kernel_cmdline(cmdline); |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 297 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 298 | void 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 Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 301 | using is_iter = std::istream_iterator<std::string>; |
| 302 | std::copy(is_iter(args_stream), is_iter(), |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 303 | std::inserter(kernel_cmdline_set, kernel_cmdline_set.begin())); |
| 304 | add_kernel_cmdline(kernel_cmdline_set); |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 305 | } |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 306 | std::string CuttlefishConfig::kernel_cmdline_as_string() const { |
| 307 | auto args_set = kernel_cmdline(); |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 308 | 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. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | std::string CuttlefishConfig::ramdisk_image_path() const { |
| 315 | return (*dictionary_)[kRamdiskImagePath].asString(); |
| 316 | } |
| 317 | void CuttlefishConfig::set_ramdisk_image_path( |
| 318 | const std::string& ramdisk_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 319 | SetPath(kRamdiskImagePath, ramdisk_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | std::string CuttlefishConfig::system_image_path() const { |
| 323 | return (*dictionary_)[kSystemImagePath].asString(); |
| 324 | } |
| 325 | void CuttlefishConfig::set_system_image_path( |
| 326 | const std::string& system_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 327 | SetPath(kSystemImagePath, system_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | std::string CuttlefishConfig::cache_image_path() const { |
| 331 | return (*dictionary_)[kCacheImagePath].asString(); |
| 332 | } |
| 333 | void CuttlefishConfig::set_cache_image_path( |
| 334 | const std::string& cache_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 335 | SetPath(kCacheImagePath, cache_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | std::string CuttlefishConfig::data_image_path() const { |
| 339 | return (*dictionary_)[kDataImagePath].asString(); |
| 340 | } |
| 341 | void CuttlefishConfig::set_data_image_path(const std::string& data_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 342 | SetPath(kDataImagePath, data_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | std::string CuttlefishConfig::vendor_image_path() const { |
| 346 | return (*dictionary_)[kVendorImagePath].asString(); |
| 347 | } |
| 348 | void CuttlefishConfig::set_vendor_image_path( |
| 349 | const std::string& vendor_image_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 350 | SetPath(kVendorImagePath, vendor_image_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | std::string CuttlefishConfig::dtb_path() const { |
| 354 | return (*dictionary_)[kDtbPath].asString(); |
| 355 | } |
| 356 | void CuttlefishConfig::set_dtb_path(const std::string& dtb_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 357 | SetPath(kDtbPath, dtb_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 360 | std::string CuttlefishConfig::gsi_fstab_path() const { |
| 361 | return (*dictionary_)[kGsiFstabPath].asString(); |
| 362 | } |
| 363 | void CuttlefishConfig::set_gsi_fstab_path(const std::string& path){ |
| 364 | SetPath(kGsiFstabPath, path); |
| 365 | } |
| 366 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 367 | std::string CuttlefishConfig::mempath() const { |
| 368 | return (*dictionary_)[kMempath].asString(); |
| 369 | } |
| 370 | void CuttlefishConfig::set_mempath(const std::string& mempath) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 371 | SetPath(kMempath, mempath); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | std::string CuttlefishConfig::ivshmem_qemu_socket_path() const { |
| 375 | return (*dictionary_)[kIvshmemQemuSocketPath].asString(); |
| 376 | } |
| 377 | void CuttlefishConfig::set_ivshmem_qemu_socket_path( |
| 378 | const std::string& ivshmem_qemu_socket_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 379 | SetPath(kIvshmemQemuSocketPath, ivshmem_qemu_socket_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | std::string CuttlefishConfig::ivshmem_client_socket_path() const { |
| 383 | return (*dictionary_)[kIvshmemClientSocketPath].asString(); |
| 384 | } |
| 385 | void CuttlefishConfig::set_ivshmem_client_socket_path( |
| 386 | const std::string& ivshmem_client_socket_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 387 | SetPath(kIvshmemClientSocketPath, ivshmem_client_socket_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | int CuttlefishConfig::ivshmem_vector_count() const { |
| 391 | return (*dictionary_)[kIvshmemVectorCount].asInt(); |
| 392 | } |
| 393 | void CuttlefishConfig::set_ivshmem_vector_count(int ivshmem_vector_count) { |
| 394 | (*dictionary_)[kIvshmemVectorCount] = ivshmem_vector_count; |
| 395 | } |
| 396 | |
| 397 | std::string CuttlefishConfig::usb_v1_socket_name() const { |
| 398 | return (*dictionary_)[kUsbV1SocketName].asString(); |
| 399 | } |
| 400 | void CuttlefishConfig::set_usb_v1_socket_name( |
| 401 | const std::string& usb_v1_socket_name) { |
| 402 | (*dictionary_)[kUsbV1SocketName] = usb_v1_socket_name; |
| 403 | } |
| 404 | |
| 405 | int CuttlefishConfig::vhci_port() const { |
| 406 | return (*dictionary_)[kVhciPort].asInt(); |
| 407 | } |
| 408 | void CuttlefishConfig::set_vhci_port(int vhci_port) { |
| 409 | (*dictionary_)[kVhciPort] = vhci_port; |
| 410 | } |
| 411 | |
| 412 | std::string CuttlefishConfig::usb_ip_socket_name() const { |
| 413 | return (*dictionary_)[kUsbIpSocketName].asString(); |
| 414 | } |
| 415 | void CuttlefishConfig::set_usb_ip_socket_name( |
| 416 | const std::string& usb_ip_socket_name) { |
| 417 | (*dictionary_)[kUsbIpSocketName] = usb_ip_socket_name; |
| 418 | } |
| 419 | |
| 420 | std::string CuttlefishConfig::kernel_log_socket_name() const { |
| 421 | return (*dictionary_)[kKernelLogSocketName].asString(); |
| 422 | } |
| 423 | void 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. Moreira | 81afca1 | 2018-07-26 16:48:49 -0700 | [diff] [blame] | 428 | bool CuttlefishConfig::deprecated_boot_completed() const { |
| 429 | return (*dictionary_)[kDeprecatedBootCompleted].asBool(); |
| 430 | } |
| 431 | void CuttlefishConfig::set_deprecated_boot_completed( |
| 432 | bool deprecated_boot_completed) { |
| 433 | (*dictionary_)[kDeprecatedBootCompleted] = deprecated_boot_completed; |
| 434 | } |
| 435 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 436 | std::string CuttlefishConfig::console_path() const { |
| 437 | return (*dictionary_)[kConsolePath].asString(); |
| 438 | } |
| 439 | void CuttlefishConfig::set_console_path(const std::string& console_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 440 | SetPath(kConsolePath, console_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | std::string CuttlefishConfig::logcat_path() const { |
| 444 | return (*dictionary_)[kLogcatPath].asString(); |
| 445 | } |
| 446 | void CuttlefishConfig::set_logcat_path(const std::string& logcat_path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 447 | SetPath(kLogcatPath, logcat_path); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Jorge E. Moreira | 50a0775 | 2018-07-18 18:49:04 -0700 | [diff] [blame] | 450 | std::string CuttlefishConfig::launcher_monitor_socket_path() const { |
| 451 | return (*dictionary_)[kLauncherMonitorPath].asString(); |
| 452 | } |
| 453 | void CuttlefishConfig::set_launcher_monitor_socket_path( |
Jorge E. Moreira | be7049a | 2018-07-26 18:12:13 -0700 | [diff] [blame] | 454 | const std::string& launcher_monitor_path) { |
| 455 | SetPath(kLauncherMonitorPath, launcher_monitor_path); |
Jorge E. Moreira | 50a0775 | 2018-07-18 18:49:04 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Jorge E. Moreira | 66f6ec8 | 2018-07-16 16:43:15 -0700 | [diff] [blame] | 458 | std::string CuttlefishConfig::launcher_log_path() const { |
| 459 | return (*dictionary_)[kLauncherLogPath].asString(); |
| 460 | } |
| 461 | void CuttlefishConfig::set_launcher_log_path( |
| 462 | const std::string& launcher_log_path) { |
| 463 | (*dictionary_)[kLauncherLogPath] = launcher_log_path; |
| 464 | } |
| 465 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 466 | std::string CuttlefishConfig::mobile_bridge_name() const { |
| 467 | return (*dictionary_)[kMobileBridgeName].asString(); |
| 468 | } |
| 469 | void CuttlefishConfig::set_mobile_bridge_name( |
| 470 | const std::string& mobile_bridge_name) { |
| 471 | (*dictionary_)[kMobileBridgeName] = mobile_bridge_name; |
| 472 | } |
| 473 | |
Cody Schuffelen | 975175a | 2018-06-14 18:20:02 -0700 | [diff] [blame] | 474 | std::string CuttlefishConfig::wifi_bridge_name() const { |
| 475 | return (*dictionary_)[kWifiBridgeName].asString(); |
| 476 | } |
| 477 | void CuttlefishConfig::set_wifi_bridge_name( |
| 478 | const std::string& wifi_bridge_name) { |
| 479 | (*dictionary_)[kWifiBridgeName] = wifi_bridge_name; |
| 480 | } |
| 481 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 482 | std::string CuttlefishConfig::wifi_guest_mac_addr() const { |
| 483 | return (*dictionary_)[kWifiGuestMacAddr].asString(); |
| 484 | } |
| 485 | void CuttlefishConfig::set_wifi_guest_mac_addr( |
| 486 | const std::string& wifi_guest_mac_addr) { |
| 487 | (*dictionary_)[kWifiGuestMacAddr] = wifi_guest_mac_addr; |
| 488 | } |
| 489 | |
| 490 | std::string CuttlefishConfig::wifi_host_mac_addr() const { |
| 491 | return (*dictionary_)[kWifiHostMacAddr].asString(); |
| 492 | } |
| 493 | void CuttlefishConfig::set_wifi_host_mac_addr( |
| 494 | const std::string& wifi_host_mac_addr) { |
| 495 | (*dictionary_)[kWifiHostMacAddr] = wifi_host_mac_addr; |
| 496 | } |
| 497 | |
| 498 | std::string CuttlefishConfig::mobile_tap_name() const { |
| 499 | return (*dictionary_)[kMobileTapName].asString(); |
| 500 | } |
| 501 | void CuttlefishConfig::set_mobile_tap_name(const std::string& mobile_tap_name) { |
| 502 | (*dictionary_)[kMobileTapName] = mobile_tap_name; |
| 503 | } |
| 504 | |
Cody Schuffelen | 975175a | 2018-06-14 18:20:02 -0700 | [diff] [blame] | 505 | std::string CuttlefishConfig::wifi_tap_name() const { |
| 506 | return (*dictionary_)[kWifiTapName].asString(); |
| 507 | } |
| 508 | void CuttlefishConfig::set_wifi_tap_name(const std::string& wifi_tap_name) { |
| 509 | (*dictionary_)[kWifiTapName] = wifi_tap_name; |
| 510 | } |
| 511 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 512 | std::string CuttlefishConfig::entropy_source() const { |
| 513 | return (*dictionary_)[kEntropySource].asString(); |
| 514 | } |
| 515 | void CuttlefishConfig::set_entropy_source(const std::string& entropy_source) { |
| 516 | (*dictionary_)[kEntropySource] = entropy_source; |
| 517 | } |
| 518 | |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 519 | int CuttlefishConfig::vsock_guest_cid() const { |
| 520 | return (*dictionary_)[kVsockGuestCid].asInt(); |
| 521 | } |
| 522 | |
| 523 | void CuttlefishConfig::set_vsock_guest_cid(int vsock_guest_cid) { |
| 524 | (*dictionary_)[kVsockGuestCid] = vsock_guest_cid; |
| 525 | } |
| 526 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 527 | std::string CuttlefishConfig::uuid() const { |
| 528 | return (*dictionary_)[kUuid].asString(); |
| 529 | } |
| 530 | void CuttlefishConfig::set_uuid(const std::string& uuid) { |
| 531 | (*dictionary_)[kUuid] = uuid; |
| 532 | } |
| 533 | |
Greg Hartman | 6abdbb9 | 2018-05-24 09:49:00 -0700 | [diff] [blame] | 534 | void CuttlefishConfig::set_cuttlefish_env_path(const std::string& path) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 535 | SetPath(kCuttlefishEnvPath, path); |
Greg Hartman | 6abdbb9 | 2018-05-24 09:49:00 -0700 | [diff] [blame] | 536 | } |
| 537 | std::string CuttlefishConfig::cuttlefish_env_path() const { |
| 538 | return (*dictionary_)[kCuttlefishEnvPath].asString(); |
| 539 | } |
| 540 | |
Ryan Haining | 4a1abea | 2018-07-10 16:20:19 -0700 | [diff] [blame] | 541 | std::string CuttlefishConfig::adb_mode() const { |
| 542 | return (*dictionary_)[kAdbMode].asString(); |
| 543 | } |
| 544 | |
| 545 | void CuttlefishConfig::set_adb_mode(const std::string& mode) { |
| 546 | (*dictionary_)[kAdbMode] = mode; |
| 547 | } |
| 548 | |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 549 | std::string CuttlefishConfig::adb_ip_and_port() const { |
| 550 | return (*dictionary_)[kAdbIPAndPort].asString(); |
| 551 | } |
| 552 | |
| 553 | void CuttlefishConfig::set_adb_ip_and_port(const std::string& ip_port) { |
| 554 | (*dictionary_)[kAdbIPAndPort] = ip_port; |
| 555 | } |
| 556 | |
| 557 | std::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 Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 567 | std::string CuttlefishConfig::device_title() const { |
| 568 | return (*dictionary_)[kDeviceTitle].asString(); |
| 569 | } |
| 570 | |
| 571 | void CuttlefishConfig::set_device_title(const std::string& title) { |
| 572 | (*dictionary_)[kDeviceTitle] = title; |
| 573 | } |
| 574 | |
Greg Hartman | f1f28c5 | 2018-09-20 17:19:19 -0700 | [diff] [blame] | 575 | std::string CuttlefishConfig::setupwizard_mode() const { |
| 576 | return (*dictionary_)[kSetupWizardMode].asString(); |
| 577 | } |
| 578 | |
| 579 | void CuttlefishConfig::set_setupwizard_mode(const std::string& mode) { |
| 580 | (*dictionary_)[kSetupWizardMode] = mode; |
| 581 | } |
| 582 | |
Cody Schuffelen | 5898003 | 2018-10-11 17:11:13 -0700 | [diff] [blame] | 583 | std::string CuttlefishConfig::qemu_binary() const { |
| 584 | return (*dictionary_)[kQemuBinary].asString(); |
| 585 | } |
| 586 | |
| 587 | void CuttlefishConfig::set_qemu_binary(const std::string& qemu_binary) { |
| 588 | (*dictionary_)[kQemuBinary] = qemu_binary; |
| 589 | } |
| 590 | |
Jorge E. Moreira | ba62662 | 2019-01-28 17:47:50 -0800 | [diff] [blame] | 591 | std::string CuttlefishConfig::crosvm_binary() const { |
| 592 | return (*dictionary_)[kCrosvmBinary].asString(); |
| 593 | } |
| 594 | |
| 595 | void CuttlefishConfig::set_crosvm_binary(const std::string& crosvm_binary) { |
| 596 | (*dictionary_)[kCrosvmBinary] = crosvm_binary; |
| 597 | } |
| 598 | |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 599 | std::string CuttlefishConfig::ivserver_binary() const { |
| 600 | return (*dictionary_)[kIvServerBinary].asString(); |
| 601 | } |
| 602 | |
| 603 | void CuttlefishConfig::set_ivserver_binary(const std::string& ivserver_binary) { |
| 604 | (*dictionary_)[kIvServerBinary] = ivserver_binary; |
| 605 | } |
| 606 | |
Cody Schuffelen | 55676ca | 2019-01-28 22:00:05 -0800 | [diff] [blame] | 607 | std::string CuttlefishConfig::kernel_log_monitor_binary() const { |
| 608 | return (*dictionary_)[kKernelLogMonitorBinary].asString(); |
| 609 | } |
| 610 | |
| 611 | void CuttlefishConfig::set_kernel_log_monitor_binary( |
| 612 | const std::string& kernel_log_monitor_binary) { |
| 613 | (*dictionary_)[kKernelLogMonitorBinary] = kernel_log_monitor_binary; |
| 614 | } |
| 615 | |
Cody Schuffelen | 17b3472 | 2019-01-28 22:57:14 -0800 | [diff] [blame] | 616 | bool CuttlefishConfig::enable_vnc_server() const { |
| 617 | return (*dictionary_)[kEnableVncServer].asBool(); |
| 618 | } |
| 619 | |
| 620 | void CuttlefishConfig::set_enable_vnc_server(bool enable_vnc_server) { |
| 621 | (*dictionary_)[kEnableVncServer] = enable_vnc_server; |
| 622 | } |
| 623 | |
| 624 | std::string CuttlefishConfig::vnc_server_binary() const { |
| 625 | return (*dictionary_)[kVncServerBinary].asString(); |
| 626 | } |
| 627 | |
| 628 | void CuttlefishConfig::set_vnc_server_binary( |
| 629 | const std::string& vnc_server_binary) { |
| 630 | (*dictionary_)[kVncServerBinary] = vnc_server_binary; |
| 631 | } |
| 632 | |
| 633 | int CuttlefishConfig::vnc_server_port() const { |
| 634 | return (*dictionary_)[kVncServerPort].asInt(); |
| 635 | } |
| 636 | |
| 637 | void CuttlefishConfig::set_vnc_server_port(int vnc_server_port) { |
| 638 | (*dictionary_)[kVncServerPort] = vnc_server_port; |
| 639 | } |
| 640 | |
| 641 | bool CuttlefishConfig::enable_stream_audio() const { |
| 642 | return (*dictionary_)[kEnableStreamAudio].asBool(); |
| 643 | } |
| 644 | |
| 645 | void CuttlefishConfig::set_enable_stream_audio(bool enable_stream_audio) { |
| 646 | (*dictionary_)[kEnableStreamAudio] = enable_stream_audio; |
| 647 | } |
| 648 | |
| 649 | std::string CuttlefishConfig::stream_audio_binary() const { |
| 650 | return (*dictionary_)[kStreamAudioBinary].asString(); |
| 651 | } |
| 652 | |
| 653 | void CuttlefishConfig::set_stream_audio_binary( |
| 654 | const std::string& stream_audio_binary) { |
| 655 | (*dictionary_)[kStreamAudioBinary] = stream_audio_binary; |
| 656 | } |
| 657 | |
| 658 | int CuttlefishConfig::stream_audio_port() const { |
| 659 | return (*dictionary_)[kStreamAudioPort].asInt(); |
| 660 | } |
| 661 | |
| 662 | void CuttlefishConfig::set_stream_audio_port(int stream_audio_port) { |
| 663 | (*dictionary_)[kStreamAudioPort] = stream_audio_port; |
| 664 | } |
| 665 | |
Cody Schuffelen | d12e0c9 | 2019-01-29 15:44:45 -0800 | [diff] [blame] | 666 | bool CuttlefishConfig::restart_subprocesses() const { |
| 667 | return (*dictionary_)[kRestartSubprocesses].asBool(); |
| 668 | } |
| 669 | |
| 670 | void CuttlefishConfig::set_restart_subprocesses(bool restart_subprocesses) { |
| 671 | (*dictionary_)[kRestartSubprocesses] = restart_subprocesses; |
| 672 | } |
| 673 | |
Cody Schuffelen | 1f08d97 | 2019-01-29 16:21:12 -0800 | [diff] [blame] | 674 | bool CuttlefishConfig::run_adb_connector() const { |
Jorge E. Moreira | b86922b | 2019-02-04 10:52:58 -0800 | [diff] [blame] | 675 | return (*dictionary_)[kRunAdbConnector].asBool(); |
Cody Schuffelen | 1f08d97 | 2019-01-29 16:21:12 -0800 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | void CuttlefishConfig::set_run_adb_connector(bool run_adb_connector) { |
| 679 | (*dictionary_)[kRunAdbConnector] = run_adb_connector; |
| 680 | } |
| 681 | |
| 682 | std::string CuttlefishConfig::adb_connector_binary() const { |
| 683 | return (*dictionary_)[kAdbConnectorBinary].asString(); |
| 684 | } |
| 685 | |
| 686 | void CuttlefishConfig::set_adb_connector_binary( |
| 687 | const std::string& adb_connector_binary) { |
| 688 | (*dictionary_)[kAdbConnectorBinary] = adb_connector_binary; |
| 689 | } |
| 690 | |
| 691 | std::string CuttlefishConfig::virtual_usb_manager_binary() const { |
| 692 | return (*dictionary_)[kVirtualUsbManagerBinary].asString(); |
| 693 | } |
| 694 | |
| 695 | void CuttlefishConfig::set_virtual_usb_manager_binary( |
| 696 | const std::string& virtual_usb_manager_binary) { |
| 697 | (*dictionary_)[kVirtualUsbManagerBinary] = virtual_usb_manager_binary; |
| 698 | } |
| 699 | |
| 700 | std::string CuttlefishConfig::socket_forward_proxy_binary() const { |
| 701 | return (*dictionary_)[kSocketForwardProxyBinary].asString(); |
| 702 | } |
| 703 | |
| 704 | void CuttlefishConfig::set_socket_forward_proxy_binary( |
| 705 | const std::string& socket_forward_proxy_binary) { |
| 706 | (*dictionary_)[kSocketForwardProxyBinary] = socket_forward_proxy_binary; |
| 707 | } |
| 708 | |
| 709 | std::string CuttlefishConfig::socket_vsock_proxy_binary() const { |
| 710 | return (*dictionary_)[kSocketVsockProxyBinary].asString(); |
| 711 | } |
| 712 | |
| 713 | void CuttlefishConfig::set_socket_vsock_proxy_binary( |
| 714 | const std::string& socket_vsock_proxy_binary) { |
| 715 | (*dictionary_)[kSocketVsockProxyBinary] = socket_vsock_proxy_binary; |
| 716 | } |
| 717 | |
Cody Schuffelen | 5024973 | 2019-01-29 16:42:55 -0800 | [diff] [blame] | 718 | bool CuttlefishConfig::run_as_daemon() const { |
| 719 | return (*dictionary_)[kRunAsDaemon].asBool(); |
| 720 | } |
| 721 | |
| 722 | void CuttlefishConfig::set_run_as_daemon(bool run_as_daemon) { |
| 723 | (*dictionary_)[kRunAsDaemon] = run_as_daemon; |
| 724 | } |
| 725 | |
Cody Schuffelen | 3a64095 | 2019-01-29 17:14:41 -0800 | [diff] [blame] | 726 | bool CuttlefishConfig::run_e2e_test() const { |
| 727 | return (*dictionary_)[kRunE2eTest].asBool(); |
| 728 | } |
| 729 | |
| 730 | void CuttlefishConfig::set_run_e2e_test(bool run_e2e_test) { |
| 731 | (*dictionary_)[kRunE2eTest] = run_e2e_test; |
| 732 | } |
| 733 | |
| 734 | std::string CuttlefishConfig::e2e_test_binary() const { |
| 735 | return (*dictionary_)[kE2eTestBinary].asString(); |
| 736 | } |
| 737 | |
| 738 | void CuttlefishConfig::set_e2e_test_binary(const std::string& e2e_test_binary) { |
| 739 | (*dictionary_)[kE2eTestBinary] = e2e_test_binary; |
| 740 | } |
| 741 | |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 742 | std::string CuttlefishConfig::data_policy() const { |
| 743 | return (*dictionary_)[kDataPolicy].asString(); |
| 744 | } |
| 745 | |
| 746 | void CuttlefishConfig::set_data_policy(const std::string& data_policy) { |
| 747 | (*dictionary_)[kDataPolicy] = data_policy; |
| 748 | } |
| 749 | |
| 750 | int CuttlefishConfig::blank_data_image_mb() const { |
Cody Schuffelen | e3269ed | 2019-02-11 18:38:42 -0800 | [diff] [blame] | 751 | return (*dictionary_)[kBlankDataImageMb].asInt(); |
Cody Schuffelen | 2b51bab | 2019-01-29 18:14:48 -0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void CuttlefishConfig::set_blank_data_image_mb(int blank_data_image_mb) { |
| 755 | (*dictionary_)[kBlankDataImageMb] = blank_data_image_mb; |
| 756 | } |
| 757 | |
| 758 | std::string CuttlefishConfig::blank_data_image_fmt() const { |
| 759 | return (*dictionary_)[kBlankDataImageFmt].asString(); |
| 760 | } |
| 761 | |
| 762 | void CuttlefishConfig::set_blank_data_image_fmt(const std::string& blank_data_image_fmt) { |
| 763 | (*dictionary_)[kBlankDataImageFmt] = blank_data_image_fmt; |
| 764 | } |
| 765 | |
Jorge E. Moreira | f4b202b | 2019-02-05 17:51:06 -0800 | [diff] [blame] | 766 | |
Jorge E. Moreira | fd10cae | 2019-02-19 15:35:42 -0800 | [diff] [blame] | 767 | void CuttlefishConfig::set_logcat_mode(const std::string& mode) { |
| 768 | (*dictionary_)[kLogcatMode] = mode; |
| 769 | } |
| 770 | |
| 771 | std::string CuttlefishConfig::logcat_mode() const { |
| 772 | return (*dictionary_)[kLogcatMode].asString(); |
| 773 | } |
| 774 | |
| 775 | void CuttlefishConfig::set_logcat_vsock_port(int port) { |
| 776 | (*dictionary_)[kLogcatVsockPort] = port; |
| 777 | } |
| 778 | |
| 779 | int CuttlefishConfig::logcat_vsock_port() const { |
| 780 | return (*dictionary_)[kLogcatVsockPort].asInt(); |
| 781 | } |
| 782 | |
| 783 | void CuttlefishConfig::set_logcat_receiver_binary(const std::string& binary) { |
| 784 | SetPath(kLogcatReceiverBinary, binary); |
| 785 | } |
| 786 | |
| 787 | std::string CuttlefishConfig::logcat_receiver_binary() const { |
| 788 | return (*dictionary_)[kLogcatReceiverBinary].asString(); |
| 789 | } |
| 790 | |
| 791 | |
Jorge E. Moreira | f4b202b | 2019-02-05 17:51:06 -0800 | [diff] [blame] | 792 | bool CuttlefishConfig::enable_ivserver() const { |
Jorge E. Moreira | fd1a6b0 | 2019-02-27 16:25:00 -0800 | [diff] [blame^] | 793 | return hardware_name() == "cutf_ivsh"; |
Jorge E. Moreira | f4b202b | 2019-02-05 17:51:06 -0800 | [diff] [blame] | 794 | } |
| 795 | |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 796 | // Creates the (initially empty) config object and populates it with values from |
Cody Schuffelen | f219a16 | 2018-10-11 19:01:57 -0700 | [diff] [blame] | 797 | // the config file if the CUTTLEFISH_CONFIG_FILE env variable is present. |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 798 | // Returns nullptr if there was an error loading from file |
| 799 | /*static*/ CuttlefishConfig* CuttlefishConfig::BuildConfigImpl() { |
Jorge E. Moreira | a00584e | 2018-10-25 15:07:52 -0700 | [diff] [blame] | 800 | auto config_file_path = cvd::StringFromEnv(kCuttlefishConfigEnvVarName, |
| 801 | vsoc::GetGlobalConfigFileLink()); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 802 | auto ret = new CuttlefishConfig(); |
Jorge E. Moreira | a00584e | 2018-10-25 15:07:52 -0700 | [diff] [blame] | 803 | if (ret) { |
| 804 | auto loaded = ret->LoadFromFile(config_file_path.c_str()); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 805 | if (!loaded) { |
Cody Schuffelen | f219a16 | 2018-10-11 19:01:57 -0700 | [diff] [blame] | 806 | delete ret; |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 807 | return nullptr; |
| 808 | } |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 809 | } |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 810 | return ret; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 813 | /*static*/ CuttlefishConfig* CuttlefishConfig::Get() { |
| 814 | static std::shared_ptr<CuttlefishConfig> config(BuildConfigImpl()); |
| 815 | return config.get(); |
| 816 | } |
| 817 | |
| 818 | CuttlefishConfig::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 |
| 821 | CuttlefishConfig::~CuttlefishConfig() {} |
| 822 | |
| 823 | bool CuttlefishConfig::LoadFromFile(const char* file) { |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 824 | auto real_file_path = cvd::AbsolutePath(file); |
Ryan Haining | 10e4231 | 2018-07-17 12:11:52 -0700 | [diff] [blame] | 825 | if (real_file_path.empty()) { |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 826 | LOG(ERROR) << "Could not get real path for file " << file; |
| 827 | return false; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 828 | } |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 829 | Json::Reader reader; |
| 830 | std::ifstream ifs(real_file_path); |
| 831 | if (!reader.parse(ifs, *dictionary_)) { |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 832 | LOG(ERROR) << "Could not read config file " << file << ": " |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 833 | << reader.getFormattedErrorMessages(); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 834 | return false; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 835 | } |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 836 | return true; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 837 | } |
| 838 | bool 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 | |
| 848 | std::string CuttlefishConfig::PerInstancePath(const char* file_name) const { |
| 849 | return (instance_dir() + "/") + file_name; |
| 850 | } |
| 851 | |
| 852 | std::string CuttlefishConfig::instance_name() const { |
| 853 | return GetPerInstanceDefault("cvd-"); |
| 854 | } |
| 855 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 856 | int GetInstance() { |
| 857 | static int instance_id = InstanceFromEnvironment(); |
| 858 | return instance_id; |
| 859 | } |
| 860 | |
Jorge E. Moreira | 015c000 | 2018-07-19 11:01:16 -0700 | [diff] [blame] | 861 | std::string GetGlobalConfigFileLink() { |
| 862 | return cvd::StringFromEnv("HOME", ".") + "/.cuttlefish_config.json"; |
| 863 | } |
| 864 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 865 | std::string GetDomain() { |
| 866 | return CuttlefishConfig::Get()->ivshmem_client_socket_path(); |
| 867 | } |
| 868 | |
| 869 | std::string GetPerInstanceDefault(const char* prefix) { |
| 870 | std::ostringstream stream; |
| 871 | stream << prefix << std::setfill('0') << std::setw(2) << GetInstance(); |
| 872 | return stream.str(); |
| 873 | } |
| 874 | int GetPerInstanceDefault(int base) { return base + GetInstance() - 1; } |
| 875 | |
| 876 | std::string GetDefaultPerInstanceDir() { |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 877 | std::ostringstream stream; |
Jorge E. Moreira | d966837 | 2019-01-28 22:40:42 -0800 | [diff] [blame] | 878 | stream << std::getenv("HOME") << "/cuttlefish_runtime"; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 879 | return stream.str(); |
| 880 | } |
| 881 | |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 882 | std::string GetDefaultMempath() { |
| 883 | return GetPerInstanceDefault("/var/run/shm/cvd-"); |
| 884 | } |
| 885 | |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 886 | int GetDefaultPerInstanceVsockCid() { |
| 887 | constexpr int kFirstGuestCid = 3; |
| 888 | return vsoc::HostSupportsVsock() ? GetPerInstanceDefault(kFirstGuestCid) : 0; |
| 889 | } |
| 890 | |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 891 | std::string DefaultHostArtifactsPath(const std::string& file_name) { |
| 892 | return (cvd::StringFromEnv("ANDROID_HOST_OUT", |
| 893 | cvd::StringFromEnv("HOME", ".")) + |
| 894 | "/") + |
| 895 | file_name; |
| 896 | } |
| 897 | |
| 898 | std::string DefaultGuestImagePath(const std::string& file_name) { |
| 899 | return (cvd::StringFromEnv("ANDROID_PRODUCT_OUT", |
Ryan Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 900 | cvd::StringFromEnv("HOME", ".")) + |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 901 | "/") + |
| 902 | file_name; |
| 903 | } |
| 904 | |
| 905 | bool 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 Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 911 | |
| 912 | bool 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. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 918 | } // namespace vsoc |