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 | #pragma once |
| 17 | |
| 18 | #include <memory> |
| 19 | #include <string> |
Cody Schuffelen | efadb8d | 2018-08-10 16:10:35 -0700 | [diff] [blame] | 20 | #include <set> |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 21 | |
| 22 | namespace Json { |
| 23 | class Value; |
| 24 | } |
| 25 | |
| 26 | namespace vsoc { |
| 27 | |
Jorge E. Moreira | b8dfb99 | 2018-07-22 20:53:56 -0700 | [diff] [blame] | 28 | constexpr char kDefaultUuidPrefix[] = "699acfc4-c8c4-11e7-882b-5065f31dc1"; |
Cody Schuffelen | f219a16 | 2018-10-11 19:01:57 -0700 | [diff] [blame] | 29 | constexpr char kCuttlefishConfigEnvVarName[] = "CUTTLEFISH_CONFIG_FILE"; |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 30 | constexpr char kVsocUserPrefix[] = "vsoc-"; |
Jorge E. Moreira | b8dfb99 | 2018-07-22 20:53:56 -0700 | [diff] [blame] | 31 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 32 | // Holds the configuration of the cuttlefish instances. |
| 33 | class CuttlefishConfig { |
| 34 | public: |
| 35 | static CuttlefishConfig* Get(); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 36 | |
| 37 | CuttlefishConfig(); |
| 38 | ~CuttlefishConfig(); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 39 | |
| 40 | // Saves the configuration object in a file, it can then be read in other |
| 41 | // processes by passing the --config_file option. |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 42 | bool SaveToFile(const std::string& file) const; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 43 | |
| 44 | // Returns the path to a file with the given name in the instance directory.. |
| 45 | std::string PerInstancePath(const char* file_name) const; |
| 46 | |
| 47 | std::string instance_name() const; |
| 48 | |
| 49 | void disable_usb_adb() { |
| 50 | // This seems to be the way usb is being disbled in the launcher |
| 51 | set_usb_v1_socket_name(""); |
| 52 | } |
| 53 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 54 | std::string instance_dir() const; |
| 55 | void set_instance_dir(const std::string& instance_dir); |
| 56 | |
Jorge E. Moreira | 8832283 | 2018-07-22 16:41:01 -0700 | [diff] [blame] | 57 | std::string vm_manager() const; |
| 58 | void set_vm_manager(const std::string& name); |
| 59 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 60 | std::string serial_number() const; |
| 61 | void set_serial_number(const std::string& serial_number); |
| 62 | |
| 63 | int cpus() const; |
| 64 | void set_cpus(int cpus); |
| 65 | |
| 66 | int memory_mb() const; |
| 67 | void set_memory_mb(int memory_mb); |
| 68 | |
| 69 | int dpi() const; |
| 70 | void set_dpi(int dpi); |
| 71 | |
| 72 | int x_res() const; |
| 73 | void set_x_res(int x_res); |
| 74 | |
| 75 | int y_res() const; |
| 76 | void set_y_res(int y_res); |
| 77 | |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 78 | int num_screen_buffers() const; |
| 79 | void set_num_screen_buffers(int num_screen_buffers); |
| 80 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 81 | int refresh_rate_hz() const; |
| 82 | void set_refresh_rate_hz(int refresh_rate_hz); |
| 83 | |
| 84 | std::string kernel_image_path() const; |
| 85 | void set_kernel_image_path(const std::string& kernel_image_path); |
| 86 | |
Jorge E. Moreira | b2427ba | 2018-08-23 17:11:55 -0700 | [diff] [blame] | 87 | std::set<std::string> kernel_cmdline() const; |
| 88 | void set_kernel_cmdline(const std::set<std::string>& kernel_cmdline); |
| 89 | void add_kernel_cmdline(const std::string& arg); |
| 90 | void add_kernel_cmdline(const std::set<std::string>& kernel_cmdline); |
| 91 | std::string kernel_cmdline_as_string() const; |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 92 | |
Greg Hartman | 91f8142 | 2018-07-09 16:04:49 -0700 | [diff] [blame] | 93 | std::string gdb_flag() const; |
| 94 | void set_gdb_flag(const std::string& gdb); |
| 95 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 96 | std::string ramdisk_image_path() const; |
| 97 | void set_ramdisk_image_path(const std::string& ramdisk_image_path); |
| 98 | |
| 99 | std::string system_image_path() const; |
| 100 | void set_system_image_path(const std::string& system_image_path); |
| 101 | |
| 102 | std::string cache_image_path() const; |
| 103 | void set_cache_image_path(const std::string& cache_image_path); |
| 104 | |
| 105 | std::string data_image_path() const; |
| 106 | void set_data_image_path(const std::string& data_image_path); |
| 107 | |
| 108 | std::string vendor_image_path() const; |
| 109 | void set_vendor_image_path(const std::string& vendor_image_path); |
| 110 | |
| 111 | std::string dtb_path() const; |
| 112 | void set_dtb_path(const std::string& dtb_path); |
| 113 | |
| 114 | std::string mempath() const; |
| 115 | void set_mempath(const std::string& mempath); |
| 116 | |
| 117 | std::string ivshmem_qemu_socket_path() const; |
| 118 | void set_ivshmem_qemu_socket_path( |
| 119 | const std::string& ivshmem_qemu_socket_path); |
| 120 | |
| 121 | std::string ivshmem_client_socket_path() const; |
| 122 | void set_ivshmem_client_socket_path( |
| 123 | const std::string& ivshmem_client_socket_path); |
| 124 | |
| 125 | int ivshmem_vector_count() const; |
| 126 | void set_ivshmem_vector_count(int ivshmem_vector_count); |
| 127 | |
| 128 | // The name of the socket that will be used to forward access to USB gadget. |
| 129 | // This is for V1 of the USB bus. |
| 130 | std::string usb_v1_socket_name() const; |
| 131 | void set_usb_v1_socket_name(const std::string& usb_v1_socket_name); |
| 132 | |
| 133 | int vhci_port() const; |
| 134 | void set_vhci_port(int vhci_port); |
| 135 | |
| 136 | std::string usb_ip_socket_name() const; |
| 137 | void set_usb_ip_socket_name(const std::string& usb_ip_socket_name); |
| 138 | |
| 139 | std::string kernel_log_socket_name() const; |
| 140 | void set_kernel_log_socket_name(const std::string& kernel_log_socket_name); |
| 141 | |
Jorge E. Moreira | 81afca1 | 2018-07-26 16:48:49 -0700 | [diff] [blame] | 142 | bool deprecated_boot_completed() const; |
| 143 | void set_deprecated_boot_completed(bool deprecated_boot_completed); |
| 144 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 145 | std::string console_path() const; |
| 146 | void set_console_path(const std::string& console_path); |
| 147 | |
| 148 | std::string logcat_path() const; |
| 149 | void set_logcat_path(const std::string& logcat_path); |
| 150 | |
Jorge E. Moreira | 66f6ec8 | 2018-07-16 16:43:15 -0700 | [diff] [blame] | 151 | std::string launcher_log_path() const; |
| 152 | void set_launcher_log_path(const std::string& launcher_log_path); |
| 153 | |
Jorge E. Moreira | 50a0775 | 2018-07-18 18:49:04 -0700 | [diff] [blame] | 154 | std::string launcher_monitor_socket_path() const; |
| 155 | void set_launcher_monitor_socket_path( |
| 156 | const std::string& launhcer_monitor_path); |
| 157 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 158 | std::string mobile_bridge_name() const; |
| 159 | void set_mobile_bridge_name(const std::string& mobile_bridge_name); |
| 160 | |
| 161 | std::string mobile_tap_name() const; |
| 162 | void set_mobile_tap_name(const std::string& mobile_tap_name); |
| 163 | |
Cody Schuffelen | 975175a | 2018-06-14 18:20:02 -0700 | [diff] [blame] | 164 | std::string wifi_bridge_name() const; |
| 165 | void set_wifi_bridge_name(const std::string& wifi_bridge_name); |
| 166 | |
| 167 | std::string wifi_tap_name() const; |
| 168 | void set_wifi_tap_name(const std::string& wifi_tap_name); |
| 169 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 170 | std::string wifi_guest_mac_addr() const; |
| 171 | void set_wifi_guest_mac_addr(const std::string& wifi_guest_mac_addr); |
| 172 | |
| 173 | std::string wifi_host_mac_addr() const; |
| 174 | void set_wifi_host_mac_addr(const std::string& wifi_host_mac_addr); |
| 175 | |
| 176 | std::string entropy_source() const; |
| 177 | void set_entropy_source(const std::string& entropy_source); |
| 178 | |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 179 | void set_vsock_guest_cid(int vsock_guest_cid); |
| 180 | int vsock_guest_cid() const; |
| 181 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 182 | std::string uuid() const; |
| 183 | void set_uuid(const std::string& uuid); |
| 184 | |
Greg Hartman | 6abdbb9 | 2018-05-24 09:49:00 -0700 | [diff] [blame] | 185 | void set_cuttlefish_env_path(const std::string& path); |
| 186 | std::string cuttlefish_env_path() const; |
| 187 | |
Ryan Haining | 4a1abea | 2018-07-10 16:20:19 -0700 | [diff] [blame] | 188 | void set_adb_mode(const std::string& mode); |
| 189 | std::string adb_mode() const; |
| 190 | |
Ryan Haining | 7338d35 | 2018-10-24 17:41:52 -0700 | [diff] [blame] | 191 | void set_adb_ip_and_port(const std::string& ip_port); |
| 192 | std::string adb_ip_and_port() const; |
| 193 | |
| 194 | std::string adb_device_name() const; |
| 195 | |
Ryan Haining | 6d821ec | 2018-07-27 11:39:09 -0700 | [diff] [blame] | 196 | void set_device_title(const std::string& title); |
| 197 | std::string device_title() const; |
| 198 | |
Greg Hartman | f1f28c5 | 2018-09-20 17:19:19 -0700 | [diff] [blame] | 199 | void set_setupwizard_mode(const std::string& title); |
| 200 | std::string setupwizard_mode() const; |
| 201 | |
Cody Schuffelen | 5898003 | 2018-10-11 17:11:13 -0700 | [diff] [blame] | 202 | void set_qemu_binary(const std::string& qemu_binary); |
| 203 | std::string qemu_binary() const; |
| 204 | |
Cody Schuffelen | 5bc697c | 2019-01-28 21:05:29 -0800 | [diff] [blame] | 205 | void set_ivserver_binary(const std::string& ivserver_binary); |
| 206 | std::string ivserver_binary() const; |
| 207 | |
Cody Schuffelen | 55676ca | 2019-01-28 22:00:05 -0800 | [diff] [blame] | 208 | void set_kernel_log_monitor_binary( |
| 209 | const std::string& kernel_log_monitor_binary); |
| 210 | std::string kernel_log_monitor_binary() const; |
| 211 | |
Cody Schuffelen | 17b3472 | 2019-01-28 22:57:14 -0800 | [diff] [blame] | 212 | void set_enable_vnc_server(bool enable_vnc_server); |
| 213 | bool enable_vnc_server() const; |
| 214 | |
| 215 | void set_vnc_server_port(int vnc_server_port); |
| 216 | int vnc_server_port() const; |
| 217 | |
| 218 | void set_vnc_server_binary(const std::string& vnc_server_binary); |
| 219 | std::string vnc_server_binary() const; |
| 220 | |
| 221 | void set_enable_stream_audio(bool enable_stream_audio); |
| 222 | bool enable_stream_audio() const; |
| 223 | |
| 224 | void set_stream_audio_port(int stream_audio_port); |
| 225 | int stream_audio_port() const; |
| 226 | |
| 227 | void set_stream_audio_binary(const std::string& stream_audio_binary); |
| 228 | std::string stream_audio_binary() const; |
| 229 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 230 | private: |
| 231 | std::unique_ptr<Json::Value> dictionary_; |
| 232 | |
Ryan Haining | d3f185d | 2018-07-19 12:11:47 -0700 | [diff] [blame] | 233 | void SetPath(const std::string& key, const std::string& path); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 234 | bool LoadFromFile(const char* file); |
| 235 | static CuttlefishConfig* BuildConfigImpl(); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 236 | |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 237 | CuttlefishConfig(const CuttlefishConfig&) = delete; |
| 238 | CuttlefishConfig& operator=(const CuttlefishConfig&) = delete; |
| 239 | }; |
| 240 | |
| 241 | // Returns the instance number as obtained from the CUTTLEFISH_INSTANCE |
| 242 | // environment variable or the username. |
| 243 | int GetInstance(); |
Jorge E. Moreira | 015c000 | 2018-07-19 11:01:16 -0700 | [diff] [blame] | 244 | // Returns a path where the launhcer puts a link to the config file which makes |
| 245 | // it easily discoverable regardless of what vm manager is in use |
| 246 | std::string GetGlobalConfigFileLink(); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 247 | |
| 248 | // Returns the path to the ivserver's client socket. |
| 249 | std::string GetDomain(); |
| 250 | |
| 251 | // These functions modify a given base value to make it different accross |
| 252 | // different instances by appending the instance id in case of strings or adding |
| 253 | // it in case of integers. |
| 254 | std::string GetPerInstanceDefault(const char* prefix); |
| 255 | int GetPerInstanceDefault(int base); |
| 256 | |
| 257 | std::string GetDefaultPerInstanceDir(); |
Jorge E. Moreira | 077d300 | 2018-07-20 11:43:05 -0700 | [diff] [blame] | 258 | std::string GetDefaultMempath(); |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 259 | int GetDefaultPerInstanceVsockCid(); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 260 | |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 261 | std::string DefaultHostArtifactsPath(const std::string& file); |
| 262 | std::string DefaultGuestImagePath(const std::string& file); |
| 263 | |
Jorge E. Moreira | d966837 | 2019-01-28 22:40:42 -0800 | [diff] [blame^] | 264 | // Whether the host supports qemu |
Jorge E. Moreira | a8142f9 | 2018-06-13 17:33:55 -0700 | [diff] [blame] | 265 | bool HostSupportsQemuCli(); |
Cody Schuffelen | d946b5f | 2018-12-12 11:54:48 -0800 | [diff] [blame] | 266 | bool HostSupportsVsock(); |
Jorge E. Moreira | 577383b | 2018-05-24 14:17:51 -0700 | [diff] [blame] | 267 | } // namespace vsoc |