From 673cbd2b6932b39d6804cda2969b7f059c1ce748 Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Sat, 30 Jan 2016 18:30:55 -0800 Subject: Improved logic for determining visiblility of activities in the home stack - No other activity in the home stack should be visible behind the home activity. Home activities is usually a translucent activity with the wallpaper behind them. However, when they don't have the wallpaper behind them, we want to show activities in the next application stack behind them vs. another activity in the home stack like recents. - We don't want any other activities in the home stack visible if the recents activity is going to be returning to an application activity type. We do this to preserve the visible order the user used to get into the recents activity. The recents activity is normally translucent and if it doesn't have the wallpaper behind it the next activity in the home stack shouldn't be visible when the home stack is brought to the front to display the recents activity from an app. - Also fixed issue with not setting correct return type for tasks when they don't have Intent.FLAG_ACTIVITY_TASK_ON_HOME flag set. Bug: 26571156 Change-Id: I45ef795c6a19ab859e9f6204fb059e875ad798c5 --- .../java/com/android/server/am/ActivityStack.java | 32 ++++++++++++++++++++-- .../com/android/server/am/ActivityStarter.java | 32 ++++++++++++++-------- .../java/com/android/server/am/TaskRecord.java | 6 ++-- 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 7de254ef9482..d201e43c76fc 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -1673,11 +1673,37 @@ final class ActivityStack { TaskRecord task, ActivityRecord r) { if (r.fullscreen) { if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Fullscreen: at " + r - + " stackInvisible=" + stackInvisible - + " behindFullscreenActivity=" + behindFullscreenActivity); + + " stackInvisible=" + stackInvisible + + " behindFullscreenActivity=" + behindFullscreenActivity); // At this point, nothing else needs to be shown in this task. behindFullscreenActivity = true; - } else if (!isHomeStack() && r.frontOfTask && task.isOverHomeStack()) { + } else if (isHomeStack()) { + if (r.isHomeActivity()) { + if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Home activity: at " + r + + " stackInvisible=" + stackInvisible + + " behindFullscreenActivity=" + behindFullscreenActivity); + // No other activity in the home stack should be visible behind the home activity. + // Home activities is usually a translucent activity with the wallpaper behind them. + // However, when they don't have the wallpaper behind them, we want to show + // activities in the next application stack behind them vs. another activity in the + // home stack like recents. + behindFullscreenActivity = true; + } else if (r.isRecentsActivity() + && task.getTaskToReturnTo() == APPLICATION_ACTIVITY_TYPE) { + if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, + "Recents activity returning to app: at " + r + + " stackInvisible=" + stackInvisible + + " behindFullscreenActivity=" + behindFullscreenActivity); + // We don't want any other activities in the home stack visible if the recents + // activity is going to be returning to an application activity type. + // We do this to preserve the visible order the user used to get into the recents + // activity. The recents activity is normally translucent and if it doesn't have + // the wallpaper behind it the next activity in the home stack shouldn't be visible + // when the home stack is brought to the front to display the recents activity from + // an app. + behindFullscreenActivity = true; + } + } else if (r.frontOfTask && task.isOverHomeStack()) { if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Showing home: at " + r + " stackInvisible=" + stackInvisible + " behindFullscreenActivity=" + behindFullscreenActivity); diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java index 4015c088c6e1..df3f76ab3b37 100644 --- a/services/core/java/com/android/server/am/ActivityStarter.java +++ b/services/core/java/com/android/server/am/ActivityStarter.java @@ -48,6 +48,7 @@ import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_USER_LEAV import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM; import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.am.ActivityManagerService.ANIMATE; +import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE; import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE; import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE; import static com.android.server.am.ActivityStack.ActivityState.RESUMED; @@ -941,12 +942,8 @@ class ActivityStarter { Slog.e(TAG, "Attempted Lock Task Mode violation mStartActivity=" + mStartActivity); return START_RETURN_LOCK_TASK_MODE_VIOLATION; } - if (!mMovedHome - && (mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) - == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) { - // Caller wants to appear on home activity, so before starting - // their own activity we will bring home to the front. - mStartActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); + if (!mMovedHome) { + updateTaskReturnToType(mStartActivity.task, mLaunchFlags, topStack); } } else if (mSourceRecord != null) { if (mSupervisor.isLockTaskModeViolation(mSourceRecord.task)) { @@ -1280,11 +1277,7 @@ class ActivityStarter { mOptions, mStartActivity.appTimeTracker, "bringingFoundTaskToFront"); mMovedToFront = true; } - if ((mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) - == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) { - // Caller wants to appear on home activity. - intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); - } + updateTaskReturnToType(intentActivity.task, mLaunchFlags, focusStack); mOptions = null; } } @@ -1301,6 +1294,23 @@ class ActivityStarter { return intentActivity; } + private void updateTaskReturnToType( + TaskRecord task, int launchFlags, ActivityStack focusedStack) { + if ((launchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) + == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) { + // Caller wants to appear on home activity. + task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); + return; + } else if (focusedStack == null || focusedStack.mStackId == HOME_STACK_ID) { + // Task will be launched over the home stack, so return home. + task.setTaskToReturnTo(HOME_ACTIVITY_TYPE); + return; + } + + // Else we are coming from an application stack so return to an application. + task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE); + } + private void setTaskFromIntentActivity(ActivityRecord intentActivity) { if ((mLaunchFlags & (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) { diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index be97c5a7657f..5590018927ce 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -128,8 +128,6 @@ final class TaskRecord { private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail"; - static final boolean IGNORE_RETURN_TO_RECENTS = true; - static final int INVALID_TASK_ID = -1; final int taskId; // Unique identifier for this task. @@ -459,8 +457,8 @@ final class TaskRecord { } void setTaskToReturnTo(int taskToReturnTo) { - mTaskToReturnTo = (IGNORE_RETURN_TO_RECENTS && taskToReturnTo == RECENTS_ACTIVITY_TYPE) - ? HOME_ACTIVITY_TYPE : taskToReturnTo; + mTaskToReturnTo = (taskToReturnTo == RECENTS_ACTIVITY_TYPE) + ? HOME_ACTIVITY_TYPE : taskToReturnTo; } int getTaskToReturnTo() { -- cgit v1.2.3-59-g8ed1b