82

My screen is dead and I want to unlock my phone so I can access it through Kies to back up my pictures.

I locked the phone through Android Device Manager, setting an easy password (I was hoping for an Unlock option once I locked it) and tried various methods to unlock it. For example:

adb shell input text 1234

Since I don't know what the lock screen looks like, I'm not sure of the correct inputs to unlock it.

I know the phone is on and that it responds to adb. I am also able to run apps on it through Eclipse.

It's a Samsung Galaxy S5 with Android 5.0.

2
  • This is not a programming question; try asking here instead: android.stackexchange.com
    – GoBusto
    Commented Mar 16, 2015 at 8:37
  • Thanks I'll try there as well. However, if I can unlock my phone by uploading an app through Eclipse that would work as well.
    – schoel
    Commented Mar 16, 2015 at 8:55

15 Answers 15

82

If you have to click OK after entering your passcode, this command will unlock your phone:

adb shell input text XXXX && adb shell input keyevent 66

Where

  • XXXX is your passcode.
  • 66 is the keycode of the OK button.
  • adb shell input text XXXX will enter your passcode.
  • adb shell input keyevent 66 will simulate clicking the OK button.
7
  • Thanks! After posting I tried this and got "Invalid pin code" (managed to see the screen through USB with Droid@Screen) even though I'm sure it was the correct pin.
    – schoel
    Commented Mar 16, 2015 at 18:44
  • 1
    @Tien Could you update your answer to use XXXX instead of 0000 and mention that XXXX is your passcode, as people will use 0000 without thinking.
    – Samveen
    Commented Mar 20, 2016 at 10:52
  • 14
    What if we have pattern password?
    – trusktr
    Commented May 5, 2016 at 18:58
  • 3
    What if you want (1) turn on screen (can use this way for this part), (2) swipe it up (for showing pin/password input pad on android >= 5) (3) and then input pin/password? Commented Dec 17, 2016 at 12:32
  • 6
    I didn't tried to combine all above actions but I found this on stackoverflow to swipe up: stackoverflow.com/questions/25500567/… I tried this "adb shell input touchscreen swipe 530 1420 530 1120" and it works
    – Tien
    Commented Dec 23, 2016 at 16:23
55

This command helps you to unlock phone using ADB

adb shell input keyevent 82 # unlock
4
  • 1
    This just sends a menu key event - that does not unlock my phone.
    – schoel
    Commented Mar 16, 2015 at 9:49
  • 1
    I'm not sure how kies works bu tBhaskar is right, you might want to send a "26" keyevent before 82 to ensure your screen is on.
    – Srini
    Commented Mar 18, 2015 at 9:08
  • 10
    This works well when you have to swipe to unlock with no pass code.
    – farmir
    Commented Aug 4, 2015 at 2:22
  • @Srini Except if the screen is already on, that will turn it off Commented Oct 4, 2018 at 18:49
54

Tested in Nexus 5:

adb shell input keyevent 26 #Pressing the lock button
adb shell input touchscreen swipe 930 880 930 380 #Swipe UP
adb shell input text XXXX #Entering your passcode
adb shell input keyevent 66 #Pressing Enter

Worked for me.

1
  • 2
    Instead of 26 and 66 you can also write POWER and ENTER, which are equivalent. You're also able to use this same trick to bypass the Google login verification screen by sending TAB and ENTER when the popup appears. Source: Pixel 7 testing and gist.github.com/arjunv/2bbcca9a1a1c127749f8dcb6d36fb0bc
    – Ray Foss
    Commented Apr 15, 2023 at 22:14
31

If you have USB-Debugging/ADB enabled on your phone and your PC is authorized for debugging on your phone then you can try one of the following tools:

scrcpy

scrcpy connects over adb to your device and executes a temporary app to stream the contents of your screen to your PC and you're able to remote control your device. It works on GNU/Linux, Windows and macOS.

Vysor

Vysor is a chrome web app that connects to your device via adb and installs a companion app to stream your screen content to the PC. You can then remote control your device with your mouse.

MonkeyRemote

MonkeyRemote is a remote control tool written by myself before I found Vysor. It also connects through adb and lets you control your device by mouse but in contrast to Vysor, the streamed screen content updates very slow (~1 frame per second). The upside is that there is no need for a companion app to be installed.

7
  • My Oneplus One screen broke and this to my rescue! I would like to try to unlock as well via dab commands. Will do it soon, thanks anyways
    – stack_ved
    Commented Mar 28, 2016 at 7:01
  • WOW! Vysor simply worked like charm on my rooted SGS4. Thanks a lot. Just a question out of curiosity- Does both Vysor and MonkeyRemote work for non-rooted phone?
    – bozzmob
    Commented Apr 24, 2016 at 9:31
  • Yes they work on non-rooted devices. The only requirements are USB-Debugging/ADB enabled and an authorized PC.
    – ns130291
    Commented Apr 30, 2016 at 8:14
  • 1
    MonkeyRemote worked beautifully to unlock a broken screen of my Nexus 5. Thank you!
    – Alex P
    Commented Dec 14, 2016 at 3:57
  • MonkeyRemote did the trick perfectly. Thanks for sharing it. I'll send you a PR with some love :)
    – voghDev
    Commented Jan 14, 2019 at 10:29
20

Another way just for your information.

Use an USB OTG cable and connect with an USB mouse, you can touch the screen by clicking your mouse !

1
  • 3
    Upgrade of this solution: Use an USB-Hub and plug in a mouse and a keyboard.
    – DBX12
    Commented Apr 2, 2017 at 17:01
19

Below commands works both when screen is on and off

To lock the screen:

adb shell input keyevent 82 && adb shell input keyevent 26 && adb shell input keyevent 26

To lock the screen and turn it off

adb shell input keyevent 82 && adb shell input keyevent 26

To unlock the screen without pass

adb shell input keyevent 82 && adb shell input keyevent 66

To unlock the screen that has pass 1234

adb shell input keyevent 82 && adb shell input text 1234 && adb shell input keyevent 66
2
  • 2
    Some phones may need two "input keyevent 82" to unlock and get to the password entry in my experience. Commented Aug 7, 2017 at 7:11
  • 1
    FYI there are a few alternative to keycode 82 to bring up the keyguard. I found that 23 (D-Pad center), 62 (space) and 66 (enter) also did the job.
    – Sam
    Commented Jun 28, 2020 at 2:05
14

if the device is locked with black screen run the following:

  1. adb shell input keyevent 26 - this will turn screen on
  2. adb shell input keyevent 82 - this will unlock and ask for pin
  3. adb shell input text xxxx && adb shell input keyevent 66 - this will input your pin and press enter, unlocking device to home screen
1
  • Confirmed to work on Nexus 6p running 7.1.2 (AOSP/PureNexus), locked with fingerprint & backup PIN.
    – Bitbang3r
    Commented Aug 1, 2017 at 20:04
4

If you had MyPhoneExplorer installed and connected (not sure this is a must, happened to be my setup already), you could use it to control the screen with your computer mouse. It connects via ADB, for which your normal USB cable is enough.

Another solution I found that even worked without a reboot is updating tables in settings.db and locksettings.db I had to switch to root to open the settings.db though:

adb shell
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
update secure set value=1 where name='lockscreen.disabled';
.quit
sqlite3 /data/system/locksettings.db
update locksettings set value=0 where name='lock_pattern_autlock';
update locksettings set value=1 where name='lockscreen.disabled';
.quit

Source that made me edit my tables

2
  • I don't have the locksettings table under Nexus One.
    – powder366
    Commented Oct 30, 2016 at 8:15
  • The "lockscreen.disabled" entry did not exist on my phone's database, so I had to create it using insert into secure (name,value) values ('lockscreen.disabled', 1);. Commented Mar 19, 2019 at 21:12
4

Slightly modifying answer by @Yogeesh Seralathan. His answer works perfectly, just run these commands at once.

adb shell input keyevent 26 && adb shell input keyevent 82 && adb shell input text XXXX && adb shell input keyevent 66

// OR
adb shell input keyevent 26 && adb shell input touchscreen swipe 930 880 930 380 && adb shell input text XXXX && adb shell input keyevent 66

Where:
input Keyevent 26 denotes Power Button Pressed.
input touchscreen swipe 930 880 930 380 denotes Swipe Up.
input text XXXX denotes your Password entered.
input keyevent 66 denotes Enter key Pressed.

1
  • Converted to useful alias => alias unlock="adb shell 'input keyevent 26 && input keyevent 82 && input text 12345678 && input keyevent 66'"
    – Alexey
    Commented Dec 14, 2022 at 8:47
3

If you want to open your phone without touching it here is the way

Steps

  1. Make sure you have completed the adb setup in both pc and android
  2. open cmd(Command Prompt)
  3. type adb devices to cheek if your phone is ready or not
  4. If it shows something like
List of devices attached
059c97f4        device

then enter the following command

adb shell input keyevent 26 && adb shell input swipe 600 600 0 0 && adb shell input text <pass> && adb shell input keyevent 66

put your password in <pass> and done. You phone is hopefully opened

1
  • Thanks! Although adb shell input keyevent 26 causes a problem if the phone is already switched on (because then the command switches the phone off...). However, executing adb shell input keyevent KEYCODE_MENU instead... works whether if the phone is on or off :-) . Therefore, the resulting code that always works for me (even if a fingerprint is expected or the phone is switched off) is: adb shell input keyevent KEYCODE_MENU && adb shell input swipe 600 600 0 0 && adb shell input text <pass> && adb shell input keyevent KEYCODE_ENTER
    – Ganton
    Commented Dec 5, 2020 at 13:56
2

I would like to share my way, first of all i had Huawei ascend p7 and my touch screen stopped handling touch, so none of the above solutions helped me to be unlock the phone, i have found a better clever way to do it since i can see the screen on thus i thought that my display is 1080 x 1920 px thus i had to simulate a drawing on my photoshop with keypad with (x,y) so i can try instead with input mouse tap command.

screenshot of simulation

Since i have pin lock as you can see in the picture, i have got all the (x,y) for all the numbers on the screen to simulate touch and unlock my screen and have to backup my data, thus if my password is 123 i did all the following commands

adb shell input mouse tap 100 1150
adb shell input mouse tap 500 1150
adb shell input mouse tap 900 1150

And then my phone just got unlocked, i hope it was helpful.

1
  • turn on show pointer location for current touch data in debug settings, then you can record which pixel location your button press is (by looking at the xy at the top) and write an adb command adb shell input tap x y where x is x location and y is y location. Note i skiped the 'mouse' part - it is unnecessary
    – DitherDude
    Commented Feb 18 at 3:05
2

On my Pixel 7 Pro with a smashed screen, and fingerprint unlock as well as unlock PIN, I used scrcpy, which is amazing for accessing a broken phone. However, on newer Android versions (I think >10), pin number screens, and other "admin" views are not mirrored.

This is what worked for me, which is a combination of the techniques for this question:

I connected via adb then ran:

  1. shell
  2. input keyevent POWER # alias for key 26
  3. input keyevent 82 # unlock I think
  1. input keyevent 82 # twice, unsure why
  2. input text XXXXXXXXXXXX # PIN code here
  1. input keyevent ENTER # alias for key 66

I needed a few tries to get this to work, since I think there are some timing dependencies. I used the CLI up/down history to quickly retry some of these until I could unlock.


I almost tried doing what @AaoIi did, getting exact coordinates for input mouse tap XX YY or input touch tap XX YY, to better simulate the PIN pad.

Another way to get the coordinates needed for this approach (after adb shell), is getevent -t -l -v=32, which translates to:

  • -t add timestamps
  • -l use nice labels for everything
  • -v=32 show position events only, but there might be an even better option

This will be quite noisy, and the positions are in hexademical :(, but you can do something (terrible) like:

getevents -your_options | grep ABS_MT_POSITION | awk -FS'[\s\\[\\]]+' '{printf "%s,%s,$d\n" $1, $4, $5}' --fair to ban me from SO for this mess - It pipes the grep-ed logs through awk using SPACE, [ & ] as delimiters, and prints out the timestamp, label (X or Y position), and the hex position in decimal format.

I put this into a pivot table using a jupyter notebook, but something like clipivot or datamash can do this. So can awk but it looks messy. You need this to rearrange the X and Y coords, which are logged sequentially, into 2d (x,y) data points

2

Building on @Bhaskar's answer and others, here's a full command to unlock (tested on Pixel 3):

adb shell input keyevent 26 && adb shell input keyevent 82 && adb shell input text <password> && adb shell input keyevent 66
2

Swipe unlock (works on Pixel 3a):

adb shell input keyevent 26 && adb shell input touchscreen swipe 2 4400 500 2
-1

I had found a particular case where swiping (ADB shell input touchscreen swipe ... ) to unlock the home screen doesn't work. More exactly for Acer Z160 and Acer S57. The phones are history but still, they need to be taken into consideration by us developers. Here is the code source that solved my problem. I had made my app to start with the device. and in the "onCreate" function I had changed temporarily the lock type.

Also, just in case google drive does something to the zip file I will post fragments of that code below.

AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.gresanuemanuelvasi.test_wakeup">
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".ServiceStarter" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
            android:directBootAware="true" tools:targetApi="n">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>
    </application>
</manifest>
class ServiceStarter: BroadcastReceiver() {
    @SuppressLint("CommitPrefEdits")
    override fun onReceive(context: Context?, intent: Intent?) {
        Log.d("EMY_","Calling onReceive")
         context?.let {
             Log.i("EMY_", "Received action: ${intent!!.getAction()}, user unlocked: " + UserManagerCompat.isUserUnlocked(context))

             val sp =it.getSharedPreferences("EMY_", Context.MODE_PRIVATE)
             sp.edit().putString(MainActivity.MY_KEY, "M-am activat asa cum trebuie!")

             if (intent!!.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
                 val i = Intent(it, MainActivity::class.java)
                 i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                 it.startActivity(i)
             }
        }
    }
}

class MainActivity : AppCompatActivity() {

    companion object {
        const val MY_KEY="MY_KEY"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
        val kgl = kgm.newKeyguardLock(MainActivity::class.java.simpleName)
        if (kgm.inKeyguardRestrictedInputMode()) {
            kgl.disableKeyguard()
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(arrayOf(Manifest.permission.RECEIVE_BOOT_COMPLETED), 1234)
        }
        else
        {
            afisareRezultat()
        }
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

        if(1234 == requestCode )
        {
            afisareRezultat()
        }

        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }

    private fun afisareRezultat() {
        Log.d("EMY_","Calling afisareRezultat")
        val sp = getSharedPreferences("EMY_", Context.MODE_PRIVATE);
        val raspuns = sp.getString(MY_KEY, "Doesn't exists")
        Log.d("EMY_", "AM primit: ${raspuns}")
        sp.edit().remove(MY_KEY).apply()
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.