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

Commit c062580b authored by Winson Chung's avatar Winson Chung
Browse files

Wait for the task to be in recents before validation

- There are two issues:
  1) Currently the system does not add the task to the task list until
     the activity starting the task has been resumed (to be fixed in a
     follow up platform CL). When the three activities are started in
     sequence, it's possible for one of the activities to not reach the
     resumed state leading to an unexpected number of recent tasks the
     next time it's fetched.
  2) When swiping up, it may take time for getTasks to return and call
     applyLoadPlan, so try and wait until the task views have had a
     chance to be applied before continuing.
  3) Use the launcher activity tracker instead of activity rule since it
     will return the same activity even after the activity is destroyed
- Move the margin handling to the caller instead of the scroll method

Bug: 141580748
Change-Id: I2b7634f5ac6869ba4b369b3bd60e0f63747c0f0b
parent c039634c
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -5,16 +5,18 @@ import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import android.content.Context;
import android.os.Bundle;

import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.testing.TestInformationHandler;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.uioverrides.states.OverviewState;
import com.android.launcher3.uioverrides.touchcontrollers.PortraitStatesTouchController;
import com.android.launcher3.util.DefaultDisplay;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.shared.recents.model.Task;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class QuickstepTestInformationHandler extends TestInformationHandler {

@@ -54,10 +56,8 @@ public class QuickstepTestInformationHandler extends TestInformationHandler {
                    final int leftMargin = MAIN_EXECUTOR.submit(() ->
                            getRecentsView().getLeftGestureMargin()).get();
                    response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, leftMargin);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
                return response;
            }
@@ -67,11 +67,29 @@ public class QuickstepTestInformationHandler extends TestInformationHandler {
                    final int rightMargin = MAIN_EXECUTOR.submit(() ->
                            getRecentsView().getRightGestureMargin()).get();
                    response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, rightMargin);
                } catch (ExecutionException e) {
                    e.printStackTrace();
                } catch (ExecutionException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
                return response;
            }

            case TestProtocol.REQUEST_RECENT_TASKS_LIST: {
                ArrayList<String> taskBaseIntentComponents = new ArrayList<>();
                CountDownLatch latch = new CountDownLatch(1);
                RecentsModel.INSTANCE.get(mContext).getTasks((tasks) -> {
                    for (Task t : tasks) {
                        taskBaseIntentComponents.add(
                                t.key.baseIntent.getComponent().flattenToString());
                    }
                    latch.countDown();
                });
                try {
                    latch.await(2, TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
                response.putStringArrayList(TestProtocol.TEST_INFO_RESPONSE_FIELD,
                        taskBaseIntentComponents);
                return response;
            }
        }
+30 −11
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS;
import static com.android.launcher3.tapl.TestHelpers.getHomeIntentInPackage;
import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;
import static com.android.launcher3.ui.AbstractLauncherUiTest.DEFAULT_ACTIVITY_TIMEOUT;
import static com.android.launcher3.ui.AbstractLauncherUiTest.DEFAULT_UI_TIMEOUT;
import static com.android.launcher3.ui.AbstractLauncherUiTest.resolveSystemApp;
import static com.android.launcher3.ui.AbstractLauncherUiTest.startAppFast;
@@ -36,6 +37,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -55,7 +57,6 @@ import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
import com.android.launcher3.util.rule.SimpleActivityRule;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
import com.android.quickstep.views.RecentsView;

@@ -86,10 +87,6 @@ public class FallbackRecentsTest {
    @Rule
    public final TestRule mOrderSensitiveRules;

    @Rule
    public final SimpleActivityRule<RecentsActivity> mActivityMonitor =
            new SimpleActivityRule(RecentsActivity.class);

    public FallbackRecentsTest() throws RemoteException {
        Instrumentation instrumentation = getInstrumentation();
        Context context = instrumentation.getContext();
@@ -143,7 +140,7 @@ public class FallbackRecentsTest {
    @NavigationModeSwitch
    @Test
    public void goToOverviewFromApp() {
        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
        startAppFastAndWaitForRecentTask(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));

        mLauncher.getBackground().switchToOverview();
    }
@@ -159,7 +156,7 @@ public class FallbackRecentsTest {
        if (!TestHelpers.isInLauncherProcess()) return null;
        Object[] result = new Object[1];
        Wait.atMost("Failed to get from recents", () -> MAIN_EXECUTOR.submit(() -> {
            RecentsActivity activity = mActivityMonitor.getActivity();
            RecentsActivity activity = RecentsActivity.ACTIVITY_TRACKER.getCreatedActivity();
            if (activity == null) {
                return false;
            }
@@ -177,13 +174,15 @@ public class FallbackRecentsTest {
    @NavigationModeSwitch
    @Test
    public void testOverview() {
        startAppFast(getAppPackageName());
        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
        startAppFastAndWaitForRecentTask(getAppPackageName());
        startAppFastAndWaitForRecentTask(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
        startTestActivity(2);
        Wait.atMost("Expected three apps in the task list",
                () -> mLauncher.getRecentTasks().size() >= 3, DEFAULT_ACTIVITY_TIMEOUT);

        BaseOverview overview = mLauncher.getBackground().switchToOverview();
        executeOnRecents(
                recents -> assertTrue("Don't have at least 3 tasks", getTaskCount(recents) >= 3));
        executeOnRecents(recents ->
                assertTrue("Don't have at least 3 tasks", getTaskCount(recents) >= 3));

        // Test flinging forward and backward.
        overview.flingForward();
@@ -229,4 +228,24 @@ public class FallbackRecentsTest {
    private int getTaskCount(RecentsActivity recents) {
        return recents.<RecentsView>getOverviewPanel().getTaskViewCount();
    }

    /**
     * Workaround for b/141580748, there was an issue where the recent task is only updated when the
     * activity starting the task is resumed.  In this case, we should wait until the task is in
     * the recents task list before continuing.
     */
    private void startAppFastAndWaitForRecentTask(String packageName) {
        startAppFast(packageName);
        Wait.atMost("Expected app in task list",
                () -> containsRecentTaskWithPackage(packageName), DEFAULT_ACTIVITY_TIMEOUT);
    }

    private boolean containsRecentTaskWithPackage(String packageName) {
        for (ComponentName cn : mLauncher.getRecentTasks()) {
            if (cn.getPackageName().equals(packageName)) {
                return true;
            }
        }
        return false;
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -115,9 +115,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
                            mLauncher.getAppsView().getAppsStore().getDeferUpdatesFlags()).get();
                    response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
                            deferUpdatesFlags);
                } catch (ExecutionException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                } catch (ExecutionException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
                break;
@@ -130,9 +128,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
                            .get();
                    response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD,
                            deferUpdatesFlags);
                } catch (ExecutionException e) {
                    throw new RuntimeException(e);
                } catch (InterruptedException e) {
                } catch (ExecutionException | InterruptedException e) {
                    throw new RuntimeException(e);
                }
                break;
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public final class TestProtocol {
    public static final String REQUEST_JAVA_LEAK = "java-leak";
    public static final String REQUEST_NATIVE_LEAK = "native-leak";
    public static final String REQUEST_VIEW_LEAK = "view-leak";
    public static final String REQUEST_RECENT_TASKS_LIST = "recent-tasks-list";

    public static boolean sDebugTracing = false;
    public static final String REQUEST_ENABLE_DEBUG_TRACING = "enable-debug-tracing";
+2 −2
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            final int leftMargin = mLauncher.getTestInfo(
                    TestProtocol.REQUEST_OVERVIEW_LEFT_GESTURE_MARGIN).
                    getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
            mLauncher.scroll(overview, Direction.LEFT, new Rect(leftMargin, 0, 0, 0), 20);
            mLauncher.scroll(overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20);
            verifyActiveContainer();
        }
    }
@@ -89,7 +89,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            final int rightMargin = mLauncher.getTestInfo(
                    TestProtocol.REQUEST_OVERVIEW_RIGHT_GESTURE_MARGIN).
                    getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
            mLauncher.scroll(overview, Direction.RIGHT, new Rect(0, 0, rightMargin, 0), 20);
            mLauncher.scroll(overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20);
            verifyActiveContainer();
        }
    }
Loading