Loading services/core/java/com/android/server/wm/RecentTasks.java +12 −16 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.Environment; import android.os.IBinder; import android.os.IBinder; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserHandle; import android.text.TextUtils; import android.text.TextUtils; Loading Loading @@ -185,7 +184,6 @@ class RecentTasks { // front. Newly created tasks, or tasks that are removed from the list will continue to change // front. Newly created tasks, or tasks that are removed from the list will continue to change // the list. This does not affect affiliated tasks. // the list. This does not affect affiliated tasks. private boolean mFreezeTaskListReordering; private boolean mFreezeTaskListReordering; private long mFreezeTaskListReorderingTime; private long mFreezeTaskListTimeoutMs = FREEZE_TASK_LIST_TIMEOUT_MS; private long mFreezeTaskListTimeoutMs = FREEZE_TASK_LIST_TIMEOUT_MS; // Mainly to avoid object recreation on multiple calls. // Mainly to avoid object recreation on multiple calls. Loading Loading @@ -220,6 +218,9 @@ class RecentTasks { } } }; }; private final Runnable mResetFreezeTaskListOnTimeoutRunnable = this::resetFreezeTaskListReorderingOnTimeout; @VisibleForTesting @VisibleForTesting RecentTasks(ActivityTaskManagerService service, TaskPersister taskPersister) { RecentTasks(ActivityTaskManagerService service, TaskPersister taskPersister) { mService = service; mService = service; Loading Loading @@ -255,8 +256,7 @@ class RecentTasks { } } @VisibleForTesting @VisibleForTesting void setFreezeTaskListTimeoutParams(long reorderingTime, long timeoutMs) { void setFreezeTaskListTimeout(long timeoutMs) { mFreezeTaskListReorderingTime = reorderingTime; mFreezeTaskListTimeoutMs = timeoutMs; mFreezeTaskListTimeoutMs = timeoutMs; } } Loading @@ -272,7 +272,8 @@ class RecentTasks { // Always update the reordering time when this is called to ensure that the timeout // Always update the reordering time when this is called to ensure that the timeout // is reset // is reset mFreezeTaskListReordering = true; mFreezeTaskListReordering = true; mFreezeTaskListReorderingTime = SystemClock.elapsedRealtime(); mService.mH.removeCallbacks(mResetFreezeTaskListOnTimeoutRunnable); mService.mH.postDelayed(mResetFreezeTaskListOnTimeoutRunnable, mFreezeTaskListTimeoutMs); } } /** /** Loading @@ -286,6 +287,7 @@ class RecentTasks { // Once we end freezing the task list, reset the existing task order to the stable state // Once we end freezing the task list, reset the existing task order to the stable state mFreezeTaskListReordering = false; mFreezeTaskListReordering = false; mService.mH.removeCallbacks(mResetFreezeTaskListOnTimeoutRunnable); // If the top task is provided, then restore the top task to the front of the list // If the top task is provided, then restore the top task to the front of the list if (topTask != null) { if (topTask != null) { Loading @@ -295,6 +297,8 @@ class RecentTasks { // Resume trimming tasks // Resume trimming tasks trimInactiveRecentTasks(); trimInactiveRecentTasks(); mService.getTaskChangeNotificationController().notifyTaskStackChanged(); } } /** /** Loading @@ -302,13 +306,8 @@ class RecentTasks { * before we need to iterate the task list in order (either for purposes of returning the list * before we need to iterate the task list in order (either for purposes of returning the list * to SystemUI or if we need to trim tasks in order) * to SystemUI or if we need to trim tasks in order) */ */ @VisibleForTesting void resetFreezeTaskListReorderingOnTimeout() { void resetFreezeTaskListReorderingOnTimeout() { // Unfreeze the recent task list if the time heuristic has passed if (mFreezeTaskListReorderingTime > (SystemClock.elapsedRealtime() - mFreezeTaskListTimeoutMs)) { return; } final ActivityStack focusedStack = mService.getTopDisplayFocusedStack(); final ActivityStack focusedStack = mService.getTopDisplayFocusedStack(); final TaskRecord topTask = focusedStack != null final TaskRecord topTask = focusedStack != null ? focusedStack.topTask() ? focusedStack.topTask() Loading Loading @@ -875,9 +874,6 @@ class RecentTasks { final Set<Integer> includedUsers = getProfileIds(userId); final Set<Integer> includedUsers = getProfileIds(userId); includedUsers.add(Integer.valueOf(userId)); includedUsers.add(Integer.valueOf(userId)); // Check if the frozen task list has timed out resetFreezeTaskListReorderingOnTimeout(); final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>(); final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>(); final int size = mTasks.size(); final int size = mTasks.size(); int numVisibleTasks = 0; int numVisibleTasks = 0; Loading Loading @@ -1654,8 +1650,8 @@ class RecentTasks { pw.println("mRecentsUid=" + mRecentsUid); pw.println("mRecentsUid=" + mRecentsUid); pw.println("mRecentsComponent=" + mRecentsComponent); pw.println("mRecentsComponent=" + mRecentsComponent); pw.println("mFreezeTaskListReordering=" + mFreezeTaskListReordering); pw.println("mFreezeTaskListReordering=" + mFreezeTaskListReordering); pw.println("mFreezeTaskListReorderingTime (time since)=" pw.println("mFreezeTaskListReorderingPendingTimeout=" + (SystemClock.elapsedRealtime() - mFreezeTaskListReorderingTime) + "ms"); + mService.mH.hasCallbacks(mResetFreezeTaskListOnTimeoutRunnable)); if (mTasks.isEmpty()) { if (mTasks.isEmpty()) { return; return; } } Loading services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java +2 −5 Original line number Original line Diff line number Diff line Loading @@ -712,7 +712,6 @@ public class RecentTasksTest extends ActivityTestsBase { mRecentTasks.add(mTasks.get(4)); mRecentTasks.add(mTasks.get(4)); // Freeze the list // Freeze the list long freezeTime = SystemClock.elapsedRealtime(); mRecentTasks.setFreezeTaskListReordering(); mRecentTasks.setFreezeTaskListReordering(); assertTrue(mRecentTasks.isFreezeTaskListReorderingSet()); assertTrue(mRecentTasks.isFreezeTaskListReorderingSet()); Loading @@ -720,13 +719,11 @@ public class RecentTasksTest extends ActivityTestsBase { mRecentTasks.add(mTasks.get(2)); mRecentTasks.add(mTasks.get(2)); mRecentTasks.add(mTasks.get(1)); mRecentTasks.add(mTasks.get(1)); // Override the freeze timeout params to simulate the timeout (simulate the freeze at 100ms // ago with a timeout of 1ms) mRecentTasks.setFreezeTaskListTimeoutParams(freezeTime - 100, 1); ActivityStack stack = mTasks.get(2).getStack(); ActivityStack stack = mTasks.get(2).getStack(); stack.moveToFront("", mTasks.get(2)); stack.moveToFront("", mTasks.get(2)); doReturn(stack).when(mTestService.mRootActivityContainer).getTopDisplayFocusedStack(); doReturn(stack).when(mTestService.mRootActivityContainer).getTopDisplayFocusedStack(); // Simulate the reset from the timeout mRecentTasks.resetFreezeTaskListReorderingOnTimeout(); mRecentTasks.resetFreezeTaskListReorderingOnTimeout(); assertFalse(mRecentTasks.isFreezeTaskListReorderingSet()); assertFalse(mRecentTasks.isFreezeTaskListReorderingSet()); Loading Loading
services/core/java/com/android/server/wm/RecentTasks.java +12 −16 Original line number Original line Diff line number Diff line Loading @@ -60,7 +60,6 @@ import android.os.Bundle; import android.os.Environment; import android.os.Environment; import android.os.IBinder; import android.os.IBinder; import android.os.RemoteException; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemProperties; import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserHandle; import android.text.TextUtils; import android.text.TextUtils; Loading Loading @@ -185,7 +184,6 @@ class RecentTasks { // front. Newly created tasks, or tasks that are removed from the list will continue to change // front. Newly created tasks, or tasks that are removed from the list will continue to change // the list. This does not affect affiliated tasks. // the list. This does not affect affiliated tasks. private boolean mFreezeTaskListReordering; private boolean mFreezeTaskListReordering; private long mFreezeTaskListReorderingTime; private long mFreezeTaskListTimeoutMs = FREEZE_TASK_LIST_TIMEOUT_MS; private long mFreezeTaskListTimeoutMs = FREEZE_TASK_LIST_TIMEOUT_MS; // Mainly to avoid object recreation on multiple calls. // Mainly to avoid object recreation on multiple calls. Loading Loading @@ -220,6 +218,9 @@ class RecentTasks { } } }; }; private final Runnable mResetFreezeTaskListOnTimeoutRunnable = this::resetFreezeTaskListReorderingOnTimeout; @VisibleForTesting @VisibleForTesting RecentTasks(ActivityTaskManagerService service, TaskPersister taskPersister) { RecentTasks(ActivityTaskManagerService service, TaskPersister taskPersister) { mService = service; mService = service; Loading Loading @@ -255,8 +256,7 @@ class RecentTasks { } } @VisibleForTesting @VisibleForTesting void setFreezeTaskListTimeoutParams(long reorderingTime, long timeoutMs) { void setFreezeTaskListTimeout(long timeoutMs) { mFreezeTaskListReorderingTime = reorderingTime; mFreezeTaskListTimeoutMs = timeoutMs; mFreezeTaskListTimeoutMs = timeoutMs; } } Loading @@ -272,7 +272,8 @@ class RecentTasks { // Always update the reordering time when this is called to ensure that the timeout // Always update the reordering time when this is called to ensure that the timeout // is reset // is reset mFreezeTaskListReordering = true; mFreezeTaskListReordering = true; mFreezeTaskListReorderingTime = SystemClock.elapsedRealtime(); mService.mH.removeCallbacks(mResetFreezeTaskListOnTimeoutRunnable); mService.mH.postDelayed(mResetFreezeTaskListOnTimeoutRunnable, mFreezeTaskListTimeoutMs); } } /** /** Loading @@ -286,6 +287,7 @@ class RecentTasks { // Once we end freezing the task list, reset the existing task order to the stable state // Once we end freezing the task list, reset the existing task order to the stable state mFreezeTaskListReordering = false; mFreezeTaskListReordering = false; mService.mH.removeCallbacks(mResetFreezeTaskListOnTimeoutRunnable); // If the top task is provided, then restore the top task to the front of the list // If the top task is provided, then restore the top task to the front of the list if (topTask != null) { if (topTask != null) { Loading @@ -295,6 +297,8 @@ class RecentTasks { // Resume trimming tasks // Resume trimming tasks trimInactiveRecentTasks(); trimInactiveRecentTasks(); mService.getTaskChangeNotificationController().notifyTaskStackChanged(); } } /** /** Loading @@ -302,13 +306,8 @@ class RecentTasks { * before we need to iterate the task list in order (either for purposes of returning the list * before we need to iterate the task list in order (either for purposes of returning the list * to SystemUI or if we need to trim tasks in order) * to SystemUI or if we need to trim tasks in order) */ */ @VisibleForTesting void resetFreezeTaskListReorderingOnTimeout() { void resetFreezeTaskListReorderingOnTimeout() { // Unfreeze the recent task list if the time heuristic has passed if (mFreezeTaskListReorderingTime > (SystemClock.elapsedRealtime() - mFreezeTaskListTimeoutMs)) { return; } final ActivityStack focusedStack = mService.getTopDisplayFocusedStack(); final ActivityStack focusedStack = mService.getTopDisplayFocusedStack(); final TaskRecord topTask = focusedStack != null final TaskRecord topTask = focusedStack != null ? focusedStack.topTask() ? focusedStack.topTask() Loading Loading @@ -875,9 +874,6 @@ class RecentTasks { final Set<Integer> includedUsers = getProfileIds(userId); final Set<Integer> includedUsers = getProfileIds(userId); includedUsers.add(Integer.valueOf(userId)); includedUsers.add(Integer.valueOf(userId)); // Check if the frozen task list has timed out resetFreezeTaskListReorderingOnTimeout(); final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>(); final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>(); final int size = mTasks.size(); final int size = mTasks.size(); int numVisibleTasks = 0; int numVisibleTasks = 0; Loading Loading @@ -1654,8 +1650,8 @@ class RecentTasks { pw.println("mRecentsUid=" + mRecentsUid); pw.println("mRecentsUid=" + mRecentsUid); pw.println("mRecentsComponent=" + mRecentsComponent); pw.println("mRecentsComponent=" + mRecentsComponent); pw.println("mFreezeTaskListReordering=" + mFreezeTaskListReordering); pw.println("mFreezeTaskListReordering=" + mFreezeTaskListReordering); pw.println("mFreezeTaskListReorderingTime (time since)=" pw.println("mFreezeTaskListReorderingPendingTimeout=" + (SystemClock.elapsedRealtime() - mFreezeTaskListReorderingTime) + "ms"); + mService.mH.hasCallbacks(mResetFreezeTaskListOnTimeoutRunnable)); if (mTasks.isEmpty()) { if (mTasks.isEmpty()) { return; return; } } Loading
services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java +2 −5 Original line number Original line Diff line number Diff line Loading @@ -712,7 +712,6 @@ public class RecentTasksTest extends ActivityTestsBase { mRecentTasks.add(mTasks.get(4)); mRecentTasks.add(mTasks.get(4)); // Freeze the list // Freeze the list long freezeTime = SystemClock.elapsedRealtime(); mRecentTasks.setFreezeTaskListReordering(); mRecentTasks.setFreezeTaskListReordering(); assertTrue(mRecentTasks.isFreezeTaskListReorderingSet()); assertTrue(mRecentTasks.isFreezeTaskListReorderingSet()); Loading @@ -720,13 +719,11 @@ public class RecentTasksTest extends ActivityTestsBase { mRecentTasks.add(mTasks.get(2)); mRecentTasks.add(mTasks.get(2)); mRecentTasks.add(mTasks.get(1)); mRecentTasks.add(mTasks.get(1)); // Override the freeze timeout params to simulate the timeout (simulate the freeze at 100ms // ago with a timeout of 1ms) mRecentTasks.setFreezeTaskListTimeoutParams(freezeTime - 100, 1); ActivityStack stack = mTasks.get(2).getStack(); ActivityStack stack = mTasks.get(2).getStack(); stack.moveToFront("", mTasks.get(2)); stack.moveToFront("", mTasks.get(2)); doReturn(stack).when(mTestService.mRootActivityContainer).getTopDisplayFocusedStack(); doReturn(stack).when(mTestService.mRootActivityContainer).getTopDisplayFocusedStack(); // Simulate the reset from the timeout mRecentTasks.resetFreezeTaskListReorderingOnTimeout(); mRecentTasks.resetFreezeTaskListReorderingOnTimeout(); assertFalse(mRecentTasks.isFreezeTaskListReorderingSet()); assertFalse(mRecentTasks.isFreezeTaskListReorderingSet()); Loading