Is there a way to unlock android phone via adb, if I KNOW the pattern
Asked Answered
S

5

9

Basically, idea is to add a pattern unlock in script, running on a computer, connected to phone via adb. So, something like adb shell input events. Pattern is KNOWN, no hacking.

Skipbomb answered 7/5, 2014 at 22:17 Comment(0)
C
10

This is an old question but in the interest of helping anyone who finds this post, check out my android-pattern-unlock shell script.

It uses ADB's sendevent to draw a known unlock pattern into the lock screen. Worked for me and allowed me to gain access with a broken screen.

Crumley answered 3/5, 2015 at 10:14 Comment(4)
Had to change /bin/sh to /bin/bash and it worked like a charm! (Nexus 4, Android 5.1.1)Reynoso
You just linked to a script but didn't explain how to use it with ADB. I have ADB sitting here, and I can see my device, but how do I make use of the script? And no, the comments in the script file do not help very much. Thanks!Circumspection
@Circumspection - open a terminal, cd to the folder with the script in, then run the commands in the comments: "chmod +x unlock.sh" then "./unlock.sh". Note the script is designed to run on a Mac or Linux machine and you need to have adb set up. The script will run adb commands for you.Crumley
Do you have a variant for the Windows?Mellisamellisent
A
6

I tried Matt Wilson's android-pattern-unlock shell script on my S4, but I had to make some adjustments to make it work. Here are the steps I followed:

  1. Use ADB to view your device's screen with this handy bit of code (adbcontrol). It allows you to view your device's screen and input tap and swipe events. You will not be able to input your pattern using this program no matter how hard you try.
  2. Get the coordinates of your pattern by clicking on the points in order. Use the output window from adbcontrol to see the coordinates. Now you will have a set of coordinates {(x1, y1), (x2, y2), (x3, y3), (x4, y4)} (for a 4 point pattern).
  3. Copy the following commands into your terminal, replacing xi and yi with your coordinates.

`

adb shell input keyevent 26
adb shell sendevent /dev/input/event3 3 57 14

adb shell sendevent /dev/input/event3 1 330 1

adb shell sendevent /dev/input/event3 3 53 x1
adb shell sendevent /dev/input/event3 3 54 y1
adb shell sendevent /dev/input/event3 3 58 57
adb shell sendevent /dev/input/event3 0 0 0

adb shell sendevent /dev/input/event3 3 53 x2
adb shell sendevent /dev/input/event3 3 54 y2
adb shell sendevent /dev/input/event3 3 58 57
adb shell sendevent /dev/input/event3 0 0 0

adb shell sendevent /dev/input/event3 3 53 x3
adb shell sendevent /dev/input/event3 3 54 y3
adb shell sendevent /dev/input/event3 3 58 57
adb shell sendevent /dev/input/event3 0 0 0

...

adb shell sendevent /dev/input/event3 3 53 xn
adb shell sendevent /dev/input/event3 3 54 yn
adb shell sendevent /dev/input/event3 3 58 57
adb shell sendevent /dev/input/event3 0 0 0

adb shell sendevent /dev/input/event3 3 57 4294967295
adb shell sendevent /dev/input/event3 1 330 0
adb shell sendevent /dev/input/event3 0 0 0

`

These steps worked on a Galaxy S4, it looks like Matt Wilson's code is written for the Nexus 4.

Notes:

-My S4 uses /dev/input/event3 as the touchscreen device, it looks like the Nexus 4 uses /dev/input/event2. If your device uses a different file, change all the commands to sendevents to that file. You can see a list of devices by running adb shell getevent

-I had to add in some commands to make this work on the S4, specifically:

adb shell sendevent /dev/input/event3 1 330 1

and

adb shell sendevent /dev/input/event3 1 330 0

I am not sure, but I think the first command indicates a finger-press event on the touchscreen and the second command a finger-lift event on the touchscreen. I figured them out by looking at getevent output for /dev/input/event3 on a different S4.

Atwater answered 29/9, 2015 at 0:17 Comment(4)
The bottom part of my touchscreen is broken - I used getevent as described to grab the coordinates of the top half of my unlock pattern, deduced the coordinates of the bottom half, and used your script to unlock the phone and then remove the unlock pattern. Lifesaver!Carbone
I had to change Matt Wilson's script to have my Galaxy Note 4 to be working. And your notes helped a lot. Thanks. For someone like me, linkCirrostratus
This isnt working on my S5, it seems like the sendevent commands are failing because all I see is "use: sendevent device type code value". Any idea what is happening?Morten
You can use adb shell getevent -pcommand to see the touchscreen's id, so that you could change the commands' /dev/inpux/event3 to /dev/input/event#where # is the id of your touchscreen.Mcquoid
H
4

There is a command locksettings where you can create, change or clear your pattern, pin, and password

 locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN
 locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN
 locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD
 locksettings clear [--old OLD_CREDENTIAL]

Yaa, you can change or create a pattern from command line the usage is

locksettings set-pattern: A pattern is specified by a non-separated list of numbers that index the cell on the pattern in a 1-based manner in left to right and top to bottom order, i.e. the top-left cell is indexed with 1, whereas the bottom-right cell is indexed with 9. Example: 1234

So briefly, to unlock the phone clear the pattern, open phone then again set the pattern

Code

adb shell "locksettings clear --old XXXX" This will clear your pattern.

adb shell "input keyevent 26" This will press the power button for waking up the screen.

adb shell "input swipe 300 1000 300 300" This will slide up the screen. Now your phone is clearly unlocked.

adb shell "locksettings set-pattern XXXX" This will again set the pattern to old key

Heat answered 8/7, 2018 at 12:15 Comment(1)
The pattern syntax is a string of digits in the arrangement of a phone keyboard, e.g. 14789 is a big L.Subserve
Z
2

What seems to be the easiest (and what worked for me on my Galaxy S4 with JDC Optimized CM 13) is Vysior, a Chrome extension which just worked for me "out of the box".

To be more precise, here is what I did after the Screen of my S4 became defunct.

  1. Install Minimal ADB and Fastboot as explained here. In my case, I had ADB debugging activated already, so that saved me a lot of trouble.
  2. Based in the instructions here, I tried the following but it did not work because apparently I did not have write access:

    adb shell echo "persist.service.adb.enable=1" >>/system/build.prop echo "persist.service.debuggable=1" >>/system/build.prop echo "persist.sys.usb.config=mass_storage,adb" >>/system/build.prop reboot

  3. So, based in this answer, I did the following instead, and that worked (in the sense that I had no nore write access errors):

    adb remount adb shell echo "persist.service.adb.enable=1" >>/system/build.prop echo "persist.service.debuggable=1" >>/system/build.prop echo "persist.sys.usb.config=mass_storage,adb" >>/system/build.prop reboot

  4. But the magic that was supposed to happen (i.e. my phone's screen showing up on my PC screen) did not happen. I figured that my pattern lockscreen must be preventing things from happening. This is when I installend Vysor and after a minute or so, during which it installed the Vysor app on the phone, I saw my lockscreen on my computer screen and was able to enter the pattern to unlock (it even worked with my finger on the touchscreen of my tablet PC!).

Zelazny answered 21/11, 2016 at 22:41 Comment(1)
How did you start the Vysor app on your phone?Mccurry
G
-9

I think - No. Because you cannot simulate touch events (especially if the lock is a swipe combination or number)

Gorrono answered 8/5, 2014 at 1:30 Comment(1)
We can send `adb shell input keyevent <KEYCODE> to do literally anything on the device.Mellisamellisent

© 2022 - 2024 — McMap. All rights reserved.