aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2024-06-27 11:06:59 +0800
committerPo Lu2024-06-27 11:07:38 +0800
commit860840621a1ebe2e4f17ba8ae78d441ea75650b2 (patch)
treece491e28fbd0ec6867b9669f77e92c151e8f28c7 /java
parentd5c6eb1f9646781cf103124fb7e88d1fa1cf2473 (diff)
downloademacs-860840621a1ebe2e4f17ba8ae78d441ea75650b2.tar.gz
emacs-860840621a1ebe2e4f17ba8ae78d441ea75650b2.zip
Prevent crashes and related issues if initial activity is destroyed on Android
* java/org/gnu/emacs/EmacsWindow.java (EmacsWindow) <initialWindowCreated>: New variable. (EmacsWindow): If the initial frame has not yet been created, set attachmentToken to -1. * java/org/gnu/emacs/EmacsWindowManager.java (registerWindow): When the window's attachment token is -1 (i.e., it is the default window), start EmacsActivity rather than EmacsMultitaskActivity. Catch exceptions around startActivity.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsWindow.java11
-rw-r--r--java/org/gnu/emacs/EmacsWindowManager.java43
2 files changed, 47 insertions, 7 deletions
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java
index 0a4d04971e7..218c5639c89 100644
--- a/java/org/gnu/emacs/EmacsWindow.java
+++ b/java/org/gnu/emacs/EmacsWindow.java
@@ -74,6 +74,9 @@ public final class EmacsWindow extends EmacsHandleObject
74{ 74{
75 private static final String TAG = "EmacsWindow"; 75 private static final String TAG = "EmacsWindow";
76 76
77 /* Whether any windows have yet been created in this session. */
78 private static boolean initialWindowCreated;
79
77 private static class Coordinate 80 private static class Coordinate
78 { 81 {
79 /* Integral coordinate. */ 82 /* Integral coordinate. */
@@ -192,6 +195,14 @@ public final class EmacsWindow extends EmacsHandleObject
192 this.parent = parent; 195 this.parent = parent;
193 this.overrideRedirect = overrideRedirect; 196 this.overrideRedirect = overrideRedirect;
194 197
198 /* The initial frame should always be bound to the startup
199 activity. */
200 if (!initialWindowCreated)
201 {
202 this.attachmentToken = -1;
203 initialWindowCreated = true;
204 }
205
195 /* Create the list of children. */ 206 /* Create the list of children. */
196 children = new ArrayList<EmacsWindow> (); 207 children = new ArrayList<EmacsWindow> ();
197 208
diff --git a/java/org/gnu/emacs/EmacsWindowManager.java b/java/org/gnu/emacs/EmacsWindowManager.java
index 03487e853fb..e4bd995f15a 100644
--- a/java/org/gnu/emacs/EmacsWindowManager.java
+++ b/java/org/gnu/emacs/EmacsWindowManager.java
@@ -174,6 +174,27 @@ public final class EmacsWindowManager
174 } 174 }
175 } 175 }
176 176
177 /* Do not create a multitasking activity for the initial frame,
178 but arrange to start EmacsActivity. */
179 if (window.attachmentToken == -1)
180 {
181 intent = new Intent (EmacsService.SERVICE,
182 EmacsActivity.class);
183 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
184
185 try
186 {
187 EmacsService.SERVICE.startActivity (intent);
188 }
189 catch (Exception e)
190 {
191 Log.w (TAG, "an activity could not be started on behalf"
192 + " of the mapped default window " + window.handle);
193 }
194
195 return;
196 }
197
177 intent = new Intent (EmacsService.SERVICE, 198 intent = new Intent (EmacsService.SERVICE,
178 EmacsMultitaskActivity.class); 199 EmacsMultitaskActivity.class);
179 200
@@ -205,14 +226,22 @@ public final class EmacsWindowManager
205 window.attachmentToken = token; 226 window.attachmentToken = token;
206 intent.putExtra (ACTIVITY_TOKEN, token); 227 intent.putExtra (ACTIVITY_TOKEN, token);
207 228
208 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) 229 try
209 EmacsService.SERVICE.startActivity (intent); 230 {
210 else 231 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
232 EmacsService.SERVICE.startActivity (intent);
233 else
234 {
235 /* Specify the desired window size. */
236 options = ActivityOptions.makeBasic ();
237 options.setLaunchBounds (window.getGeometry ());
238 EmacsService.SERVICE.startActivity (intent, options.toBundle ());
239 }
240 }
241 catch (Exception e)
211 { 242 {
212 /* Specify the desired window size. */ 243 Log.w (TAG, "an activity could not be started on behalf"
213 options = ActivityOptions.makeBasic (); 244 + " of a mapped window, " + window.handle);
214 options.setLaunchBounds (window.getGeometry ());
215 EmacsService.SERVICE.startActivity (intent, options.toBundle ());
216 } 245 }
217 246
218 pruneWindows (); 247 pruneWindows ();