User:Magick777/Opportunistic Power Saving

Line 1: Line 1:
-
<source lang="text">
+
* Maintain phone in GSM mode by default (when on battery)
-
#!/bin/sh
+
-
# Test the current radio mode and abort if in 3G or dual mode already
+
** Switch to 2G mode opportunistically when all seems to be quiet
-
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 | grep "byte [02]"`
+
*** trigger by phone locked, but test the following
-
if [ ! -z "$TEST" ]
+
**** are we on charge? don't bother switching
-
then
+
**** are we on a call? don't break my 3G link
-
echo "Phone is already in either 3G or dual mode, aborting."
+
**** is 3G still required? work out how to decide
-
exit 1
+
***** are we using an application that should block the downgrade?
-
fi
+
***** analyse IP traffic flows or bytecounters?
 +
***** look for specific applications running
 +
***** allow one or two minutes cooling off period
-
# Test whether the phone is on a call, if it is then don't mess with it
+
** Switch to 3G when something requires 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 "uint32 0"`
+
*** don't change anything if we're on a voice call
-
#if phone is on call, grep filters out any call status but 0/idle, so we get a zero length output
+
*** don't bother if we're already on WiFi
-
if [ -z "$TEST" ]
+
-
then
+
-
echo "Phone is making or receiving a call, aborting."
+
-
exit 1
+
-
fi
+
-
 
+
-
#Before we change the radio mode, check that we're not on WiFi
+
-
TEST=`grep 1 /tmp/onwifi`
+
-
 
+
-
if [ ! -z "$TEST" ]
+
-
then
+
-
echo "Phone is connected via WiFi, no point autoswitching to dual mode."
+
-
exit 1
+
-
fi
+
-
 
+
-
 
+
-
# Make the change to 3G
+
-
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:0
+
-
</source>
+
-
 
+
-
==/usr/bin/set2g==
+
-
<source lang="text">
+
-
#!/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
+
-
 
+
-
</source>
+

Revision as of 21:35, 19 July 2010

  • Maintain phone in GSM mode by default (when on battery)
    • Switch to 2G mode opportunistically when all seems to be quiet
      • trigger by phone locked, but test the following
        • are we on charge? don't bother switching
        • are we on a call? don't break my 3G link
        • is 3G still required? work out how to decide
          • are we using an application that should block the downgrade?
          • analyse IP traffic flows or bytecounters?
          • look for specific applications running
          • allow one or two minutes cooling off period
    • Switch to 3G when something requires it
      • don't change anything if we're on a voice call
      • don't bother if we're already on WiFi