aboutsummaryrefslogtreecommitdiffstats
path: root/java/org/gnu
diff options
context:
space:
mode:
authorPo Lu2023-05-26 15:20:39 +0800
committerPo Lu2023-05-26 15:20:39 +0800
commit0eb1f4e57125117006f109a5549082008fc9fbb1 (patch)
tree12fdeab1893c34654b31cb3ad5efae188d08e405 /java/org/gnu
parentddaca337e3a81e811de6e0f61ed78c414a1986be (diff)
downloademacs-0eb1f4e57125117006f109a5549082008fc9fbb1.tar.gz
emacs-0eb1f4e57125117006f109a5549082008fc9fbb1.zip
Allow starting Emacs --debug-init on Android
* doc/emacs/android.texi (Android Troubleshooting): Document `debug-init' option. * java/AndroidManifest.xml.in (EmacsLauncherPreferencesActivity): New activity. Export on systems older than Android 7.0. * java/org/gnu/emacs/EmacsActivity.java (onCreate): Adjust for string startup argument. * java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java: New file. * java/org/gnu/emacs/EmacsPreferencesActivity.java (EmacsPreferencesActivity): Don't make final. (startEmacsQ): Give start-up argument as an argument, not as a boolean. (startEmacsDebugInit): New function. (onCreate): Register new listener; make final. * java/org/gnu/emacs/EmacsService.java (onCreate): Pass extraStartupArgument. * java/org/gnu/emacs/EmacsThread.java (EmacsThread): Rename startDashQ to extraStartupArgument. (run): Adjust accordingly. * java/res/values-v24/bool.xml: * java/res/values/bool.xml: * java/res/values/strings.xml: New files. * java/res/xml/preferences.xml: Add new option. Move string resources around.
Diffstat (limited to 'java/org/gnu')
-rw-r--r--java/org/gnu/emacs/EmacsActivity.java8
-rw-r--r--java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java31
-rw-r--r--java/org/gnu/emacs/EmacsPreferencesActivity.java41
-rw-r--r--java/org/gnu/emacs/EmacsService.java7
-rw-r--r--java/org/gnu/emacs/EmacsThread.java19
5 files changed, 85 insertions, 21 deletions
diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java
index b480fc40b2e..7ba268ba42d 100644
--- a/java/org/gnu/emacs/EmacsActivity.java
+++ b/java/org/gnu/emacs/EmacsActivity.java
@@ -193,11 +193,11 @@ public class EmacsActivity extends Activity
193 ViewTreeObserver observer; 193 ViewTreeObserver observer;
194 int matchParent; 194 int matchParent;
195 195
196 /* See if Emacs should be started with -Q. */ 196 /* See if Emacs should be started with any extra arguments, such
197 as `--quick'. */
197 intent = getIntent (); 198 intent = getIntent ();
198 EmacsService.needDashQ 199 EmacsService.extraStartupArgument
199 = intent.getBooleanExtra ("org.gnu.emacs.START_DASH_Q", 200 = intent.getStringExtra ("org.gnu.emacs.STARTUP_ARGUMENT");
200 false);
201 201
202 matchParent = FrameLayout.LayoutParams.MATCH_PARENT; 202 matchParent = FrameLayout.LayoutParams.MATCH_PARENT;
203 params 203 params
diff --git a/java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java b/java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java
new file mode 100644
index 00000000000..1e1e5d97631
--- /dev/null
+++ b/java/org/gnu/emacs/EmacsLauncherPreferencesActivity.java
@@ -0,0 +1,31 @@
1/* Communication module for Android terminals. -*- c-file-style: "GNU" -*-
2
3Copyright (C) 2023 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or (at
10your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20package org.gnu.emacs;
21
22/* This class only exists because EmacsPreferencesActivity is already
23 defined as an activity, the system wants a new class in order to
24 define a new activity, and only activities can be enabled or
25 disabled per the API level of the host. */
26
27public final class EmacsLauncherPreferencesActivity
28 extends EmacsPreferencesActivity
29{
30
31}
diff --git a/java/org/gnu/emacs/EmacsPreferencesActivity.java b/java/org/gnu/emacs/EmacsPreferencesActivity.java
index 70934fa4bd4..7e67cc3679b 100644
--- a/java/org/gnu/emacs/EmacsPreferencesActivity.java
+++ b/java/org/gnu/emacs/EmacsPreferencesActivity.java
@@ -42,10 +42,11 @@ import android.preference.*;
42 Unfortunately, there is no alternative that looks the same way. */ 42 Unfortunately, there is no alternative that looks the same way. */
43 43
44@SuppressWarnings ("deprecation") 44@SuppressWarnings ("deprecation")
45public final class EmacsPreferencesActivity extends PreferenceActivity 45public class EmacsPreferencesActivity extends PreferenceActivity
46{ 46{
47 /* Restart Emacs with -Q. Call EmacsThread.exit to kill Emacs now, and 47 /* Restart Emacs with -Q. Call EmacsThread.exit to kill Emacs now,
48 tell the system to EmacsActivity with some parameters later. */ 48 and tell the system to start EmacsActivity with some parameters
49 later. */
49 50
50 private void 51 private void
51 startEmacsQ () 52 startEmacsQ ()
@@ -55,7 +56,24 @@ public final class EmacsPreferencesActivity extends PreferenceActivity
55 intent = new Intent (this, EmacsActivity.class); 56 intent = new Intent (this, EmacsActivity.class);
56 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK 57 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
57 | Intent.FLAG_ACTIVITY_CLEAR_TASK); 58 | Intent.FLAG_ACTIVITY_CLEAR_TASK);
58 intent.putExtra ("org.gnu.emacs.START_DASH_Q", true); 59 intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--quick");
60 startActivity (intent);
61 System.exit (0);
62 }
63
64 /* Restart Emacs with `--debug-init'. Call EmacsThread.exit to kill
65 Emacs now, and tell the system to EmacsActivity with some
66 parameters later. */
67
68 private void
69 startEmacsDebugInit ()
70 {
71 Intent intent;
72
73 intent = new Intent (this, EmacsActivity.class);
74 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
75 | Intent.FLAG_ACTIVITY_CLEAR_TASK);
76 intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--debug-init");
59 startActivity (intent); 77 startActivity (intent);
60 System.exit (0); 78 System.exit (0);
61 } 79 }
@@ -89,7 +107,7 @@ public final class EmacsPreferencesActivity extends PreferenceActivity
89 } 107 }
90 108
91 @Override 109 @Override
92 public void 110 public final void
93 onCreate (Bundle savedInstanceState) 111 onCreate (Bundle savedInstanceState)
94 { 112 {
95 Preference tem; 113 Preference tem;
@@ -111,7 +129,6 @@ public final class EmacsPreferencesActivity extends PreferenceActivity
111 items. */ 129 items. */
112 130
113 tem = findPreference ("start_quick"); 131 tem = findPreference ("start_quick");
114
115 listener = new Preference.OnPreferenceClickListener () { 132 listener = new Preference.OnPreferenceClickListener () {
116 @Override 133 @Override
117 public boolean 134 public boolean
@@ -123,9 +140,19 @@ public final class EmacsPreferencesActivity extends PreferenceActivity
123 }; 140 };
124 141
125 tem.setOnPreferenceClickListener (listener); 142 tem.setOnPreferenceClickListener (listener);
143 tem = findPreference ("start_debug_init");
144 listener = new Preference.OnPreferenceClickListener () {
145 @Override
146 public boolean
147 onPreferenceClick (Preference preference)
148 {
149 startEmacsDebugInit ();
150 return true;
151 }
152 };
126 153
154 tem.setOnPreferenceClickListener (listener);
127 tem = findPreference ("erase_dump"); 155 tem = findPreference ("erase_dump");
128
129 listener = new Preference.OnPreferenceClickListener () { 156 listener = new Preference.OnPreferenceClickListener () {
130 @Override 157 @Override
131 public boolean 158 public boolean
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index 30ef71540a9..bb17d27bcf8 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -79,7 +79,10 @@ public final class EmacsService extends Service
79{ 79{
80 public static final String TAG = "EmacsService"; 80 public static final String TAG = "EmacsService";
81 public static volatile EmacsService SERVICE; 81 public static volatile EmacsService SERVICE;
82 public static boolean needDashQ; 82
83 /* If non-NULL, an extra argument to pass to
84 `android_emacs_init'. */
85 public static String extraStartupArgument;
83 86
84 private EmacsThread thread; 87 private EmacsThread thread;
85 private Handler handler; 88 private Handler handler;
@@ -231,7 +234,7 @@ public final class EmacsService extends Service
231 (float) pixelDensityY, 234 (float) pixelDensityY,
232 classPath, EmacsService.this); 235 classPath, EmacsService.this);
233 } 236 }
234 }, needDashQ, 237 }, extraStartupArgument,
235 /* If any file needs to be opened, open it now. */ 238 /* If any file needs to be opened, open it now. */
236 EmacsOpenActivity.fileToOpen); 239 EmacsOpenActivity.fileToOpen);
237 thread.start (); 240 thread.start ();
diff --git a/java/org/gnu/emacs/EmacsThread.java b/java/org/gnu/emacs/EmacsThread.java
index d175fe332b5..468c6530af0 100644
--- a/java/org/gnu/emacs/EmacsThread.java
+++ b/java/org/gnu/emacs/EmacsThread.java
@@ -29,8 +29,9 @@ public class EmacsThread extends Thread
29{ 29{
30 private static final String TAG = "EmacsThread"; 30 private static final String TAG = "EmacsThread";
31 31
32 /* Whether or not Emacs should be started -Q. */ 32 /* Whether or not Emacs should be started with an additional
33 private boolean startDashQ; 33 argument, and that additional argument if non-NULL. */
34 private String extraStartupArgument;
34 35
35 /* Runnable run to initialize Emacs. */ 36 /* Runnable run to initialize Emacs. */
36 private Runnable paramsClosure; 37 private Runnable paramsClosure;
@@ -40,10 +41,10 @@ public class EmacsThread extends Thread
40 41
41 public 42 public
42 EmacsThread (EmacsService service, Runnable paramsClosure, 43 EmacsThread (EmacsService service, Runnable paramsClosure,
43 boolean startDashQ, String fileToOpen) 44 String extraStartupArgument, String fileToOpen)
44 { 45 {
45 super ("Emacs main thread"); 46 super ("Emacs main thread");
46 this.startDashQ = startDashQ; 47 this.extraStartupArgument = extraStartupArgument;
47 this.paramsClosure = paramsClosure; 48 this.paramsClosure = paramsClosure;
48 this.fileToOpen = fileToOpen; 49 this.fileToOpen = fileToOpen;
49 } 50 }
@@ -56,18 +57,20 @@ public class EmacsThread extends Thread
56 57
57 if (fileToOpen == null) 58 if (fileToOpen == null)
58 { 59 {
59 if (!startDashQ) 60 if (extraStartupArgument == null)
60 args = new String[] { "libandroid-emacs.so", }; 61 args = new String[] { "libandroid-emacs.so", };
61 else 62 else
62 args = new String[] { "libandroid-emacs.so", "-Q", }; 63 args = new String[] { "libandroid-emacs.so",
64 extraStartupArgument, };
63 } 65 }
64 else 66 else
65 { 67 {
66 if (!startDashQ) 68 if (extraStartupArgument != null)
67 args = new String[] { "libandroid-emacs.so", 69 args = new String[] { "libandroid-emacs.so",
68 fileToOpen, }; 70 fileToOpen, };
69 else 71 else
70 args = new String[] { "libandroid-emacs.so", "-Q", 72 args = new String[] { "libandroid-emacs.so",
73 extraStartupArgument,
71 fileToOpen, }; 74 fileToOpen, };
72 } 75 }
73 76