diff options
| author | Po Lu | 2023-03-10 09:40:41 +0800 |
|---|---|---|
| committer | Po Lu | 2023-03-10 09:40:41 +0800 |
| commit | 488a75f2e2b73038ff341f3484a8cf8584633eff (patch) | |
| tree | 4871fe49e7009816a004f96d59fcb3b945c294d8 /src | |
| parent | 4392423cb6df5a8af9a0520da04378e189fd387e (diff) | |
| download | emacs-488a75f2e2b73038ff341f3484a8cf8584633eff.tar.gz emacs-488a75f2e2b73038ff341f3484a8cf8584633eff.zip | |
Port Android battery status to Android 4.4 and earlier
* java/org/gnu/emacs/EmacsService.java (EmacsService)
(queryBattery19): New function.
(queryBattery): Call it on old systems. Also, return AC line
status and temperature.
* lisp/battery.el (battery-android): Implement more format
directives.
* src/android.c (android_query_battery): Handle new status
fields.
* src/android.h (struct android_battery_state): Add `plugged'
and `temperature'.
* src/androidfns.c (Fandroid_query_battery): Return new fields.
Diffstat (limited to 'src')
| -rw-r--r-- | src/android.c | 4 | ||||
| -rw-r--r-- | src/android.h | 12 | ||||
| -rw-r--r-- | src/androidfns.c | 16 |
3 files changed, 25 insertions, 7 deletions
diff --git a/src/android.c b/src/android.c index 69c87e731bd..763e17e9430 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -5754,7 +5754,7 @@ android_get_current_api_level (void) | |||
| 5754 | } | 5754 | } |
| 5755 | 5755 | ||
| 5756 | /* Query the status of the battery, and place it in *STATUS. | 5756 | /* Query the status of the battery, and place it in *STATUS. |
| 5757 | Value is 1 if the system is too old, else 0. */ | 5757 | Value is 1 upon failure, else 0. */ |
| 5758 | 5758 | ||
| 5759 | int | 5759 | int |
| 5760 | android_query_battery (struct android_battery_state *status) | 5760 | android_query_battery (struct android_battery_state *status) |
| @@ -5783,6 +5783,8 @@ android_query_battery (struct android_battery_state *status) | |||
| 5783 | status->current_now = longs[3]; | 5783 | status->current_now = longs[3]; |
| 5784 | status->remaining = longs[4]; | 5784 | status->remaining = longs[4]; |
| 5785 | status->status = longs[5]; | 5785 | status->status = longs[5]; |
| 5786 | status->plugged = longs[6]; | ||
| 5787 | status->temperature = longs[7]; | ||
| 5786 | 5788 | ||
| 5787 | (*android_java_env)->ReleaseLongArrayElements (android_java_env, | 5789 | (*android_java_env)->ReleaseLongArrayElements (android_java_env, |
| 5788 | array, longs, | 5790 | array, longs, |
diff --git a/src/android.h b/src/android.h index ed0089ad94e..450f3859df9 100644 --- a/src/android.h +++ b/src/android.h | |||
| @@ -160,6 +160,18 @@ struct android_battery_state | |||
| 160 | but is not charging either. | 160 | but is not charging either. |
| 161 | 1, if the battery state is unknown. */ | 161 | 1, if the battery state is unknown. */ |
| 162 | int status; | 162 | int status; |
| 163 | |||
| 164 | /* The power source of the battery. Value is: | ||
| 165 | |||
| 166 | 0, if on battery power. | ||
| 167 | 1, for line power. | ||
| 168 | 8, for dock power. | ||
| 169 | 2, for USB power. | ||
| 170 | 4, for wireless power. */ | ||
| 171 | int plugged; | ||
| 172 | |||
| 173 | /* The temperature of the battery in 10 * degrees centigrade. */ | ||
| 174 | int temperature; | ||
| 163 | }; | 175 | }; |
| 164 | 176 | ||
| 165 | extern Lisp_Object android_browse_url (Lisp_Object); | 177 | extern Lisp_Object android_browse_url (Lisp_Object); |
diff --git a/src/androidfns.c b/src/androidfns.c index 5a23e8bd196..2724b9595c1 100644 --- a/src/androidfns.c +++ b/src/androidfns.c | |||
| @@ -2797,11 +2797,13 @@ frame_parm_handler android_frame_parm_handlers[] = | |||
| 2797 | DEFUN ("android-query-battery", Fandroid_query_battery, | 2797 | DEFUN ("android-query-battery", Fandroid_query_battery, |
| 2798 | Sandroid_query_battery, 0, 0, 0, | 2798 | Sandroid_query_battery, 0, 0, 0, |
| 2799 | doc: /* Perform a query for battery information. | 2799 | doc: /* Perform a query for battery information. |
| 2800 | This function will not work before Android 5.0. | ||
| 2801 | Value is nil upon failure, or a list of the form: | 2800 | Value is nil upon failure, or a list of the form: |
| 2802 | 2801 | ||
| 2803 | (CAPACITY CHARGE-COUNTER CURRENT-AVERAGE CURRENT-NOW STATUS | 2802 | (CAPACITY CHARGE-COUNTER CURRENT-AVERAGE CURRENT-NOW STATUS |
| 2804 | REMAINING) | 2803 | REMAINING PLUGGED TEMP) |
| 2804 | |||
| 2805 | where REMAINING, CURRENT-AVERAGE, and CURRENT-NOW are undefined prior | ||
| 2806 | to Android 5.0. | ||
| 2805 | 2807 | ||
| 2806 | See the documentation at | 2808 | See the documentation at |
| 2807 | 2809 | ||
| @@ -2822,12 +2824,14 @@ for more details about these values. */) | |||
| 2822 | if (android_query_battery (&state)) | 2824 | if (android_query_battery (&state)) |
| 2823 | return Qnil; | 2825 | return Qnil; |
| 2824 | 2826 | ||
| 2825 | return listn (6, make_int (state.capacity), | 2827 | return listn (8, make_int (state.capacity), |
| 2826 | make_int (state.charge_counter), | 2828 | make_fixnum (state.charge_counter), |
| 2827 | make_int (state.current_average), | 2829 | make_int (state.current_average), |
| 2828 | make_int (state.current_now), | 2830 | make_int (state.current_now), |
| 2829 | make_int (state.status), | 2831 | make_fixnum (state.status), |
| 2830 | make_int (state.remaining)); | 2832 | make_int (state.remaining), |
| 2833 | make_fixnum (state.plugged), | ||
| 2834 | make_fixnum (state.temperature)); | ||
| 2831 | } | 2835 | } |
| 2832 | 2836 | ||
| 2833 | #endif | 2837 | #endif |