Not using magic constant for edge sensitivity
+Some cleanup in TAPL
Change-Id: I886a6c4abacf8b806ee5507e633ec21f2e7ad1d4
diff --git a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java
index f5ac9c9..895485d 100644
--- a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java
+++ b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java
@@ -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 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 @@
@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 =
@@ -144,4 +150,4 @@
return base;
}
}
-}
+}
\ No newline at end of file
diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
index 4205188..74a17ce 100644
--- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
+++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java
@@ -48,8 +48,7 @@
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 @@
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();
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index ef3cb1f..c72f7d0 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -22,7 +22,6 @@
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 @@
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 @@
// 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 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
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 68b007e..f04afa0 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -148,8 +148,7 @@
*/
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 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();