Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providing enough information for rust-battery / starship #364

Closed
alexanderadam opened this issue Aug 11, 2020 · 3 comments
Closed

Providing enough information for rust-battery / starship #364

alexanderadam opened this issue Aug 11, 2020 · 3 comments

Comments

@alexanderadam
Copy link

Feature description

The Rust library rust-battery allows Rust applications, like the popular prompt starship, to consume battery information (independent from the underlying operating system). The current output isn't enough and is leading to compile errors.

The maintainer @Svartal wrote:

I'm definitely up for adding functionality needed to run battery (and starship as a consequence) inside of the termux env, but it is out of my scope to work on that directly; if you want to raise an issue for termux-api and communicate with its developers to extend provided API, that would be great.

The current output of termux-battery-status is

{
  "health": "GOOD",
  "percentage": 59,
  "plugged": "UNPLUGGED",
  "status": "DISCHARGING",
  "temperature": 27.200000762939453,
  "current": -693
}

but the current Battery struct needs:

Attribute Description
state_of_charge Battery state of charge
energy Amount of energy currently available in the battery
energy_full Amount of energy in the battery when it's considered full.
energy_full_design Amount of energy the battery is designed to hold when it's considered full.
energy_rate Amount of energy being drained from the battery.
voltage Battery voltage.
state_of_health Gets battery state of health.
state Battery current state.
technology Battery technology.
temperature Battery temperature.
cycle_count Number of charge/discharge cycles.
vendor Battery vendor.
model Battery model.
serial_number Battery serial number.
time_to_full Remaining time till full battery.
time_to_empty Remaining time till empty battery.

Would it be possible to extend termux-battery-status to enable support for rust-battery?

PS: Thank you so much for your work! Termux is awesome and enables an impressive level of productivity on Android! 🙏

@Grimler91
Copy link
Member

Since we are accessing the android API we can only get the values defined in it, these are listed here: https://developer.android.com/reference/android/os/BatteryManager.

but the current Battery struct needs:

Does "needs" mean that these values are absolutely necessary or can some be set to NULL?

technology, vendor and model would have to be implemented manually as a huge map for every phone and I do not think anyone wants to implement that (and it would not be 100 % correct anyways as many (older) phones have replaceable batteries).

serial_number would be impossible to access.

How does other OS's handle this, are technology, vendor, model and serial_number always accessible?

Since rust-battery would anyways need to handle termux/android as a special OS I think it would make sense to set the unknown fields to NULL there rather than having termux-api return some fields which are always NULL.

@ghost
Copy link

ghost commented Aug 11, 2020

Since we are accessing the android API we can only get the values defined in it, these are listed here: https://developer.android.com/reference/android/os/BatteryManager.

Yes, because other values are vendor specific and usually exposed through sysfs only at

/sys/class/power_supply/battery

Entries here are device-specific, some of them may be absent or have access restricted by SELinux.

How does other OS's handle this, are technology, vendor, model and serial_number always accessible?

On laptop these values accessible through sysfs:

~ $ ls /sys/class/power_supply/BAT0
alarm                   device              model_name     subsystem
capacity                energy_full         power          technology
capacity_level          energy_full_design  power_now      type
charge_start_threshold  energy_now          present        uevent
charge_stop_threshold   hwmon2              serial_number  voltage_min_design
cycle_count             manufacturer        status         voltage_now

Unlike Android devices, entries here are standard.

@alexanderadam
Copy link
Author

alexanderadam commented Sep 9, 2020

Sorry, the maintainer of rust-battery just wrote

to this point I don't see how Android' BatteryManager data can be mapped to Battery from this crate.

😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants