• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <sys/types.h>
19 #include <array>
20 #include <cstdint>
21 #include <map>
22 #include <memory>
23 #include <optional>
24 #include <string>
25 #include <set>
26 #include <vector>
27 
28 #include "common/libs/utils/environment.h"
29 #include "common/libs/utils/result.h"
30 #include "host/libs/config/config_fragment.h"
31 
32 namespace Json {
33 class Value;
34 }
35 
36 namespace cuttlefish {
37 constexpr char kLogcatSerialMode[] = "serial";
38 constexpr char kLogcatVsockMode[] = "vsock";
39 
40 constexpr char kDefaultUuidPrefix[] = "699acfc4-c8c4-11e7-882b-5065f31dc1";
41 constexpr char kCuttlefishConfigEnvVarName[] = "CUTTLEFISH_CONFIG_FILE";
42 constexpr char kCuttlefishInstanceEnvVarName[] = "CUTTLEFISH_INSTANCE";
43 constexpr char kVsocUserPrefix[] = "vsoc-";
44 constexpr char kCvdNamePrefix[] = "cvd-";
45 constexpr char kBootStartedMessage[] ="VIRTUAL_DEVICE_BOOT_STARTED";
46 constexpr char kBootCompletedMessage[] = "VIRTUAL_DEVICE_BOOT_COMPLETED";
47 constexpr char kBootFailedMessage[] = "VIRTUAL_DEVICE_BOOT_FAILED";
48 constexpr char kMobileNetworkConnectedMessage[] =
49     "VIRTUAL_DEVICE_NETWORK_MOBILE_CONNECTED";
50 constexpr char kWifiConnectedMessage[] =
51     "VIRTUAL_DEVICE_NETWORK_WIFI_CONNECTED";
52 constexpr char kEthernetConnectedMessage[] =
53     "VIRTUAL_DEVICE_NETWORK_ETHERNET_CONNECTED";
54 // TODO(b/131864854): Replace this with a string less likely to change
55 constexpr char kAdbdStartedMessage[] =
56     "init: starting service 'adbd'...";
57 constexpr char kFastbootdStartedMessage[] =
58     "init: starting service 'fastbootd'...";
59 constexpr char kScreenChangedMessage[] = "VIRTUAL_DEVICE_SCREEN_CHANGED";
60 constexpr char kDisplayPowerModeChangedMessage[] =
61     "VIRTUAL_DEVICE_DISPLAY_POWER_MODE_CHANGED";
62 constexpr char kInternalDirName[] = "internal";
63 constexpr char kGrpcSocketDirName[] = "grpc_socket";
64 constexpr char kSharedDirName[] = "shared";
65 constexpr char kLogDirName[] = "logs";
66 constexpr char kCrosvmVarEmptyDir[] = "/var/empty";
67 constexpr char kKernelLoadedMessage[] = "] Linux version";
68 constexpr char kBootloaderLoadedMessage[] = "U-Boot 20";
69 
70 enum class SecureHal {
71   Unknown,
72   Keymint,
73   Gatekeeper,
74   Oemlock,
75 };
76 
77 // Holds the configuration of the cuttlefish instances.
78 class CuttlefishConfig {
79  public:
80   static const CuttlefishConfig* Get();
81   static std::unique_ptr<const CuttlefishConfig> GetFromFile(
82       const std::string& path);
83   static bool ConfigExists();
84 
85   CuttlefishConfig();
86   CuttlefishConfig(CuttlefishConfig&&);
87   ~CuttlefishConfig();
88   CuttlefishConfig& operator=(CuttlefishConfig&&);
89 
90   // Saves the configuration object in a file, it can then be read in other
91   // processes by passing the --config_file option.
92   bool SaveToFile(const std::string& file) const;
93 
94   bool SaveFragment(const ConfigFragment&);
95   bool LoadFragment(ConfigFragment&) const;
96 
97   std::string root_dir() const;
98   void set_root_dir(const std::string& root_dir);
99 
100   std::string instances_dir() const;
101   std::string InstancesPath(const std::string&) const;
102 
103   std::string assembly_dir() const;
104   std::string AssemblyPath(const std::string&) const;
105 
106   std::string instances_uds_dir() const;
107   std::string InstancesUdsPath(const std::string&) const;
108 
109   std::string vm_manager() const;
110   void set_vm_manager(const std::string& name);
111 
112   struct DisplayConfig {
113     int width;
114     int height;
115     int dpi;
116     int refresh_rate_hz;
117   };
118 
119   void set_secure_hals(const std::set<std::string>& hals);
120   std::set<SecureHal> secure_hals() const;
121 
122   void set_crosvm_binary(const std::string& crosvm_binary);
123   std::string crosvm_binary() const;
124 
125   void set_gem5_debug_flags(const std::string& gem5_debug_flags);
126   std::string gem5_debug_flags() const;
127 
128   void set_enable_host_uwb(bool enable_host_uwb);
129   bool enable_host_uwb() const;
130 
131   void set_enable_host_uwb_connector(bool enable_host_uwb);
132   bool enable_host_uwb_connector() const;
133 
134   void set_enable_host_bluetooth(bool enable_host_bluetooth);
135   bool enable_host_bluetooth() const;
136 
137   // Bluetooth is enabled by bt_connector and rootcanal
138   void set_enable_host_bluetooth_connector(bool enable_host_bluetooth);
139   bool enable_host_bluetooth_connector() const;
140 
141   // Flags for the set of radios that are connected to netsim
142   enum NetsimRadio {
143     Bluetooth = 0b00000001,
144     Wifi      = 0b00000010,
145     Uwb       = 0b00000100,
146   };
147 
148   void netsim_radio_enable(NetsimRadio flag);
149   bool netsim_radio_enabled(NetsimRadio flag) const;
150 
151   enum Answer {
152     kUnknown = 0,
153     kYes,
154     kNo,
155   };
156 
157   void set_enable_metrics(std::string enable_metrics);
158   CuttlefishConfig::Answer enable_metrics() const;
159 
160   void set_metrics_binary(const std::string& metrics_binary);
161   std::string metrics_binary() const;
162 
163   void set_extra_kernel_cmdline(const std::string& extra_cmdline);
164   std::vector<std::string> extra_kernel_cmdline() const;
165 
166   void set_extra_bootconfig_args(const std::string& extra_bootconfig_args);
167   std::vector<std::string> extra_bootconfig_args() const;
168 
169   // A directory containing the SSL certificates for the signaling server
170   void set_webrtc_certs_dir(const std::string& certs_dir);
171   std::string webrtc_certs_dir() const;
172 
173   // The port for the webrtc signaling server. It's used by the signaling server
174   // to bind to it and by the webrtc process to connect to and register itself
175   void set_sig_server_port(int port);
176   int sig_server_port() const;
177 
178   // The address of the signaling server
179   void set_sig_server_address(const std::string& addr);
180   std::string sig_server_address() const;
181 
182   // The path section of the url where the webrtc process registers itself with
183   // the signaling server
184   void set_sig_server_path(const std::string& path);
185   std::string sig_server_path() const;
186 
187   // Whether the webrtc process should use a secure connection (WSS) to the
188   // signaling server.
189   void set_sig_server_secure(bool secure);
190   bool sig_server_secure() const;
191 
192   // Whether the webrtc process should attempt to verify the authenticity of the
193   // signaling server (reject self signed certificates)
194   void set_sig_server_strict(bool strict);
195   bool sig_server_strict() const;
196 
197   void set_host_tools_version(const std::map<std::string, uint32_t>&);
198   std::map<std::string, uint32_t> host_tools_version() const;
199 
200   void set_virtio_mac80211_hwsim(bool virtio_mac80211_hwsim);
201   bool virtio_mac80211_hwsim() const;
202 
203   void set_vhost_user_mac80211_hwsim(const std::string& path);
204   std::string vhost_user_mac80211_hwsim() const;
205 
206   void set_wmediumd_api_server_socket(const std::string& path);
207   std::string wmediumd_api_server_socket() const;
208 
209   void set_ap_rootfs_image(const std::string& path);
210   std::string ap_rootfs_image() const;
211 
212   void set_ap_kernel_image(const std::string& path);
213   std::string ap_kernel_image() const;
214 
215   void set_wmediumd_config(const std::string& path);
216   std::string wmediumd_config() const;
217 
218   void set_pica_uci_port(int pica_uci_port);
219   int pica_uci_port() const;
220 
221   void set_rootcanal_args(const std::string& rootcanal_args);
222   std::vector<std::string> rootcanal_args() const;
223 
224   void set_rootcanal_hci_port(int rootcanal_hci_port);
225   int rootcanal_hci_port() const;
226 
227   void set_rootcanal_link_port(int rootcanal_link_port);
228   int rootcanal_link_port() const;
229 
230   void set_rootcanal_link_ble_port(int rootcanal_link_ble_port);
231   int rootcanal_link_ble_port() const;
232 
233   void set_rootcanal_test_port(int rootcanal_test_port);
234   int rootcanal_test_port() const;
235 
236   void set_rootcanal_config_file(const std::string& rootcanal_config_file);
237   std::string rootcanal_config_file() const;
238 
239   void set_rootcanal_default_commands_file(
240       const std::string& rootcanal_default_commands_file);
241   std::string rootcanal_default_commands_file() const;
242 
243   // The path of an AP image in composite disk
244   std::string ap_image_dev_path() const;
245   void set_ap_image_dev_path(const std::string& dev_path);
246 
247   class InstanceSpecific;
248   class MutableInstanceSpecific;
249 
250   MutableInstanceSpecific ForInstance(int instance_num);
251   InstanceSpecific ForInstance(int instance_num) const;
252   InstanceSpecific ForInstanceName(const std::string& name) const;
253   InstanceSpecific ForDefaultInstance() const;
254 
255   std::vector<InstanceSpecific> Instances() const;
256   std::vector<std::string> instance_dirs() const;
257 
258   void set_instance_names(const std::vector<std::string>& instance_names);
259   std::vector<std::string> instance_names() const;
260 
261   // A view into an existing CuttlefishConfig object for a particular instance.
262   class InstanceSpecific {
263     const CuttlefishConfig* config_;
264     std::string id_;
265     friend InstanceSpecific CuttlefishConfig::ForInstance(int num) const;
266     friend std::vector<InstanceSpecific> CuttlefishConfig::Instances() const;
267 
InstanceSpecific(const CuttlefishConfig * config,const std::string & id)268     InstanceSpecific(const CuttlefishConfig* config, const std::string& id)
269         : config_(config), id_(id) {}
270 
271     Json::Value* Dictionary();
272     const Json::Value* Dictionary() const;
273   public:
274     std::string serial_number() const;
275     // If any of the following port numbers is 0, the relevant service is not
276     // running on the guest.
277 
278     // Port number for qemu to run a vnc server on the host
279     int qemu_vnc_server_port() const;
280     // Port number to connect to the tombstone receiver on the host
281     int tombstone_receiver_port() const;
282     // Port number to connect to the config server on the host
283     int config_server_port() const;
284     // Port number to connect to the keyboard server on the host. (Only
285     // operational if QEMU is the vmm.)
286     int keyboard_server_port() const;
287     // Port number to connect to the touch server on the host. (Only
288     // operational if QEMU is the vmm.)
289     int touch_server_port() const;
290     // Port number to connect to the audiocontrol server on the guest
291     int audiocontrol_server_port() const;
292     // Port number to connect to the adb server on the host
293     int adb_host_port() const;
294     // Port number to connect to the fastboot server on the host
295     int fastboot_host_port() const;
296     // Device-specific ID to distinguish modem simulators. Must be 4 digits.
297     int modem_simulator_host_id() const;
298     // Port number to connect to the gnss grpc proxy server on the host
299     int gnss_grpc_proxy_server_port() const;
300     std::string adb_ip_and_port() const;
301     // Port number to connect to the camera hal on the guest
302     int camera_server_port() const;
303 
304     std::string adb_device_name() const;
305     std::string gnss_file_path() const;
306     std::string fixed_location_file_path() const;
307     std::string mobile_bridge_name() const;
308     std::string mobile_tap_name() const;
309     std::string mobile_mac() const;
310     std::string wifi_bridge_name() const;
311     std::string wifi_tap_name() const;
312     std::string wifi_mac() const;
313     bool use_bridged_wifi_tap() const;
314     std::string ethernet_tap_name() const;
315     std::string ethernet_bridge_name() const;
316     std::string ethernet_mac() const;
317     std::string ethernet_ipv6() const;
318     uint32_t session_id() const;
319     bool use_allocd() const;
320     int vsock_guest_cid() const;
321     std::string uuid() const;
322     std::string instance_name() const;
323     std::vector<std::string> virtual_disk_paths() const;
324 
325     // Returns the path to a file with the given name in the instance
326     // directory..
327     std::string PerInstancePath(const std::string& file_name) const;
328     std::string PerInstanceInternalPath(const std::string& file_name) const;
329     std::string PerInstanceLogPath(const std::string& file_name) const;
330 
331     std::string instance_dir() const;
332 
333     std::string instance_internal_dir() const;
334 
335     // Return the Unix domain socket path with given name. Because the
336     // length limitation of Unix domain socket name, it needs to be in
337     // the another directory than normal Instance path.
338     std::string PerInstanceUdsPath(const std::string& file_name) const;
339     std::string PerInstanceInternalUdsPath(const std::string& file_name) const;
340     std::string PerInstanceGrpcSocketPath(const std::string& socket_name) const;
341 
342     std::string instance_uds_dir() const;
343 
344     std::string instance_internal_uds_dir() const;
345 
346     std::string touch_socket_path(int screen_idx) const;
347     std::string keyboard_socket_path() const;
348     std::string switches_socket_path() const;
349     std::string frames_socket_path() const;
350 
351     std::string access_kregistry_path() const;
352 
353     std::string hwcomposer_pmem_path() const;
354 
355     std::string pstore_path() const;
356 
357     std::string console_path() const;
358 
359     std::string logcat_path() const;
360 
361     std::string kernel_log_pipe_name() const;
362 
363     std::string console_pipe_prefix() const;
364     std::string console_in_pipe_name() const;
365     std::string console_out_pipe_name() const;
366 
367     std::string gnss_pipe_prefix() const;
368     std::string gnss_in_pipe_name() const;
369     std::string gnss_out_pipe_name() const;
370 
371     std::string logcat_pipe_name() const;
372 
373     std::string launcher_log_path() const;
374 
375     std::string launcher_monitor_socket_path() const;
376 
377     std::string sdcard_path() const;
378 
379     std::string persistent_composite_disk_path() const;
380 
381     std::string persistent_ap_composite_disk_path() const;
382 
383     std::string os_composite_disk_path() const;
384 
385     std::string ap_composite_disk_path() const;
386 
387     std::string uboot_env_image_path() const;
388 
389     std::string ap_uboot_env_image_path() const;
390 
391     std::string ap_esp_image_path() const;
392 
393     std::string otheros_esp_image_path() const;
394 
395     std::string otheros_esp_grub_config() const;
396 
397     std::string ap_esp_grub_config() const;
398 
399     std::string audio_server_path() const;
400 
401     enum class BootFlow {
402       Android,
403       Linux,
404       Fuchsia
405     };
406 
407     BootFlow boot_flow() const;
408 
409     // modem simulator related
410     std::string modem_simulator_ports() const;
411 
412     // The device id the webrtc process should use to register with the
413     // signaling server
414     std::string webrtc_device_id() const;
415 
416     // Whether this instance should start the webrtc signaling server
417     bool start_webrtc_sig_server() const;
418 
419     // Whether to start a reverse proxy to the webrtc signaling server already
420     // running in the host
421     bool start_webrtc_sig_server_proxy() const;
422 
423     // Whether this instance should start the wmediumd process
424     bool start_wmediumd() const;
425 
426     // Whether this instance should start a rootcanal instance
427     bool start_rootcanal() const;
428 
429     // Whether this instance should start a pica instance
430     bool start_pica() const;
431 
432     // Whether this instance should start a netsim instance
433     bool start_netsim() const;
434 
435     enum class APBootFlow {
436       // Not starting AP at all (for example not the 1st instance)
437       None,
438       // Generating ESP and using U-BOOT to boot AP
439       Grub,
440       // Using legacy way to boot AP in case we cannot generate ESP image.
441       // Currently we have only one case when we cannot do it. When users
442       // have ubuntu bionic which doesn't have monolith binaris in the
443       // grub-efi-arm64-bin (for arm64) and grub-efi-ia32-bin (x86) deb packages.
444       // TODO(b/260337906): check is it possible to add grub binaries into the AOSP
445       // to deliver the proper grub environment
446       // TODO(b/260338443): use grub-mkimage from grub-common in case we cannot overcome
447       // legal issues
448       LegacyDirect
449     };
450     APBootFlow ap_boot_flow() const;
451 
452     // Wifi MAC address inside the guest
453     int wifi_mac_prefix() const;
454 
455     std::string factory_reset_protected_path() const;
456 
457     std::string persistent_bootconfig_path() const;
458 
459     std::string vbmeta_path() const;
460 
461     std::string ap_vbmeta_path() const;
462 
463     std::string id() const;
464 
465     std::string gem5_binary_dir() const;
466 
467     std::string gem5_checkpoint_dir() const;
468 
469     // Serial console
470     bool console() const;
471     std::string console_dev() const;
472     bool enable_sandbox() const;
473 
474     // KGDB configuration for kernel debugging
475     bool kgdb() const;
476 
477     // TODO (b/163575714) add virtio console support to the bootloader so the
478     // virtio console path for the console device can be taken again. When that
479     // happens, this function can be deleted along with all the code paths it
480     // forces.
481     bool use_bootloader() const;
482 
483     Arch target_arch() const;
484 
485     int cpus() const;
486 
487     std::string data_policy() const;
488 
489     int blank_data_image_mb() const;
490 
491     int gdb_port() const;
492 
493     std::vector<DisplayConfig> display_configs() const;
494 
495     std::string grpc_socket_path() const;
496     int memory_mb() const;
497     int ddr_mem_mb() const;
498     std::string setupwizard_mode() const;
499     std::string userdata_format() const;
500     bool guest_enforce_security() const;
501     bool use_sdcard() const;
502     bool pause_in_bootloader() const;
503     bool run_as_daemon() const;
504     bool enable_audio() const;
505     bool enable_gnss_grpc_proxy() const;
506     bool enable_bootanimation() const;
507     bool record_screen() const;
508     std::string gem5_debug_file() const;
509     bool protected_vm() const;
510     bool mte() const;
511     std::string boot_slot() const;
512 
513     // Kernel and bootloader logging
514     bool enable_kernel_log() const;
515     bool vhost_net() const;
516 
517     // The dns address of mobile network (RIL)
518     std::string ril_dns() const;
519 
520     bool enable_webrtc() const;
521     std::string webrtc_assets_dir() const;
522 
523     // The range of TCP ports available for webrtc sessions.
524     std::pair<uint16_t, uint16_t> webrtc_tcp_port_range() const;
525 
526     // The range of UDP ports available for webrtc sessions.
527     std::pair<uint16_t, uint16_t> webrtc_udp_port_range() const;
528 
529     bool smt() const;
530     std::string crosvm_binary() const;
531     std::string seccomp_policy_dir() const;
532     std::string qemu_binary_dir() const;
533 
534     // Configuration flags for a minimal device
535     bool enable_minimal_mode() const;
536     bool enable_modem_simulator() const;
537     int modem_simulator_instance_number() const;
538     int modem_simulator_sim_type() const;
539 
540     std::string gpu_mode() const;
541     std::string gpu_angle_feature_overrides_enabled() const;
542     std::string gpu_angle_feature_overrides_disabled() const;
543     std::string gpu_capture_binary() const;
544     bool enable_gpu_udmabuf() const;
545 
546     std::string hwcomposer() const;
547 
548     bool restart_subprocesses() const;
549 
550     // android artifacts
551     std::string boot_image() const;
552     std::string new_boot_image() const;
553     std::string init_boot_image() const;
554     std::string data_image() const;
555     std::string super_image() const;
556     std::string new_super_image() const;
557     std::string misc_image() const;
558     std::string new_misc_image() const;
559     std::string misc_info_txt() const;
560     std::string metadata_image() const;
561     std::string new_metadata_image() const;
562     std::string vendor_boot_image() const;
563     std::string new_vendor_boot_image() const;
564     std::string vbmeta_image() const;
565     std::string vbmeta_system_image() const;
566     std::string vbmeta_vendor_dlkm_image() const;
567     std::string new_vbmeta_vendor_dlkm_image() const;
568 
569     // otheros artifacts
570     std::string otheros_esp_image() const;
571 
572     // linux artifacts for otheros flow
573     std::string linux_kernel_path() const;
574     std::string linux_initramfs_path() const;
575     std::string linux_root_image() const;
576 
577     std::string fuchsia_zedboot_path() const;
578     std::string fuchsia_multiboot_bin_path() const;
579     std::string fuchsia_root_image() const;
580 
581     std::string custom_partition_path() const;
582 
583     int blank_metadata_image_mb() const;
584     int blank_sdcard_image_mb() const;
585     std::string bootloader() const;
586     std::string initramfs_path() const;
587     std::string kernel_path() const;
588     std::string guest_android_version() const;
589     bool bootconfig_supported() const;
590     std::string filename_encryption_mode() const;
591   };
592 
593   // A view into an existing CuttlefishConfig object for a particular instance.
594   class MutableInstanceSpecific {
595     CuttlefishConfig* config_;
596     std::string id_;
597     friend MutableInstanceSpecific CuttlefishConfig::ForInstance(int num);
598 
599     MutableInstanceSpecific(CuttlefishConfig* config, const std::string& id);
600 
601     Json::Value* Dictionary();
602   public:
603     void set_serial_number(const std::string& serial_number);
604     void set_qemu_vnc_server_port(int qemu_vnc_server_port);
605     void set_tombstone_receiver_port(int tombstone_receiver_port);
606     void set_config_server_port(int config_server_port);
607     void set_frames_server_port(int config_server_port);
608     void set_touch_server_port(int config_server_port);
609     void set_keyboard_server_port(int config_server_port);
610     void set_gatekeeper_vsock_port(int gatekeeper_vsock_port);
611     void set_keymaster_vsock_port(int keymaster_vsock_port);
612     void set_audiocontrol_server_port(int audiocontrol_server_port);
613     void set_adb_host_port(int adb_host_port);
614     void set_modem_simulator_host_id(int modem_simulator_id);
615     void set_adb_ip_and_port(const std::string& ip_port);
616     void set_fastboot_host_port(int fastboot_host_port);
617     void set_camera_server_port(int camera_server_port);
618     void set_mobile_bridge_name(const std::string& mobile_bridge_name);
619     void set_mobile_tap_name(const std::string& mobile_tap_name);
620     void set_mobile_mac(const std::string& mac);
621     void set_wifi_bridge_name(const std::string& wifi_bridge_name);
622     void set_wifi_tap_name(const std::string& wifi_tap_name);
623     void set_wifi_mac(const std::string& mac);
624     void set_use_bridged_wifi_tap(bool use_bridged_wifi_tap);
625     void set_ethernet_tap_name(const std::string& ethernet_tap_name);
626     void set_ethernet_bridge_name(const std::string& set_ethernet_bridge_name);
627     void set_ethernet_mac(const std::string& mac);
628     void set_ethernet_ipv6(const std::string& ip);
629     void set_session_id(uint32_t session_id);
630     void set_use_allocd(bool use_allocd);
631     void set_vsock_guest_cid(int vsock_guest_cid);
632     void set_uuid(const std::string& uuid);
633     // modem simulator related
634     void set_modem_simulator_ports(const std::string& modem_simulator_ports);
635     void set_virtual_disk_paths(const std::vector<std::string>& disk_paths);
636     void set_webrtc_device_id(const std::string& id);
637     void set_start_webrtc_signaling_server(bool start);
638     void set_start_webrtc_sig_server_proxy(bool start);
639     void set_start_wmediumd(bool start);
640     void set_start_rootcanal(bool start);
641     void set_start_pica(bool start);
642     void set_start_netsim(bool start);
643     void set_ap_boot_flow(InstanceSpecific::APBootFlow flow);
644     // Wifi MAC address inside the guest
645     void set_wifi_mac_prefix(const int wifi_mac_prefix);
646     // Gnss grpc proxy server port inside the host
647     void set_gnss_grpc_proxy_server_port(int gnss_grpc_proxy_server_port);
648     // Gnss grpc proxy local file path
649     void set_gnss_file_path(const std::string &gnss_file_path);
650     void set_fixed_location_file_path(
651         const std::string& fixed_location_file_path);
652     void set_gem5_binary_dir(const std::string& gem5_binary_dir);
653     void set_gem5_checkpoint_dir(const std::string& gem5_checkpoint_dir);
654     // Serial console
655     void set_console(bool console);
656     void set_enable_sandbox(const bool enable_sandbox);
657     void set_kgdb(bool kgdb);
658     void set_target_arch(Arch target_arch);
659     void set_cpus(int cpus);
660     void set_data_policy(const std::string& data_policy);
661     void set_blank_data_image_mb(int blank_data_image_mb);
662     void set_gdb_port(int gdb_port);
663     void set_display_configs(const std::vector<DisplayConfig>& display_configs);
664     void set_memory_mb(int memory_mb);
665     void set_ddr_mem_mb(int ddr_mem_mb);
666     Result<void> set_setupwizard_mode(const std::string& title);
667     void set_userdata_format(const std::string& userdata_format);
668     void set_guest_enforce_security(bool guest_enforce_security);
669     void set_use_sdcard(bool use_sdcard);
670     void set_pause_in_bootloader(bool pause_in_bootloader);
671     void set_run_as_daemon(bool run_as_daemon);
672     void set_enable_audio(bool enable);
673     void set_enable_gnss_grpc_proxy(const bool enable_gnss_grpc_proxy);
674     void set_enable_bootanimation(const bool enable_bootanimation);
675     void set_record_screen(bool record_screen);
676     void set_gem5_debug_file(const std::string& gem5_debug_file);
677     void set_protected_vm(bool protected_vm);
678     void set_mte(bool mte);
679     void set_boot_slot(const std::string& boot_slot);
680     void set_grpc_socket_path(const std::string& sockets);
681 
682     // Kernel and bootloader logging
683     void set_enable_kernel_log(bool enable_kernel_log);
684 
685     void set_enable_webrtc(bool enable_webrtc);
686     void set_webrtc_assets_dir(const std::string& webrtc_assets_dir);
687 
688     // The range of TCP ports available for webrtc sessions.
689     void set_webrtc_tcp_port_range(std::pair<uint16_t, uint16_t> range);
690 
691     // The range of UDP ports available for webrtc sessions.
692     void set_webrtc_udp_port_range(std::pair<uint16_t, uint16_t> range);
693 
694     void set_smt(bool smt);
695     void set_crosvm_binary(const std::string& crosvm_binary);
696     void set_seccomp_policy_dir(const std::string& seccomp_policy_dir);
697     void set_qemu_binary_dir(const std::string& qemu_binary_dir);
698 
699     void set_vhost_net(bool vhost_net);
700 
701     // The dns address of mobile network (RIL)
702     void set_ril_dns(const std::string& ril_dns);
703 
704     // Configuration flags for a minimal device
705     void set_enable_minimal_mode(bool enable_minimal_mode);
706     void set_enable_modem_simulator(bool enable_modem_simulator);
707     void set_modem_simulator_instance_number(int instance_numbers);
708     void set_modem_simulator_sim_type(int sim_type);
709 
710     void set_gpu_mode(const std::string& name);
711     void set_gpu_angle_feature_overrides_enabled(const std::string& overrides);
712     void set_gpu_angle_feature_overrides_disabled(const std::string& overrides);
713     void set_gpu_capture_binary(const std::string&);
714     void set_enable_gpu_udmabuf(const bool enable_gpu_udmabuf);
715 
716     void set_hwcomposer(const std::string&);
717 
718     void set_restart_subprocesses(bool restart_subprocesses);
719 
720     // system image files
721     void set_boot_image(const std::string& boot_image);
722     void set_new_boot_image(const std::string& new_boot_image);
723     void set_init_boot_image(const std::string& init_boot_image);
724     void set_data_image(const std::string& data_image);
725     void set_super_image(const std::string& super_image);
726     void set_new_super_image(const std::string& super_image);
727     void set_misc_image(const std::string& misc_image);
728     void set_new_misc_image(const std::string& new_misc_image);
729     void set_misc_info_txt(const std::string& misc_image);
730     void set_metadata_image(const std::string& metadata_image);
731     void set_new_metadata_image(const std::string& new_metadata_image);
732     void set_vendor_boot_image(const std::string& vendor_boot_image);
733     void set_new_vendor_boot_image(const std::string& new_vendor_boot_image);
734     void set_vbmeta_image(const std::string& vbmeta_image);
735     void set_vbmeta_system_image(const std::string& vbmeta_system_image);
736     void set_vbmeta_vendor_dlkm_image(
737         const std::string& vbmeta_vendor_dlkm_image);
738     void set_new_vbmeta_vendor_dlkm_image(
739         const std::string& vbmeta_vendor_dlkm_image);
740     void set_otheros_esp_image(const std::string& otheros_esp_image);
741     void set_linux_kernel_path(const std::string& linux_kernel_path);
742     void set_linux_initramfs_path(const std::string& linux_initramfs_path);
743     void set_linux_root_image(const std::string& linux_root_image);
744     void set_fuchsia_zedboot_path(const std::string& fuchsia_zedboot_path);
745     void set_fuchsia_multiboot_bin_path(const std::string& fuchsia_multiboot_bin_path);
746     void set_fuchsia_root_image(const std::string& fuchsia_root_image);
747     void set_custom_partition_path(const std::string& custom_partition_path);
748     void set_blank_metadata_image_mb(int blank_metadata_image_mb);
749     void set_blank_sdcard_image_mb(int blank_sdcard_image_mb);
750     void set_bootloader(const std::string& bootloader);
751     void set_initramfs_path(const std::string& initramfs_path);
752     void set_kernel_path(const std::string& kernel_path);
753     void set_guest_android_version(const std::string& guest_android_version);
754     void set_bootconfig_supported(bool bootconfig_supported);
755     void set_filename_encryption_mode(const std::string& userdata_format);
756 
757    private:
758     void SetPath(const std::string& key, const std::string& path);
759   };
760 
761  private:
762   std::unique_ptr<Json::Value> dictionary_;
763 
764   bool LoadFromFile(const char* file);
765   static CuttlefishConfig* BuildConfigImpl(const std::string& path);
766 
767   CuttlefishConfig(const CuttlefishConfig&) = delete;
768   CuttlefishConfig& operator=(const CuttlefishConfig&) = delete;
769 };
770 
771 // Returns the instance number as obtained from the
772 // *kCuttlefishInstanceEnvVarName environment variable or the username.
773 int GetInstance();
774 
775 // Returns default Vsock CID, which is
776 // GetInstance() + 2
777 int GetDefaultVsockCid();
778 
779 // Calculates vsock server port number
780 // return base + (vsock_guest_cid - 3)
781 int GetVsockServerPort(const int base,
782                        const int vsock_guest_cid);
783 
784 // Returns a path where the launhcer puts a link to the config file which makes
785 // it easily discoverable regardless of what vm manager is in use
786 std::string GetGlobalConfigFileLink();
787 
788 // These functions modify a given base value to make it different accross
789 // different instances by appending the instance id in case of strings or adding
790 // it in case of integers.
791 std::string ForCurrentInstance(const char* prefix);
792 int ForCurrentInstance(int base);
793 
794 // Returns a random serial number appeneded to a given prefix.
795 std::string RandomSerialNumber(const std::string& prefix);
796 
797 std::string DefaultHostArtifactsPath(const std::string& file);
798 std::string HostBinaryPath(const std::string& file);
799 std::string DefaultGuestImagePath(const std::string& file);
800 std::string DefaultEnvironmentPath(const char* environment_key,
801                                    const char* default_value,
802                                    const char* path);
803 
804 // Whether the host supports qemu
805 bool HostSupportsQemuCli();
806 
807 // GPU modes
808 extern const char* const kGpuModeAuto;
809 extern const char* const kGpuModeDrmVirgl;
810 extern const char* const kGpuModeGfxstream;
811 extern const char* const kGpuModeGfxstreamGuestAngle;
812 extern const char* const kGpuModeGuestSwiftshader;
813 extern const char* const kGpuModeNone;
814 
815 // HwComposer modes
816 extern const char* const kHwComposerAuto;
817 extern const char* const kHwComposerDrm;
818 extern const char* const kHwComposerRanchu;
819 extern const char* const kHwComposerNone;
820 }  // namespace cuttlefish
821