User:Magick777/Opportunistic Power Saving

/usr/bin/set2g

 * 1) !/bin/sh


 * 1) This script is intended to be run indirectly from dbus-scripts and to be triggered on
 * 2) phone lock. It will then attempt to determine whether it makes sense to change the radio
 * 3) mode to GSM in order to save battery life.


 * 1) Test the current radio mode and abort if we're in GSM mode already

TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_selected_radio_access_technology | g$ if [ ! -z "$TEST" ] then echo "Phone is already in 2G mode, aborting." exit 1 fi

TEST=`grep 1 /tmp/oncharge` if [ ! -z "$TEST" ] then echo "Phone is on charge, no need to set 2G mode, aborting." exit 1 fi
 * 1) If we're on charge, we don't need to save battery so don't downgrade.
 * 1) it's a non-zero value so we're on charge, abort gracefully

TEST=`dbus-send --system --type=method_call --print-reply --dest=com.nokia.csd.Call /com/nokia/csd/call/1 com.nokia.csd.Call.Instance.GetStatus | grep "uint$
 * 1) Test whether the phone is on a call, if it is don't mess with it

if [ -z "$TEST" ] then echo "Phone is making or receiving a call, aborting." exit 1 fi
 * 1) if phone is on call, grep filters out any call status but 0/idle, so we get a zero length output


 * 1) Adding a 30 cooling off period means that if the device gets unlocked again within 30 seconds, we can
 * 2) kill this script whilst it's sleeping and leave 3G intact.

echo "Scheduling switch to 2G in 30 seconds..." sleep 30


 * 1) Make the actual change to 2G radio mode

run-standalone.sh dbus-send --system --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.set_selected_radio_access_technology byte:1 echo "Phone set to 2G mode." exit 0