From bdef5377759da4571b72cc560d8a43bc4eee1a00 Mon Sep 17 00:00:00 2001 From: Yorke Lee Date: Mon, 10 Apr 2017 16:38:51 -0700 Subject: [PATCH] Don't end task in finishActivityLocked if task is being reused In scenarios when the task is being cleared for reuse, endTask is true in finishActivityLocked even though the task is not actually going to be removed later on. On Arc++, this leads to issues because the notifyTaskRemovalStarted notification is delivered and cleanup work happens for a task that isn't actually removed. Fix this by looking at TaskRecord.mReuseTask, which is set to true when the task is cleared in order to be reused. Cherry-picked from I3c422f57a8cda55f7b0c08e183f4f1a15d3b7ddd Bug: 37093330 Test: Launch a test activity that relaunches itself with FLAG_ACTIVITY_NEW_TASK AND FLAG_ACTIVITY_CLEAR_TASK, verify that notifyTaskRemovalStarted call back is not sent. Change-Id: Ifee23ad7104124e38b5ee5e6c520eb25a5846ef2 --- .../core/java/com/android/server/am/ActivityStack.java | 2 +- services/core/java/com/android/server/am/TaskRecord.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 78887c6d82096..334d75a25c9a0 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -3582,7 +3582,7 @@ class ActivityStack extends ConfigurationContai finishActivityResultsLocked(r, resultCode, resultData); - final boolean endTask = index <= 0; + final boolean endTask = index <= 0 && !task.isClearingToReuseTask(); final int transit = endTask ? TRANSIT_TASK_CLOSE : TRANSIT_ACTIVITY_CLOSE; if (mResumedActivity == r) { if (DEBUG_VISIBILITY || DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 0c2c2043fb15e..0ae36193213b5 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -1564,6 +1564,13 @@ final class TaskRecord extends ConfigurationContainer implements TaskWindowConta && (mResizeMode != RESIZE_MODE_FORCE_RESIZABLE_LANDSCAPE_ONLY || landscape); } + /** + * @return {@code true} if the task is being cleared for the purposes of being reused. + */ + boolean isClearingToReuseTask() { + return mReuseTask; + } + /** * Find the activity in the history stack within the given task. Returns * the index within the history at which it's found, or < 0 if not found.