Cartucho / android-touch-record-replay

How to record and replay touchscreen events on an Android device.
Apache License 2.0
224 stars 46 forks source link

Use 'exec-out' instead of 'shell'. Fixes last touch not being fully recorded #16

Closed peterdk closed 4 years ago

peterdk commented 4 years ago

A simple fix to make recording working as it should: capturing all data. When using shell there is some buffering at play which causes the last touch events not being fully recorded resulting in weird hanging touch at the end of playback. exec-out is shell without buffering.

peterdk commented 4 years ago

Should fix #12 and #6

Cartucho commented 4 years ago

In my phone, it works the other way around... If I replace shell with exect-out it stops working and hangs at the end of playback.

image

Do you think this depends on the Android version?

peterdk commented 4 years ago

Ok, frustrating. I am running the command from OSX, maybe that is the issue? I will check on Ubuntu to see if I can replicate your behaviour.

I assume you are displaying the recorded .txt file in your screenshot?

Cartucho commented 4 years ago

Yes, I am using Ubuntu, which version of adb is the default one in OS?

Yes that is the .txt file

Cartucho commented 4 years ago

We could use the following:

if [[ "$OSTYPE" == "linux-gnu" ]]; then
        adb shell getevent -t "${TOUCH_DEVICE#*-> }" > recorded_touch_events.txt
else
        #exec-out is shell without buffering, fixing missing last touch data event
        adb exec-out getevent -t "${TOUCH_DEVICE#*-> }" > recorded_touch_events.txt
fi

It will work fine on both.

peterdk commented 4 years ago

I tried on Ubuntu 18.04, and with shell I get half end line, and with exec-out I get full last line. So unfortunately itś not due to OSX. ADB on Ubuntu is: Android Debug Bridge version 1.0.39 Version 1:8.1.0+r23-5

I am using a Android 9 phone.

Cartucho commented 4 years ago

Ok, it must have to do with the Android version, my phone is using version 6.0... very old! I think expect-out was only introduced in 5.0 so it may be that my phone does not have it yet. Let me see if there is a way to check for the Android version if <= 6.0 we use the shell.

peterdk commented 4 years ago

I tested with a 6.0, 7.0 and a 7.1 emulator and can indeed reproduce. On 6.0 shell gives full lines, and exec-out cut off lines. On 7.0 and higher it's reversed.

Cartucho commented 4 years ago

perfect! I just added a condition check in the file, if the version <= 6.0 then it uses the shell

peterdk commented 4 years ago

Nice

Cartucho commented 4 years ago

It should be working fine now! Thank you!

peterdk commented 4 years ago

Maybe it's easier to use the sdk int? ro.build.version.sdk

Cartucho commented 4 years ago

is it dependent on the SDK or on the Android version?

peterdk commented 4 years ago

SDK int is same indicator as Android version, only in simple int instead of a more complex float like number.

peterdk commented 4 years ago

https://source.android.com/setup/start/build-numbers

So 24 and higher should use exec-out

Cartucho commented 4 years ago

Ok, I will fix it then

Cartucho commented 4 years ago

done! :+1:

peterdk commented 4 years ago

Ok, great!

Can't it be simplified to: if ((ANDROID_VERSION > MIN_VERSION)) ? I am not a bash expert, but it looks a bit too complicated now since we only use simpel ints.

Cartucho commented 4 years ago

done