diff --git a/quickstep/src/com/android/launcher3/model/AppEventProducer.java b/quickstep/src/com/android/launcher3/model/AppEventProducer.java index 5c669441c7..9f3be69a01 100644 --- a/quickstep/src/com/android/launcher3/model/AppEventProducer.java +++ b/quickstep/src/com/android/launcher3/model/AppEventProducer.java @@ -62,6 +62,7 @@ import androidx.annotation.AnyThread; import androidx.annotation.Nullable; import androidx.annotation.WorkerThread; +import com.android.launcher3.Utilities; import com.android.launcher3.logger.LauncherAtom; import com.android.launcher3.logger.LauncherAtom.ContainerInfo; import com.android.launcher3.logger.LauncherAtom.FolderContainer; @@ -116,7 +117,8 @@ public class AppEventProducer implements StatsLogConsumer { @AnyThread private void sendEvent(AppTarget target, LauncherAtom.ItemInfo locationInfo, int eventId, int targetPredictor) { - if (target != null) { + // TODO: remove the running test check when b/231648228 is fixed. + if (target != null && !Utilities.IS_RUNNING_IN_TEST_HARNESS) { AppTargetEvent event = new AppTargetEvent.Builder(target, eventId) .setLaunchLocation(getContainer(locationInfo)) .build(); diff --git a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java index 10c56c9e8c..85ef6cb16e 100644 --- a/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java +++ b/quickstep/src/com/android/quickstep/logging/StatsLogCompatManager.java @@ -130,7 +130,7 @@ public class StatsLogCompatManager extends StatsLogManager { if (IS_VERBOSE) { Log.d(TAG, String.format("\nwriteSnapshot(%d):\n%s", instanceId.getId(), info)); } - if (!Utilities.ATLEAST_R) { + if (!Utilities.ATLEAST_R || Utilities.IS_RUNNING_IN_TEST_HARNESS) { return; } SysUiStatsLog.write(SysUiStatsLog.LAUNCHER_SNAPSHOT, @@ -415,6 +415,10 @@ public class StatsLogCompatManager extends StatsLogManager { consumer.consume(event, atomInfo); } + // TODO: remove this when b/231648228 is fixed. + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + return; + } SysUiStatsLog.write( SysUiStatsLog.LAUNCHER_EVENT, SysUiStatsLog.LAUNCHER_UICHANGED__ACTION__DEFAULT_ACTION /* deprecated */, @@ -510,6 +514,9 @@ public class StatsLogCompatManager extends StatsLogManager { } private static int getCardinality(LauncherAtom.ItemInfo info) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + return 0; + } switch (info.getContainerInfo().getContainerCase()) { case PREDICTED_HOTSEAT_CONTAINER: return info.getContainerInfo().getPredictedHotseatContainer().getCardinality(); @@ -625,6 +632,9 @@ public class StatsLogCompatManager extends StatsLogManager { } private static int getHierarchy(LauncherAtom.ItemInfo info) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + return 0; + } if (info.getContainerInfo().getContainerCase() == FOLDER) { return info.getContainerInfo().getFolder().getParentContainerCase().getNumber() + FOLDER_HIERARCHY_OFFSET; @@ -665,6 +675,9 @@ public class StatsLogCompatManager extends StatsLogManager { } private static int getSearchAttributes(LauncherAtom.ItemInfo info) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + return 0; + } ContainerInfo containerInfo = info.getContainerInfo(); if (containerInfo.getContainerCase() == EXTENDED_CONTAINERS && containerInfo.getExtendedContainers().getContainerCase() diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java index 4d38822f26..4bf247c75d 100644 --- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java +++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java @@ -52,6 +52,8 @@ import org.junit.runner.RunWith; public class TaplTestsQuickstep extends AbstractQuickStepTest { private static final String APP_NAME = "LauncherTestApp"; + private static final String CALCULATOR_APP_PACKAGE = + resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); @Before public void setUp() throws Exception { @@ -73,7 +75,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { public static void startTestApps() throws Exception { startAppFast(getAppPackageName()); - startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); + startAppFast(CALCULATOR_APP_PACKAGE); startTestActivity(2); } @@ -207,7 +209,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { @NavigationModeSwitch @PortraitLandscape public void testBackground() throws Exception { - startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); + startAppFast(CALCULATOR_APP_PACKAGE); final LaunchedAppState launchedAppState = getAndAssertLaunchedApp(); assertNotNull("Background.switchToOverview() returned null", @@ -302,7 +304,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { mLauncher.getWorkspace(); waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL); - startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); + startAppFast(CALCULATOR_APP_PACKAGE); mLauncher.pressBack(); mLauncher.getWorkspace(); waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL); diff --git a/tests/tapl/com/android/launcher3/tapl/HomeQsb.java b/tests/tapl/com/android/launcher3/tapl/HomeQsb.java new file mode 100644 index 0000000000..5f921996cd --- /dev/null +++ b/tests/tapl/com/android/launcher3/tapl/HomeQsb.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 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.launcher3.tapl; + +/** + * Operations on home screen qsb. + */ +public class HomeQsb { + + private final LauncherInstrumentation mLauncher; + + HomeQsb(LauncherInstrumentation launcher) { + mLauncher = launcher; + mLauncher.waitForLauncherObject("search_container_hotseat"); + } + + /** + * Show search result page from tapping qsb. + */ + public SearchResultFromQsb showSearchResult() { + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to open search result page"); + LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + mLauncher.clickLauncherObject( + mLauncher.waitForLauncherObject("search_container_hotseat")); + try (LauncherInstrumentation.Closable c2 = mLauncher.addContextLayer( + "clicked qsb to open search result page")) { + return new SearchResultFromQsb(mLauncher); + } + } + } +} diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index 45a01968ed..39cd4ffeff 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -33,7 +33,7 @@ import com.android.launcher3.testing.TestProtocol; /** * Ancestor for AppIcon and AppMenuItem. */ -abstract class Launchable { +public abstract class Launchable { protected static final int DEFAULT_DRAG_STEPS = 10; diff --git a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java new file mode 100644 index 0000000000..82652c7f27 --- /dev/null +++ b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2022 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.launcher3.tapl; + +import android.widget.TextView; + +import androidx.test.uiautomator.By; +import androidx.test.uiautomator.UiObject2; + +/** + * Operations on search result page opened from home screen qsb. + */ +public class SearchResultFromQsb { + // The input resource id in the search box. + private static final String INPUT_RES = "input"; + private final LauncherInstrumentation mLauncher; + + SearchResultFromQsb(LauncherInstrumentation launcher) { + mLauncher = launcher; + mLauncher.waitForLauncherObject("search_container_all_apps"); + } + + /** Set the input to the search input edit text and update search results. */ + public void searchForInput(String input) { + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to search for result with an input"); + LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + mLauncher.waitForLauncherObject(INPUT_RES).setText(input); + } + } + + /** Find the app from search results with app name. */ + public Launchable findAppIcon(String appName) { + UiObject2 icon = mLauncher.waitForLauncherObject(By.clazz(TextView.class).text(appName)); + return new AllAppsAppIcon(mLauncher, icon); + } +} diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index b0b42ba3f5..954af3d61d 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -111,6 +111,18 @@ public final class Workspace extends Home { } } + /** + * Returns the home qsb. + * + * The qsb must already be visible when calling this method. + */ + public HomeQsb getQsb() { + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to get the home qsb")) { + return new HomeQsb(mLauncher); + } + } + /** * Returns an icon for the app, if currently visible. *