Skip to content

Commit 74138d4

Browse files
authored
fix: regression detecting Android process PID with app ID suffix (#509)
regression from #505 ## Summary Fix Android `run_with_application_id_suffix` so the suffixed application id is used consistently for both launching the activity and resolving the running process for logcat. This prevents debug/release side-by-side installs from attaching logcat to the wrong package, and avoids waiting on the base package when only the suffixed variant is running. ## Test plan - `cargo test android::device::test::test_resolve_activity_name` - `cargo fmt --check`
1 parent 07625e1 commit 74138d4

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

.changes/fix-android-regression.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+
Fixed Android logcat process detection when running an app with `--application-id-suffix`.

src/android/device.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,11 @@ impl<'a> Device<'a> {
435435
.map_err(RunError::ApkInstallFailed)?;
436436
}
437437

438-
let activity = Device::resolve_activity_name(
439-
config.app().identifier().to_string(),
440-
application_id_suffix,
441-
activity,
438+
let app_identifier = Device::resolve_application_id(
439+
config.app().identifier(),
440+
application_id_suffix.as_deref(),
442441
);
442+
let activity = Device::resolve_activity_name(app_identifier.clone(), activity);
443443
let activity_ = activity.clone();
444444
let cmd = self
445445
.adb(env)
@@ -476,7 +476,7 @@ impl<'a> Device<'a> {
476476
let stdout = loop {
477477
let cmd = duct::cmd(
478478
env.platform_tools_path().join("adb"),
479-
["shell", "pidof", "-s", config.app().identifier()],
479+
["shell", "pidof", "-s", app_identifier.as_str()],
480480
)
481481
.vars(env.explicit_env())
482482
.stderr_capture()
@@ -556,6 +556,16 @@ impl<'a> Device<'a> {
556556
Ok(())
557557
}
558558

559+
/**
560+
* The application ID is the package name of the variant to launch.
561+
*/
562+
fn resolve_application_id(app_identifier: &str, application_id_suffix: Option<&str>) -> String {
563+
format!(
564+
"{app_identifier}{}",
565+
application_id_suffix.unwrap_or_default()
566+
)
567+
}
568+
559569
/**
560570
* The activity name is the fully qualified class name of the activity to launch.
561571
* Here are the expected formats for the activity name: of the release and debug variants
@@ -570,15 +580,8 @@ impl<'a> Device<'a> {
570580
* Debug variants have 1 acceptable format:
571581
* * `com.example.app.debug/com.example.app.MainActivity`
572582
*/
573-
fn resolve_activity_name(
574-
app_identifier: String,
575-
application_id_suffix: Option<String>,
576-
activity: String,
577-
) -> String {
578-
return format!(
579-
"{app_identifier}{}/{activity}",
580-
application_id_suffix.unwrap_or_default()
581-
);
583+
fn resolve_activity_name(app_identifier: String, activity: String) -> String {
584+
format!("{app_identifier}/{activity}")
582585
}
583586
}
584587

@@ -616,11 +619,8 @@ mod test {
616619
activity: String,
617620
expected: String,
618621
) {
619-
let activity = Device::resolve_activity_name(
620-
app_identifier,
621-
application_id_suffix.map(|s| s.to_string()),
622-
activity,
623-
);
622+
let app_identifier = Device::resolve_application_id(&app_identifier, application_id_suffix);
623+
let activity = Device::resolve_activity_name(app_identifier, activity);
624624
assert_eq!(activity, expected);
625625
}
626626
}

0 commit comments

Comments
 (0)