How to unlock android phone through ADB

后端 未结 12 1153
自闭症患者
自闭症患者 2020-12-12 15:04

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

I locked the phone through Android Device Manager setting an e

相关标签:
12条回答
  • 2020-12-12 15:32

    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.

    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.

    0 讨论(0)
  • 2020-12-12 15:35

    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 !

    0 讨论(0)
  • 2020-12-12 15:39

    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()
        }
    }
    
    0 讨论(0)
  • 2020-12-12 15:40

    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
    0 讨论(0)
  • 2020-12-12 15:43

    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.

    0 讨论(0)
  • 2020-12-12 15:45

    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

    0 讨论(0)
提交回复
热议问题