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

Commit 24eb1c9c authored by vadimt's avatar vadimt
Browse files

Not using magic constant for edge sensitivity

+Some cleanup in TAPL

Change-Id: I886a6c4abacf8b806ee5507e633ec21f2e7ad1d4
parent 077df72a
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.quickstep;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import static com.android.quickstep.NavigationModeSwitchRule.Mode.ALL;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.TWO_BUTTON;
@@ -26,18 +27,23 @@ import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_

import android.content.Context;
import android.util.Log;

import androidx.test.uiautomator.UiDevice;

import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.android.systemui.shared.system.QuickStepContract;

import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Test rule that allows executing a test with Quickstep on and then Quickstep off.
 * The test should be annotated with @QuickstepOnOff.
@@ -72,9 +78,9 @@ public class NavigationModeSwitchRule implements TestRule {
                @Override
                public void evaluate() throws Throwable {
                    final Context context = getInstrumentation().getContext();
                    final String prevOverlayPkg = LauncherInstrumentation.isGesturalMode(context)
                    final String prevOverlayPkg = QuickStepContract.isGesturalMode(context)
                            ? NAV_BAR_MODE_GESTURAL_OVERLAY
                            : LauncherInstrumentation.isSwipeUpMode(context)
                            : QuickStepContract.isSwipeUpMode(context)
                                    ? NAV_BAR_MODE_2BUTTON_OVERLAY
                                    : NAV_BAR_MODE_3BUTTON_OVERLAY;
                    final LauncherInstrumentation.NavigationModel originalMode =
+2 −4
Original line number Diff line number Diff line
@@ -48,8 +48,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
                     mLauncher.addContextLayer("want to fling forward in overview")) {
            LauncherInstrumentation.log("Overview.flingForward before fling");
            final UiObject2 overview = verifyActiveContainer();
            final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
            overview.setGestureMargins(margin, 0, 0, 0);
            overview.setGestureMargins(mLauncher.getEdgeSensitivityWidth(), 0, 0, 0);
            overview.fling(Direction.LEFT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            mLauncher.waitForIdle();
            verifyActiveContainer();
@@ -86,8 +85,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
                     mLauncher.addContextLayer("want to fling backward in overview")) {
            LauncherInstrumentation.log("Overview.flingBackward before fling");
            final UiObject2 overview = verifyActiveContainer();
            final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
            overview.setGestureMargins(0, 0, margin, 0);
            overview.setGestureMargins(0, 0, mLauncher.getEdgeSensitivityWidth(), 0);
            overview.fling(Direction.RIGHT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            mLauncher.waitForIdle();
            verifyActiveContainer();
+13 −33
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.app.UiAutomation;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Point;
import android.net.Uri;
import android.os.Build;
@@ -65,8 +64,6 @@ import java.util.concurrent.TimeoutException;
public final class LauncherInstrumentation {

    private static final String TAG = "Tapl";
    private static final String NAV_BAR_INTERACTION_MODE_RES_NAME =
            "config_navBarInteractionMode";
    private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 20;

    // Types for launcher containers that the user is interacting with. "Background" is a
@@ -175,11 +172,11 @@ public final class LauncherInstrumentation {
            // Workaround, use constructed context because both the instrumentation context and the
            // app context are not constructed with resources that take overlays into account
            final Context ctx = baseContext.createPackageContext("android", 0);
            if (isGesturalMode(ctx)) {
            if (QuickStepContract.isGesturalMode(ctx)) {
                return NavigationModel.ZERO_BUTTON;
            } else if (isSwipeUpMode(ctx)) {
            } else if (QuickStepContract.isSwipeUpMode(ctx)) {
                return NavigationModel.TWO_BUTTON;
            } else if (isLegacyMode(ctx)) {
            } else if (QuickStepContract.isLegacyMode(ctx)) {
                return NavigationModel.THREE_BUTTON;
            } else {
                fail("Can't detect navigation mode");
@@ -610,37 +607,20 @@ public final class LauncherInstrumentation {
        }
    }

    public static boolean isGesturalMode(Context context) {
        return QuickStepContract.isGesturalMode(
                getSystemIntegerRes(context, NAV_BAR_INTERACTION_MODE_RES_NAME));
    }

    public static boolean isSwipeUpMode(Context context) {
        return QuickStepContract.isSwipeUpMode(
                getSystemIntegerRes(context, NAV_BAR_INTERACTION_MODE_RES_NAME));
    }

    public static boolean isLegacyMode(Context context) {
        return QuickStepContract.isLegacyMode(
                getSystemIntegerRes(context, NAV_BAR_INTERACTION_MODE_RES_NAME));
    }

    private static int getSystemIntegerRes(Context context, String resName) {
        Resources res = context.getResources();
        int resId = res.getIdentifier(resName, "integer", "android");

        if (resId != 0) {
            return res.getInteger(resId);
        } else {
            Log.e(TAG, "Failed to get system resource ID. Incompatible framework version?");
            return -1;
        }
    }

    static void sleep(int duration) {
        try {
            Thread.sleep(duration);
        } catch (InterruptedException e) {
        }
    }

    int getEdgeSensitivityWidth() {
        try {
            return QuickStepContract.getEdgeSensitivityWidth(
                    mInstrumentation.getTargetContext().createPackageContext("android", 0)) + 1;
        } catch (PackageManager.NameNotFoundException e) {
            fail("Can't get edge sensitivity: " + e);
            return 0;
        }
    }
}
 No newline at end of file
+2 −4
Original line number Diff line number Diff line
@@ -148,8 +148,7 @@ public final class Workspace extends Home {
     */
    public void flingForward() {
        final UiObject2 workspace = verifyActiveContainer();
        final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
        workspace.setGestureMargins(0, 0, margin, 0);
        workspace.setGestureMargins(0, 0, mLauncher.getEdgeSensitivityWidth(), 0);
        workspace.fling(Direction.RIGHT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
        mLauncher.waitForIdle();
        verifyActiveContainer();
@@ -161,8 +160,7 @@ public final class Workspace extends Home {
     */
    public void flingBackward() {
        final UiObject2 workspace = verifyActiveContainer();
        final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
        workspace.setGestureMargins(margin, 0, 0, 0);
        workspace.setGestureMargins(mLauncher.getEdgeSensitivityWidth(), 0, 0, 0);
        workspace.fling(Direction.LEFT, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
        mLauncher.waitForIdle();
        verifyActiveContainer();