root/src/android.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


     1 /* Android initialization for GNU Emacs.
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 /* On Android, Emacs is built as a shared library loaded from Java
    21    using the Java Native Interface.  Emacs's `main' function is
    22    renamed `android_emacs_init', and runs with some modifications
    23    inside a separate thread, communicating with the Java code through
    24    a table of function pointers.  */
    25 
    26 #ifndef _ANDROID_H_
    27 #ifndef ANDROID_STUBIFY
    28 #include <jni.h>
    29 #include <pwd.h>
    30 
    31 #include <sys/stat.h>
    32 #include <dirent.h>
    33 #include <stdio.h>
    34 
    35 #include <android/bitmap.h>
    36 
    37 #include "androidgui.h"
    38 #include "lisp.h"
    39 #endif /* ANDROID_STUBIFY */
    40 
    41 extern bool android_init_gui;
    42 
    43 #ifndef ANDROID_STUBIFY
    44 
    45 extern char *android_cache_dir;
    46 
    47 extern int android_emacs_init (int, char **, char *);
    48 extern int android_select (int, fd_set *, fd_set *, fd_set *,
    49                            struct timespec *);
    50 extern char *android_user_full_name (struct passwd *);
    51 
    52 
    53 
    54 /* File I/O operations.  Many of these are defined in
    55    androidvfs.c.  */
    56 
    57 extern const char *android_is_special_directory (const char *, const char *);
    58 extern const char *android_get_home_directory (void);
    59 
    60 extern void android_vfs_init (JNIEnv *, jobject);
    61 
    62 extern int android_open (const char *, int, mode_t);
    63 extern int android_fstat (int, struct stat *);
    64 extern int android_fstatat (int, const char *restrict,
    65                             struct stat *restrict, int);
    66 extern int android_faccessat (int, const char *, int, int);
    67 extern int android_close (int);
    68 extern FILE *android_fdopen (int, const char *);
    69 extern int android_fclose (FILE *);
    70 extern int android_unlink (const char *);
    71 extern int android_symlink (const char *, const char *);
    72 extern int android_rmdir (const char *);
    73 extern int android_mkdir (const char *, mode_t);
    74 extern int android_renameat_noreplace (int, const char *,
    75                                        int, const char *);
    76 extern int android_rename (const char *, const char *);
    77 extern int android_fchmodat (int, const char *, mode_t, int);
    78 
    79 
    80 
    81 extern double android_pixel_density_x, android_pixel_density_y;
    82 extern double android_scaled_pixel_density;
    83 
    84 enum android_handle_type
    85   {
    86     ANDROID_HANDLE_WINDOW,
    87     ANDROID_HANDLE_GCONTEXT,
    88     ANDROID_HANDLE_PIXMAP,
    89     ANDROID_HANDLE_CURSOR,
    90   };
    91 
    92 extern jobject android_resolve_handle (android_handle,
    93                                        enum android_handle_type);
    94 extern unsigned char *android_lock_bitmap (android_drawable,
    95                                            AndroidBitmapInfo *,
    96                                            jobject *);
    97 extern void android_damage_window (android_window,
    98                                    struct android_rectangle *);
    99 extern int android_get_screen_width (void);
   100 extern int android_get_screen_height (void);
   101 extern int android_get_mm_width (void);
   102 extern int android_get_mm_height (void);
   103 extern bool android_detect_mouse (void);
   104 
   105 extern void android_set_dont_focus_on_map (android_window, bool);
   106 extern void android_set_dont_accept_focus (android_window, bool);
   107 
   108 extern int android_verify_jni_string (const char *);
   109 extern jstring android_build_string (Lisp_Object);
   110 extern jstring android_build_jstring (const char *);
   111 extern void android_exception_check (void);
   112 extern void android_exception_check_1 (jobject);
   113 extern void android_exception_check_2 (jobject, jobject);
   114 extern void android_exception_check_3 (jobject, jobject, jobject);
   115 extern void android_exception_check_4 (jobject, jobject, jobject, jobject);
   116 extern void android_exception_check_nonnull (void *, jobject);
   117 extern void android_exception_check_nonnull_1 (void *, jobject, jobject);
   118 
   119 extern void android_get_keysym_name (int, char *, size_t);
   120 extern void android_wait_event (void);
   121 extern void android_toggle_on_screen_keyboard (android_window, bool);
   122 extern _Noreturn void android_restart_emacs (void);
   123 extern int android_request_directory_access (void);
   124 extern int android_get_current_api_level (void)
   125   __attribute__ ((pure));
   126 
   127 /* Define `android_get_current_api_level' to a macro that the compiler
   128    knows will always return at least __ANDROID_API__.  */
   129 
   130 #define android_get_current_api_level()                         \
   131   ({ int value;                                                 \
   132                                                                 \
   133      value = (android_get_current_api_level) ();                \
   134      eassume (value >= __ANDROID_API__); value; })
   135 
   136 
   137 
   138 /* Directory listing emulation.  */
   139 
   140 struct android_vdir;
   141 
   142 extern struct android_vdir *android_opendir (const char *);
   143 extern int android_dirfd (struct android_vdir *);
   144 extern struct dirent *android_readdir (struct android_vdir *);
   145 extern void android_closedir (struct android_vdir *);
   146 
   147 
   148 
   149 /* External asset manager interface.  */
   150 
   151 struct android_fd_or_asset
   152 {
   153   /* The file descriptor.  */
   154   int fd;
   155 
   156   /* The asset.  If set, FD is not a real file descriptor.  */
   157   void *asset;
   158 };
   159 
   160 extern struct android_fd_or_asset android_open_asset (const char *,
   161                                                       int, mode_t);
   162 extern int android_close_asset (struct android_fd_or_asset);
   163 extern ssize_t android_asset_read_quit (struct android_fd_or_asset,
   164                                         void *, size_t);
   165 extern ssize_t android_asset_read (struct android_fd_or_asset,
   166                                    void *, size_t);
   167 extern off_t android_asset_lseek (struct android_fd_or_asset, off_t, int);
   168 extern int android_asset_fstat (struct android_fd_or_asset,
   169                                 struct stat *);
   170 
   171 
   172 
   173 /* Very miscellaneous functions.  */
   174 
   175 struct android_battery_state
   176 {
   177   /* Battery charge level in integer percentage.  */
   178   intmax_t capacity;
   179 
   180   /* Battery charge level in microampere-hours.  */
   181   intmax_t charge_counter;
   182 
   183   /* Battery current in microampere-hours.  */
   184   intmax_t current_average;
   185 
   186   /* Instantaneous battery current in microampere-hours.  */
   187   intmax_t current_now;
   188 
   189   /* Estimate as to the amount of time remaining until the battery is
   190      charged, in milliseconds.  */
   191   intmax_t remaining;
   192 
   193   /* Battery status.  The value is either:
   194 
   195        2, if the battery is charging.
   196        3, if the battery is discharging.
   197        5, if the battery is full.
   198        4, if the battery is not full or discharging,
   199           but is not charging either.
   200        1, if the battery state is unknown.  */
   201   int status;
   202 
   203   /* The power source of the battery.  Value is:
   204 
   205        0, if on battery power.
   206        1, for line power.
   207        8, for dock power.
   208        2, for USB power.
   209        4, for wireless power.  */
   210   int plugged;
   211 
   212   /* The temperature of the battery in 10 * degrees centigrade.  */
   213   int temperature;
   214 };
   215 
   216 extern Lisp_Object android_browse_url (Lisp_Object, Lisp_Object);
   217 extern int android_query_battery (struct android_battery_state *);
   218 extern void android_display_toast (const char *);
   219 
   220 
   221 
   222 /* Event loop functions.  */
   223 
   224 extern void android_check_query_urgent (void);
   225 extern int android_run_in_emacs_thread (void (*) (void *), void *);
   226 extern void android_write_event (union android_event *);
   227 
   228 extern unsigned int event_serial;
   229 
   230 
   231 
   232 /* Process related functions.  */
   233 extern int android_rewrite_spawn_argv (const char ***);
   234 
   235 #else /* ANDROID_STUBIFY */
   236 
   237 /* Define a substitute for use during Emacs compilation.  */
   238 
   239 #define android_is_special_directory(name, dir) ((const char *) NULL)
   240 
   241 #endif /* !ANDROID_STUBIFY */
   242 
   243 /* JNI functions should not be built when Emacs is stubbed out for the
   244    build.  These should be documented in EmacsNative.java.  */
   245 
   246 #ifndef ANDROID_STUBIFY
   247 #include <jni.h>
   248 
   249 struct android_emacs_service
   250 {
   251   jclass class;
   252   jmethodID fill_rectangle;
   253   jmethodID fill_polygon;
   254   jmethodID draw_rectangle;
   255   jmethodID draw_line;
   256   jmethodID draw_point;
   257   jmethodID clear_window;
   258   jmethodID clear_area;
   259   jmethodID ring_bell;
   260   jmethodID query_tree;
   261   jmethodID get_screen_width;
   262   jmethodID get_screen_height;
   263   jmethodID detect_mouse;
   264   jmethodID name_keysym;
   265   jmethodID browse_url;
   266   jmethodID restart_emacs;
   267   jmethodID update_ic;
   268   jmethodID reset_ic;
   269   jmethodID open_content_uri;
   270   jmethodID check_content_uri;
   271   jmethodID query_battery;
   272   jmethodID update_extracted_text;
   273   jmethodID update_cursor_anchor_info;
   274   jmethodID get_document_authorities;
   275   jmethodID request_directory_access;
   276   jmethodID get_document_trees;
   277   jmethodID document_id_from_name;
   278   jmethodID get_tree_uri;
   279   jmethodID stat_document;
   280   jmethodID access_document;
   281   jmethodID open_document_directory;
   282   jmethodID read_directory_entry;
   283   jmethodID open_document;
   284   jmethodID create_document;
   285   jmethodID create_directory;
   286   jmethodID delete_document;
   287   jmethodID rename_document;
   288   jmethodID move_document;
   289   jmethodID valid_authority;
   290 };
   291 
   292 extern JNIEnv *android_java_env;
   293 
   294 /* The EmacsService object.  */
   295 extern jobject emacs_service;
   296 
   297 /* Various methods associated with the EmacsService.  */
   298 extern struct android_emacs_service service_class;
   299 
   300 #define ANDROID_DELETE_LOCAL_REF(ref)                           \
   301   ((*android_java_env)->DeleteLocalRef (android_java_env,       \
   302                                         (ref)))
   303 
   304 #define NATIVE_NAME(name) Java_org_gnu_emacs_EmacsNative_##name
   305 
   306 /* Prologue which must be inserted before each JNI function.
   307    See initEmacs for why.  */
   308 
   309 #if defined __i386__
   310 extern void *unused_pointer;
   311 
   312 #define JNI_STACK_ALIGNMENT_PROLOGUE                            \
   313   __attribute__ ((aligned (32))) char stack_align_buffer[32];   \
   314                                                                 \
   315   /* Trick GCC into not optimizing this variable away.  */      \
   316   unused_pointer = stack_align_buffer;
   317 
   318 #else /* !__i386__ */
   319 #define JNI_STACK_ALIGNMENT_PROLOGUE ((void) 0)
   320 #endif /* __i386__ */
   321 
   322 #endif /* !ANDROID_STUBIFY */
   323 #endif /* _ANDROID_H_ */

/* [<][>][^][v][top][bottom][index][help] */