My Java skills are low, but I'm mastering shell.

Is use LineageOS 14.1 (forked from cyanogenmod).

I would like to create a shell script on a rooted devive to enable/disable lockscreen (PIN).

I would like to unlock my screen at home when a special SSID is present.

I'm able to discover my known network by running :


iw dev wlan0 scan | grep MY_SSID

Now, is there a command line to disable/enable the PIN based lock screen depending of the output of this command please ?

Maybe something based on

am <something> <stop|start>

Tried to make a diff from ps with and without lockscreen, but I only have cyanogenmod.snap as diff, tried to kill the process, but still the lockscreen.

Any hint please ?


1 Answer 1


The script below is a partial solution. Partial because it will not disable the Pin. What it does is to wake the device up when it is connected to a chosen wifi, input your password and unlock it.


mySSID="no wifi present"

    #Get the network
    mySSID=`dumpsys netstats | awk -F '[/=|,]' '/iface/ {print $8}' | head -1`


echo 'Start running script\n\n'


while true
#Check if connected to wifi or mobile data. If connected string is not empty
    if [ "$mySSID" != '' ]

        if [ "$mySSID" == "YourHomeSSID" ] #connected to home wifi

            echo "Connected to $mySSID\n"
            #Check if the screen is on or off
            screen_status=`dumpsys power | awk -F '[/=]' '/Display Power/ {print $2}'`

            if [ "$screen_status" == "OFF" ]
                echo 'The screen is off, Will now input the password'
                #Press the power button to switch the screen on
                input keyevent 26
                #Simulate swipe up gesture
                input touchscreen swipe 320 940 320 100
                #Input your PIN. Change XXXX with your PIN
                input text XXXX 
                #Simulate OK/Enter
                input keyevent 66



    fi #not connected to wifi nor mobile data

    #Wait for 3 seconds, then check again if connected to home wifi
    sleep 3


The main disadvantage of the script is that the screen will be on nearly all the time when connected to your home wifi. To stop the script from running, press CTRL+C from the terminal.

My phone doesn't have iw command. I had to use dumpsys netstats to get the networkID.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .