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.
This commit is contained in:
Po Lu 2023-11-09 10:12:24 +08:00
parent 06e4ebc81a
commit 21f3670526
3 changed files with 35 additions and 0 deletions

View file

@ -92,6 +92,10 @@ public static native void setEmacsParams (AssetManager assetManager,
loadup.el itself. */
public static native void initEmacs (String argv[], String dumpFile);
/* Call shut_down_emacs to auto-save and unlock files in the main
thread, then return. */
public static native void shutDownEmacs ();
/* Abort and generate a native core dump. */
public static native void emacsAbort ();

View file

@ -321,6 +321,18 @@ invocation of app_process (through android-emacs) can
}
}
@Override
public void
onDestroy ()
{
/* This function is called immediately before the system kills
Emacs. In this respect, it is rather akin to a SIGDANGER
signal, so force an auto-save accordingly. */
EmacsNative.shutDownEmacs ();
super.onDestroy ();
}
/* Functions from here on must only be called from the Emacs

View file

@ -1938,6 +1938,25 @@ NATIVE_NAME (quit) (JNIEnv *env, jobject object)
kill (getpid (), SIGIO);
}
/* Call shut_down_emacs subsequent to a call to the service's
onDestroy callback. CLOSURE is ignored. */
static void
android_shut_down_emacs (void *closure)
{
__android_log_print (ANDROID_LOG_INFO, __func__,
"The Emacs service is being shut down");
shut_down_emacs (0, Qnil);
}
JNIEXPORT void JNICALL
NATIVE_NAME (shutDownEmacs) (JNIEnv *env, jobject object)
{
JNI_STACK_ALIGNMENT_PROLOGUE;
android_run_in_emacs_thread (android_shut_down_emacs, NULL);
}
JNIEXPORT jlong JNICALL
NATIVE_NAME (sendConfigureNotify) (JNIEnv *env, jobject object,
jshort window, jlong time,