User:Magick777/Opportunistic Power Saving

/usr/bin/set2g

#!/bin/sh
 
# This script is intended to be run indirectly from dbus-scripts and to be triggered on
# phone lock. It will then attempt to determine whether it makes sense to change the radio
# mode to GSM in order to save battery life.
 
# 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
 
# If we're on charge, we don't need to save battery so don't downgrade.
TEST=`grep 1 /tmp/oncharge`
if [ ! -z "$TEST" ]
then
# it's a non-zero value so we're on charge, abort gracefully
echo "Phone is on charge, no need to set 2G mode, aborting."
exit 1
fi
 
# Test whether the phone is on a call, if it is don't mess with it
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$
 
#if phone is on call, grep filters out any call status but 0/idle, so we get a zero length output
if [ -z "$TEST" ]
then
echo "Phone is making or receiving a call, aborting."
exit 1
fi
 
## Adding a 30 cooling off period means that if the device gets unlocked again within 30 seconds, we can
## kill this script whilst it's sleeping and leave 3G intact.
 
echo "Scheduling switch to 2G in 30 seconds..."
sleep 30
 
 
# 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