Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2adf8cf authored by Orhan Uysal's avatar Orhan Uysal
Browse files

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
parent 2aedf52b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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
    //
+18 −10
Original line number Diff line number Diff line
@@ -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,15 +4307,20 @@ 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(
                () -> {
        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);
                    }
                }
            }
        });
    }