Charger Control

Rating: 
4.8
Your rating: None Average: 4.8 (5 votes)

Charger Control

Charger control is designed for the original Jolla Phone and allows you to control how the battery is charged/discharged when a USB cable is connected.

The app gives you three options:

  • CHARGE - The battery is charged normally. This is the default after the phone is started or when the app is not installed.
  • DO NOT CHARGE - The battery is not charged. USB power is used to power the phone only. Using this you can keep your battery level at say 80% and still have it use USB power to power the phone.
  • DISCHARGE - USB power is not used at all. This is handy if you have the phone connected to a laptop without a charger and don't want to drain the laptop battery yet still want to communicate over USB.

NOTE: This app has not been tested on any other Sailfish device than the original Jolla Phone. Use it at your own risk on other Sailfish devices. In fact, you use the program at your own risk on any device. The app uses low-level interfaces to control the charger on the device and obviously they have not been thoroughly tested by Jolla. I have however been using the app on my own phone for over a year and it has been working perfectly.

The app is completely controlled using cover actions. The cover also actively shows the state of the application like "Charging", "Discharging", "Not charging", "Battery Full" and also the amount of current/power going from/to the battery.

After startup the phone is always in the default CHARGE mode. After you start the app and change modes the mode remains active until you change it with the app or restart your phone. Even if you shut down the app the mode will stay. Only restarting the phone resets the mode back to CHARGE.

Please note that it is fully possible for the phone to use more power (when running heavy applications) than is available from USB, especially if you connect to a charger/laptop that provides less than the maximum charging power to the phone. In this case the cover status indicators will show you that the phone is actually discharging despite being configured to CHARGE or NO CHARGE modes.

The current & power indicators show positive values when the battery is charging and negative values when the battery is draining. When in "NO CHARGE" mode or when battery is full, and the phone is using less power than available over USB, the current & power indicators will show values very close to, but not exactly zero. For example 1.72mA and 7.16mW. This seems to be normal. :)

The app has been written to use as little battery power itself as possible. I have not noticed any difference in battery draining times when the app is running or not. Whenever the cover is not visible, the monitoring is shut down and the app basically waits for the cover to become visible again before doing anything. When swithcing modes the app reconfigures the hardware, so there is no active monitoring needed to achieve the different charging modes. The monitoring is only for keeping the user informed when the cover is visible. Please note though that future versions MAY provide additional features where this is no longer the case, but I promise they will not be enabled by default. :)

Technical note: Because the hardware controls to control the charging are not accessible to normal apps in current Sailfish OS releases, I had to write a systemd service that changes the permissions of the controls when the app is installed and when phone starts up. The permissions are set so that only Charger Control can access them, so it does not decrease security of those controls outside the Charger Control app. The app itself is run in "setgid" mode to give it permissions to the hardware controls. Due to these two special arrangements (systemd service + setgid) the app is not eligible for the Jolla Store. If at any point in the future Sailfish OS loosens the permissions of these hardware controls then these arrangements are no longer necessary and the app can be submitted to the store.

The source code for the app is available on GitHub: https://github.com/xkr47/sailfish-charger-control/. Please file your issues, suggestions and pull requests there. General comments are also welcome and can be submitted via https://openrepos.net/content/xkr47/charger-control/. IRC support channel #chargercontrol on freenode.

Flattr this - Flattr this

Screenshots: 
Application versions: 
AttachmentSizeDate
charger-control-0.1-1.armv7hl.rpm49.18 KB06/07/2016 - 12:20
Changelog: 

(none)

Comments

objectifnul's picture

Update needed for SailfishX 2.1.3.5 and/or Xperia X compatibility.

Qleg's picture

Don't work for Intex AquaFish(v.2.0.2.45) - "Simulated. USB cable disconnected"...

alina's picture

Just a question:

You wrote: “I had to write a systemd service that changes the permissions of the controls when the app is installed.” Does it revert the changes when uninstalling the app?

I just want to make sure everything will be the same as before, after uninstalling the app in any case.

xkr47's picture

The changes are lost every time you shut down/restart your phone. That's why the service is needed to apply the changes every time the phone is started. The uninstall script does not currently undo the changes but a simple restart will do the trick. Sorry for that. Also if you leave the phone in NO CHARGE or DISCHARGE mode when you uninstall the app, the phone will stay in that mode until you restart.

I created a new issue #4 to improve this. Thanks for your feedback.

alina's picture

Thank you! However, I'm ok with this. Great app!

MoritzJT's picture

I'd like to suggest some automated switch conditions. Like switching to usb powers phone after battery charged to XX % and switch back to charging after battery falls below XX % Could this be done as a daemon so we do not need any Cover open?

This app is awesome! With the help of any USB power source powerful enough to run the device, I can hotswap the battery :D

xkr47's picture

Automated switch conditions looks like the most wanted feature, not surprisingly :) Created GitHub issue #1.

I think a daemon will be the best approach but it might take some time for me to pull off with dbus services and whatnot it requires, so I think I would first just implement it in-app, release that and then try to create a separate daemon for it - #2.

Crazy that you are using this to hotswap batteries :D I would be very interested in the stats when that happens; could you run the below commands in a no-battery situation and paste the output somewhere? (I dare not try it myself hehe.) Then I could perhaps make the app correctly report "No battery" or something :D

cd /sys/devices/platform/msm_ssbi.0/pm8038-core/pm8921-charger/power_supply/battery/
grep . *
MoritzJT's picture

Using username "nemo".
Last login: Fri Jul  8 04:00:03 2016
,---
| SailfishOS 2.0.2.45 (Aurajoki) (armv7hl)
'---
[nemo@Sailfish ~]$ cd /sys/devices/platform/msm_ssbi.0/pm8038-core/pm8921-charger/power_supply/battery/

[nemo@Sailfish battery]$ grep . *
capacity:95
charge_full:1939300
charge_full_design:2100000
charge_now:1842335
charge_type:Fast
current_max:3932897
current_now:-375614
energy_empty:0
energy_empty_design:0
energy_full:7369340
energy_full_design:7980000
energy_now:7000873
health:Good
present:1
status:Charging
technology:Li-ion
temp:273
type:Battery
uevent:POWER_SUPPLY_NAME=battery
uevent:POWER_SUPPLY_STATUS=Charging
uevent:POWER_SUPPLY_CHARGE_TYPE=Fast
uevent:POWER_SUPPLY_HEALTH=Good
uevent:POWER_SUPPLY_PRESENT=1
uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
uevent:POWER_SUPPLY_VOLTAGE_MAX_DESIGN=4350000
uevent:POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3400000
uevent:POWER_SUPPLY_VOLTAGE_NOW=4374609
uevent:POWER_SUPPLY_CAPACITY=95
uevent:POWER_SUPPLY_CURRENT_MAX=3932897
uevent:POWER_SUPPLY_CURRENT_NOW=-376419
uevent:POWER_SUPPLY_TEMP=273
uevent:POWER_SUPPLY_CHARGE_FULL=1939300
uevent:POWER_SUPPLY_CHARGE_FULL_DESIGN=2100000
uevent:POWER_SUPPLY_CHARGE_NOW=1842335
uevent:POWER_SUPPLY_ENERGY_FULL_DESIGN=7980000
uevent:POWER_SUPPLY_ENERGY_EMPTY_DESIGN=0
uevent:POWER_SUPPLY_ENERGY_FULL=7369340
uevent:POWER_SUPPLY_ENERGY_EMPTY=0
uevent:POWER_SUPPLY_ENERGY_NOW=7000873
voltage_max_design:4350000
voltage_min_design:3400000
voltage_now:4375194

[nemo@Sailfish battery]$ grep . *
capacity:0
charge_full:1939300
charge_full_design:2100000
charge_now:0
charge_type:N/A
current_max:4124649
current_now:4026
energy_empty:0
energy_empty_design:0
energy_full:7369340
energy_full_design:7980000
energy_now:0
health:Cold
present:0
status:Not charging
technology:Li-ion
temp:-300
type:Battery
uevent:POWER_SUPPLY_NAME=battery
uevent:POWER_SUPPLY_STATUS=Not charging
uevent:POWER_SUPPLY_CHARGE_TYPE=N/A
uevent:POWER_SUPPLY_HEALTH=Cold
uevent:POWER_SUPPLY_PRESENT=0
uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
uevent:POWER_SUPPLY_VOLTAGE_MAX_DESIGN=4350000
uevent:POWER_SUPPLY_VOLTAGE_MIN_DESIGN=3400000
uevent:POWER_SUPPLY_VOLTAGE_NOW=1050294
uevent:POWER_SUPPLY_CAPACITY=0
uevent:POWER_SUPPLY_CURRENT_MAX=4124649
uevent:POWER_SUPPLY_CURRENT_NOW=4026
uevent:POWER_SUPPLY_TEMP=-300
uevent:POWER_SUPPLY_CHARGE_FULL=1939300
uevent:POWER_SUPPLY_CHARGE_FULL_DESIGN=2100000
uevent:POWER_SUPPLY_CHARGE_NOW=0
uevent:POWER_SUPPLY_ENERGY_FULL_DESIGN=7980000
uevent:POWER_SUPPLY_ENERGY_EMPTY_DESIGN=0
uevent:POWER_SUPPLY_ENERGY_FULL=7369340
uevent:POWER_SUPPLY_ENERGY_EMPTY=0
uevent:POWER_SUPPLY_ENERGY_NOW=0
voltage_max_design:4350000
voltage_min_design:3400000
voltage_now:1043262

 

The phone shut down after a while, even though I had replaced the battery back, I wasn't quick enough this time. It worked before however ;)

EDIT: it does not shutdown when you do not use the powersave feature under settings from here: https://openrepos.net/content/coderus/jolla-powersave-settings

I still get a message that the device battery is critically low and I should return the device to normal environmental conditions.

After reinserting my other battery, it did not properly detect its charge and shut down the device.

I'll keep up with the Issuetracker then. Thank you for this piece of gold!

xkr47's picture

Thanks! I guess the "present:1" and "present:0" are the best indicators here. After all, battery temperature could be -30°C :D

update: Ok implemented now! Beware of the new scary icon: https://github.com/xkr47/sailfish-charger-control/blob/master/qml/cover/charger-control-nobattery.png. Will be included in next release.

MoritzJT's picture

Looking good still. Is this app still maintained? I have recently switched to a Jolla C but I can't find the same trick to work on it. It seems it ain't possible to control the hardware this way :-(

Igorion's picture

Very usefull, thanks. Only miss one function. Please, add option for automatically stop charging when the charge level has reached <user selectable>%.

Markkyboy's picture

Nicely done xkr47,

very good and very useful, as my phone spends much of its time connected to my laptop and I have 3 new batteries to condition (which I've done some of using my own app), but your app is great!, nice presentation and a working cover! (I failed miserably on that front!).

I like this app, very much, this is a keeper and it was certainly worth nudging you to upload! :)

Regards,

objectifnul's picture

This is a must-have if your device is laptop-connected most of the time. Thanks.

Collateral benefit: it allows to deal with the old "Sorry" bug (try an other charger, etc.) without having to unplug/replug the USB cable. Remember that many phones die after the USB connector fails due to too many manipulations.

4 stars only, because I'd like to have this triggered automatically when a power source is connected.

xkr47's picture

Thanks! Could you clarify what you would like to be triggered automatically (when a power source is connected)?

objectifnul's picture

Just to have Charger Control replacing (or enhancing) the genuine Jolla choice between Dev/PC/Charge connection that appears automatically when a data+power USB cable is plugged.

xkr47's picture

Interesting idea. Not sure if the current menu supports enhancing/replacing or not but worth a look! Added issue #3.