Skip to content

Instantly share code, notes, and snippets.

@Geofferey
Created October 25, 2018 08:23
Show Gist options
  • Save Geofferey/66b9ffb722dc5517c0664cc50badb5ad to your computer and use it in GitHub Desktop.
Save Geofferey/66b9ffb722dc5517c0664cc50badb5ad to your computer and use it in GitHub Desktop.
inputs unlock pattern via adb, ssh or terminal on Google Pixel (sailfish)
#!/system/xbin/bash
#
# Google Pixel Pattern Input
# OG Author: Matt Wilson
# Modified for Pixel aka sailfish
# By: Geofferey Eakins
# License: Free to use, modify and share
#
# This script sends simulated touch input for
# remotely swiping pattern on a Google Pixel
#
# You may use this script to unlock
# the device via ADB, SSH, Telnet etc
#
# Installation Instructions:
# Ensure DM-Verity is not enabled
# Otherwise place in "/su/bin/"
# instead of "/system/xbin/"
#
# mount -o rw,remount /system
# cp adb_pattern_input-sailfish.sh /system/bin/pattern-input
# chmod +x /system/xbin/pattern-input
# pattern-input
#
# =======================================================================================================================
#
# Variables
#
# Coordinates will vary depending on
# the resolution & DPI of your device
# ( defaults are for Pixel at 1,080 x 1,920 )
# The pattern should be set based on the
# following layout:
# 1 2 3
# 4 5 6
# 7 8 9
PatternUnlock() {
echo "pattern-unlock_wakelock" >> /sys/power/wake_lock
FORCED_DPI="$(settings get secure display_density_forced)"
if dumpsys power | grep mHoldingDisplaySuspendBlocker=false; then
WAKE_SCREEN_ENABLED=true
else
WAKE_SCREEN_ENABLED=false
fi
read -p "Enter Unlock Pattern: " PATTERN
if [ "$FORCED_DPI" = "" ]; then
COL_1=255 # X lock dots column 1 (in pixels)
COL_2=544 # X lock dots column 2 (in pixels)
COL_3=820 # X lock dots column 3 (in pixels)
ROW_1=1080 # Y lock dots row 1 (in pixels)
ROW_2=1388 # Y lock dots row 2 (in pixels)
ROW_3=1670 # Y lock dots row 2 (in pixels)
fi
if [ "$FORCED_DPI" = 540 ]; then
COL_1=227
COL_2=537
COL_3=849
ROW_1=1002
ROW_2=1309
ROW_3=1620
fi
if [ "$FORCED_DPI" = 500 ]; then
COL_1=252
COL_2=539
COL_3=826
ROW_1=1068
ROW_2=1355
ROW_3=1643
fi
if [ "$FORCED_DPI" = 460 ]; then
COL_1=247
COL_2=540
COL_3=834
ROW_1=1067
ROW_2=1361
ROW_3=1653
fi
if [ "$FORCED_DPI" = 378 ]; then
COL_1=283
COL_2=539
COL_3=793
ROW_1=1167
ROW_2=1422
ROW_3=1677
fi
if [ "$FORCED_DPI" = 336 ]; then
COL_1=313
COL_2=539
COL_3=766
ROW_1=1252
ROW_2=1478
ROW_3=1704
fi
if [ "$FORCED_DPI" = 294 ]; then
COL_1=339
COL_2=539
COL_3=735
ROW_1=1334
ROW_2=1533
ROW_3=1729
fi
MULTIPLIER=1 # Multiplication factor for coordinates. For Pixel, set this to 1. For low res phones such as
# Samsung Galaxy S2, set this to 1. Experiment with this value if you can't see anything happening.
SWIPE_UP_ENABLED=true # If true, the script will swipe upwards before drawing the pattern (e.g. for lollipop lockscreen)
SWIPE_UP_X=537 # X coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true
SWIPE_UP_Y_FROM=1369 # Start Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true
SWIPE_UP_Y_TO=200 # End Y coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true
# =======================================================================================================================
# Define X&Y coordinates for each of the 9 positions.
X[1]=$(( ${COL_1} * ${MULTIPLIER} ))
X[2]=$(( ${COL_2} * ${MULTIPLIER} ))
X[3]=$(( ${COL_3} * ${MULTIPLIER} ))
X[4]=$(( ${COL_1} * ${MULTIPLIER} ))
X[5]=$(( ${COL_2} * ${MULTIPLIER} ))
X[6]=$(( ${COL_3} * ${MULTIPLIER} ))
X[7]=$(( ${COL_1} * ${MULTIPLIER} ))
X[8]=$(( ${COL_2} * ${MULTIPLIER} ))
X[9]=$(( ${COL_3} * ${MULTIPLIER} ))
Y[1]=$(( ${ROW_1} * ${MULTIPLIER} ))
Y[2]=$(( ${ROW_1} * ${MULTIPLIER} ))
Y[3]=$(( ${ROW_1} * ${MULTIPLIER} ))
Y[4]=$(( ${ROW_2} * ${MULTIPLIER} ))
Y[5]=$(( ${ROW_2} * ${MULTIPLIER} ))
Y[6]=$(( ${ROW_2} * ${MULTIPLIER} ))
Y[7]=$(( ${ROW_3} * ${MULTIPLIER} ))
Y[8]=$(( ${ROW_3} * ${MULTIPLIER} ))
Y[9]=$(( ${ROW_3} * ${MULTIPLIER} ))
# Function definitions
WakeScreen() {
if [ "$WAKE_SCREEN_ENABLED" = true ]; then
input keyevent 26
fi
}
SwipeUp() {
if [ "$SWIPE_UP_ENABLED" = true ]; then
input swipe ${SWIPE_UP_X} ${SWIPE_UP_Y_FROM} ${SWIPE_UP_X} ${SWIPE_UP_Y_TO}
fi
}
StartTouch() {
sendevent /dev/input/event3 3 57 14
}
SendCoordinates() {
sendevent /dev/input/event3 3 53 $1
sendevent /dev/input/event3 3 54 $2
sendevent /dev/input/event3 3 58 57
sendevent /dev/input/event3 0 0 0
}
FinishTouch() {
sendevent /dev/input/event3 3 57 4294967295
sendevent /dev/input/event3 0 0 0
}
SwipePattern() {
for NUM in $PATTERN
do
echo "Sending $NUM: ${X[$NUM]}, ${Y[$NUM]}"
SendCoordinates ${X[$NUM]} ${Y[$NUM]}
done
}
# Actions
WakeScreen
SwipeUp
StartTouch
SwipePattern
FinishTouch
WakeScreen
echo "pattern-unlock_wakelock" >> /sys/power/wake_unlock
}
PatternUnlock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment