Git Product home page Git Product logo

huawei-wmi's Introduction

huawei-wmi

Sets group write privileges and reinstates battery charge-thresholds.

Also reinstates keyboard backlight timeout and power mode unlock if supported.

Why?

As the Huawei WMI controller is known to forget above settings after hibernation, a few reboots, or several hours of being powered off, this repository provides a udev rule and two systemd units to reinstate them as required. A surprising but expected behavior is that while the MateBook is powered off, there is nothing running which can reinstate the charge-thresholds and hence it still might charge to 100 %. Therefore, it is recommended to unplug the power supply when powered off. Further peculiarities are documented in the Linux on MateBook guide.

How?

The settings to be reinstated are stored in /etc/default/huawei-wmi/ and the current settings of the kernel driver interface are mapped in /sys/devices/platform/huawei-wmi/. The udev rule fires the static one-shot huawei-wmi-privilege service as soon as the kernel driver interface has been populated. It sets group write privileges for the members of the system group huawei-wmi and initializes non-existent settings in former directory with the current settings of latter directory. Afterwards, it fires the non-static one-shot huawei-wmi-reinstate service which reinstates the settings by copying the files from former to latter directory. Latter service is refired when waking up from hibernation. Only non-static services can be enabled or disabled.

Installation

The services rely on the mainlined kernel driver. They are supported by the cross-platform MateBook applet as well as the native Gnome extension and can be installed via Makefile or distribution packages. The installer will ask for a list of desktop users separated by space which will gain mandatory group write privileges to the kernel driver interface. For the changes to take effect, the listed users have to be logged out. This is reliably achieved by rebooting the MateBook.

Makefile

Packages

Troubleshooting

Ensure your desktop user is a member of the system group huawei-wmi:

$ groups | xargs -n 1 | grep huawei-wmi
huawei-wmi

Ensure your desktop user has write privileges for default and current settings:

$ echo 40 70 | tee {/etc/default,/sys/devices/platform}/huawei-wmi/charge_control_thresholds
40 70

Ensure the charge capacity lies between above charge-thresholds or choose them accordingly:

$ cat /sys/class/power_supply/BAT?/capacity
60 # for example

Ensure the battery is not charging:

$ cat /sys/class/power_supply/BAT?/status
Not charging

Note that above and especially the Gnome/KDE charge status might be delayed by a few minutes.

Smart Charge

Newer models starting from 2020 feature a smart-charge mode which ignores any charge-thresholds if enabled. It might get enabled by updating the BIOS, starting PC Manager on Windows, or setting one of the thresholds to zero.

Disable smart-charge mode which would otherwise ignore charge-thresholds:

$ echo 0x462848011503 | tee /sys/kernel/debug/huawei-wmi/arg
0x462848011503
$ cat /sys/kernel/debug/huawei-wmi/call
# ...
$ cat /sys/kernel/debug/huawei-wmi/call # yes, twice
# ...

This basically enables home mode and hence sets charge-thresholds to "40 70".

License

Licensed under Fair.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the works by you shall be licensed as above, without any additional terms or conditions.

huawei-wmi's People

Contributors

egormanga avatar n3vu0r avatar nekr0z avatar shirokumacode avatar tsivinsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

huawei-wmi's Issues

Executable bit set on service file

dmesg gives me the following output:

[    1.797312] systemd[1]: Configuration file /usr/lib/systemd/system/huawei-wmi-reinstate.service
 is marked executable. Please remove executable permission bits. Proceeding anyway.

I agree with dmesg here, and think the service file shouldn't be executable (right?)

Support for next-gen driver

I've been in contact with Ayman, and he confirmed that the next version of his driver (already in development in master branch) will have /sys/class/power_supply/BAT[x]/charge_control_[start|end]_threshold (where x is 0 for our machines) for battery control, and /sys/devices/platform/huawei-wmi/charge_tresholds is going extinct for good (fn_lock_state is staying). I'll be updating the applet (hopefully by next weekend) to support this, and humbly suggest you look into this too.

Currently, failing to find charge_thresholds, the unit panics and gives up, and doesn't even change the permissions on fn_lock_state.

Battery modes no longer supported after bios update?

Hello, MateBook 14 AMD here. After bios updated 1.18 it seems like battery mode settings no longer do anything. I've checked /sys/devices/platform/huawei-wmi/charge_control_thresholds and they are all set correctly but still has no effect. Fn-lock still works correctly though. Also in Huawei PC Manager there are now feature called 'Smart charge' and battery modes are only selectable if you disable that. Can anyone confirm that? Do battery modes work for you on latest bios? Or do we need a kernel wmi interface update?

Battery Control not working on my Huawei Matebook D AMD 2018 edition

Hi,

on my Huawei matebook D AMD (Arch KDE) Huawei WMI does not work for battery protection. I have a problem with all the distro I tried those years (Ubuntu, Arch, Manjaro, Debian based and so on) that on ma laptop that is a Huawei Matebook D AMD SoC even if Huawei-WMI driver is included in the kernel (so I can use FN key and OSD for volume ...) the battery protection doesn't work even in theory system say it stop charging at 70% , it charge 100%.
if I boot to windows (with HuaweiPCManager that set battery to 70%) and reboot to linux battery stay at 70% but after 2 or 3 reboot to linux it loose the setting and goes to fully charged 100%, because of that I install Huawei-WMI to sets group write privileges and reinstates battery charge-thresholds. I have 2 services : huawei-wmi-reinstate and huawei-wmi-privilege but both are unloaded and inactive on systemd, how to get those 2 service loaded at startup and active? Trying to activate I have this error: $ sudo systemctl enable --now huawei-wmi-privilege.service Unit /usr/lib/systemd/system/huawei-wmi-privilege.service is added as a depende ncy to a non-existent unit sys-devices-platform-huawei\x2dwmi.device
Command sudo systemctl enable --now huawei-wmi-reinstate.service doesn,t provide errors but is not active and still unloaded
Can you check? Battery protection is the only thing not working on my huawei Matebook D 2018 version AMD
Thanks!!!

systemd complains "Special user nobody configured, this is not safe!"

systemd states in [1]:

This is not safe. The @OFFENDING_USER@ user's main purpose on Linux-based operating systems is to be the owner of files that otherwise cannot be mapped to any local user. It's used by the NFS client and Linux user namespacing, among others. By running a unit's processes under the identity of this user they might possibly get read and even write access to such files that cannot otherwise be mapped.

It is strongly recommended to avoid running services under this user identity, in particular on systems using NFS or running containers. Allocate a user ID specific to this service, either statically via systemd-sysusers or dynamically via the DynamicUser= service setting.

Thus, the line User=nobody in huawei-wmi-reinstate.service should be changed to DynamicUser=yes. Tested the change on Arch Linux and it successfully removed the warning.

Gnome Extension and permission problem

Hi,
my system is on Archlinux 5.16 and uptodate. I installed your package from AUR and I added my user to the huawei-wmi. Finally I installed and enabled the gnome extension..
I restarted the system but from the extension panel, I cannot change the protection mode.
I checked logs and I saw that:
"JS ERROR: Gio.IOErrorEnum: Error opening file “/sys/devices/platform/huawei-wmi/charge_control_thresholds”: Permission denied
_set_bpm@/home/cihat/.local/share/gnome-shell/extensions/[email protected]/extension.js:70:25
_init/<@/home/cihat/.local/share/gnome-shell/extensions/[email protected]/extension.js:49:40
activate@resource:///org/gnome/shell/ui/popupMenu.js:191:14
vfunc_button_release_event@resource:///org/gnome/shell/ui/popupMenu.js:138:14"
What should I do?
Best,
Cihat.

HUAWEI MateBook X Pro 2022 "Unkwon key pressed, code 0x02c1"

I have an Arch Linux installation in a Huawei MateBook X Pro 2022 laptop and there's an annoying message that keeps spamming in the journal:

...
ene 08 17:49:16 logos kernel: input input12: Unknown key pressed, code: 0x02c1
ene 08 17:49:16 logos kernel: input input12: Unknown key pressed, code: 0x02c1
ene 08 17:49:17 logos kernel: input input12: Unknown key pressed, code: 0x02c1
...

The main problem with it is that it floods the journal and can make it difficult to use journalctl normally.

One workaround could be to add { KE_IGNORE, 0x2c1, { KEY_RESERVED } }, to huawei-wmi.c.

This Archlinux forum thread describes the issue with more detail.

Repository planned?

Do you plan to host a repository, or do you plan publishing straight to Debian?

I've put up a repo for matebook-applet, hope you don't mind me including huawei-wmi .deb until you publish, so that dependency gets resolved?

Debian only?

Up until and including 7f66556 this repo could be cloned and used on any distro, even LFS (providing it had systemd, udev and usual GNU utils). Now sudo make install would fail on anything but Debian. Are you planning to support other distros (I'm not talking packages here, but at least the way it was in 7f66556)?

"usermod: user $user does not exist after" error while installing using debian repo on PopOs

 ❯❯❯ whoami                                                                                                                                                                                     ✘ 100 
edgardo
~ ❯❯❯ uname -a
Linux pop-os 5.8.0-7642-generic #47~1612288990~20.10~b8113e7-Ubuntu SMP Wed Feb 3 02:27:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
~ ❯❯❯ sudo apt install huawei-wmi
Reading package lists... Done
Building dependency tree       
Reading state information... Done
huawei-wmi is already the newest version (1.1.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up huawei-wmi (1.1.1) ...
usermod: user 'edgardo,' does not exist
dpkg: error processing package huawei-wmi (--configure):
 installed huawei-wmi package post-installation script subprocess returned error exit status 6
Errors were encountered while processing:
 huawei-wmi
E: Sub-process /usr/bin/dpkg returned an error code (1)

ExecStart path is not absolute

Hi,

when installing the services (generic) on Ubuntu 18.04 we get

...
systemd[1]: /lib/systemd/system/huawei-wmi-reinstate.service:12: Executable path is not absolute: sh -c 'echo Old charge thresholds $(cat ${SYS}/charge_thresholds)'
systemd[1]: /lib/systemd/system/huawei-wmi-privilege.service:9: Executable path is not absolute: chgrp huawei-wmi ${SYS}/charge_thresholds ${SYS}/fn_lock_state
...

According to docs, ExecStart paths are supposed to be absolute.

Changing those paths to absolute (eg. /bin/sh, among others) fixes the errors and the scripts execute successfully.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.