Skip to content

Commit 1c8c96a

Browse files
dimorinnyDatabean
authored andcommitted
1 parent 53077df commit 1c8c96a

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

base/cvd/cuttlefish/common/libs/utils/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ cc_library(
9696
"archive.cpp",
9797
"base64.cpp",
9898
"container.cpp",
99+
"device_type.cpp",
99100
"files.cpp",
100101
"flag_parser.cpp",
101102
"flags_validator.cpp",
@@ -121,6 +122,7 @@ cc_library(
121122
"cf_endian.h",
122123
"container.h",
123124
"contains.h",
125+
"device_type.h",
124126
"files.h",
125127
"flag_parser.h",
126128
"flags_validator.h",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2025 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 "common/libs/utils/device_type.h"
18+
19+
namespace cuttlefish {
20+
21+
// Parse device type from android-info.txt config field.
22+
DeviceType ParseDeviceType(std::string_view type_name) {
23+
if (type_name == "phone") {
24+
return DeviceType::Phone;
25+
} else if (type_name == "wear") {
26+
return DeviceType::Wear;
27+
} else if (type_name == "auto" || type_name == "auto_portrait" ||
28+
type_name == "auto_dd" || type_name == "auto_md") {
29+
return DeviceType::Auto;
30+
} else if (type_name == "foldable") {
31+
return DeviceType::Foldable;
32+
} else if (type_name == "tv") {
33+
return DeviceType::Tv;
34+
} else if (type_name == "minidroid") {
35+
return DeviceType::Minidroid;
36+
} else if (type_name == "go") {
37+
return DeviceType::Go;
38+
} else {
39+
return DeviceType::Unknown;
40+
}
41+
}
42+
43+
} // namespace cuttlefish
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2025 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 <string>
19+
20+
namespace cuttlefish {
21+
22+
enum class DeviceType {
23+
Unknown = 0,
24+
Phone,
25+
Wear,
26+
Auto,
27+
Foldable,
28+
Tv,
29+
Minidroid,
30+
Go,
31+
};
32+
33+
// Parse device type android-info.txt config field.
34+
DeviceType ParseDeviceType(std::string_view type_name);
35+
36+
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,15 @@ Result<std::vector<GuestConfig>> ReadGuestConfig() {
724724
system_image_dir[instance_index] + "/android-info.txt";
725725
}
726726

727+
auto res_device_type =
728+
GetAndroidInfoConfig(instance_android_info_txt, "device_type");
729+
// If that "device_type" is not explicitly set, fall back to parse "config".
730+
if (!res_device_type.ok()) {
731+
res_device_type =
732+
GetAndroidInfoConfig(instance_android_info_txt, "config");
733+
}
734+
guest_config.device_type = ParseDeviceType(res_device_type.value_or(""));
735+
727736
auto res = GetAndroidInfoConfig(instance_android_info_txt, "gfxstream");
728737
guest_config.gfxstream_supported =
729738
res.ok() && res.value() == "supported";
@@ -1637,6 +1646,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration(
16371646
"instance_index " << instance_index << " out of boundary "
16381647
<< guest_configs.size());
16391648
instance.set_target_arch(guest_configs[instance_index].target_arch);
1649+
instance.set_device_type(guest_configs[instance_index].device_type);
16401650
instance.set_guest_android_version(
16411651
guest_configs[instance_index].android_version_number);
16421652
instance.set_console(console_vec[instance_index]);

base/cvd/cuttlefish/host/commands/assemble_cvd/flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace cuttlefish {
3030

3131
struct GuestConfig {
3232
Arch target_arch;
33+
DeviceType device_type;
3334
bool bootconfig_supported = false;
3435
bool hctr2_supported = false;
3536
std::string android_version_number;

base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <fmt/ostream.h>
3030

3131
#include "common/libs/utils/architecture.h"
32+
#include "common/libs/utils/device_type.h"
3233
#include "common/libs/utils/result.h"
3334
#include "host/libs/config/config_constants.h"
3435
#include "host/libs/config/config_fragment.h"
@@ -594,6 +595,8 @@ class CuttlefishConfig {
594595
// forces.
595596
bool use_bootloader() const;
596597

598+
DeviceType device_type() const;
599+
597600
Arch target_arch() const;
598601

599602
int cpus() const;
@@ -835,6 +838,7 @@ class CuttlefishConfig {
835838
void set_enable_sandbox(const bool enable_sandbox);
836839
void set_enable_virtiofs(const bool enable_virtiofs);
837840
void set_kgdb(bool kgdb);
841+
void set_device_type(DeviceType type);
838842
void set_target_arch(Arch target_arch);
839843
void set_cpus(int cpus);
840844
void set_vcpu_config_path(const std::string& vcpu_config_path);

base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,15 @@ Arch CuttlefishConfig::InstanceSpecific::target_arch() const {
14071407
return static_cast<Arch>((*Dictionary())[kTargetArch].asInt());
14081408
}
14091409

1410+
static constexpr char kDeviceType[] = "device_type";
1411+
void CuttlefishConfig::MutableInstanceSpecific::set_device_type(
1412+
DeviceType type) {
1413+
(*Dictionary())[kDeviceType] = static_cast<int>(type);
1414+
}
1415+
DeviceType CuttlefishConfig::InstanceSpecific::device_type() const {
1416+
return static_cast<DeviceType>((*Dictionary())[kDeviceType].asInt());
1417+
}
1418+
14101419
static constexpr char kEnableSandbox[] = "enable_sandbox";
14111420
void CuttlefishConfig::MutableInstanceSpecific::set_enable_sandbox(const bool enable_sandbox) {
14121421
(*Dictionary())[kEnableSandbox] = enable_sandbox;

0 commit comments

Comments
 (0)