mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-28 08:11:05 -08:00
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.
This commit is contained in:
parent
d5cccfdc56
commit
8e4c5db193
11 changed files with 414 additions and 166 deletions
|
|
@ -54,9 +54,9 @@ import android.content.res.AssetManager;
|
|||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
import android.os.IBinder;
|
||||
|
|
@ -762,4 +762,59 @@ public class EmacsService extends Service
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the status of the battery. See struct
|
||||
android_battery_status for the order of the elements
|
||||
returned.
|
||||
|
||||
Value may be null upon failure. */
|
||||
|
||||
public long[]
|
||||
queryBattery ()
|
||||
{
|
||||
Object tem;
|
||||
BatteryManager manager;
|
||||
long capacity, chargeCounter, currentAvg, currentNow;
|
||||
long status, remaining;
|
||||
int prop;
|
||||
|
||||
/* Android 4.4 or earlier require applications to listen to
|
||||
changes to the battery instead of querying for its status. */
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||
return null;
|
||||
|
||||
tem = getSystemService (Context.BATTERY_SERVICE);
|
||||
manager = (BatteryManager) tem;
|
||||
remaining = -1;
|
||||
|
||||
prop = BatteryManager.BATTERY_PROPERTY_CAPACITY;
|
||||
capacity = manager.getLongProperty (prop);
|
||||
prop = BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER;
|
||||
chargeCounter = manager.getLongProperty (prop);
|
||||
prop = BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE;
|
||||
currentAvg = manager.getLongProperty (prop);
|
||||
prop = BatteryManager.BATTERY_PROPERTY_CURRENT_NOW;
|
||||
currentNow = manager.getLongProperty (prop);
|
||||
|
||||
/* Return the battery status. N.B. that Android 7.1 and earlier
|
||||
only return ``charging'' or ``discharging''. */
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
status = manager.getIntProperty (BatteryManager.BATTERY_PROPERTY_STATUS);
|
||||
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
status = (manager.isCharging ()
|
||||
? BatteryManager.BATTERY_STATUS_CHARGING
|
||||
: BatteryManager.BATTERY_STATUS_DISCHARGING);
|
||||
else
|
||||
status = (currentNow > 0
|
||||
? BatteryManager.BATTERY_STATUS_CHARGING
|
||||
: BatteryManager.BATTERY_STATUS_DISCHARGING);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||
remaining = manager.computeChargeTimeRemaining ();
|
||||
|
||||
return new long[] { capacity, chargeCounter, currentAvg,
|
||||
currentNow, remaining, status, };
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue