Battery drain on standby with 4G is still a problem on focal, so I updated the script and created a small systemd service to automatically run the script at startup. Maybe this will be useful for some.
The greeter in focal is called "com.lomiri.LomiriGreeter" instead of "com.canonical.UnityGreeter". So i changed that in the script and tested that it indeed still works.
I placed the updated script in:
/home/phablet/.local/bin
#!/bin/bash
primary_preference="lte"
saving_preference="gsm"
sim_slot="/ril_0"
interface=org.freedesktop.DBus.Properties
member=PropertiesChanged
dbus-monitor --session "type=signal,interface='${interface}',member='${member}'" |
while read -r line; do
if [[ ${line} == *"com.lomiri.LomiriGreeter"* ]]; then
read; read; read -r line
if [[ ${line} == *"IsActive"* ]]; then
read -r line
[[ ${line} == *"true"* ]] && /usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${saving_preference}" 1>/dev/null
[[ ${line} == *"false"* ]] && /usr/share/ofono/scripts/set-tech-preference "${sim_slot}" "${primary_preference}" 1>/dev/null
fi
fi
done
Don't forget to make it executable:
chmod u+x /home/phablet/.local/bin/lte-battery-saver.sh
Ubuntu 20.04 uses systemd instead of upstart so I created a systemd user service in:
/home/phablet/.config/systemd/user/lte-battery-saver.service
[Unit]
Description=LTE battery saver
Requires=dbus.socket
After=dbus.socket
[Service]
ExecStart=/home/phablet/.local/bin/lte-battery-saver.sh
[Install]
WantedBy=dbus.socket
Now to enable the service:
systemctl --user enable --now lte-battery-saver
Verify that it is running and up:
systemctl --user status lte-battery-saver
It should return active and enabled:
● lte-battery-saver.service - LTE battery saver
Loaded: loaded (/home/phablet/.config/systemd/user/lte-battery-saver.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-04-29 18:44:27 CEST; 1h 11min ago
That's it, now everytime the phone is locked the connection will drop to 2G and back to 4G/LTE once unlocked.
I tested and verified it on my Oneplus 5T, but it should work on other devices running focal.