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 extern ssize_t android_readlinkat (int, const char *restrict, char *restrict,
    79                                    size_t);
    80 
    81 
    82 
    83 extern double android_pixel_density_x, android_pixel_density_y;
    84 extern double android_scaled_pixel_density;
    85 
    86 enum android_handle_type
    87   {
    88     ANDROID_HANDLE_WINDOW,
    89     ANDROID_HANDLE_GCONTEXT,
    90     ANDROID_HANDLE_PIXMAP,
    91     ANDROID_HANDLE_CURSOR,
    92   };
    93 
    94 extern jobject android_resolve_handle (android_handle,
    95                                        enum android_handle_type);
    96 extern unsigned char *android_lock_bitmap (android_drawable,
    97                                            AndroidBitmapInfo *,
    98                                            jobject *);
    99 extern void android_damage_window (android_window,
   100                                    struct android_rectangle *);
   101 extern int android_get_screen_width (void);
   102 extern int android_get_screen_height (void);
   103 extern int android_get_mm_width (void);
   104 extern int android_get_mm_height (void);
   105 extern bool android_detect_mouse (void);
   106 
   107 extern void android_set_dont_focus_on_map (android_window, bool);
   108 extern void android_set_dont_accept_focus (android_window, bool);
   109 
   110 extern int android_verify_jni_string (const char *);
   111 extern jstring android_build_string (Lisp_Object);
   112 extern jstring android_build_jstring (const char *);
   113 extern void android_exception_check (void);
   114 extern void android_exception_check_1 (jobject);
   115 extern void android_exception_check_2 (jobject, jobject);
   116 extern void android_exception_check_3 (jobject, jobject, jobject);
   117 extern void android_exception_check_4 (jobject, jobject, jobject, jobject);
   118 extern void android_exception_check_nonnull (void *, jobject);
   119 extern void android_exception_check_nonnull_1 (void *, jobject, jobject);
   120 
   121 extern void android_get_keysym_name (int, char *, size_t);
   122 extern void android_wait_event (void);
   123 extern void android_toggle_on_screen_keyboard (android_window, bool);
   124 extern _Noreturn void android_restart_emacs (void);
   125 extern int android_request_directory_access (void);
   126 extern int android_get_current_api_level (void)
   127   __attribute__ ((pure));
   128 
   129 /* Define `android_get_current_api_level' to a macro that the compiler
   130    knows will always return at least __ANDROID_API__.  */
   131 
   132 #define android_get_current_api_level()                         \
   133   ({ int value;                                                 \
   134                                                                 \
   135      value = (android_get_current_api_level) ();                \
   136      eassume (value >= __ANDROID_API__); value; })
   137 
   138 
   139 
   140 /* Directory listing emulation.  */
   141 
   142 struct android_vdir;
   143 
   144 extern struct android_vdir *android_opendir (const char *);
   145 extern int android_dirfd (struct android_vdir *);
   146 extern struct dirent *android_readdir (struct android_vdir *);
   147 extern void android_closedir (struct android_vdir *);
   148 
   149 
   150 
   151 /* External asset manager interface.  */
   152 
   153 struct android_fd_or_asset
   154 {
   155   /* The file descriptor.  */
   156   int fd;
   157 
   158   /* The asset.  If set, FD is not a real file descriptor.  */
   159   void *asset;
   160 };
   161 
   162 extern struct android_fd_or_asset android_open_asset (const char *,
   163                                                       int, mode_t);
   164 extern int android_close_asset (struct android_fd_or_asset);
   165 extern ssize_t android_asset_read_quit (struct android_fd_or_asset,
   166                                         void *, size_t);
   167 extern ssize_t android_asset_read (struct android_fd_or_asset,
   168                                    void *, size_t);
   169 extern off_t android_asset_lseek (struct android_fd_or_asset, off_t, int);
   170 extern int android_asset_fstat (struct android_fd_or_asset,
   171                                 struct stat *);
   172 
   173 
   174 
   175 /* Very miscellaneous functions.  */
   176 
   177 struct android_battery_state
   178 {
   179   /* Battery charge level in integer percentage.  */
   180   intmax_t capacity;
   181 
   182   /* Battery charge level in microampere-hours.  */
   183   intmax_t charge_counter;
   184 
   185   /* Battery current in microampere-hours.  */
   186   intmax_t current_average;
   187 
   188   /* Instantaneous battery current in microampere-hours.  */
   189   intmax_t current_now;
   190 
   191   /* Estimate as to the amount of time remaining until the battery is
   192      charged, in milliseconds.  */
   193   intmax_t remaining;
   194 
   195   /* Battery status.  The value is either:
   196 
   197        2, if the battery is charging.
   198        3, if the battery is discharging.
   199        5, if the battery is full.
   200        4, if the battery is not full or discharging,
   201           but is not charging either.
   202        1, if the battery state is unknown.  */
   203   int status;
   204 
   205   /* The power source of the battery.  Value is:
   206 
   207        0, if on battery power.
   208        1, for line power.
   209        8, for dock power.
   210        2, for USB power.
   211        4, for wireless power.  */
   212   int plugged;
   213 
   214   /* The temperature of the battery in 10 * degrees centigrade.  */
   215   int temperature;
   216 };
   217 
   218 extern Lisp_Object android_browse_url (Lisp_Object, Lisp_Object);
   219 extern int android_query_battery (struct android_battery_state *);
   220 extern void android_display_toast (const char *);
   221 
   222 
   223 
   224 /* Event loop functions.  */
   225 
   226 extern void android_check_query_urgent (void);
   227 extern int android_run_in_emacs_thread (void (*) (void *), void *);
   228 extern void android_write_event (union android_event *);
   229 
   230 extern unsigned int event_serial;
   231 
   232 
   233 
   234 /* Process related functions.  */
   235 extern int android_rewrite_spawn_argv (const char ***);
   236 
   237 #else /* ANDROID_STUBIFY */
   238 
   239 /* Define a substitute for use during Emacs compilation.  */
   240 
   241 #define android_is_special_directory(name, dir) ((const char *) NULL)
   242 
   243 #endif /* !ANDROID_STUBIFY */
   244 
   245 /* JNI functions should not be built when Emacs is stubbed out for the
   246    build.  These should be documented in EmacsNative.java.  */
   247 
   248 #ifndef ANDROID_STUBIFY
   249 #include <jni.h>
   250 
   251 struct android_emacs_service
   252 {
   253   jclass class;
   254   jmethodID fill_rectangle;
   255   jmethodID fill_polygon;
   256   jmethodID draw_rectangle;
   257   jmethodID draw_line;
   258   jmethodID draw_point;
   259   jmethodID clear_window;
   260   jmethodID clear_area;
   261   jmethodID ring_bell;
   262   jmethodID query_tree;
   263   jmethodID get_screen_width;
   264   jmethodID get_screen_height;
   265   jmethodID detect_mouse;
   266   jmethodID name_keysym;
   267   jmethodID browse_url;
   268   jmethodID restart_emacs;
   269   jmethodID update_ic;
   270   jmethodID reset_ic;
   271   jmethodID open_content_uri;
   272   jmethodID check_content_uri;
   273   jmethodID query_battery;
   274   jmethodID update_extracted_text;
   275   jmethodID update_cursor_anchor_info;
   276   jmethodID get_document_authorities;
   277   jmethodID request_directory_access;
   278   jmethodID get_document_trees;
   279   jmethodID document_id_from_name;
   280   jmethodID get_tree_uri;
   281   jmethodID stat_document;
   282   jmethodID access_document;
   283   jmethodID open_document_directory;
   284   jmethodID read_directory_entry;
   285   jmethodID open_document;
   286   jmethodID create_document;
   287   jmethodID create_directory;
   288   jmethodID delete_document;
   289   jmethodID rename_document;
   290   jmethodID move_document;
   291   jmethodID valid_authority;
   292 };
   293 
   294 extern JNIEnv *android_java_env;
   295 
   296 /* The EmacsService object.  */
   297 extern jobject emacs_service;
   298 
   299 /* Various methods associated with the EmacsService.  */
   300 extern struct android_emacs_service service_class;
   301 
   302 #define ANDROID_DELETE_LOCAL_REF(ref)                           \
   303   ((*android_java_env)->DeleteLocalRef (android_java_env,       \
   304                                         (ref)))
   305 
   306 #define NATIVE_NAME(name) Java_org_gnu_emacs_EmacsNative_##name
   307 
   308 /* Prologue which must be inserted before each JNI function.
   309    See initEmacs for why.  */
   310 
   311 #if defined __i386__
   312 extern void *unused_pointer;
   313 
   314 #define JNI_STACK_ALIGNMENT_PROLOGUE                            \
   315   __attribute__ ((aligned (32))) char stack_align_buffer[32];   \
   316                                                                 \
   317   /* Trick GCC into not optimizing this variable away.  */      \
   318   unused_pointer = stack_align_buffer;
   319 
   320 #else /* !__i386__ */
   321 #define JNI_STACK_ALIGNMENT_PROLOGUE ((void) 0)
   322 #endif /* __i386__ */
   323 
   324 #endif /* !ANDROID_STUBIFY */
   325 #endif /* _ANDROID_H_ */

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