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
19 #include <android-base/logging.h>
20 #include <json/json.h>
21
22 #include "common/libs/utils/files.h"
23
24 namespace cuttlefish {
25 namespace {
26
27 const char* kInstances = "instances";
28
29 } // namespace
30
Dictionary()31 Json::Value* CuttlefishConfig::MutableInstanceSpecific::Dictionary() {
32 return &(*config_->dictionary_)[kInstances][id_];
33 }
34
Dictionary() const35 const Json::Value* CuttlefishConfig::InstanceSpecific::Dictionary() const {
36 return &(*config_->dictionary_)[kInstances][id_];
37 }
38
39 static constexpr char kInstanceDir[] = "instance_dir";
instance_dir() const40 std::string CuttlefishConfig::InstanceSpecific::instance_dir() const {
41 return (*Dictionary())[kInstanceDir].asString();
42 }
set_instance_dir(const std::string & instance_dir)43 void CuttlefishConfig::MutableInstanceSpecific::set_instance_dir(
44 const std::string& instance_dir) {
45 (*Dictionary())[kInstanceDir] = instance_dir;
46 }
47
instance_internal_dir() const48 std::string CuttlefishConfig::InstanceSpecific::instance_internal_dir() const {
49 return PerInstancePath(kInternalDirName);
50 }
51
52 static constexpr char kSerialNumber[] = "serial_number";
serial_number() const53 std::string CuttlefishConfig::InstanceSpecific::serial_number() const {
54 return (*Dictionary())[kSerialNumber].asString();
55 }
set_serial_number(const std::string & serial_number)56 void CuttlefishConfig::MutableInstanceSpecific::set_serial_number(
57 const std::string& serial_number) {
58 (*Dictionary())[kSerialNumber] = serial_number;
59 }
60
61 static constexpr char kVirtualDiskPaths[] = "virtual_disk_paths";
virtual_disk_paths() const62 std::vector<std::string> CuttlefishConfig::InstanceSpecific::virtual_disk_paths() const {
63 std::vector<std::string> virtual_disks;
64 auto virtual_disks_json_obj = (*Dictionary())[kVirtualDiskPaths];
65 for (const auto& disk : virtual_disks_json_obj) {
66 virtual_disks.push_back(disk.asString());
67 }
68 return virtual_disks;
69 }
set_virtual_disk_paths(const std::vector<std::string> & virtual_disk_paths)70 void CuttlefishConfig::MutableInstanceSpecific::set_virtual_disk_paths(
71 const std::vector<std::string>& virtual_disk_paths) {
72 Json::Value virtual_disks_json_obj(Json::arrayValue);
73 for (const auto& arg : virtual_disk_paths) {
74 virtual_disks_json_obj.append(arg);
75 }
76 (*Dictionary())[kVirtualDiskPaths] = virtual_disks_json_obj;
77 }
78
kernel_log_pipe_name() const79 std::string CuttlefishConfig::InstanceSpecific::kernel_log_pipe_name() const {
80 return AbsolutePath(PerInstanceInternalPath("kernel-log-pipe"));
81 }
82
console_pipe_prefix() const83 std::string CuttlefishConfig::InstanceSpecific::console_pipe_prefix() const {
84 return AbsolutePath(PerInstanceInternalPath("console"));
85 }
86
console_in_pipe_name() const87 std::string CuttlefishConfig::InstanceSpecific::console_in_pipe_name() const {
88 return console_pipe_prefix() + ".in";
89 }
90
console_out_pipe_name() const91 std::string CuttlefishConfig::InstanceSpecific::console_out_pipe_name() const {
92 return console_pipe_prefix() + ".out";
93 }
94
gnss_pipe_prefix() const95 std::string CuttlefishConfig::InstanceSpecific::gnss_pipe_prefix() const {
96 return AbsolutePath(PerInstanceInternalPath("gnss"));
97 }
98
gnss_in_pipe_name() const99 std::string CuttlefishConfig::InstanceSpecific::gnss_in_pipe_name() const {
100 return gnss_pipe_prefix() + ".in";
101 }
102
gnss_out_pipe_name() const103 std::string CuttlefishConfig::InstanceSpecific::gnss_out_pipe_name() const {
104 return gnss_pipe_prefix() + ".out";
105 }
106
107 static constexpr char kGnssGrpcProxyServerPort[] =
108 "gnss_grpc_proxy_server_port";
gnss_grpc_proxy_server_port() const109 int CuttlefishConfig::InstanceSpecific::gnss_grpc_proxy_server_port() const {
110 return (*Dictionary())[kGnssGrpcProxyServerPort].asInt();
111 }
set_gnss_grpc_proxy_server_port(int gnss_grpc_proxy_server_port)112 void CuttlefishConfig::MutableInstanceSpecific::set_gnss_grpc_proxy_server_port(
113 int gnss_grpc_proxy_server_port) {
114 (*Dictionary())[kGnssGrpcProxyServerPort] = gnss_grpc_proxy_server_port;
115 }
116
117 static constexpr char kGnssFilePath[] = "gnss_file_path";
gnss_file_path() const118 std::string CuttlefishConfig::InstanceSpecific::gnss_file_path() const {
119 return (*Dictionary())[kGnssFilePath].asString();
120 }
set_gnss_file_path(const std::string & gnss_file_path)121 void CuttlefishConfig::MutableInstanceSpecific::set_gnss_file_path(
122 const std::string& gnss_file_path) {
123 (*Dictionary())[kGnssFilePath] = gnss_file_path;
124 }
125
logcat_pipe_name() const126 std::string CuttlefishConfig::InstanceSpecific::logcat_pipe_name() const {
127 return AbsolutePath(PerInstanceInternalPath("logcat-pipe"));
128 }
129
access_kregistry_path() const130 std::string CuttlefishConfig::InstanceSpecific::access_kregistry_path() const {
131 return AbsolutePath(PerInstancePath("access-kregistry"));
132 }
133
pstore_path() const134 std::string CuttlefishConfig::InstanceSpecific::pstore_path() const {
135 return AbsolutePath(PerInstancePath("pstore"));
136 }
137
console_path() const138 std::string CuttlefishConfig::InstanceSpecific::console_path() const {
139 return AbsolutePath(PerInstancePath("console"));
140 }
141
logcat_path() const142 std::string CuttlefishConfig::InstanceSpecific::logcat_path() const {
143 return AbsolutePath(PerInstancePath("logcat"));
144 }
145
launcher_monitor_socket_path() const146 std::string CuttlefishConfig::InstanceSpecific::launcher_monitor_socket_path()
147 const {
148 return AbsolutePath(PerInstancePath("launcher_monitor.sock"));
149 }
150
151 static constexpr char kModemSimulatorPorts[] = "modem_simulator_ports";
modem_simulator_ports() const152 std::string CuttlefishConfig::InstanceSpecific::modem_simulator_ports() const {
153 return (*Dictionary())[kModemSimulatorPorts].asString();
154 }
set_modem_simulator_ports(const std::string & modem_simulator_ports)155 void CuttlefishConfig::MutableInstanceSpecific::set_modem_simulator_ports(
156 const std::string& modem_simulator_ports) {
157 (*Dictionary())[kModemSimulatorPorts] = modem_simulator_ports;
158 }
159
launcher_log_path() const160 std::string CuttlefishConfig::InstanceSpecific::launcher_log_path() const {
161 return AbsolutePath(PerInstancePath("launcher.log"));
162 }
163
sdcard_path() const164 std::string CuttlefishConfig::InstanceSpecific::sdcard_path() const {
165 return AbsolutePath(PerInstancePath("sdcard.img"));
166 }
167
os_composite_disk_path() const168 std::string CuttlefishConfig::InstanceSpecific::os_composite_disk_path() const {
169 return AbsolutePath(PerInstancePath("os_composite.img"));
170 }
171
persistent_composite_disk_path() const172 std::string CuttlefishConfig::InstanceSpecific::persistent_composite_disk_path()
173 const {
174 return AbsolutePath(PerInstancePath("persistent_composite.img"));
175 }
176
uboot_env_image_path() const177 std::string CuttlefishConfig::InstanceSpecific::uboot_env_image_path() const {
178 return AbsolutePath(PerInstancePath("uboot_env.img"));
179 }
180
vendor_boot_image_path() const181 std::string CuttlefishConfig::InstanceSpecific::vendor_boot_image_path() const {
182 return AbsolutePath(PerInstancePath("vendor_boot_repacked.img"));
183 }
184
185 static constexpr char kMobileBridgeName[] = "mobile_bridge_name";
186
audio_server_path() const187 std::string CuttlefishConfig::InstanceSpecific::audio_server_path() const {
188 return AbsolutePath(PerInstanceInternalPath("audio_server.sock"));
189 }
190
mobile_bridge_name() const191 std::string CuttlefishConfig::InstanceSpecific::mobile_bridge_name() const {
192 return (*Dictionary())[kMobileBridgeName].asString();
193 }
set_mobile_bridge_name(const std::string & mobile_bridge_name)194 void CuttlefishConfig::MutableInstanceSpecific::set_mobile_bridge_name(
195 const std::string& mobile_bridge_name) {
196 (*Dictionary())[kMobileBridgeName] = mobile_bridge_name;
197 }
198
199 static constexpr char kMobileTapName[] = "mobile_tap_name";
mobile_tap_name() const200 std::string CuttlefishConfig::InstanceSpecific::mobile_tap_name() const {
201 return (*Dictionary())[kMobileTapName].asString();
202 }
set_mobile_tap_name(const std::string & mobile_tap_name)203 void CuttlefishConfig::MutableInstanceSpecific::set_mobile_tap_name(
204 const std::string& mobile_tap_name) {
205 (*Dictionary())[kMobileTapName] = mobile_tap_name;
206 }
207
confui_hal_guest_socket_path() const208 std::string CuttlefishConfig::InstanceSpecific::confui_hal_guest_socket_path()
209 const {
210 return PerInstanceInternalPath("confui_mock_hal_guest.sock");
211 }
212
213 static constexpr char kWifiTapName[] = "wifi_tap_name";
wifi_tap_name() const214 std::string CuttlefishConfig::InstanceSpecific::wifi_tap_name() const {
215 return (*Dictionary())[kWifiTapName].asString();
216 }
set_wifi_tap_name(const std::string & wifi_tap_name)217 void CuttlefishConfig::MutableInstanceSpecific::set_wifi_tap_name(
218 const std::string& wifi_tap_name) {
219 (*Dictionary())[kWifiTapName] = wifi_tap_name;
220 }
221
222 static constexpr char kEthernetTapName[] = "ethernet_tap_name";
ethernet_tap_name() const223 std::string CuttlefishConfig::InstanceSpecific::ethernet_tap_name() const {
224 return (*Dictionary())[kEthernetTapName].asString();
225 }
set_ethernet_tap_name(const std::string & ethernet_tap_name)226 void CuttlefishConfig::MutableInstanceSpecific::set_ethernet_tap_name(
227 const std::string& ethernet_tap_name) {
228 (*Dictionary())[kEthernetTapName] = ethernet_tap_name;
229 }
230
231 static constexpr char kUseAllocd[] = "use_allocd";
use_allocd() const232 bool CuttlefishConfig::InstanceSpecific::use_allocd() const {
233 return (*Dictionary())[kUseAllocd].asBool();
234 }
set_use_allocd(bool use_allocd)235 void CuttlefishConfig::MutableInstanceSpecific::set_use_allocd(
236 bool use_allocd) {
237 (*Dictionary())[kUseAllocd] = use_allocd;
238 }
239
240 static constexpr char kSessionId[] = "session_id";
session_id() const241 uint32_t CuttlefishConfig::InstanceSpecific::session_id() const {
242 return (*Dictionary())[kSessionId].asUInt();
243 }
set_session_id(uint32_t session_id)244 void CuttlefishConfig::MutableInstanceSpecific::set_session_id(
245 uint32_t session_id) {
246 (*Dictionary())[kSessionId] = session_id;
247 }
248
249 static constexpr char kVsockGuestCid[] = "vsock_guest_cid";
vsock_guest_cid() const250 int CuttlefishConfig::InstanceSpecific::vsock_guest_cid() const {
251 return (*Dictionary())[kVsockGuestCid].asInt();
252 }
set_vsock_guest_cid(int vsock_guest_cid)253 void CuttlefishConfig::MutableInstanceSpecific::set_vsock_guest_cid(
254 int vsock_guest_cid) {
255 (*Dictionary())[kVsockGuestCid] = vsock_guest_cid;
256 }
257
258 static constexpr char kUuid[] = "uuid";
uuid() const259 std::string CuttlefishConfig::InstanceSpecific::uuid() const {
260 return (*Dictionary())[kUuid].asString();
261 }
set_uuid(const std::string & uuid)262 void CuttlefishConfig::MutableInstanceSpecific::set_uuid(const std::string& uuid) {
263 (*Dictionary())[kUuid] = uuid;
264 }
265
266 static constexpr char kHostPort[] = "host_port";
host_port() const267 int CuttlefishConfig::InstanceSpecific::host_port() const {
268 return (*Dictionary())[kHostPort].asInt();
269 }
set_host_port(int host_port)270 void CuttlefishConfig::MutableInstanceSpecific::set_host_port(int host_port) {
271 (*Dictionary())[kHostPort] = host_port;
272 }
273
274 static constexpr char kAdbIPAndPort[] = "adb_ip_and_port";
adb_ip_and_port() const275 std::string CuttlefishConfig::InstanceSpecific::adb_ip_and_port() const {
276 return (*Dictionary())[kAdbIPAndPort].asString();
277 }
set_adb_ip_and_port(const std::string & ip_port)278 void CuttlefishConfig::MutableInstanceSpecific::set_adb_ip_and_port(
279 const std::string& ip_port) {
280 (*Dictionary())[kAdbIPAndPort] = ip_port;
281 }
282
adb_device_name() const283 std::string CuttlefishConfig::InstanceSpecific::adb_device_name() const {
284 if (adb_ip_and_port() != "") {
285 return adb_ip_and_port();
286 }
287 LOG(ERROR) << "no adb_mode found, returning bad device name";
288 return "NO_ADB_MODE_SET_NO_VALID_DEVICE_NAME";
289 }
290
291 static constexpr char kDeviceTitle[] = "device_title";
device_title() const292 std::string CuttlefishConfig::InstanceSpecific::device_title() const {
293 return (*Dictionary())[kDeviceTitle].asString();
294 }
set_device_title(const std::string & title)295 void CuttlefishConfig::MutableInstanceSpecific::set_device_title(
296 const std::string& title) {
297 (*Dictionary())[kDeviceTitle] = title;
298 }
299
300 static constexpr char kVncServerPort[] = "vnc_server_port";
vnc_server_port() const301 int CuttlefishConfig::InstanceSpecific::vnc_server_port() const {
302 return (*Dictionary())[kVncServerPort].asInt();
303 }
set_vnc_server_port(int vnc_server_port)304 void CuttlefishConfig::MutableInstanceSpecific::set_vnc_server_port(int vnc_server_port) {
305 (*Dictionary())[kVncServerPort] = vnc_server_port;
306 }
307
308 static constexpr char kFramesServerPort[] = "frames_server_port";
frames_server_port() const309 int CuttlefishConfig::InstanceSpecific::frames_server_port() const {
310 return (*Dictionary())[kFramesServerPort].asInt();
311 }
set_frames_server_port(int frames_server_port)312 void CuttlefishConfig::MutableInstanceSpecific::set_frames_server_port(int frames_server_port) {
313 (*Dictionary())[kFramesServerPort] = frames_server_port;
314 }
315
316 static constexpr char kTouchServerPort[] = "touch_server_port";
touch_server_port() const317 int CuttlefishConfig::InstanceSpecific::touch_server_port() const {
318 return (*Dictionary())[kTouchServerPort].asInt();
319 }
320
set_touch_server_port(int touch_server_port)321 void CuttlefishConfig::MutableInstanceSpecific::set_touch_server_port(int touch_server_port) {
322 (*Dictionary())[kTouchServerPort] = touch_server_port;
323 }
324
325 static constexpr char kKeyboardServerPort[] = "keyboard_server_port";
keyboard_server_port() const326 int CuttlefishConfig::InstanceSpecific::keyboard_server_port() const {
327 return (*Dictionary())[kKeyboardServerPort].asInt();
328 }
set_keyboard_server_port(int keyboard_server_port)329 void CuttlefishConfig::MutableInstanceSpecific::set_keyboard_server_port(int keyboard_server_port) {
330 (*Dictionary())[kKeyboardServerPort] = keyboard_server_port;
331 }
332
333 static constexpr char kTombstoneReceiverPort[] = "tombstone_receiver_port";
tombstone_receiver_port() const334 int CuttlefishConfig::InstanceSpecific::tombstone_receiver_port() const {
335 return (*Dictionary())[kTombstoneReceiverPort].asInt();
336 }
set_tombstone_receiver_port(int tombstone_receiver_port)337 void CuttlefishConfig::MutableInstanceSpecific::set_tombstone_receiver_port(int tombstone_receiver_port) {
338 (*Dictionary())[kTombstoneReceiverPort] = tombstone_receiver_port;
339 }
340
341 static constexpr char kVehicleHalServerPort[] = "vehicle_hal_server_port";
vehicle_hal_server_port() const342 int CuttlefishConfig::InstanceSpecific::vehicle_hal_server_port() const {
343 return (*Dictionary())[kVehicleHalServerPort].asInt();
344 }
set_vehicle_hal_server_port(int vehicle_hal_server_port)345 void CuttlefishConfig::MutableInstanceSpecific::set_vehicle_hal_server_port(int vehicle_hal_server_port) {
346 (*Dictionary())[kVehicleHalServerPort] = vehicle_hal_server_port;
347 }
348
349 static constexpr char kAudioControlServerPort[] = "audiocontrol_server_port";
audiocontrol_server_port() const350 int CuttlefishConfig::InstanceSpecific::audiocontrol_server_port() const {
351 return (*Dictionary())[kAudioControlServerPort].asInt();
352 }
set_audiocontrol_server_port(int audiocontrol_server_port)353 void CuttlefishConfig::MutableInstanceSpecific::set_audiocontrol_server_port(int audiocontrol_server_port) {
354 (*Dictionary())[kAudioControlServerPort] = audiocontrol_server_port;
355 }
356
357 static constexpr char kConfigServerPort[] = "config_server_port";
config_server_port() const358 int CuttlefishConfig::InstanceSpecific::config_server_port() const {
359 return (*Dictionary())[kConfigServerPort].asInt();
360 }
set_config_server_port(int config_server_port)361 void CuttlefishConfig::MutableInstanceSpecific::set_config_server_port(int config_server_port) {
362 (*Dictionary())[kConfigServerPort] = config_server_port;
363 }
364
365 static constexpr char kRootcanalHciPort[] = "rootcanal_hci_port";
rootcanal_hci_port() const366 int CuttlefishConfig::InstanceSpecific::rootcanal_hci_port() const {
367 return (*Dictionary())[kRootcanalHciPort].asInt();
368 }
set_rootcanal_hci_port(int rootcanal_hci_port)369 void CuttlefishConfig::MutableInstanceSpecific::set_rootcanal_hci_port(
370 int rootcanal_hci_port) {
371 (*Dictionary())[kRootcanalHciPort] = rootcanal_hci_port;
372 }
373
374 static constexpr char kRootcanalLinkPort[] = "rootcanal_link_port";
rootcanal_link_port() const375 int CuttlefishConfig::InstanceSpecific::rootcanal_link_port() const {
376 return (*Dictionary())[kRootcanalLinkPort].asInt();
377 }
set_rootcanal_link_port(int rootcanal_link_port)378 void CuttlefishConfig::MutableInstanceSpecific::set_rootcanal_link_port(
379 int rootcanal_link_port) {
380 (*Dictionary())[kRootcanalLinkPort] = rootcanal_link_port;
381 }
382
383 static constexpr char kRootcanalTestPort[] = "rootcanal_test_port";
rootcanal_test_port() const384 int CuttlefishConfig::InstanceSpecific::rootcanal_test_port() const {
385 return (*Dictionary())[kRootcanalTestPort].asInt();
386 }
set_rootcanal_test_port(int rootcanal_test_port)387 void CuttlefishConfig::MutableInstanceSpecific::set_rootcanal_test_port(
388 int rootcanal_test_port) {
389 (*Dictionary())[kRootcanalTestPort] = rootcanal_test_port;
390 }
391
392 static constexpr char kRootcanalConfigFile[] = "rootcanal_config_file";
rootcanal_config_file() const393 std::string CuttlefishConfig::InstanceSpecific::rootcanal_config_file() const {
394 return (*Dictionary())[kRootcanalConfigFile].asString();
395 }
set_rootcanal_config_file(const std::string & rootcanal_config_file)396 void CuttlefishConfig::MutableInstanceSpecific::set_rootcanal_config_file(
397 const std::string& rootcanal_config_file) {
398 (*Dictionary())[kRootcanalConfigFile] =
399 DefaultHostArtifactsPath(rootcanal_config_file);
400 }
401
402 static constexpr char kRootcanalDefaultCommandsFile[] =
403 "rootcanal_default_commands_file";
404 std::string
rootcanal_default_commands_file() const405 CuttlefishConfig::InstanceSpecific::rootcanal_default_commands_file() const {
406 return (*Dictionary())[kRootcanalDefaultCommandsFile].asString();
407 }
408 void CuttlefishConfig::MutableInstanceSpecific::
set_rootcanal_default_commands_file(const std::string & rootcanal_default_commands_file)409 set_rootcanal_default_commands_file(
410 const std::string& rootcanal_default_commands_file) {
411 (*Dictionary())[kRootcanalDefaultCommandsFile] =
412 DefaultHostArtifactsPath(rootcanal_default_commands_file);
413 }
414
415 static constexpr char kWebrtcDeviceId[] = "webrtc_device_id";
set_webrtc_device_id(const std::string & id)416 void CuttlefishConfig::MutableInstanceSpecific::set_webrtc_device_id(
417 const std::string& id) {
418 (*Dictionary())[kWebrtcDeviceId] = id;
419 }
webrtc_device_id() const420 std::string CuttlefishConfig::InstanceSpecific::webrtc_device_id() const {
421 return (*Dictionary())[kWebrtcDeviceId].asString();
422 }
423
424 static constexpr char kStartSigServer[] = "webrtc_start_sig_server";
set_start_webrtc_signaling_server(bool start)425 void CuttlefishConfig::MutableInstanceSpecific::set_start_webrtc_signaling_server(bool start) {
426 (*Dictionary())[kStartSigServer] = start;
427 }
start_webrtc_sig_server() const428 bool CuttlefishConfig::InstanceSpecific::start_webrtc_sig_server() const {
429 return (*Dictionary())[kStartSigServer].asBool();
430 }
431
touch_socket_path() const432 std::string CuttlefishConfig::InstanceSpecific::touch_socket_path() const {
433 return PerInstanceInternalPath("touch.sock");
434 }
435
keyboard_socket_path() const436 std::string CuttlefishConfig::InstanceSpecific::keyboard_socket_path() const {
437 return PerInstanceInternalPath("keyboard.sock");
438 }
439
switches_socket_path() const440 std::string CuttlefishConfig::InstanceSpecific::switches_socket_path() const {
441 return PerInstanceInternalPath("switches.sock");
442 }
443
frames_socket_path() const444 std::string CuttlefishConfig::InstanceSpecific::frames_socket_path() const {
445 return PerInstanceInternalPath("frames.sock");
446 }
447
448 static constexpr char kWifiMacAddress[] = "wifi_mac_address";
set_wifi_mac_address(const std::array<unsigned char,6> & mac_address)449 void CuttlefishConfig::MutableInstanceSpecific::set_wifi_mac_address(
450 const std::array<unsigned char, 6>& mac_address) {
451 Json::Value mac_address_obj(Json::arrayValue);
452 for (const auto& num : mac_address) {
453 mac_address_obj.append(num);
454 }
455 (*Dictionary())[kWifiMacAddress] = mac_address_obj;
456 }
wifi_mac_address() const457 std::array<unsigned char, 6> CuttlefishConfig::InstanceSpecific::wifi_mac_address() const {
458 std::array<unsigned char, 6> mac_address{0, 0, 0, 0, 0, 0};
459 auto mac_address_obj = (*Dictionary())[kWifiMacAddress];
460 if (mac_address_obj.size() != 6) {
461 LOG(ERROR) << kWifiMacAddress << " entry had wrong size";
462 return {};
463 }
464 for (int i = 0; i < 6; i++) {
465 mac_address[i] = mac_address_obj[i].asInt();
466 }
467 return mac_address;
468 }
469
factory_reset_protected_path() const470 std::string CuttlefishConfig::InstanceSpecific::factory_reset_protected_path() const {
471 return PerInstanceInternalPath("factory_reset_protected.img");
472 }
473
persistent_bootconfig_path() const474 std::string CuttlefishConfig::InstanceSpecific::persistent_bootconfig_path()
475 const {
476 return PerInstanceInternalPath("bootconfig");
477 }
478
PerInstancePath(const char * file_name) const479 std::string CuttlefishConfig::InstanceSpecific::PerInstancePath(
480 const char* file_name) const {
481 return (instance_dir() + "/") + file_name;
482 }
483
PerInstanceInternalPath(const char * file_name) const484 std::string CuttlefishConfig::InstanceSpecific::PerInstanceInternalPath(
485 const char* file_name) const {
486 if (file_name[0] == '\0') {
487 // Don't append a / if file_name is empty.
488 return PerInstancePath(kInternalDirName);
489 }
490 auto relative_path = (std::string(kInternalDirName) + "/") + file_name;
491 return PerInstancePath(relative_path.c_str());
492 }
493
instance_name() const494 std::string CuttlefishConfig::InstanceSpecific::instance_name() const {
495 return "cvd-" + id_;
496 }
497
498 } // namespace cuttlefish
499