aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2024-04-07 12:15:39 +0800
committerPo Lu2024-04-07 12:15:39 +0800
commitae296d762bc7366879e74f9dca90bc7edd89e860 (patch)
tree396c469faabe8380f6a9feb11aabe6b55d253052 /java
parentec25f5ad3d4323b56f239a06186f965c8d4cb695 (diff)
downloademacs-ae296d762bc7366879e74f9dca90bc7edd89e860.tar.gz
emacs-ae296d762bc7366879e74f9dca90bc7edd89e860.zip
Port new Android window management strategy to Android 5.0
* doc/emacs/android.texi (Android Windowing): Revise to match. * java/org/gnu/emacs/EmacsWindowManager.java (registerWindow) (removeWindowConsumer, pruneWindows): Decrease minimum API for monitoring of tasks to Android 5.0. (getTaskToken): Ignore misleading documentation and access baseIntent by way of RecentTaskInfo.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsWindowManager.java50
1 files changed, 28 insertions, 22 deletions
diff --git a/java/org/gnu/emacs/EmacsWindowManager.java b/java/org/gnu/emacs/EmacsWindowManager.java
index 41ea3a15809..22629cad329 100644
--- a/java/org/gnu/emacs/EmacsWindowManager.java
+++ b/java/org/gnu/emacs/EmacsWindowManager.java
@@ -23,9 +23,9 @@ import java.util.ArrayList;
23import java.util.List; 23import java.util.List;
24 24
25import android.app.ActivityManager.AppTask; 25import android.app.ActivityManager.AppTask;
26import android.app.ActivityManager.RecentTaskInfo;
26import android.app.ActivityManager; 27import android.app.ActivityManager;
27import android.app.ActivityOptions; 28import android.app.ActivityOptions;
28import android.app.TaskInfo;
29 29
30import android.content.Context; 30import android.content.Context;
31import android.content.Intent; 31import android.content.Intent;
@@ -60,7 +60,7 @@ import android.util.Log;
60 getAttachmentToken () 60 getAttachmentToken ()
61 61
62 should return a token uniquely identifying a consumer, which, on API 62 should return a token uniquely identifying a consumer, which, on API
63 29 and up, enables attributing the tasks of activities to the windows 63 21 and up, enables attributing the tasks of activities to the windows
64 for which they were created, and with that, consistent interaction 64 for which they were created, and with that, consistent interaction
65 between user-visible window state and their underlying frames. */ 65 between user-visible window state and their underlying frames. */
66 66
@@ -182,7 +182,21 @@ public final class EmacsWindowManager
182 /* Intent.FLAG_ACTIVITY_NEW_DOCUMENT is lamentably unavailable on 182 /* Intent.FLAG_ACTIVITY_NEW_DOCUMENT is lamentably unavailable on
183 older systems than Lolipop. */ 183 older systems than Lolipop. */
184 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 184 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
185 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_DOCUMENT); 185 {
186 intent.addFlags (Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
187
188 /* Bind this window to the activity in advance, i.e., before its
189 creation, so that its ID will be recorded in the RecentTasks
190 list. */
191 token = ++nextActivityToken;
192 }
193 else
194 /* APIs required for linking activities to windows are not
195 available in earlier Android versions. */
196 token = -2;
197
198 window.attachmentToken = token;
199 intent.putExtra (ACTIVITY_TOKEN, token);
186 200
187 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) 201 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
188 EmacsService.SERVICE.startActivity (intent); 202 EmacsService.SERVICE.startActivity (intent);
@@ -191,19 +205,6 @@ public final class EmacsWindowManager
191 /* Specify the desired window size. */ 205 /* Specify the desired window size. */
192 options = ActivityOptions.makeBasic (); 206 options = ActivityOptions.makeBasic ();
193 options.setLaunchBounds (window.getGeometry ()); 207 options.setLaunchBounds (window.getGeometry ());
194
195 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
196 /* Bind this window to the activity in advance, i.e., before
197 its creation, so that its ID will be recorded in the
198 RecentTasks list. */
199 token = ++nextActivityToken;
200 else
201 /* APIs required for linking activities to windows are not
202 available in earlier Android versions. */
203 token = -2;
204
205 window.attachmentToken = token;
206 intent.putExtra (ACTIVITY_TOKEN, token);
207 EmacsService.SERVICE.startActivity (intent, options.toBundle ()); 208 EmacsService.SERVICE.startActivity (intent, options.toBundle ());
208 } 209 }
209 210
@@ -228,7 +229,7 @@ public final class EmacsWindowManager
228 the system-started task. */ 229 the system-started task. */
229 if (isFinishing 230 if (isFinishing
230 && (!(consumer instanceof EmacsMultitaskActivity) 231 && (!(consumer instanceof EmacsMultitaskActivity)
231 || Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)) 232 || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP))
232 window.onActivityDetached (); 233 window.onActivityDetached ();
233 } 234 }
234 235
@@ -297,12 +298,17 @@ public final class EmacsWindowManager
297 private static long 298 private static long
298 getTaskToken (AppTask task) 299 getTaskToken (AppTask task)
299 { 300 {
300 TaskInfo info; 301 RecentTaskInfo info;
302
303 info = task.getTaskInfo ();
301 304
302 info = (TaskInfo) task.getTaskInfo (); 305 /* baseIntent is a member of info's superclass, TaskInfo, on Android
306 10 and later. Prior to this release, it had been a member of
307 RecentTaskInfo since SDK 1, and whatever the misleading
308 documentation might suggest, a reference to `baseIntent' through
309 TaskInfo is just as good a reference to RecentTaskInfo. */
303 return (info.baseIntent != null 310 return (info.baseIntent != null
304 ? info.baseIntent.getLongExtra (ACTIVITY_TOKEN, 311 ? info.baseIntent.getLongExtra (ACTIVITY_TOKEN, -1l)
305 -1l)
306 : 0); 312 : 0);
307 } 313 }
308 314
@@ -319,7 +325,7 @@ public final class EmacsWindowManager
319 long taskToken; 325 long taskToken;
320 boolean set; 326 boolean set;
321 327
322 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q 328 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
323 || EmacsService.SERVICE == null) 329 || EmacsService.SERVICE == null)
324 return; 330 return;
325 331