From c2adf8cf9cc38d73d1e5b23960c0db0963101556 Mon Sep 17 00:00:00 2001 From: Orhan Uysal Date: Thu, 3 Oct 2024 12:14:33 +0000 Subject: [PATCH] Use desktop API to remove desktop for dismiss When overview tile for desktop is dismissed, use the shell API instead of calling the system server directly to remove tasks in the desktop. This let's desktop fix it's state and call the system server instead. Bug: 370757235 Test: m and dismiss overview tile from desktop Flag: com.android.window.flags.enable_desktop_windowing_back_navigation Change-Id: Ia2abd0ab5a27759c92e0328beb460810ad2af898 --- .../com/android/quickstep/SystemUiProxy.java | 11 ++++++++ .../android/quickstep/views/RecentsView.java | 28 ++++++++++++------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index a55cf186ea..4a87e3a0ae 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -1492,6 +1492,17 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle, SafeCloseable { } } + /** Call shell to remove the desktop that is on given `displayId` */ + public void removeDesktop(int displayId) { + if (mDesktopMode != null) { + try { + mDesktopMode.removeDesktop(displayId); + } catch (RemoteException e) { + Log.w(TAG, "Failed call removeDesktop", e); + } + } + } + // // Unfold transition // diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 82f08e58e5..8ea26cc25a 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -130,6 +130,7 @@ import android.widget.ListView; import android.widget.OverScroller; import android.widget.Toast; import android.window.PictureInPictureSurfaceTransaction; +import android.window.flags.DesktopModeFlags; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -3934,9 +3935,11 @@ public abstract class RecentsView< if (shouldRemoveTask) { if (dismissedTaskView.isRunningTask()) { finishRecentsAnimation(true /* toRecents */, false /* shouldPip */, - () -> removeTaskInternal(dismissedTaskViewId)); + () -> removeTaskInternal(dismissedTaskViewId, + dismissedTaskView instanceof DesktopTaskView)); } else { - removeTaskInternal(dismissedTaskViewId); + removeTaskInternal(dismissedTaskViewId, + dismissedTaskView instanceof DesktopTaskView); } announceForAccessibility( getResources().getString(R.string.task_view_closed)); @@ -4304,16 +4307,21 @@ public abstract class RecentsView< return lastVisibleIndex; } - private void removeTaskInternal(int dismissedTaskViewId) { + private void removeTaskInternal(int dismissedTaskViewId, boolean isDesktop) { int[] taskIds = getTaskIdsForTaskViewId(dismissedTaskViewId); - UI_HELPER_EXECUTOR.getHandler().post( - () -> { - for (int taskId : taskIds) { - if (taskId != -1) { - ActivityManagerWrapper.getInstance().removeTask(taskId); - } + UI_HELPER_EXECUTOR.getHandler().post(() -> { + if (DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_BACK_NAVIGATION.isTrue() && isDesktop) { + // TODO: b/372005228 - Use the api with desktop id instead. + SystemUiProxy.INSTANCE.get(getContext()).removeDesktop( + mContainer.getDisplay().getDisplayId()); + } else { + for (int taskId : taskIds) { + if (taskId != -1) { + ActivityManagerWrapper.getInstance().removeTask(taskId); } - }); + } + } + }); } protected void onDismissAnimationEnds() {