From 6a54c2cc589e1203d89cdabe203e60efe4f96fb8 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 12 Jul 2024 14:31:33 +0800 Subject: [PATCH] Render more Android functions safe to execute in a batch session * src/androidfns.c (Fx_display_mm_width, Fx_display_mm_height) (Fandroid_display_monitor_attributes_list) (Fandroid_external_storage_available_p) (Fandroid_request_storage_access): Verify that a display connection or service object is available. * src/androidselect.c (Fandroid_get_clipboard) (Fandroid_browse_url_internal, Fandroid_get_clipboard_targets) (Fandroid_get_clipboard_data, Fandroid_notifications_notify): Moderate tone of error messages. (cherry picked from commit b22ab99f0a85f73a1aec582f7aba0e6b5101b953) --- src/androidfns.c | 11 +++++++++++ src/androidselect.c | 10 +++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/androidfns.c b/src/androidfns.c index 7595e176618..af2247ad962 100644 --- a/src/androidfns.c +++ b/src/androidfns.c @@ -1374,6 +1374,7 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, error ("Android cross-compilation stub called!"); return Qnil; #else + check_android_display_info (terminal); return make_fixnum (android_get_mm_width ()); #endif } @@ -1386,6 +1387,7 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, error ("Android cross-compilation stub called!"); return Qnil; #else + check_android_display_info (terminal); return make_fixnum (android_get_mm_height ()); #endif } @@ -1469,6 +1471,7 @@ Internal use only, use `display-monitor-attributes-list' instead. */) #else struct MonitorInfo monitor; + check_android_display_info (terminal); memset (&monitor, 0, sizeof monitor); monitor.geom.width = android_get_screen_width (); monitor.geom.height = android_get_screen_height (); @@ -3270,6 +3273,11 @@ External storage on Android encompasses the `/sdcard' and absent these permissions. */) (void) { + /* Implement a rather undependable fallback when no GUI is + available. */ + if (!android_init_gui) + return Ffile_accessible_directory_p (build_string ("/sdcard")); + return android_external_storage_available_p () ? Qt : Qnil; } @@ -3284,6 +3292,9 @@ Use `android-external-storage-available-p' (which see) to verify whether Emacs has actually received such access permissions. */) (void) { + if (!android_init_gui) + return Qnil; + android_request_storage_access (); return Qnil; } diff --git a/src/androidselect.c b/src/androidselect.c index d5783b75417..cbd163c6c9f 100644 --- a/src/androidselect.c +++ b/src/androidselect.c @@ -189,7 +189,7 @@ Alternatively, return nil if the clipboard is empty. */) const char *data; if (!android_init_gui) - error ("No Android display connection!"); + error ("No Android display connection"); method = clipboard_class.get_clipboard; text @@ -258,7 +258,7 @@ for. Use `android-browse-url' instead. */) Lisp_Object value; if (!android_init_gui) - error ("No Android display connection!"); + error ("No Android display connection"); CHECK_STRING (url); value = android_browse_url (url, send); @@ -290,7 +290,7 @@ data type available from the clipboard. */) Lisp_Object targets, tem; if (!android_init_gui) - error ("No Android display connection!"); + error ("No Android display connection"); targets = Qnil; block_input (); @@ -544,7 +544,7 @@ does not have any corresponding data. In that case, use char *buffer, *start; if (!android_init_gui) - error ("No Android display connection!"); + error ("No Android display connection"); CHECK_STRING (type); @@ -1003,7 +1003,7 @@ usage: (android-notifications-notify &rest ARGS) */) AUTO_STRING (default_icon, "ic_dialog_alert"); if (!android_init_gui) - error ("No Android display connection!"); + error ("No Android display connection"); /* Clear each variable above. */ title = body = replaces_id = group = icon = urgency = actions = Qnil; -- 2.39.2