[android] How to unlock android phone through ADB

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()
    }
}