Skip to content

Commit 9aada83

Browse files
committed
fix: launch android settings by component
1 parent 8be34b4 commit 9aada83

4 files changed

Lines changed: 31 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,10 @@ jobs:
490490
$env:SIMDECK_INTEGRATION_REQUIRE_RUNNING_ANDROID = "1"
491491
$env:SIMDECK_INTEGRATION_VERBOSE = "1"
492492
npm run test:integration:android
493-
if ($LASTEXITCODE -ne 0) {
493+
$testExitCode = $LASTEXITCODE
494+
if ($testExitCode -ne 0) {
494495
Write-EmulatorDiagnostics
495-
throw "Android integration tests failed with exit code $LASTEXITCODE."
496+
throw "Android integration tests failed with exit code $testExitCode."
496497
}
497498
498499
- name: Stop Android emulator (Windows)

packages/server/src/android.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ impl AndroidBridge {
447447

448448
pub fn launch_package(&self, id: &str, package: &str) -> Result<(), AppError> {
449449
let serial = self.serial_for_id(id)?;
450+
if is_android_component_name(package) {
451+
self.run_adb(["-s", &serial, "shell", "am", "start", "-n", package])?;
452+
return Ok(());
453+
}
450454
self.run_adb([
451455
"-s",
452456
&serial,
@@ -1708,6 +1712,13 @@ fn parse_online_emulator_serials(output: &str) -> Vec<String> {
17081712
.collect()
17091713
}
17101714

1715+
fn is_android_component_name(value: &str) -> bool {
1716+
value
1717+
.split_once('/')
1718+
.map(|(package, activity)| !package.is_empty() && !activity.is_empty())
1719+
.unwrap_or(false)
1720+
}
1721+
17111722
fn android_cmdline_tool_path(name: &str) -> PathBuf {
17121723
let root = sdk_root();
17131724
let latest = android_sdk_tool_path_for_os(
@@ -2634,6 +2645,17 @@ abcd1234\tdevice
26342645

26352646
assert_eq!(parse_online_emulator_serials(output), vec!["emulator-5554"]);
26362647
}
2648+
2649+
#[test]
2650+
fn android_component_names_require_package_and_activity() {
2651+
assert!(is_android_component_name("com.android.settings/.Settings"));
2652+
assert!(is_android_component_name(
2653+
"com.example/com.example.MainActivity"
2654+
));
2655+
assert!(!is_android_component_name("com.example"));
2656+
assert!(!is_android_component_name("com.example/"));
2657+
assert!(!is_android_component_name("/.MainActivity"));
2658+
}
26372659
}
26382660

26392661
mod grpc {

scripts/github-actions.test.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ test("Android integration runner resolves Windows executables", () => {
114114
androidIntegration,
115115
/fallbackAvdName && avds\.size === 0 && devices\.length === 1/,
116116
);
117+
assert.match(androidIntegration, /com\.android\.settings\/\.Settings/);
117118
assert.match(androidIntegration, /simdeck-bin\.exe/);
118119
assert.match(androidIntegration, /simdeck-bin-win32-x64\.exe/);
119120
assert.match(androidIntegration, /AppData", "Local", "Android", "Sdk/);

scripts/integration/android.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const requireRunningAndroid =
1616
process.env.SIMDECK_INTEGRATION_REQUIRE_RUNNING_ANDROID === "1" ||
1717
process.env.CI === "true";
1818
const requestedAvd = process.env.SIMDECK_INTEGRATION_ANDROID_AVD;
19+
const androidLaunchTarget =
20+
process.env.SIMDECK_INTEGRATION_ANDROID_LAUNCH_TARGET ??
21+
"com.android.settings/.Settings";
1922
const defaultStepTimeoutMs = Number(
2023
process.env.SIMDECK_INTEGRATION_STEP_TIMEOUT_MS ?? "180000",
2124
);
@@ -213,7 +216,7 @@ async function runCliSurface() {
213216
}
214217
});
215218
await measuredStep("CLI app launch and URL", () => {
216-
simdeckJson(["launch", androidUDID, "com.android.settings"], {
219+
simdeckJson(["launch", androidUDID, androidLaunchTarget], {
217220
timeoutMs: 60_000,
218221
});
219222
simdeckJson(["open-url", androidUDID, "https://example.com"], {
@@ -355,7 +358,7 @@ async function runJsSurface() {
355358
}
356359
});
357360
await measuredStep("JS app launch and URL", async () => {
358-
await session.launch(androidUDID, "com.android.settings");
361+
await session.launch(androidUDID, androidLaunchTarget);
359362
await session.openUrl(androidUDID, "https://example.com");
360363
await session.home(androidUDID);
361364
});

0 commit comments

Comments
 (0)