meta data for this page

Table of Contents

Automation

This page is for tools/tips on automation. The main focus is for testing, documentaion, etc.

Tool

There are various tools for automation on this platform.

dbus-send

This is a built in tool that can be used for various gnome-ish things. Here are some examples:

Initiate a reboot:
dbus-send –print-reply –dest=“org.gnome.SessionManager” /org/gnome/SessionManager org.gnome.SessionManager.Reboot

Lock the screen (and also turns off screen):
dbus-send –type=method_call –dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

ydotool

Since Mobian uses Wayland, the classic automation tool, xdotool, doesn't function. Thus a new tool has been created, ydotool.

Source: https://github.com/ReimuNotMoe/ydotool
Documentation: https://www.mankier.com/1/ydotool

These instructions are gleaned from bash history, terminal scroll back. There may be a step missing. Additionally this may not be the correct way to do it, but it's one way that worked.

This tool is not available in the repos, and must be compiled from source, but takes a little bit of work.

Required packages:
sudo apt-get install libboost1.71-dev libboost-program-options1.71-dev

Technically a third package is required, libevdevplus-dev, however, the package in the repos isn't compiled in the way that ydotool needs on aarch64.

Installing libevdevplus-dev from the repos will result in a compilation error attempting to compile libydotool.so:

[ 88%] Linking CXX shared library libydotool.so
/usr/bin/ld: /usr/lib/gcc/aarch64-linux-gnu/10/../../../aarch64-linux-gnu/libevdevPlus.a(Resource.cpp.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `_ZNSt13unordered_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSt4hashIS5_ESt8equal_toIS5_ESaISt4pairIKS5_iEEED1Ev' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/aarch64-linux-gnu/10/../../../aarch64-linux-gnu/libevdevPlus.a(Resource.cpp.o): in function `__static_initialization_and_destruction_0(int, int) [clone .constprop.0]':
(.text.startup+0x2e8): dangerous relocation: unsupported relocation

The issue here is that Resource.cpp.o in the archive /usr/lib/aarch64-linux-gnu/libevdevPlus.a isn't compiled with -fPIC. This can be worked around by downloading the source package for libevdevplus-dev and recompiling this with the necessary option. (Reference: https://stackoverflow.com/questions/13812185/how-to-recompile-with-fpic)

Here is how to re-compile the package from source with the necessary switch:

Download the source package.

mkdir -p ~/src/libevdevplus-dev
cd ~/src/libevdevplus-dev
apt-get source libevdevplus-dev
cd libevdevplus-0.1.1

Edit the ~/src/libevdevplus-dev/libevdevplus-0.1.1/CMakeLists.txt file to include add_compile_options(-fPIC)

Adding it immediately after the Resource.cpp is defined was successful:

set(SOURCE_FILES
        evdevPlus.cpp
        evdevPlus.hpp CommonIncludes.hpp InputEvent.hpp Resource.cpp)

add_compile_options(-fPIC)
add_library(evdevPlus SHARED ${SOURCE_FILES})
add_library(evdevPlus_Static STATIC ${SOURCE_FILES})

Commit, and build the new deb package:

dpkg-source --commit        # required because the next step won't build, answer anything, it's not important what they are
dpkg-buildpackage --no-sign # build the package without signing it, otherwise it will error out saying no signature

Install the newly built deb:

sudo dpkg -i ../libevdevplus-dev_0.1.1-1_arm64.deb

Now ydotool should successfully build. The instructions for building ydotool on the github work:

mkdir -p ~/src; cd ~/src
git clone https://github.com/ReimuNotMoe/ydotool.git
cd ydotool;
mkdir build; cd build
cmake ..
make -j `nproc`

The files can be placed somewhere in the file system like /opt/ydotool. These are the files that are created:

libydotool.a
libydotool.so
libydotool.so.0
libydotool.so.0.1.5
ydotool
ydotool_static
ydotoold
ydotoold_static

Usage:

ydotool works by having a server ydotoold running interface with the uinput device. Once the server is running, ydotool can be executed to enter keyboard strokes, move the mouse, click, etc.

ydotoold simply runs as root, and could be executed within a screen, or a second SSH session. Here the ydotool files have been copied to /opt/ydotool, and execute from that directory:

root@mobian:~# cd /opt/ydotool/
root@mobian:/opt/ydotool# ./ydotoold
ydotoold: listening on socket /tmp/.ydotool_socket

Once the server is started, automation can begin. Here is an automation script which forces the screen to lock, and unlocks the screen by entering the PIN, and clicking the unlock button:

#!/bin/bash

# For the screen to lock.
dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

# Now unlock the screen.
sudo /opt/ydotool/ydotool_static mousemove 1 1
sudo /opt/ydotool/ydotool_static mousemove 180 360

#sleep 1 # Wait for the screen to turn on, might not be needed.

# Enter password.

#sudo /opt/ydotool/ydotool_static type 1111
# Put in a bunch of keystrokes to wake the device up.
# This is needed otherwise the first character in the PIN may get missed.
sudo /opt/ydotool/ydotool_static key Backspace,Backspace,Backspace,Backspace
sudo /opt/ydotool/ydotool_static type  1234

# Move the mouse to over the unlock button, and click unlock.
sudo /opt/ydotool/ydotool_static mousemove 90 312
sudo /opt/ydotool/ydotool_static click 1

Note: It's not 100% reliable. There are unknown issues sometimes which cause it to be unsuccessful at bringing the screen on, or entering the PIN. Once the phone is in a good state (screen off + asleep, or screen on + logged in), the script has executed consistently.


Alternate method for automated screen unlocking (using wtype): Install wtype:

sudo apt install wtype

UnlockMobianLocal.sh

#!/bin/bash

wtype -k Up -s 1000
wtype -k Up -s 1000
wtype 123456 -s 500 -k Return 

Remote screen unlocking (using ssh and wtype):

UnlockMobianRemote.sh

#!/bin/bash

ssh mobian wtype -k Up -s 1000
ssh mobian wtype -k Up -s 1000
ssh mobian wtype 123456 -s 500 -k Return