1

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 :

#!/bin/bash

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 ?

0

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.

#!/system/bin/sh

mySSID="no wifi present"

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

}


echo 'Start running script\n\n'

connected_wifi

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

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

            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" ]
            then
                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

        fi


    fi #not connected to wifi nor mobile data

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

done

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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