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

Commit c295098e authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Enabling "in test harness" flag with a direct call

This allows running in-proc tests without enabling test harness on
Android and restarting Launcher.

Bug: 110103162
Test: TaplTests
Change-Id: Ife44eff4760eb1349a10847efe2c1f27643bf146
parent bb248848
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -136,9 +136,13 @@ public final class Utilities {
            CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE,
            TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());

    public static final boolean IS_RUNNING_IN_TEST_HARNESS =
    public static boolean IS_RUNNING_IN_TEST_HARNESS =
                    ActivityManager.isRunningInTestHarness();

    public static void enableRunningInTestHarnessForTests() {
        IS_RUNNING_IN_TEST_HARNESS = true;
    }

    public static boolean isPropertyEnabled(String propertyName) {
        return Log.isLoggable(propertyName, Log.VERBOSE);
    }
+3 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.tapl.LauncherInstrumentation;
@@ -101,6 +102,7 @@ public abstract class AbstractLauncherUiTest {
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
        if (TestHelpers.isInLauncherProcess()) Utilities.enableRunningInTestHarnessForTests();
        mLauncher = new LauncherInstrumentation(instrumentation);
    }

+9 −1
Original line number Diff line number Diff line
@@ -108,7 +108,15 @@ public final class LauncherInstrumentation {
                instrumentation.getTargetContext().getContentResolver(),
                SWIPE_UP_SETTING_NAME,
                swipeUpEnabledDefault ? 1 : 0) == 1;
        assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness());

        // Launcher should run in test harness so that custom accessibility protocol between
        // Launcher and TAPL is enabled. In-process tests enable this protocol with a direct call
        // into Launcher.
        final boolean isInLauncherProcess =
                instrumentation.getTargetContext().getPackageName().equals(
                        UiDevice.getInstance(instrumentation).getLauncherPackageName());
        assertTrue("Device must run in a test harness",
                isInLauncherProcess || ActivityManager.isRunningInTestHarness());
    }

    // Used only by TaplTests.