Skip to content

Commit 2da2b57

Browse files
authored
fix(android): empty Device::name for emulator (#481)
1 parent f45fc4e commit 2da2b57

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

.changes/empty-emulator-name.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cargo-mobile2": patch
3+
---
4+
5+
Fix empty `Device::name` when using an Android emulator.

src/android/adb/device_name.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Reportable for Error {
3434

3535
pub fn device_name(env: &Env, serial_no: &str) -> Result<String, Error> {
3636
if serial_no.starts_with("emulator") {
37-
super::check_authorized(
37+
let name = super::check_authorized(
3838
adb(env, ["-s", serial_no])
3939
.before_spawn(move |cmd| {
4040
cmd.args(["emu", "avd", "name"]);
@@ -45,8 +45,18 @@ pub fn device_name(env: &Env, serial_no: &str) -> Result<String, Error> {
4545
.start()?
4646
.wait()?,
4747
)
48-
.map(|stdout| stdout.split('\n').next().unwrap().trim().into())
49-
.map_err(Error::EmuFailed)
48+
.map(|stdout| stdout.split('\n').next().unwrap().trim().to_string())
49+
.map_err(Error::EmuFailed)?;
50+
if name.is_empty() {
51+
super::get_prop::get_prop(env, serial_no, "ro.boot.qemu.avd_name").map_err(|e| {
52+
Error::EmuFailed(super::RunCheckedError::CommandFailed(std::io::Error::new(
53+
std::io::ErrorKind::Other,
54+
e,
55+
)))
56+
})
57+
} else {
58+
Ok(name)
59+
}
5060
} else {
5161
super::check_authorized(
5262
adb(env, ["-s", serial_no])

0 commit comments

Comments
 (0)