diff options
| author | Po Lu | 2023-01-28 21:21:45 +0800 |
|---|---|---|
| committer | Po Lu | 2023-01-28 21:21:45 +0800 |
| commit | f9e32ce1575da69cc3a9e4690b6df2dbee41d14d (patch) | |
| tree | 2dad1101288c0ff381f9d7265e6ce27ad75dbdec | |
| parent | 22749d69e5892896f5ae9d26e7d6c43da67fa13d (diff) | |
| download | emacs-f9e32ce1575da69cc3a9e4690b6df2dbee41d14d.tar.gz emacs-f9e32ce1575da69cc3a9e4690b6df2dbee41d14d.zip | |
Implement `restart-emacs' on Android
* java/org/gnu/emacs/EmacsService.java (restartEmacs): New
function.
* src/android.c (struct android_emacs_service)
(android_init_emacs_service): Add new method.
(android_restart_emacs): New function.
* src/android.h: Update prototypes.
* src/emacs.c (Fkill_emacs): Call android_restart_emacs whenever
appropriate.
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 12 | ||||
| -rw-r--r-- | src/android.c | 19 | ||||
| -rw-r--r-- | src/android.h | 1 | ||||
| -rw-r--r-- | src/emacs.c | 16 |
4 files changed, 47 insertions, 1 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index eb9b61dd876..d17f6d1286c 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -611,4 +611,16 @@ public class EmacsService extends Service | |||
| 611 | 611 | ||
| 612 | return manager.thing; | 612 | return manager.thing; |
| 613 | } | 613 | } |
| 614 | |||
| 615 | public void | ||
| 616 | restartEmacs () | ||
| 617 | { | ||
| 618 | Intent intent; | ||
| 619 | |||
| 620 | intent = new Intent (this, EmacsActivity.class); | ||
| 621 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | ||
| 622 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); | ||
| 623 | startActivity (intent); | ||
| 624 | System.exit (0); | ||
| 625 | } | ||
| 614 | }; | 626 | }; |
diff --git a/src/android.c b/src/android.c index 021bea1fc2f..598d002fb1c 100644 --- a/src/android.c +++ b/src/android.c | |||
| @@ -97,6 +97,7 @@ struct android_emacs_service | |||
| 97 | jmethodID name_keysym; | 97 | jmethodID name_keysym; |
| 98 | jmethodID sync; | 98 | jmethodID sync; |
| 99 | jmethodID browse_url; | 99 | jmethodID browse_url; |
| 100 | jmethodID restart_emacs; | ||
| 100 | }; | 101 | }; |
| 101 | 102 | ||
| 102 | struct android_emacs_pixmap | 103 | struct android_emacs_pixmap |
| @@ -1659,6 +1660,7 @@ android_init_emacs_service (void) | |||
| 1659 | FIND_METHOD (sync, "sync", "()V"); | 1660 | FIND_METHOD (sync, "sync", "()V"); |
| 1660 | FIND_METHOD (browse_url, "browseUrl", "(Ljava/lang/String;)" | 1661 | FIND_METHOD (browse_url, "browseUrl", "(Ljava/lang/String;)" |
| 1661 | "Ljava/lang/String;"); | 1662 | "Ljava/lang/String;"); |
| 1663 | FIND_METHOD (restart_emacs, "restartEmacs", "()V"); | ||
| 1662 | #undef FIND_METHOD | 1664 | #undef FIND_METHOD |
| 1663 | } | 1665 | } |
| 1664 | 1666 | ||
| @@ -4987,6 +4989,23 @@ android_browse_url (Lisp_Object url) | |||
| 4987 | return tem; | 4989 | return tem; |
| 4988 | } | 4990 | } |
| 4989 | 4991 | ||
| 4992 | /* Tell the system to restart Emacs in a short amount of time, and | ||
| 4993 | then kill Emacs. Never return. This is used to implement | ||
| 4994 | `restart-emacs'. */ | ||
| 4995 | |||
| 4996 | _Noreturn void | ||
| 4997 | android_restart_emacs (void) | ||
| 4998 | { | ||
| 4999 | /* Try to call the Java side function. Normally, this should call | ||
| 5000 | System.exit to terminate this process. */ | ||
| 5001 | (*android_java_env)->CallVoidMethod (android_java_env, | ||
| 5002 | emacs_service, | ||
| 5003 | service_class.restart_emacs); | ||
| 5004 | |||
| 5005 | /* Exit anyway, in case EmacsService did not do so. */ | ||
| 5006 | exit (0); | ||
| 5007 | } | ||
| 5008 | |||
| 4990 | 5009 | ||
| 4991 | 5010 | ||
| 4992 | #else /* ANDROID_STUBIFY */ | 5011 | #else /* ANDROID_STUBIFY */ |
diff --git a/src/android.h b/src/android.h index 8234dbb07c0..9b2eca807cb 100644 --- a/src/android.h +++ b/src/android.h | |||
| @@ -89,6 +89,7 @@ extern void android_get_keysym_name (int, char *, size_t); | |||
| 89 | extern void android_wait_event (void); | 89 | extern void android_wait_event (void); |
| 90 | extern void android_toggle_on_screen_keyboard (android_window, bool); | 90 | extern void android_toggle_on_screen_keyboard (android_window, bool); |
| 91 | extern void android_window_updated (android_window, unsigned long); | 91 | extern void android_window_updated (android_window, unsigned long); |
| 92 | extern _Noreturn void android_restart_emacs (void); | ||
| 92 | 93 | ||
| 93 | 94 | ||
| 94 | 95 | ||
diff --git a/src/emacs.c b/src/emacs.c index a24f9960494..79156c63017 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -2948,7 +2948,14 @@ killed. */ | |||
| 2948 | #ifndef WINDOWSNT | 2948 | #ifndef WINDOWSNT |
| 2949 | /* Do some checking before shutting down Emacs, because errors | 2949 | /* Do some checking before shutting down Emacs, because errors |
| 2950 | can't be meaningfully reported afterwards. */ | 2950 | can't be meaningfully reported afterwards. */ |
| 2951 | if (!NILP (restart)) | 2951 | if (!NILP (restart) |
| 2952 | /* Don't perform the following checks when Emacs is running as | ||
| 2953 | an Android GUI application, because there the system is | ||
| 2954 | relied on to restart Emacs. */ | ||
| 2955 | #if defined HAVE_ANDROID && !defined ANDROID_STUBIFY | ||
| 2956 | && !android_init_gui | ||
| 2957 | #endif | ||
| 2958 | ) | ||
| 2952 | { | 2959 | { |
| 2953 | /* This is very unlikely, but it's possible to execute a binary | 2960 | /* This is very unlikely, but it's possible to execute a binary |
| 2954 | (on some systems) with no argv. */ | 2961 | (on some systems) with no argv. */ |
| @@ -3010,6 +3017,13 @@ killed. */ | |||
| 3010 | if (!NILP (restart)) | 3017 | if (!NILP (restart)) |
| 3011 | { | 3018 | { |
| 3012 | turn_on_atimers (false); | 3019 | turn_on_atimers (false); |
| 3020 | #if defined HAVE_ANDROID && !defined ANDROID_STUBIFY | ||
| 3021 | /* Re-executing the Emacs process created by the system doesn't | ||
| 3022 | work. Instead, schedule a restart for a few hundered | ||
| 3023 | milliseconds and exit Emacs. */ | ||
| 3024 | if (android_init_gui) | ||
| 3025 | android_restart_emacs (); | ||
| 3026 | #endif | ||
| 3013 | #ifdef WINDOWSNT | 3027 | #ifdef WINDOWSNT |
| 3014 | if (w32_reexec_emacs (initial_cmdline, initial_wd) < 0) | 3028 | if (w32_reexec_emacs (initial_cmdline, initial_wd) < 0) |
| 3015 | #else | 3029 | #else |