diff options
| author | Po Lu | 2023-11-09 10:12:24 +0800 |
|---|---|---|
| committer | Po Lu | 2023-11-09 10:12:24 +0800 |
| commit | 21f36705266934d5a351d4d7f360734540132139 (patch) | |
| tree | c67ff837f417bec1663df6700fe9b2b5ce330cc9 | |
| parent | 06e4ebc81a44c709b08ce72c746629c6c77e6f6e (diff) | |
| download | emacs-21f36705266934d5a351d4d7f360734540132139.tar.gz emacs-21f36705266934d5a351d4d7f360734540132139.zip | |
Guarantee files are auto-saved when Emacs is terminated by Android
* java/org/gnu/emacs/EmacsNative.java (shutDownEmacs):
* java/org/gnu/emacs/EmacsService.java (onDestroy): New
function. When invoked, call shut_down_emacs and await its
completion.
* src/android.c (android_shut_down_emacs, shutDownEmacs): New
functions.
| -rw-r--r-- | java/org/gnu/emacs/EmacsNative.java | 4 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 12 | ||||
| -rw-r--r-- | src/android.c | 19 |
3 files changed, 35 insertions, 0 deletions
diff --git a/java/org/gnu/emacs/EmacsNative.java b/java/org/gnu/emacs/EmacsNative.java index f15927bb3a7..946a38f7f84 100644 --- a/java/org/gnu/emacs/EmacsNative.java +++ b/java/org/gnu/emacs/EmacsNative.java | |||
| @@ -92,6 +92,10 @@ public final class EmacsNative | |||
| 92 | loadup.el itself. */ | 92 | loadup.el itself. */ |
| 93 | public static native void initEmacs (String argv[], String dumpFile); | 93 | public static native void initEmacs (String argv[], String dumpFile); |
| 94 | 94 | ||
| 95 | /* Call shut_down_emacs to auto-save and unlock files in the main | ||
| 96 | thread, then return. */ | ||
| 97 | public static native void shutDownEmacs (); | ||
| 98 | |||
| 95 | /* Abort and generate a native core dump. */ | 99 | /* Abort and generate a native core dump. */ |
| 96 | public static native void emacsAbort (); | 100 | public static native void emacsAbort (); |
| 97 | 101 | ||
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index 1325cd85e9b..ab6d57b9c4f 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -321,6 +321,18 @@ public final class EmacsService extends Service | |||
| 321 | } | 321 | } |
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | @Override | ||
| 325 | public void | ||
| 326 | onDestroy () | ||
| 327 | { | ||
| 328 | /* This function is called immediately before the system kills | ||
| 329 | Emacs. In this respect, it is rather akin to a SIGDANGER | ||
| 330 | signal, so force an auto-save accordingly. */ | ||
| 331 | |||
| 332 | EmacsNative.shutDownEmacs (); | ||
| 333 | super.onDestroy (); | ||
| 334 | } | ||
| 335 | |||
| 324 | 336 | ||
| 325 | 337 | ||
| 326 | /* Functions from here on must only be called from the Emacs | 338 | /* Functions from here on must only be called from the Emacs |
diff --git a/src/android.c b/src/android.c index 3397ec0e740..f5af742b422 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -1938,6 +1938,25 @@ NATIVE_NAME (quit) (JNIEnv *env, jobject object) | |||
| 1938 | kill (getpid (), SIGIO); | 1938 | kill (getpid (), SIGIO); |
| 1939 | } | 1939 | } |
| 1940 | 1940 | ||
| 1941 | /* Call shut_down_emacs subsequent to a call to the service's | ||
| 1942 | onDestroy callback. CLOSURE is ignored. */ | ||
| 1943 | |||
| 1944 | static void | ||
| 1945 | android_shut_down_emacs (void *closure) | ||
| 1946 | { | ||
| 1947 | __android_log_print (ANDROID_LOG_INFO, __func__, | ||
| 1948 | "The Emacs service is being shut down"); | ||
| 1949 | shut_down_emacs (0, Qnil); | ||
| 1950 | } | ||
| 1951 | |||
| 1952 | JNIEXPORT void JNICALL | ||
| 1953 | NATIVE_NAME (shutDownEmacs) (JNIEnv *env, jobject object) | ||
| 1954 | { | ||
| 1955 | JNI_STACK_ALIGNMENT_PROLOGUE; | ||
| 1956 | |||
| 1957 | android_run_in_emacs_thread (android_shut_down_emacs, NULL); | ||
| 1958 | } | ||
| 1959 | |||
| 1941 | JNIEXPORT jlong JNICALL | 1960 | JNIEXPORT jlong JNICALL |
| 1942 | NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object, | 1961 | NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object, |
| 1943 | jshort window, jlong time, | 1962 | jshort window, jlong time, |