1

I'm using Selendroid in order to test my app. At the beginning of each test I run adb shell screenrecord with the following function:

public static Process startScreenRecord(String fileName) throws IOException{
    ProcessBuilder builder = new ProcessBuilder(
            "cmd.exe", "/c", "cd C:\\Users\\user\\Downloads\\adt-bundle-windows-x86_64-20140702\\adt-bundle-windows-x86_64-20140702\\sdk\\platform-tools\\ && adb shell screenrecord /sdcard/" + fileName);
    builder.redirectErrorStream(true);
    Process p = builder.start();
    return p;
}

The recording is starting and everything looks OK. At the end of each test I try to stop the record via the following code:

public static void stopScreenRecord(Process p) throws IOException{
    p.destroy();
}

And in the test I use the following structure:

    Process p = CmdHelper.startScreenRecord("e1.mp4");
    //TestCode
    CmdHelper.stopScreenRecord(p);

The problem is that the video recording doesn't stop. How can I stop the call recording at the end of each test?

galvan
  • 7,400
  • 7
  • 38
  • 55
  • You may want to use adb shell operations to find and kill the screenrecord process itself. Beware android does not have a pkill or a killall, though it does now have a grep. – Chris Stratton Aug 07 '14 at 16:41
  • the problem is after killing the process the video is not saved. there is any 'clean' way to stop the process so the video will be saved? – galvan Aug 08 '14 at 15:21
  • @galvan Can you please post the solution you came up with? Did you get this to work? We are running into the same issue. Thank you – ALM Jun 09 '16 at 22:22

1 Answers1

3

The adb shell screenrecord --help documentation says that the two ways to terminate it are to set a time limit or to send it ctrl-C.

Assuming the time limit option doesn't work for you, the question would be how to send ctrl-C or its functional equivalent. If you get an output stream connected to ADB's stdin and keep it open, you might be able to send a ctrl-c down that (or you might end up interrupting ADB and not the remote).

A different option, which seems to work is to use the kill command to send SIGINT (which is what ctrl-C typically does) rather than the SIGTERM signal which kill normally sends. That should make the screenrecord process think you hit ctrl-c.

If you have found the process, id, the following seems to work and leave behind a video file:

adb shell kill -2 [pid number]

Where 2 is the usual number of SIGINT on Linux and thus Android.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • How can I find the processID of screenrecord ? – Bulma Oct 07 '15 at 05:41
  • Pipe the adb shell's `ps` into a `grep` for the process name, with grep running on whichever of the android device or your development machine better supports it. Maybe someday android will get a `pkill` – Chris Stratton Oct 08 '15 at 01:07
  • @ChrisStratton Do you have a solution with the ps -ef | grep screenrecord or how were you doing this? We are running into a similar issue. – ALM Jun 09 '16 at 22:22