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

Commit 35d2315f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ic4604342,If85d1f16 into main

* changes:
  Clear all apps in teardown to prevent build up affecting perf tests.
  Create shell command to clear all recent tasks.
parents d4815549 280850c3
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
    private final RecentTasksImpl mImpl = new RecentTasksImpl();
    private final ActivityTaskManager mActivityTaskManager;
    private final TaskStackTransitionObserver mTaskStackTransitionObserver;
    private final RecentsShellCommandHandler mRecentsShellCommandHandler;
    private RecentsTransitionHandler mTransitionHandler = null;
    private IRecentTasksListener mListener;
    private final boolean mPcFeatureEnabled;
@@ -167,6 +168,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
        mDesktopUserRepositories = desktopUserRepositories;
        mTaskStackTransitionObserver = taskStackTransitionObserver;
        mMainExecutor = mainExecutor;
        mRecentsShellCommandHandler = new RecentsShellCommandHandler(this);
        shellInit.addInitCallback(this::onInit, this);
    }

@@ -183,6 +185,7 @@ public class RecentTasksController implements TaskStackListenerCallback,
        mShellController.addExternalInterface(IRecentTasks.DESCRIPTOR,
                this::createExternalInterface, this);
        mShellCommandHandler.addDumpCallback(this::dump, this);
        mShellCommandHandler.addCommandCallback("recents", mRecentsShellCommandHandler, this);
        mUserId = ActivityManager.getCurrentUser();
        mDesktopUserRepositories.ifPresent(
                desktopUserRepositories ->
@@ -656,6 +659,11 @@ public class RecentTasksController implements TaskStackListenerCallback,
        return mActivityTaskManager.removeTask(taskId);
    }

    /** Removes all recent tasks that are visible. */
    public void removeAllVisibleRecentTasks() throws RemoteException {
        ActivityTaskManager.getService().removeAllVisibleRecentTasks();
    }

    public void dump(@NonNull PrintWriter pw, String prefix) {
        final String innerPrefix = prefix + "  ";
        pw.println(prefix + TAG);
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.recents

import android.os.RemoteException
import com.android.wm.shell.sysui.ShellCommandHandler.ShellCommandActionHandler
import java.io.PrintWriter

class RecentsShellCommandHandler(
    private val recentTasksController: RecentTasksController
) : ShellCommandActionHandler {
    override fun onShellCommand(args: Array<out String>, pw: PrintWriter): Boolean {
        when (args[0]) {
            "clearAll" -> return runClearAll(pw)
            else -> {
                pw.println("Invalid command: " + args[0])
                return false
            }
        }
    }

    override fun printShellCommandHelp(pw: PrintWriter, prefix: String) {
        pw.println("${prefix}clearAll")
        pw.println("$prefix  Clears all visible recent tasks.")
    }

    private fun runClearAll(pw: PrintWriter): Boolean {
        try {
            recentTasksController.removeAllVisibleRecentTasks()
        } catch (e: RemoteException) {
            pw.println("Exception while removing visible recent tasks:")
            e.printStackTrace(pw)
            return false
        }
        return true
    }
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.utils.RecentTasksUtils
import com.android.wm.shell.flicker.utils.SplitScreenUtils
import org.junit.After
import org.junit.Before
@@ -61,7 +62,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) {

    @After
    fun teardown() {
        primaryApp.exit(wmHelper)
        secondaryApp.exit(wmHelper)
        RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.utils.RecentTasksUtils
import com.android.wm.shell.flicker.utils.SplitScreenUtils
import org.junit.After
import org.junit.Before
@@ -74,7 +75,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) {

    @After
    fun teardown() {
        primaryApp.exit(wmHelper)
        secondaryApp.exit(wmHelper)
        RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.wm.shell.Utils
import com.android.wm.shell.flicker.utils.RecentTasksUtils
import com.android.wm.shell.flicker.utils.SplitScreenUtils
import org.junit.After
import org.junit.Before
@@ -60,7 +61,6 @@ constructor(val rotation: Rotation = Rotation.ROTATION_0) {

    @After
    fun teardown() {
        primaryApp.exit(wmHelper)
        secondaryApp.exit(wmHelper)
        RecentTasksUtils.clearAllVisibleRecentTasks(instrumentation)
    }
}
Loading