aboutsummaryrefslogtreecommitdiffstats
path: root/java
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
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')
-rw-r--r--java/AndroidManifest.xml.in17
-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
-rw-r--r--java/res/drawable/emacs_wrench.pngbin0 -> 24996 bytes
-rw-r--r--java/res/values-v24/bool.xml22
-rw-r--r--java/res/values/bool.xml1
-rw-r--r--java/res/values/strings.xml39
-rw-r--r--java/res/xml/preferences.xml12
11 files changed, 171 insertions, 26 deletions
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in
index f7f834e7582..082c4c9373e 100644
--- a/java/AndroidManifest.xml.in
+++ b/java/AndroidManifest.xml.in
@@ -180,6 +180,23 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
180 </intent-filter> 180 </intent-filter>
181 </activity> 181 </activity>
182 182
183 <!-- Android 6 and earlier don't display ``application
184 preferences'' activities in Settings, so display the
185 preferences activity as a launcher icon instead. -->
186
187 <activity android:autoRemoveFromRecents="true"
188 android:label="Emacs options"
189 android:enabled="@bool/isBeforeNougat"
190 android:exported="@bool/isBeforeNougat"
191 android:icon="@drawable/emacs_wrench"
192 android:name=".EmacsLauncherPreferencesActivity">
193 <intent-filter>
194 <action android:name="android.intent.action.MAIN" />
195 <category android:name="android.intent.category.DEFAULT" />
196 <category android:name="android.intent.category.LAUNCHER" />
197 </intent-filter>
198 </activity>
199
183 <provider android:name="org.gnu.emacs.EmacsDocumentsProvider" 200 <provider android:name="org.gnu.emacs.EmacsDocumentsProvider"
184 android:authorities="org.gnu.emacs" 201 android:authorities="org.gnu.emacs"
185 android:exported="true" 202 android:exported="true"
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
diff --git a/java/res/drawable/emacs_wrench.png b/java/res/drawable/emacs_wrench.png
new file mode 100644
index 00000000000..50572d3bed1
--- /dev/null
+++ b/java/res/drawable/emacs_wrench.png
Binary files differ
diff --git a/java/res/values-v24/bool.xml b/java/res/values-v24/bool.xml
new file mode 100644
index 00000000000..37f07992995
--- /dev/null
+++ b/java/res/values-v24/bool.xml
@@ -0,0 +1,22 @@
1<!-- Boolean resources for GNU Emacs on Android.
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
10(at your 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
20<resources>
21 <bool name="isBeforeNougat">false</bool>
22</resources>
diff --git a/java/res/values/bool.xml b/java/res/values/bool.xml
index d37eab745c0..2b253824e29 100644
--- a/java/res/values/bool.xml
+++ b/java/res/values/bool.xml
@@ -19,4 +19,5 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
19 19
20<resources> 20<resources>
21 <bool name="isAtLeastKitKat">false</bool> 21 <bool name="isAtLeastKitKat">false</bool>
22 <bool name="isBeforeNougat">true</bool>
22</resources> 23</resources>
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
new file mode 100644
index 00000000000..36a47be6c84
--- /dev/null
+++ b/java/res/values/strings.xml
@@ -0,0 +1,39 @@
1<!-- String resources used by GNU Emacs on Android.
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
10(at your 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
20<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
21 <string name="start_quick_title">
22 Restart Emacs with -Q
23 </string>
24 <string name="start_quick_caption">
25 Restart Emacs, but do not load site lisp or init files.
26 </string>
27 <string name="start_debug_init_title">
28 Restart Emacs with --debug-init
29 </string>
30 <string name="start_debug_init_caption">
31 Restart Emacs, and display the debugger should an error occur while loading initialization files.
32 </string>
33 <string name="erase_dump_title">
34 Delete dump file
35 </string>
36 <string name="erase_dump_caption">
37 Remove the dumped state created when Emacs was installed.
38 </string>
39</resources>
diff --git a/java/res/xml/preferences.xml b/java/res/xml/preferences.xml
index f0c3abb52e7..d52d28816e5 100644
--- a/java/res/xml/preferences.xml
+++ b/java/res/xml/preferences.xml
@@ -19,10 +19,12 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. -->
19 19
20<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 20<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
21 <Preference android:key="start_quick" 21 <Preference android:key="start_quick"
22 android:title="Restart Emacs with -Q" 22 android:title="@string/start_quick_title"
23 android:summary="Restart Emacs, but do not load site lisp or init files."/> 23 android:summary="@string/start_quick_caption"/>
24 24 <Preference android:key="start_debug_init"
25 android:title="@string/start_debug_init_title"
26 android:summary="@string/start_debug_init_caption"/>
25 <Preference android:key="erase_dump" 27 <Preference android:key="erase_dump"
26 android:title="Delete dump file" 28 android:title="@string/erase_dump_title"
27 android:summary="Remove the dumped state created when Emacs was installed"/> 29 android:summary="@string/erase_dump_caption"/>
28</PreferenceScreen> 30</PreferenceScreen>