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> 20 21namespace Json { 22class Value; 23} 24 25namespace vsoc { 26 27// Holds the configuration of the cuttlefish instances. 28class CuttlefishConfig { 29 public: 30 static CuttlefishConfig* Get(); 31 ~CuttlefishConfig() = default; 32 33 // Saves the configuration object in a file, it can then be read in other 34 // processes by passing the --config_file option. 35 bool SaveToFile(const std::string& file) const ; 36 37 // Returns the path to a file with the given name in the instance directory.. 38 std::string PerInstancePath(const char* file_name) const; 39 40 std::string instance_name() const; 41 42 void disable_usb_adb() { 43 // This seems to be the way usb is being disbled in the launcher 44 set_usb_v1_socket_name(""); 45 } 46 47 // Reads the kernel command line from a file and appends extra arguments. 48 bool ReadKernelArgs(const std::string& cmdline_file, 49 const std::string& extra_args); 50 51 std::string instance_dir() const; 52 void set_instance_dir(const std::string& instance_dir); 53 54 std::string serial_number() const; 55 void set_serial_number(const std::string& serial_number); 56 57 int cpus() const; 58 void set_cpus(int cpus); 59 60 int memory_mb() const; 61 void set_memory_mb(int memory_mb); 62 63 int dpi() const; 64 void set_dpi(int dpi); 65 66 int x_res() const; 67 void set_x_res(int x_res); 68 69 int y_res() const; 70 void set_y_res(int y_res); 71 72 int refresh_rate_hz() const; 73 void set_refresh_rate_hz(int refresh_rate_hz); 74 75 std::string kernel_image_path() const; 76 void set_kernel_image_path(const std::string& kernel_image_path); 77 78 std::string kernel_args() const; 79 void set_kernel_args(const std::string& kernel_args); 80 81 std::string ramdisk_image_path() const; 82 void set_ramdisk_image_path(const std::string& ramdisk_image_path); 83 84 std::string system_image_path() const; 85 void set_system_image_path(const std::string& system_image_path); 86 87 std::string cache_image_path() const; 88 void set_cache_image_path(const std::string& cache_image_path); 89 90 std::string data_image_path() const; 91 void set_data_image_path(const std::string& data_image_path); 92 93 std::string vendor_image_path() const; 94 void set_vendor_image_path(const std::string& vendor_image_path); 95 96 std::string dtb_path() const; 97 void set_dtb_path(const std::string& dtb_path); 98 99 std::string mempath() const; 100 void set_mempath(const std::string& mempath); 101 102 std::string ivshmem_qemu_socket_path() const; 103 void set_ivshmem_qemu_socket_path( 104 const std::string& ivshmem_qemu_socket_path); 105 106 std::string ivshmem_client_socket_path() const; 107 void set_ivshmem_client_socket_path( 108 const std::string& ivshmem_client_socket_path); 109 110 int ivshmem_vector_count() const; 111 void set_ivshmem_vector_count(int ivshmem_vector_count); 112 113 // The name of the socket that will be used to forward access to USB gadget. 114 // This is for V1 of the USB bus. 115 std::string usb_v1_socket_name() const; 116 void set_usb_v1_socket_name(const std::string& usb_v1_socket_name); 117 118 int vhci_port() const; 119 void set_vhci_port(int vhci_port); 120 121 std::string usb_ip_socket_name() const; 122 void set_usb_ip_socket_name(const std::string& usb_ip_socket_name); 123 124 std::string kernel_log_socket_name() const; 125 void set_kernel_log_socket_name(const std::string& kernel_log_socket_name); 126 127 std::string console_path() const; 128 void set_console_path(const std::string& console_path); 129 130 std::string logcat_path() const; 131 void set_logcat_path(const std::string& logcat_path); 132 133 std::string mobile_bridge_name() const; 134 void set_mobile_bridge_name(const std::string& mobile_bridge_name); 135 136 std::string mobile_tap_name() const; 137 void set_mobile_tap_name(const std::string& mobile_tap_name); 138 139 std::string wifi_guest_mac_addr() const; 140 void set_wifi_guest_mac_addr(const std::string& wifi_guest_mac_addr); 141 142 std::string wifi_host_mac_addr() const; 143 void set_wifi_host_mac_addr(const std::string& wifi_host_mac_addr); 144 145 std::string entropy_source() const; 146 void set_entropy_source(const std::string& entropy_source); 147 148 std::string uuid() const; 149 void set_uuid(const std::string& uuid); 150 151 bool disable_dac_security() const; 152 void set_disable_dac_security(bool disable_dac_security); 153 154 bool disable_app_armor_security() const; 155 void set_disable_app_armor_security(bool disable_app_armor_security); 156 157 private: 158 std::unique_ptr<Json::Value> dictionary_; 159 160 void LoadFromFile(const char* file); 161 162 CuttlefishConfig(); 163 CuttlefishConfig(const CuttlefishConfig&) = delete; 164 CuttlefishConfig& operator=(const CuttlefishConfig&) = delete; 165}; 166 167// Returns the instance number as obtained from the CUTTLEFISH_INSTANCE 168// environment variable or the username. 169int GetInstance(); 170 171// Returns the path to the ivserver's client socket. 172std::string GetDomain(); 173 174// These functions modify a given base value to make it different accross 175// different instances by appending the instance id in case of strings or adding 176// it in case of integers. 177std::string GetPerInstanceDefault(const char* prefix); 178int GetPerInstanceDefault(int base); 179 180std::string GetDefaultPerInstanceDir(); 181 182} // namespace vsoc 183