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

纵饮孤独 提交于 2019-12-05 13:15:51

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.

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.

Christoph

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!).

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!