diff options
| author | Po Lu | 2023-07-23 09:52:19 +0800 |
|---|---|---|
| committer | Po Lu | 2023-07-23 09:52:19 +0800 |
| commit | 44910e26f32edbad9a5c063ecdfbb6a32a759752 (patch) | |
| tree | f45043e90420bccc2f9fa0c7606d2cc1d3eb14fc /src/android.c | |
| parent | be70caa68f448438cd8170534220ca284d6a6930 (diff) | |
| download | emacs-44910e26f32edbad9a5c063ecdfbb6a32a759752.tar.gz emacs-44910e26f32edbad9a5c063ecdfbb6a32a759752.zip | |
Facilitate locating the app library directory
* doc/emacs/android.texi (Android File System): Document where
the app library directory can probably be found.
* src/android.c (android_create_lib_link): New function. Try to
symlink `lib' in the directory holding the files directory to
the app library directory.
(setEmacsParams): Call that function if Emacs is being
initialized from an application context.
Diffstat (limited to 'src/android.c')
| -rw-r--r-- | src/android.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/android.c b/src/android.c index 048773a511d..6fcaa40b2a9 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -30,6 +30,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 30 | #include <string.h> | 30 | #include <string.h> |
| 31 | #include <stdckdint.h> | 31 | #include <stdckdint.h> |
| 32 | #include <timespec.h> | 32 | #include <timespec.h> |
| 33 | #include <libgen.h> | ||
| 33 | 34 | ||
| 34 | #include <sys/stat.h> | 35 | #include <sys/stat.h> |
| 35 | #include <sys/mman.h> | 36 | #include <sys/mman.h> |
| @@ -1995,6 +1996,65 @@ android_proc_name (int fd, char *buffer, size_t size) | |||
| 1995 | return 0; | 1996 | return 0; |
| 1996 | } | 1997 | } |
| 1997 | 1998 | ||
| 1999 | /* Try to guarantee the existence of the `lib' directory within the | ||
| 2000 | parent directory of the application files directory. | ||
| 2001 | |||
| 2002 | If `/data/data/org.gnu.emacs/lib' (or | ||
| 2003 | `/data/user/N/org.gnu.emacs/lib') does not exist or is a dangling | ||
| 2004 | symbolic link, create a symlink from it to the library | ||
| 2005 | directory. | ||
| 2006 | |||
| 2007 | Newer versions of Android don't create this link by default, making | ||
| 2008 | it difficult to locate the directory containing Emacs library | ||
| 2009 | files, particularly from scripts in other programs sharing the same | ||
| 2010 | user ID as Emacs that don't have access to `exec-path'. */ | ||
| 2011 | |||
| 2012 | static void | ||
| 2013 | android_create_lib_link (void) | ||
| 2014 | { | ||
| 2015 | char *filename; | ||
| 2016 | char lib_directory[PATH_MAX]; | ||
| 2017 | int fd; | ||
| 2018 | struct stat statb; | ||
| 2019 | |||
| 2020 | /* Find the directory containing the files directory. */ | ||
| 2021 | filename = dirname (android_files_dir); | ||
| 2022 | if (!filename) | ||
| 2023 | goto failure; | ||
| 2024 | |||
| 2025 | /* Now make `lib_directory' the name of the library directory | ||
| 2026 | within. */ | ||
| 2027 | snprintf (lib_directory, PATH_MAX, "%s/lib", filename); | ||
| 2028 | |||
| 2029 | /* Try to open this directory. */ | ||
| 2030 | fd = open (lib_directory, O_DIRECTORY); | ||
| 2031 | |||
| 2032 | /* If the directory can be opened normally, close it and return | ||
| 2033 | now. */ | ||
| 2034 | if (fd >= 0) | ||
| 2035 | goto success; | ||
| 2036 | |||
| 2037 | /* Try to unlink the directory in case it's a dangling symbolic | ||
| 2038 | link. */ | ||
| 2039 | unlink (lib_directory); | ||
| 2040 | |||
| 2041 | /* Otherwise, try to symlink lib_directory to the actual library | ||
| 2042 | directory. */ | ||
| 2043 | |||
| 2044 | if (symlink (android_lib_dir, lib_directory)) | ||
| 2045 | /* Print a warning message if creating the link fails. */ | ||
| 2046 | __android_log_print (ANDROID_LOG_WARN, __func__, | ||
| 2047 | "Failed to create symbolic link from" | ||
| 2048 | " application library directory `%s'" | ||
| 2049 | " to its actual location at `%s'", | ||
| 2050 | lib_directory, android_files_dir); | ||
| 2051 | |||
| 2052 | success: | ||
| 2053 | close (fd); | ||
| 2054 | failure: | ||
| 2055 | return; | ||
| 2056 | } | ||
| 2057 | |||
| 1998 | 2058 | ||
| 1999 | 2059 | ||
| 2000 | /* JNI functions called by Java. */ | 2060 | /* JNI functions called by Java. */ |
| @@ -2229,6 +2289,16 @@ NATIVE_NAME (setEmacsParams) (JNIEnv *env, jobject object, | |||
| 2229 | 2289 | ||
| 2230 | if (!emacs_service) | 2290 | if (!emacs_service) |
| 2231 | emacs_abort (); | 2291 | emacs_abort (); |
| 2292 | |||
| 2293 | /* If the service is set this Emacs is being initialized as part | ||
| 2294 | of the Emacs application itself. | ||
| 2295 | |||
| 2296 | Try to create a symlink from where scripts expect Emacs to | ||
| 2297 | place its library files to the directory that actually holds | ||
| 2298 | them; earlier versions of Android used to do this | ||
| 2299 | automatically, but that feature has been removed. */ | ||
| 2300 | |||
| 2301 | android_create_lib_link (); | ||
| 2232 | } | 2302 | } |
| 2233 | 2303 | ||
| 2234 | /* Set up events. */ | 2304 | /* Set up events. */ |