blob: 9a9fa5361a1757f2f841e758f7d8b6091bbfd66b [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#pragma once
17
18#include <memory>
19#include <string>
Cody Schuffelenefadb8d2018-08-10 16:10:35 -070020#include <set>
Jorge E. Moreira577383b2018-05-24 14:17:51 -070021
22namespace Json {
23class Value;
24}
25
26namespace vsoc {
27
Jorge E. Moreirab8dfb992018-07-22 20:53:56 -070028constexpr char kDefaultUuidPrefix[] = "699acfc4-c8c4-11e7-882b-5065f31dc1";
Cody Schuffelenf219a162018-10-11 19:01:57 -070029constexpr char kCuttlefishConfigEnvVarName[] = "CUTTLEFISH_CONFIG_FILE";
Ryan Haining7338d352018-10-24 17:41:52 -070030constexpr char kVsocUserPrefix[] = "vsoc-";
Jorge E. Moreirab8dfb992018-07-22 20:53:56 -070031
Jorge E. Moreira577383b2018-05-24 14:17:51 -070032// Holds the configuration of the cuttlefish instances.
33class CuttlefishConfig {
34 public:
35 static CuttlefishConfig* Get();
Jorge E. Moreira077d3002018-07-20 11:43:05 -070036
37 CuttlefishConfig();
38 ~CuttlefishConfig();
Jorge E. Moreira577383b2018-05-24 14:17:51 -070039
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. Moreiraa8142f92018-06-13 17:33:55 -070042 bool SaveToFile(const std::string& file) const;
Jorge E. Moreira577383b2018-05-24 14:17:51 -070043
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. Moreira577383b2018-05-24 14:17:51 -070054 std::string instance_dir() const;
55 void set_instance_dir(const std::string& instance_dir);
56
Jorge E. Moreira88322832018-07-22 16:41:01 -070057 std::string vm_manager() const;
58 void set_vm_manager(const std::string& name);
59
Jorge E. Moreira577383b2018-05-24 14:17:51 -070060 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 Schuffelen5bc697c2019-01-28 21:05:29 -080078 int num_screen_buffers() const;
79 void set_num_screen_buffers(int num_screen_buffers);
80
Jorge E. Moreira577383b2018-05-24 14:17:51 -070081 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. Moreirab2427ba2018-08-23 17:11:55 -070087 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. Moreira577383b2018-05-24 14:17:51 -070092
Greg Hartman91f81422018-07-09 16:04:49 -070093 std::string gdb_flag() const;
94 void set_gdb_flag(const std::string& gdb);
95
Jorge E. Moreira577383b2018-05-24 14:17:51 -070096 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. Moreira81afca12018-07-26 16:48:49 -0700142 bool deprecated_boot_completed() const;
143 void set_deprecated_boot_completed(bool deprecated_boot_completed);
144
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700145 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. Moreira66f6ec82018-07-16 16:43:15 -0700151 std::string launcher_log_path() const;
152 void set_launcher_log_path(const std::string& launcher_log_path);
153
Jorge E. Moreira50a07752018-07-18 18:49:04 -0700154 std::string launcher_monitor_socket_path() const;
155 void set_launcher_monitor_socket_path(
156 const std::string& launhcer_monitor_path);
157
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700158 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 Schuffelen975175a2018-06-14 18:20:02 -0700164 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. Moreira577383b2018-05-24 14:17:51 -0700170 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 Schuffelend946b5f2018-12-12 11:54:48 -0800179 void set_vsock_guest_cid(int vsock_guest_cid);
180 int vsock_guest_cid() const;
181
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700182 std::string uuid() const;
183 void set_uuid(const std::string& uuid);
184
Greg Hartman6abdbb92018-05-24 09:49:00 -0700185 void set_cuttlefish_env_path(const std::string& path);
186 std::string cuttlefish_env_path() const;
187
Ryan Haining4a1abea2018-07-10 16:20:19 -0700188 void set_adb_mode(const std::string& mode);
189 std::string adb_mode() const;
190
Ryan Haining7338d352018-10-24 17:41:52 -0700191 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 Haining6d821ec2018-07-27 11:39:09 -0700196 void set_device_title(const std::string& title);
197 std::string device_title() const;
198
Greg Hartmanf1f28c52018-09-20 17:19:19 -0700199 void set_setupwizard_mode(const std::string& title);
200 std::string setupwizard_mode() const;
201
Cody Schuffelen58980032018-10-11 17:11:13 -0700202 void set_qemu_binary(const std::string& qemu_binary);
203 std::string qemu_binary() const;
204
Cody Schuffelen5bc697c2019-01-28 21:05:29 -0800205 void set_ivserver_binary(const std::string& ivserver_binary);
206 std::string ivserver_binary() const;
207
Cody Schuffelen55676ca2019-01-28 22:00:05 -0800208 void set_kernel_log_monitor_binary(
209 const std::string& kernel_log_monitor_binary);
210 std::string kernel_log_monitor_binary() const;
211
Cody Schuffelen17b34722019-01-28 22:57:14 -0800212 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. Moreira577383b2018-05-24 14:17:51 -0700230 private:
231 std::unique_ptr<Json::Value> dictionary_;
232
Ryan Hainingd3f185d2018-07-19 12:11:47 -0700233 void SetPath(const std::string& key, const std::string& path);
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700234 bool LoadFromFile(const char* file);
235 static CuttlefishConfig* BuildConfigImpl();
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700236
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700237 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.
243int GetInstance();
Jorge E. Moreira015c0002018-07-19 11:01:16 -0700244// 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
246std::string GetGlobalConfigFileLink();
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700247
248// Returns the path to the ivserver's client socket.
249std::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.
254std::string GetPerInstanceDefault(const char* prefix);
255int GetPerInstanceDefault(int base);
256
257std::string GetDefaultPerInstanceDir();
Jorge E. Moreira077d3002018-07-20 11:43:05 -0700258std::string GetDefaultMempath();
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800259int GetDefaultPerInstanceVsockCid();
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700260
Jorge E. Moreiraa8142f92018-06-13 17:33:55 -0700261std::string DefaultHostArtifactsPath(const std::string& file);
262std::string DefaultGuestImagePath(const std::string& file);
263
Jorge E. Moreirad9668372019-01-28 22:40:42 -0800264// Whether the host supports qemu
Jorge E. Moreiraa8142f92018-06-13 17:33:55 -0700265bool HostSupportsQemuCli();
Cody Schuffelend946b5f2018-12-12 11:54:48 -0800266bool HostSupportsVsock();
Jorge E. Moreira577383b2018-05-24 14:17:51 -0700267} // namespace vsoc