@@ -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
392412export async function stopAndroidRecording ( params : {
0 commit comments