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

Commit 50097ef2 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Waiting for app install to finish before procedding with the test

Bug: 256659409
Test: Presubmit
Change-Id: Ia0f4cdd072c4c439d09070b0395fcfd6909c2a8f
parent 9e1f6002
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.launcher3.testing;

import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;

import android.app.Activity;
import android.app.Application;
@@ -248,6 +249,9 @@ public class DebugTestInformationHandler extends TestInformationHandler {
                return response;
            }

            case TestProtocol.REQUEST_MODEL_QUEUE_CLEARED:
                return getFromExecutorSync(MODEL_EXECUTOR, Bundle::new);

            default:
                return super.call(method, arg, extras);
        }
+20 −12
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ import com.android.launcher3.testing.shared.WorkspaceCellCenterRequest;
import com.android.launcher3.util.ResourceBasedOverride;
import com.android.launcher3.widget.picker.WidgetsFullSheet;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.function.Function;
import java.util.function.Supplier;

@@ -214,8 +216,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
            }

            case TestProtocol.REQUEST_HAS_TIS: {
                response.putBoolean(
                        TestProtocol.REQUEST_HAS_TIS, false);
                response.putBoolean(TestProtocol.REQUEST_HAS_TIS, false);
                return response;
            }

@@ -266,8 +267,7 @@ public class TestInformationHandler implements ResourceBasedOverride {
     */
    private static <S, T> Bundle getUIProperty(
            BundleSetter<T> bundleSetter, Function<S, T> provider, Supplier<S> targetSupplier) {
        try {
            return MAIN_EXECUTOR.submit(() -> {
        return getFromExecutorSync(MAIN_EXECUTOR, () -> {
            S target = targetSupplier.get();
            if (target == null) {
                return null;
@@ -276,7 +276,15 @@ public class TestInformationHandler implements ResourceBasedOverride {
            Bundle response = new Bundle();
            bundleSetter.set(response, TestProtocol.TEST_INFO_RESPONSE_FIELD, value);
            return response;
            }).get();
        });
    }

    /**
     * Executes the callback on the executor and waits for the result
     */
    protected static <T> T getFromExecutorSync(ExecutorService executor, Callable<T> callback) {
        try {
            return executor.submit(callback).get();
        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
+1 −0
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ public final class TestProtocol {
    public static final String REQUEST_GET_OVERVIEW_PAGE_SPACING = "get-overview-page-spacing";
    public static final String REQUEST_ENABLE_ROTATION = "enable_rotation";
    public static final String REQUEST_ENABLE_SUGGESTION = "enable-suggestion";
    public static final String REQUEST_MODEL_QUEUE_CLEARED = "model-queue-cleared";

    public static boolean sDebugTracing = false;
    public static final String REQUEST_ENABLE_DEBUG_TRACING = "enable-debug-tracing";
+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
    <uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
    <uses-permission android:name="android.permission.READ_LOGS"/>
    <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

    <application android:debuggable="true" android:extractNativeLibs="true">
        <uses-library android:name="android.test.runner"/>
+14 −6
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import static org.junit.Assume.assumeTrue;

import android.content.Intent;
import android.graphics.Point;
import android.os.SystemClock;
import android.platform.test.annotations.IwTest;

import androidx.test.filters.LargeTest;
@@ -479,7 +478,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
    @Test
    @PortraitLandscape
    public void testUninstallFromWorkspace() throws Exception {
        TestUtil.installDummyApp();
        installDummyAppAndWaitForUIUpdate();
        try {
            verifyAppUninstalledFromAllApps(
                    createShortcutInCenterIfNotExist(DUMMY_APP_NAME).uninstall(), DUMMY_APP_NAME);
@@ -492,10 +491,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
    @PortraitLandscape
    @ScreenRecord // (b/256659409)
    public void testUninstallFromAllApps() throws Exception {
        TestUtil.installDummyApp();
        installDummyAppAndWaitForUIUpdate();
        try {
            // b/256659409
            SystemClock.sleep(5000);
            Workspace workspace = mLauncher.getWorkspace();
            final HomeAllApps allApps = workspace.switchToAllApps();
            allApps.freeze();
@@ -539,7 +536,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
        Point[] gridPositions = getCornersAndCenterPositions();
        createShortcutIfNotExist(STORE_APP_NAME, gridPositions[0]);
        createShortcutIfNotExist(MAPS_APP_NAME, gridPositions[1]);
        TestUtil.installDummyApp();
        installDummyAppAndWaitForUIUpdate();
        try {
            createShortcutIfNotExist(DUMMY_APP_NAME, gridPositions[2]);
            Map<String, Point> initialPositions =
@@ -590,6 +587,17 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
                mLauncher.getWorkspace().getHotseatAppIcon(APP_NAME));
    }

    private void installDummyAppAndWaitForUIUpdate() throws IOException {
        TestUtil.installDummyApp();
        // Wait for model thread completion as it may be processing
        // the install event from the SystemService
        mLauncher.waitForModelQueueCleared();
        // Wait for Launcher UI thread completion, as it may be processing updating the UI in
        // response to the model update. Not that `waitForLauncherInitialized` is just a proxy
        // method, we can use any method which touches Launcher UI thread,
        mLauncher.waitForLauncherInitialized();
    }

    /**
     * @return List of workspace grid coordinates. Those are not pixels. See {@link
     *     Workspace#getIconGridDimensions()}
Loading