diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index cfe9e42de4d..77124a7d80f 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java @@ -1212,7 +1212,7 @@ If a display name can be requested from URI (using the resolver temp = battery.getIntExtra (BatteryManager.EXTRA_TEMPERATURE, 0); return new long[] { capacity, chargeCounter, currentAvg, - currentNow, remaining, status, plugged, + currentNow, status, remaining, plugged, temp, }; } @@ -1289,7 +1289,7 @@ else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) } return new long[] { capacity, chargeCounter, currentAvg, - currentNow, remaining, status, plugged, + currentNow, status, remaining, plugged, temp, }; } diff --git a/lisp/battery.el b/lisp/battery.el index 4aae3e0ef54..4959e48317f 100644 --- a/lisp/battery.el +++ b/lisp/battery.el @@ -33,7 +33,7 @@ ;; - BSD by using the `apm' program. ;; - Darwin (macOS) by using the `pmset' program. ;; - Windows via the GetSystemPowerStatus API call. -;; - Android 5 or later via the BatteryManager APIs. +;; - Android via the BatteryManager APIs. ;;; Code: @@ -112,7 +112,7 @@ Value does not include \".\" or \"..\"." ;; 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) + ((fboundp 'android-query-battery) #'battery-android) ((and (eq system-type 'berkeley-unix) (file-executable-p "/usr/sbin/apm")) @@ -1107,7 +1107,8 @@ The following %-sequences are provided: (rate nil) (remaining nil) (hours nil) - (minutes nil)) + (minutes nil) + (temperature nil)) ;; Figure out the percentage. (setq percentage (number-to-string (car status))) ;; Figure out the capacity @@ -1133,6 +1134,12 @@ The following %-sequences are provided: (setq remaining (format "%d:%d" hours-left mins) hours (number-to-string hours-left) minutes (number-to-string mins)))) + ;; Return the temperature, so long as its value is not downright + ;; absurd (as when the sensor is faulty or the battery controller + ;; driver does not provide temperature readouts). + (unless (or (< (nth 7 status) -1000) + (> (nth 7 status) 1000)) + (setq temperature (/ (nth 7 status) 10.0))) ;; Return results. (list (cons ?c capacity) (cons ?p percentage) @@ -1145,11 +1152,12 @@ The following %-sequences are provided: (cons ?L (cl-case (nth 6 status) (0 "off-line") (1 "on-line") - (2 "on-line (dock)") - (3 "on-line (USB)") - (4 "on-line (wireless)") + (2 "on-line (USB)") + (4 "on-line (dock)") + (8 "on-line (wireless)") (t "unknown"))) - (cons ?t (/ (or (nth 7 status) 0) 10.0)))))) + (cons ?t (/ (or (nth 7 status) 0) 10.0)) + (cons ?d temperature))))) ;;; Private functions. diff --git a/src/android.c b/src/android.c index 17b5d6d4115..3c0e3ee1558 100644 --- a/src/android.c +++ b/src/android.c @@ -6574,8 +6574,8 @@ android_query_battery (struct android_battery_state *status) status->charge_counter = longs[1]; status->current_average = longs[2]; status->current_now = longs[3]; - status->remaining = longs[4]; - status->status = longs[5]; + status->status = longs[4]; + status->remaining = longs[5]; status->plugged = longs[6]; status->temperature = longs[7];