diff --git a/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java b/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java index ecb8365710..f99155f25a 100644 --- a/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java +++ b/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java @@ -188,12 +188,27 @@ public class DebugTestInformationHandler extends TestInformationHandler { return response; } + case TestProtocol.REQUEST_REINITIALIZE_DATA: { + final long identity = Binder.clearCallingIdentity(); + try { + MODEL_EXECUTOR.execute(() -> { + LauncherModel model = LauncherAppState.getInstance(mContext).getModel(); + model.getModelDbController().createEmptyDB(); + MAIN_EXECUTOR.execute(model::forceReload); + }); + return response; + } finally { + Binder.restoreCallingIdentity(identity); + } + } + case TestProtocol.REQUEST_CLEAR_DATA: { final long identity = Binder.clearCallingIdentity(); try { MODEL_EXECUTOR.execute(() -> { LauncherModel model = LauncherAppState.getInstance(mContext).getModel(); model.getModelDbController().createEmptyDB(); + model.getModelDbController().clearEmptyDbFlag(); MAIN_EXECUTOR.execute(model::forceReload); }); return response; diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java index 36e4e76439..84c35557e6 100644 --- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -110,6 +110,7 @@ public final class TestProtocol { public static final String REQUEST_GET_TEST_EVENTS = "get-test-events"; public static final String REQUEST_GET_HAD_NONTEST_EVENTS = "get-had-nontest-events"; public static final String REQUEST_STOP_EVENT_LOGGING = "stop-event-logging"; + public static final String REQUEST_REINITIALIZE_DATA = "reinitialize-data"; public static final String REQUEST_CLEAR_DATA = "clear-data"; public static final String REQUEST_HOTSEAT_ICON_NAMES = "get-hotseat-icon-names"; public static final String REQUEST_IS_TABLET = "is-tablet"; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 7f796e7bb6..66e98f7d6c 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -293,8 +293,16 @@ public abstract class AbstractLauncherUiTest { } } - protected void clearLauncherData() { - mLauncher.clearLauncherData(); + protected void reinitializeLauncherData() { + reinitializeLauncherData(false); + } + + protected void reinitializeLauncherData(boolean clearWorkspace) { + if (clearWorkspace) { + mLauncher.clearLauncherData(); + } else { + mLauncher.reinitializeLauncherData(); + } mLauncher.waitForLauncherInitialized(); } diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 2c8acc4ddc..c1f2bb620f 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -97,7 +97,12 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } public static void initialize(AbstractLauncherUiTest test) throws Exception { - test.clearLauncherData(); + initialize(test, false); + } + + public static void initialize( + AbstractLauncherUiTest test, boolean clearWorkspace) throws Exception { + test.reinitializeLauncherData(clearWorkspace); test.mDevice.pressHome(); test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null); test.waitForState("Launcher internal state didn't switch to Home", @@ -248,7 +253,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { LauncherLayoutBuilder builder = new LauncherLayoutBuilder() .atHotseat(0).putApp("com.android.chrome", "com.google.android.apps.chrome.Main"); mLauncherLayout = TestUtil.setLauncherDefaultLayout(mTargetContext, builder); - clearLauncherData(); + reinitializeLauncherData(); final Workspace workspace = mLauncher.getWorkspace(); @@ -557,7 +562,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { allApps.unfreeze(); } // Reset the workspace for the next shortcut creation. - initialize(this); + initialize(this, true); endTime = SystemClock.uptimeMillis(); elapsedTime = endTime - startTime; Log.d("testDragAppIconToWorkspaceCellTime", diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 2286d7ef13..df63ea670a 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1855,6 +1855,12 @@ public final class LauncherInstrumentation { return tasks; } + /** Reinitializes the workspace to its default layout. */ + public void reinitializeLauncherData() { + getTestInfo(TestProtocol.REQUEST_REINITIALIZE_DATA); + } + + /** Clears the workspace, leaving it empty. */ public void clearLauncherData() { getTestInfo(TestProtocol.REQUEST_CLEAR_DATA); }