diff options
| author | Po Lu | 2024-04-14 10:36:50 +0800 |
|---|---|---|
| committer | Po Lu | 2024-04-14 10:36:50 +0800 |
| commit | 2823eae0b7cb3bd3f2472fde9e13016a8d406a9a (patch) | |
| tree | 5dfc53e8389ee6cbb8ac96e0a4259d8af5e9ed33 /java/org | |
| parent | 845246093f8ae88db1061a9beaff04184685f8f4 (diff) | |
| download | emacs-2823eae0b7cb3bd3f2472fde9e13016a8d406a9a.tar.gz emacs-2823eae0b7cb3bd3f2472fde9e13016a8d406a9a.zip | |
Remove leftover tasks from previous Emacs sessions on startup
* java/org/gnu/emacs/EmacsService.java (onCreate): Call
removeOldTasks.
* java/org/gnu/emacs/EmacsWindowManager.java (removeOldTasks):
New function.
* java/proguard.conf: Optimize optimizer configuration.
Diffstat (limited to 'java/org')
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 12 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindowManager.java | 41 |
2 files changed, 50 insertions, 3 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index b8ff98e79a7..fd052653087 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -234,6 +234,8 @@ public final class EmacsService extends Service | |||
| 234 | final double scaledDensity; | 234 | final double scaledDensity; |
| 235 | double tempScaledDensity; | 235 | double tempScaledDensity; |
| 236 | 236 | ||
| 237 | super.onCreate (); | ||
| 238 | |||
| 237 | SERVICE = this; | 239 | SERVICE = this; |
| 238 | handler = new Handler (Looper.getMainLooper ()); | 240 | handler = new Handler (Looper.getMainLooper ()); |
| 239 | manager = getAssets (); | 241 | manager = getAssets (); |
| @@ -247,9 +249,9 @@ public final class EmacsService extends Service | |||
| 247 | resolver = getContentResolver (); | 249 | resolver = getContentResolver (); |
| 248 | mainThread = Thread.currentThread (); | 250 | mainThread = Thread.currentThread (); |
| 249 | 251 | ||
| 250 | /* If the density used to compute the text size is lesser than | 252 | /* If the density used to compute the text size is smaller than 160, |
| 251 | 160, there's likely a bug with display density computation. | 253 | there's likely a bug with display density computation. Reset it |
| 252 | Reset it to 160 in that case. | 254 | to 160 in that case. |
| 253 | 255 | ||
| 254 | Note that Android uses 160 ``dpi'' as the density where 1 point | 256 | Note that Android uses 160 ``dpi'' as the density where 1 point |
| 255 | corresponds to 1 pixel, not 72 or 96 as used elsewhere. This | 257 | corresponds to 1 pixel, not 72 or 96 as used elsewhere. This |
| @@ -262,6 +264,10 @@ public final class EmacsService extends Service | |||
| 262 | the nested function below. */ | 264 | the nested function below. */ |
| 263 | scaledDensity = tempScaledDensity; | 265 | scaledDensity = tempScaledDensity; |
| 264 | 266 | ||
| 267 | /* Remove all tasks from previous Emacs sessions but the task | ||
| 268 | created by the system at startup. */ | ||
| 269 | EmacsWindowManager.MANAGER.removeOldTasks (this); | ||
| 270 | |||
| 265 | try | 271 | try |
| 266 | { | 272 | { |
| 267 | /* Configure Emacs with the asset manager and other necessary | 273 | /* Configure Emacs with the asset manager and other necessary |
diff --git a/java/org/gnu/emacs/EmacsWindowManager.java b/java/org/gnu/emacs/EmacsWindowManager.java index a193d49d0ec..49f0ebd5841 100644 --- a/java/org/gnu/emacs/EmacsWindowManager.java +++ b/java/org/gnu/emacs/EmacsWindowManager.java | |||
| @@ -27,6 +27,7 @@ import android.app.ActivityManager.RecentTaskInfo; | |||
| 27 | import android.app.ActivityManager; | 27 | import android.app.ActivityManager; |
| 28 | import android.app.ActivityOptions; | 28 | import android.app.ActivityOptions; |
| 29 | 29 | ||
| 30 | import android.content.ComponentName; | ||
| 30 | import android.content.Context; | 31 | import android.content.Context; |
| 31 | import android.content.Intent; | 32 | import android.content.Intent; |
| 32 | 33 | ||
| @@ -385,4 +386,44 @@ public final class EmacsWindowManager | |||
| 385 | window.onActivityDetached (); | 386 | window.onActivityDetached (); |
| 386 | } | 387 | } |
| 387 | } | 388 | } |
| 389 | |||
| 390 | /* Iterate over each of Emacs's tasks to delete such as belong to a | ||
| 391 | previous Emacs session, i.e., tasks created for a previous | ||
| 392 | session's non-initial frames. CONTEXT should be a context from | ||
| 393 | which to obtain a reference to the activity manager. */ | ||
| 394 | |||
| 395 | public void | ||
| 396 | removeOldTasks (Context context) | ||
| 397 | { | ||
| 398 | List<AppTask> appTasks; | ||
| 399 | RecentTaskInfo info; | ||
| 400 | ComponentName name; | ||
| 401 | String target; | ||
| 402 | Object object; | ||
| 403 | |||
| 404 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) | ||
| 405 | return; | ||
| 406 | |||
| 407 | if (activityManager == null) | ||
| 408 | { | ||
| 409 | object = context.getSystemService (Context.ACTIVITY_SERVICE); | ||
| 410 | activityManager = (ActivityManager) object; | ||
| 411 | } | ||
| 412 | |||
| 413 | appTasks = activityManager.getAppTasks (); | ||
| 414 | target = ".EmacsMultitaskActivity"; | ||
| 415 | |||
| 416 | for (AppTask task : appTasks) | ||
| 417 | { | ||
| 418 | info = task.getTaskInfo (); | ||
| 419 | |||
| 420 | /* Test whether info is a reference to | ||
| 421 | EmacsMultitaskActivity. */ | ||
| 422 | if (info.baseIntent != null | ||
| 423 | && (name = info.baseIntent.getComponent ()) != null | ||
| 424 | && name.getShortClassName ().equals (target)) | ||
| 425 | /* Delete the task. */ | ||
| 426 | task.finishAndRemoveTask (); | ||
| 427 | } | ||
| 428 | } | ||
| 388 | }; | 429 | }; |