Skip to content

Commit 0e55dc7

Browse files
committed
fix: satisfy Android recording fallow audit
1 parent a67b7a1 commit 0e55dc7

2 files changed

Lines changed: 37 additions & 17 deletions

File tree

src/daemon/handlers/record-trace-android-chunks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { RecordTraceDeps } from './record-trace-types.ts';
44
import { finalizeRecordingOverlay } from './record-trace-finalize.ts';
55
import { persistRecordingTelemetry } from '../recording-telemetry.ts';
66

7-
export const ANDROID_SCREENRECORD_TIME_LIMIT_MS = 180_000;
8-
export const ANDROID_SCREENRECORD_TIME_LIMIT_GRACE_MS = 2_000;
7+
const ANDROID_SCREENRECORD_TIME_LIMIT_MS = 180_000;
8+
const ANDROID_SCREENRECORD_TIME_LIMIT_GRACE_MS = 2_000;
99
const ANDROID_SCREENRECORD_CHUNK_MS = 170_000;
1010

1111
type AndroidRecording = Extract<NonNullable<SessionState['recording']>, { platform: 'android' }>;

src/daemon/handlers/record-trace-android.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,25 +368,45 @@ async function finishCurrentAndroidRecordingChunk(params: {
368368
},
369369
});
370370

371-
let stopError: string | undefined;
372371
if (stopResult.exitCode !== 0) {
373-
if (await isAndroidProcessRunning(device.id, recording.remotePid)) {
374-
if (!(await forceStopAndroidProcess(device.id, recording.remotePid))) {
375-
stopError = `failed to stop recording: ${formatRecordTraceExecFailure(stopResult, 'adb shell kill')}`;
376-
}
377-
}
378-
} else if (!(await waitForAndroidProcessExit(device.id, recording.remotePid))) {
379-
if (!(await forceStopAndroidProcess(device.id, recording.remotePid))) {
380-
stopError = `failed to stop recording: Android screenrecord pid ${recording.remotePid} did not exit`;
381-
}
372+
return await recoverAndroidStopSignalFailure(device.id, recording.remotePid, stopResult);
373+
}
374+
const exitError = await waitForAndroidStopExit(device.id, recording.remotePid);
375+
if (exitError) {
376+
return exitError;
382377
}
383378

384-
if (!stopError) {
385-
if (waitForRemoteFileStability) {
386-
await waitForAndroidRemoteFileStability(device.id, recording.remotePath);
387-
}
379+
if (waitForRemoteFileStability) {
380+
await waitForAndroidRemoteFileStability(device.id, recording.remotePath);
381+
}
382+
return undefined;
383+
}
384+
385+
async function recoverAndroidStopSignalFailure(
386+
deviceId: string,
387+
remotePid: string,
388+
stopResult: AndroidAdbExecutorResult,
389+
): Promise<string | undefined> {
390+
if (!(await isAndroidProcessRunning(deviceId, remotePid))) {
391+
return undefined;
392+
}
393+
if (await forceStopAndroidProcess(deviceId, remotePid)) {
394+
return undefined;
395+
}
396+
return `failed to stop recording: ${formatRecordTraceExecFailure(stopResult, 'adb shell kill')}`;
397+
}
398+
399+
async function waitForAndroidStopExit(
400+
deviceId: string,
401+
remotePid: string,
402+
): Promise<string | undefined> {
403+
if (await waitForAndroidProcessExit(deviceId, remotePid)) {
404+
return undefined;
405+
}
406+
if (await forceStopAndroidProcess(deviceId, remotePid)) {
407+
return undefined;
388408
}
389-
return stopError;
409+
return `failed to stop recording: Android screenrecord pid ${remotePid} did not exit`;
390410
}
391411

392412
export async function stopAndroidRecording(params: {

0 commit comments

Comments
 (0)