View Single Post
solbrit's Avatar
Posts: 126 | Thanked: 59 times | Joined on Jan 2011
#16
This might be a bit more interesting. It enables the security lock after 30 minutes if the phone's neither charging nor connected through wifi, both of which only occur, in my case, when at home.

Code:
#!/bin/bash

# Enable device lock on boot
/usr/bin/devicelock-enable

# Sleep time 20 --> 3 lines/minute if discharging, not connected to wlan and screen locked
while true; do sleep 20 &&

if
lshal | grep -q 'battery.rechargeable.is_charging = true'

then
> /opt/sec-lock/sec-lock.log

elif dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}' | grep -q 'unlocked' 

then
> /opt/sec-lock/sec-lock.log

elif /usr/sbin/iw dev wlan0 link | grep -q 'Connected to'

then
> /opt/sec-lock/sec-lock.log

else
echo "Screen locked..." >> /opt/sec-lock/sec-lock.log

fi

# Check if sec-lock.log is full (3 lines/minute --> 30 minutes = 90 lines)
if [ 90 -eq "$(wc -l < /opt/sec-lock/sec-lock.log)" ]

then
> /opt/sec-lock/sec-lock.log && /usr/bin/devicelock-enable

fi;

done