Skip to content

Commit bedf0a0

Browse files
thymikeeclaude
andcommitted
fix(android): keep both stop waits on the killApp path
The stop wait returned at an expired foreground fence, so killApp skipped the process wait and sampled pidof once. Kill now runs both waits as on main and classifies a survivor itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3d6a899 commit bedf0a0

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎packages/platform-android/src/__tests__/app-lifecycle-kill.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, test } from 'vitest';
1+
import { beforeEach, test, vi } from 'vitest';
22
import assert from 'node:assert/strict';
33
import { killAndroidApp } from '../app-lifecycle.ts';
44
import { withAndroidAdbProvider } from '../adb-executor.ts';
@@ -149,6 +149,39 @@ test('killAndroidApp proceeds when focus still names the target but the resumed
149149
]);
150150
});
151151

152+
test('killAndroidApp waits out a slow exit even while stale focus still names the target', async () => {
153+
vi.useFakeTimers();
154+
let pidofCalls = 0;
155+
try {
156+
await withAndroidAdbProvider(
157+
{
158+
exec: async (args) => {
159+
const command = args.join(' ');
160+
if (command === dumpsysActivityActivities) {
161+
return { stdout: RESUMED_LAUNCHER_DUMP, stderr: '', exitCode: 0 };
162+
}
163+
if (command === dumpsysWindowWindows) {
164+
return { stdout: TARGET_FOCUS_DUMP, stderr: '', exitCode: 0 };
165+
}
166+
if (command === pidofTarget) {
167+
pidofCalls += 1;
168+
return { stdout: pidofCalls <= 2 ? '12345\n' : '', stderr: '', exitCode: 0 };
169+
}
170+
return { stdout: '', stderr: '', exitCode: 0 };
171+
},
172+
reverse: noReverse,
173+
},
174+
{ serial: 'emulator-5554' },
175+
async () => {
176+
await Promise.all([killAndroidApp(DEVICE, 'com.example.app'), vi.runAllTimersAsync()]);
177+
},
178+
);
179+
assert.ok(pidofCalls > 2, `the kill polled the process until it exited (${pidofCalls})`);
180+
} finally {
181+
vi.useRealTimers();
182+
}
183+
});
184+
152185
test('killAndroidApp fails when the process survives the kill', async () => {
153186
await withAndroidAdbProvider(
154187
{

‎packages/platform-android/src/app-lifecycle.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,10 @@ async function killAndroidPackage(device: DeviceInfo, packageName: string): Prom
591591
);
592592
}
593593
await runAndroidShell(device, ['am', 'kill', packageName]);
594-
// Kill classifies a survivor itself below, so an expired fence is not its refusal.
595-
await waitForAndroidPackageStopped(device, packageName);
594+
// Both fences run as on close, but a survivor is classified below rather than refused as a
595+
// close timeout.
596+
await waitForAndroidPackageNotForeground(device, packageName);
597+
await waitForAndroidPackageProcessGone(device, packageName);
596598
const process = await readAndroidPackageProcessState(device, packageName);
597599
if (process === 'running') {
598600
throw new AppError('COMMAND_FAILED', `am kill did not stop ${packageName}`, {

0 commit comments

Comments
 (0)