Android, reproducing swipe motion to unlock device, part #3

Hello Everybody,

Previous tutorials with basics you can find here:

Part 1: essential basics
Part 2: implementing click on screen function using shell script

Dumped and converted events, we can send to unclock device:

system(“adb shell sendevent /dev/input/event2 0003 0048 00000070”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000103”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000924”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);

system(“adb shell sendevent /dev/input/event2 0003 0048 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000409”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000880”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0018 00000047”);
system(“adb shell sendevent /dev/input/event2 0003 0020 00000001”);
system(“adb shell sendevent /dev/input/event2 0000 0000 00000000”);
###
system(“adb shell sendevent /dev/input/event2 0003 0048 00000136”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000102”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000924”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);

system(“adb shell sendevent /dev/input/event2 0003 0048 00000090”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000495”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000935”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
###
system(“adb shell sendevent /dev/input/event2 0003 0020 00000002”);
system(“adb shell sendevent /dev/input/event2 0003 0021 00000002”);
system(“adb shell sendevent /dev/input/event2 0000 0000 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000102”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000924”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000119”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000493”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000928”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0018 00000079”);
system(“adb shell sendevent /dev/input/event2 0003 0020 00000001”);
system(“adb shell sendevent /dev/input/event2 0003 0021 00000001”);
system(“adb shell sendevent /dev/input/event2 0000 0000 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000102”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000924”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000126”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000494”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000930”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0018 00000016”);
system(“adb shell sendevent /dev/input/event2 0000 0000 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000102”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000924”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0048 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0050 00000010”);
system(“adb shell sendevent /dev/input/event2 0003 0053 00000494”);
system(“adb shell sendevent /dev/input/event2 0003 0054 00000930”);
system(“adb shell sendevent /dev/input/event2 0000 0002 00000000”);
system(“adb shell sendevent /dev/input/event2 0003 0018 00000079”);
system(“adb shell sendevent /dev/input/event2 0003 0020 00000000”);
system(“adb shell sendevent /dev/input/event2 0000 0000 00000000”);

Start point is 103:924.

Our main goal is to implement a swipe function for producing swipes
with specified coordinates.

Events above generated using tricky approach, I have clicked start
point and than clicked immediately end point. It is not true swipe,
but we do not care about 100 moving events between start and finish
points.

All we need – it is analyse current events sequence and group them
for a function implementation.

————- swipe function will be here asap ————————-

————- Short swipe function —————————

Short swipe it is when you are touching screen at one point releasing it and super quickly touching screen at another point using another finger. By this way most of apps will recognize this motion as a swipe/slide and proceed the motion. For us it is easily to reproduce, because we are excluding a lot of intermediate events.
Snippet bellow is written using standard perl shell script:

#!/usr/bin/perl -w

sub adbSend {
my ( $device, $type, $code, $val ) = @_;

system(“adb shell sendevent $device $type $code $val“);
}

sub Swipe {
my($x_start, $y_start, $x_end, $y_end) = @_;
adbSend(“/dev/input/event2“,3,48,10);
adbSend(“/dev/input/event2“,3,50,10);

adbSend(“/dev/input/event2“,3,53,$x_start);
adbSend(“/dev/input/event2“,3,54,$y_start);
adbSend(“/dev/input/event2“,0,2,0);
adbSend(“/dev/input/event2“,3,18,047);
adbSend(“/dev/input/event2“,3,20,1);
adbSend(“/dev/input/event2“,0,0,0);

adbSend(“/dev/input/event2“,3,48,31);
adbSend(“/dev/input/event2“,3,50,10);

adbSend(“/dev/input/event2“,3,53,$x_start+4);
adbSend(“/dev/input/event2“,3,54,($y_start + (($y_start$y_end)/2)));
adbSend(“/dev/input/event2“,0,2,0);
adbSend(“/dev/input/event2“,3,18,10);
adbSend(“/dev/input/event2“,0,0,0);

adbSend(“/dev/input/event2“,3,48,31);
adbSend(“/dev/input/event2“,3,50,10);

adbSend(“/dev/input/event2“,3,53,$x_end);
adbSend(“/dev/input/event2“,3,54,$y_end);
adbSend(“/dev/input/event2“,0,2,0);
adbSend(“/dev/input/event2“,3,21,2);
adbSend(“/dev/input/event2“,0,0,0);

adbSend(“/dev/input/event2“,3,48,0);
adbSend(“/dev/input/event2“,3,50,10);

adbSend(“/dev/input/event2“,3,53,$x_end);
adbSend(“/dev/input/event2“,3,54,$y_end);
adbSend(“/dev/input/event2“,0,2,0);
adbSend(“/dev/input/event2“,3,18,79);
adbSend(“/dev/input/event2“,3,20,0);
adbSend(“/dev/input/event2“,3,21,1);
adbSend(“/dev/input/event2“,0,0,0);
}

sub main {
# Reproduced swipe for moving chess figures:
Swipe($x_start, $y_start, $x_end, $y_end);
sleep 1;

0;
}

Just put your numbers and you will get a quick swipe 🙂 I’m using it for testing Chess game, where you are not able to use simple clicks.

————- /Short swipe function —————————

Part 4: Reproducing complicated motions.

Happy swiping and sliding (:

Best regards,
Yahor