diff options
| author | Po Lu | 2023-02-25 19:11:07 +0800 |
|---|---|---|
| committer | Po Lu | 2023-02-25 19:11:07 +0800 |
| commit | 8e4c5db193dc7baee5846520fe8b63d8bea99148 (patch) | |
| tree | 595eb65601d38b7895ae1d00ec9a71a947cd1af7 /java | |
| parent | d5cccfdc564f1486431f9674503c794df33d7fbc (diff) | |
| download | emacs-8e4c5db193dc7baee5846520fe8b63d8bea99148.tar.gz emacs-8e4c5db193dc7baee5846520fe8b63d8bea99148.zip | |
Update Android port
* doc/emacs/android.texi (Android Startup, Android File System)
(Android Environment, Android Windowing, Android
Troubleshooting): Improve documentation; fix typos.
* doc/lispref/commands.texi (Misc Events): Likewise.
* java/org/gnu/emacs/EmacsService.java (queryBattery): New
function.
* lisp/battery.el (battery-status-function): Set appropriately
for Android.
(battery-android): New function.
* src/android.c (struct android_emacs_service): New method
`query_battery'.
(android_check_content_access): Improve exception checking.
(android_init_emacs_service): Look up new method.
(android_destroy_handle, android_create_window)
(android_init_android_rect_class, android_init_emacs_gc_class)
(android_set_clip_rectangles)
(android_create_pixmap_from_bitmap_data, android_fill_polygon)
(android_get_image, android_put_image, android_bell)
(android_set_input_focus, android_raise_window)
(android_lower_window, android_query_tree, android_get_geometry)
(android_translate_coordinates, android_wc_lookup_string)
(android_damage_window, android_build_string)
(android_build_jstring, android_exception_check_1)
(android_exception_check_2): New functions.
(android_browse_url): Improve exception handling. Always use
android_exception_check and don't leak local refs.
(android_query_battery): New function.
* src/android.h (struct android_battery_state): New struct.
* src/androidfns.c (Fandroid_query_battery, syms_of_androidfns):
New function.
* src/androidfont.c (androidfont_from_lisp, DO_SYMBOL_FIELD)
(DO_CARDINAL_FIELD, androidfont_list, androidfont_match)
(androidfont_draw, androidfont_open_font)
(androidfont_close_font):
* src/androidselect.c (Fandroid_set_clipboard)
(Fandroid_get_clipboard):
* src/sfnt.c (sfnt_map_glyf_table):
* src/sfntfont.c (sfntfont_free_outline_cache)
(sfntfont_free_raster_cache, sfntfont_close): Allow font close
functions to be called twice.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index c9701ff2990..48c7c743014 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -54,9 +54,9 @@ import android.content.res.AssetManager; | |||
| 54 | import android.database.Cursor; | 54 | import android.database.Cursor; |
| 55 | import android.database.MatrixCursor; | 55 | import android.database.MatrixCursor; |
| 56 | 56 | ||
| 57 | |||
| 58 | import android.net.Uri; | 57 | import android.net.Uri; |
| 59 | 58 | ||
| 59 | import android.os.BatteryManager; | ||
| 60 | import android.os.Build; | 60 | import android.os.Build; |
| 61 | import android.os.Looper; | 61 | import android.os.Looper; |
| 62 | import android.os.IBinder; | 62 | import android.os.IBinder; |
| @@ -762,4 +762,59 @@ public class EmacsService extends Service | |||
| 762 | return false; | 762 | return false; |
| 763 | } | 763 | } |
| 764 | } | 764 | } |
| 765 | |||
| 766 | /* Return the status of the battery. See struct | ||
| 767 | android_battery_status for the order of the elements | ||
| 768 | returned. | ||
| 769 | |||
| 770 | Value may be null upon failure. */ | ||
| 771 | |||
| 772 | public long[] | ||
| 773 | queryBattery () | ||
| 774 | { | ||
| 775 | Object tem; | ||
| 776 | BatteryManager manager; | ||
| 777 | long capacity, chargeCounter, currentAvg, currentNow; | ||
| 778 | long status, remaining; | ||
| 779 | int prop; | ||
| 780 | |||
| 781 | /* Android 4.4 or earlier require applications to listen to | ||
| 782 | changes to the battery instead of querying for its status. */ | ||
| 783 | |||
| 784 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) | ||
| 785 | return null; | ||
| 786 | |||
| 787 | tem = getSystemService (Context.BATTERY_SERVICE); | ||
| 788 | manager = (BatteryManager) tem; | ||
| 789 | remaining = -1; | ||
| 790 | |||
| 791 | prop = BatteryManager.BATTERY_PROPERTY_CAPACITY; | ||
| 792 | capacity = manager.getLongProperty (prop); | ||
| 793 | prop = BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER; | ||
| 794 | chargeCounter = manager.getLongProperty (prop); | ||
| 795 | prop = BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE; | ||
| 796 | currentAvg = manager.getLongProperty (prop); | ||
| 797 | prop = BatteryManager.BATTERY_PROPERTY_CURRENT_NOW; | ||
| 798 | currentNow = manager.getLongProperty (prop); | ||
| 799 | |||
| 800 | /* Return the battery status. N.B. that Android 7.1 and earlier | ||
| 801 | only return ``charging'' or ``discharging''. */ | ||
| 802 | |||
| 803 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) | ||
| 804 | status = manager.getIntProperty (BatteryManager.BATTERY_PROPERTY_STATUS); | ||
| 805 | else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) | ||
| 806 | status = (manager.isCharging () | ||
| 807 | ? BatteryManager.BATTERY_STATUS_CHARGING | ||
| 808 | : BatteryManager.BATTERY_STATUS_DISCHARGING); | ||
| 809 | else | ||
| 810 | status = (currentNow > 0 | ||
| 811 | ? BatteryManager.BATTERY_STATUS_CHARGING | ||
| 812 | : BatteryManager.BATTERY_STATUS_DISCHARGING); | ||
| 813 | |||
| 814 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) | ||
| 815 | remaining = manager.computeChargeTimeRemaining (); | ||
| 816 | |||
| 817 | return new long[] { capacity, chargeCounter, currentAvg, | ||
| 818 | currentNow, remaining, status, }; | ||
| 819 | } | ||
| 765 | }; | 820 | }; |