mattwilson1024 / android-pattern-unlock

Utility script to automate the swiping of a lockscreen pattern on an Android device via ADB.
104 stars 48 forks source link

Not able to simulate this in Samsung Note3 #7

Open mashkurm opened 7 years ago

mashkurm commented 7 years ago

Initially it unlocks the device and swipe up, but when it comes to co-ordinates, it is sending too, but it does nothing to the device.. Please find the logs.

$ bash test.sh Sending 1: 254, 948 Sending 4: 254, 1224 Sending 7: 254, 1526 Sending 8: 513, 1526

Trying to draw L through it.. 1,4,7,8..

Here is my pattern. Please check.

PATTERN="1 4 7 8" # The unlock pattern to draw, space seperated

COL_1=254                   # X coordinate of column 1 (in pixels)
COL_2=513                   # X coordinate of column 2 (in pixels)
COL_3=818                   # X coordinate of column 3 (in pixels)

ROW_1=948                   # Y coordinate of row 1 (in pixels)
ROW_2=1224                  # Y coordinate of row 2 (in pixels)
ROW_3=1526                   # Y coordinate of row 3 (in pixels)

MULTIPLIER=1                # Multiplication factor for coordinates. For Nexus 4, set this to 2. For low res phones such as
                            # Samsung Galaxy S2, set this to 1. Experiment with this value if you can't see anything happening.

WAKE_SCREEN_ENABLED=true    # If true, the script will start by sending the power button press event

SWIPE_UP_ENABLED=true       # If true, the script will swipe upwards before drawing the pattern (e.g. for lollipop lockscreen)
SWIPE_UP_X=450              # X coordinate for initial upward swipe. Only used if SWIPE_UP_ENABLED is true
SWIPE_UP_Y_FROM=1000        # 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
        adb shell input keyevent 26
    fi
}

SwipeUp() {
    if [ "$SWIPE_UP_ENABLED" = true ]; then
        adb shell input swipe ${SWIPE_UP_X} ${SWIPE_UP_Y_FROM} ${SWIPE_UP_X} ${SWIPE_UP_Y_TO}
    fi
}

StartTouch() {
    adb shell sendevent /dev/input/event1 3 57 14
}

SendCoordinates () {
    adb shell sendevent /dev/input/event1 3 53 $1
    adb shell sendevent /dev/input/event1 3 54 $2
    adb shell sendevent /dev/input/event1 3 58 57
    adb shell sendevent /dev/input/event1 0 0 0
}

FinishTouch() {
    adb shell sendevent /dev/input/event1 3 57 4294967295
    adb shell sendevent /dev/input/event1 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
mattwilson1024 commented 7 years ago

It might just be that the coordinates / scaling factor are different on your device. I can't really test it as I don't have a Note3. You could try playing around with the numbers for the COL_1, COL_2, COL_3, ROW_1, ROW_2 and ROW_3 variables and see if it makes any difference.

Also try changing the MULTIPLIER as that seems to have an effect on devices with different screen densities.

mashkurm commented 7 years ago

I tried with same co-ordinates that I see on the device by locating pointer location. It seems that swipe-up happens but pattern doesn't unlock. I'm using Windows7 with CygWin to simulate this. Let me know if I am missing anything.

yunusemrecatalcam commented 7 years ago

i think this because of every device has a different event number for different event types. for example one device say event2 for touch input,on another touch input event9

khalidrash commented 4 years ago

please it give me device unautorized

AhmedNSane commented 4 years ago

Try changing size and density using these commands:

// Emulate device adb shell wm size 2048x1536 adb shell wm density 288 // And reset to default adb shell wm size reset adb shell wm density reset