#!/usr/bin/env bash # Builds touchinject.apk (a privileged multi-touch gesture injector) from # Injector.java using the local Android SDK. The APK must be installed under # /system/priv-app for the INJECT_EVENTS (signature|privileged) permission to # be granted — see the bottom of this file. set -euo pipefail cd "$(dirname "$0")" SDK=/home/gmp/android-sdk BT="$SDK/build-tools/35.0.0" PLAT="$SDK/platforms/android-35/android.jar" rm -rf build mkdir -p build/classes javac -nowarn -source 1.8 -target 1.8 -classpath "$PLAT" -d build/classes Injector.java "$BT/d8" --release --min-api 24 --lib "$PLAT" --output build build/classes/touch/inject/*.class # aapt2 resolves the android: namespace against the framework resource # table, which is shipped inside android.jar (resources.arsc). "$BT/aapt2" link --manifest AndroidManifest.xml -I "$PLAT" \ --min-sdk-version 24 --target-sdk-version 35 -o build/base.apk cp build/base.apk build/touchinject-unsigned.apk jar uf build/touchinject-unsigned.apk -C build classes.dex if [ ! -f build/ts.jks ]; then keytool -genkeypair -keystore build/ts.jks -storepass android -keypass android \ -alias ts -dname "CN=TouchInject, OU=Dev" -keyalg RSA -keysize 2048 -validity 10000 fi "$BT/apksigner" sign --ks build/ts.jks --ks-pass pass:android --key-pass pass:android \ --out touchinject.apk build/touchinject-unsigned.apk "$BT/apksigner" verify --print-certs touchinject.apk | head -1 echo "=== DONE: $(pwd)/touchinject.apk" # --- Install as a privileged system app (emulator, rooted) --------------- # SER=emulator-5554 # adb -s $SER root && adb -s $SER remount # adb -s $SER shell mkdir -p /system/priv-app/TouchInject # adb -s $SER push touchinject.apk /system/priv-app/TouchInject/TouchInject.apk # adb -s $SER shell chmod 644 /system/priv-app/TouchInject/TouchInject.apk # adb -s $SER reboot # permission grant is evaluated at install/boot # adb -s $SER wait-for-device && adb -s $SER shell 'while [ -z $(getprop sys.boot_completed) ]; do sleep 1; done' # adb -s $SER shell dumpsys package touch.inject | grep -A2 INJECT_EVENTS # granted=true # # --- Inject a gesture ------------------------------------------------------ # adb -s $SER shell am startservice -n touch.inject/.Injector \ # -e script "down 1 400 1000 wait 100 down 2 700 1200 wait 100 \ # move 1 380 980 move 2 720 1220 wait 50 \ # move 1 340 940 move 2 760 1260 wait 50 up 1 up 2" # adb -s $SER logcat -d -s TouchInject