From 417e0539cfe5af5ab20ffc2342b0796ad5c0ef1b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 10 Mar 2023 10:02:36 +0800 Subject: [PATCH] Avoid using Linux sysfs APIs to access battery state on Android * lisp/battery.el (battery-status-function): Don't look for /sys, /proc* on Android. Explain why. --- lisp/battery.el | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lisp/battery.el b/lisp/battery.el index a51bc5267b3..c55fcbbee8c 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -97,20 +97,21 @@ Value does not include \".\" or \"..\"." (defcustom battery-status-function (cond ((member battery-upower-service (dbus-list-activatable-names)) #'battery-upower) - ;; Try to find the relevant devices in /sys and /proc on - ;; Android as well, in case the system makes them available. - ((and (memq system-type '(gnu/linux android)) + ((and (eq system-type 'gnu/linux) (file-readable-p "/sys/") (battery--find-linux-sysfs-batteries)) #'battery-linux-sysfs) - ((and (memq system-type '(gnu/linux android)) + ((and (eq system-type 'gnu/linux) (file-directory-p "/proc/acpi/battery")) #'battery-linux-proc-acpi) - ((and (memq system-type '(gnu/linux android)) + ((and (eq system-type 'gnu/linux) (file-readable-p "/proc/") (file-readable-p "/proc/apm")) #'battery-linux-proc-apm) ;; Now try the Android battery status function. + ;; Note that even though the Linux kernel APIs are sometimes + ;; available on Android, they are badly implemented by Android + ;; kernels, so avoid using those. ((eq system-type 'android) #'battery-android) ((and (eq system-type 'berkeley-unix) -- 2.39.5