Merge "resolve merge conflicts of 8cf91e4bcc88bcd4096e125d41f562d89d0d912c to master"
diff --git a/res/values-sw340dp/dimens.xml b/res/values-sw340dp/dimens.xml
index c9f2981..33b06f5 100644
--- a/res/values-sw340dp/dimens.xml
+++ b/res/values-sw340dp/dimens.xml
@@ -19,6 +19,5 @@
<!-- Drag padding to add to the bottom of drop targets -->
<dimen name="drop_target_drag_padding">20dp</dimen>
- <dimen name="drop_target_text_size">16sp</dimen>
</resources>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 9891ff5..4473f05 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -189,8 +189,9 @@
<!-- Dragging -->
<!-- Drag padding to add to the bottom of drop targets -->
<dimen name="drop_target_drag_padding">14dp</dimen>
- <dimen name="drop_target_text_size">20sp</dimen>
+ <dimen name="drop_target_text_size">16sp</dimen>
<dimen name="drop_target_shadow_elevation">2dp</dimen>
+ <dimen name="drop_target_bar_margin_horizontal">4dp</dimen>
<!-- the distance an icon must be dragged before button drop targets accept it -->
<dimen name="drag_distanceThreshold">30dp</dimen>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 09c8b9b..a926cb5 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -258,7 +258,7 @@
<!-- Drop targets -->
<style name="DropTargetButtonBase" parent="@android:style/TextAppearance.DeviceDefault">
<item name="android:drawablePadding">8dp</item>
- <item name="android:padding">16dp</item>
+ <item name="android:padding">14dp</item>
<item name="android:textColor">@color/drop_target_text</item>
<item name="android:textSize">@dimen/drop_target_text_size</item>
<item name="android:singleLine">true</item>
diff --git a/src/com/android/launcher3/DropTargetBar.java b/src/com/android/launcher3/DropTargetBar.java
index 4a1b084..88f6c49 100644
--- a/src/com/android/launcher3/DropTargetBar.java
+++ b/src/com/android/launcher3/DropTargetBar.java
@@ -105,7 +105,8 @@
/ (2 * (grid.inv.numColumns + 1)))
+ grid.edgeMarginPx;
} else {
- gap = grid.desiredWorkspaceLeftRightMarginPx - grid.inv.defaultWidgetPadding.right;
+ gap = getContext().getResources()
+ .getDimensionPixelSize(R.dimen.drop_target_bar_margin_horizontal);
}
lp.width = grid.availableWidthPx - 2 * gap;
diff --git a/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java b/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java
index 0ec0f02..2b2fef4 100644
--- a/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java
+++ b/tests/src/com/android/launcher3/util/rule/ShellCommandRule.java
@@ -15,21 +15,27 @@
*/
package com.android.launcher3.util.rule;
-import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;
-
import static androidx.test.InstrumentationRegistry.getInstrumentation;
+import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;
+
import android.content.ComponentName;
import android.content.pm.ActivityInfo;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
+import android.util.Log;
import androidx.annotation.Nullable;
import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.UiDevice;
+import com.android.systemui.shared.system.PackageManagerWrapper;
+
+import org.junit.Assert;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+import java.util.ArrayList;
+
/**
* Test rule which executes a shell command at the start of the test.
*/
@@ -37,10 +43,19 @@
private final String mCmd;
private final String mRevertCommand;
+ private final boolean mCheckSuccess;
+ private final Runnable mAdditionalChecks;
- public ShellCommandRule(String cmd, @Nullable String revertCommand) {
+ public ShellCommandRule(String cmd, @Nullable String revertCommand, boolean checkSuccess,
+ Runnable additionalChecks) {
mCmd = cmd;
mRevertCommand = revertCommand;
+ mCheckSuccess = checkSuccess;
+ mAdditionalChecks = additionalChecks;
+ }
+
+ public ShellCommandRule(String cmd, @Nullable String revertCommand) {
+ this(cmd, revertCommand, false, null);
}
@Override
@@ -48,12 +63,27 @@
return new Statement() {
@Override
public void evaluate() throws Throwable {
- UiDevice.getInstance(getInstrumentation()).executeShellCommand(mCmd);
+ final String result =
+ UiDevice.getInstance(getInstrumentation()).executeShellCommand(mCmd);
+ if (mCheckSuccess) {
+ Assert.assertTrue(
+ "Failed command: " + mCmd + ", result: " + result,
+ "Success".equals(result.replaceAll("\\s", "")));
+ }
+ if (mAdditionalChecks != null) mAdditionalChecks.run();
try {
base.evaluate();
} finally {
if (mRevertCommand != null) {
- UiDevice.getInstance(getInstrumentation()).executeShellCommand(mRevertCommand);
+ final String revertResult = UiDevice.getInstance(
+ getInstrumentation()).executeShellCommand(
+ mRevertCommand);
+ if (mCheckSuccess) {
+ Assert.assertTrue(
+ "Failed command: " + mRevertCommand
+ + ", result: " + revertResult,
+ "Success".equals(result.replaceAll("\\s", "")));
+ }
}
}
}
@@ -72,7 +102,15 @@
* Sets the target launcher as default launcher.
*/
public static ShellCommandRule setDefaultLauncher() {
- return new ShellCommandRule(getLauncherCommand(getLauncherInMyProcess()), null);
+ final ActivityInfo launcher = getLauncherInMyProcess();
+ Log.d("b/187080582", "Launcher: " + new ComponentName(launcher.packageName, launcher.name)
+ .flattenToString());
+ return new ShellCommandRule(getLauncherCommand(launcher), null, true, () ->
+ Assert.assertEquals("Setting default launcher failed",
+ new ComponentName(launcher.packageName, launcher.name)
+ .flattenToString(),
+ PackageManagerWrapper.getInstance().getHomeActivities(new ArrayList<>())
+ .flattenToString()));
}
public static String getLauncherCommand(ActivityInfo launcher) {
diff --git a/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java b/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java
index a809e2e..710e3cd 100644
--- a/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java
+++ b/tests/tapl/com/android/launcher3/tapl/LogEventChecker.java
@@ -15,6 +15,10 @@
*/
package com.android.launcher3.tapl;
+import static com.android.launcher3.testing.TestProtocol.SEQUENCE_MAIN;
+import static com.android.launcher3.testing.TestProtocol.SEQUENCE_PILFER;
+import static com.android.launcher3.testing.TestProtocol.SEQUENCE_TIS;
+
import android.os.SystemClock;
import com.android.launcher3.testing.TestProtocol;
@@ -87,6 +91,24 @@
final ListMap<String> actualEvents = finishSync(waitForExpectedCountMs);
if (actualEvents == null) return "null event sequences because launcher likely died";
+ final String lowLevelDiags = lowLevelMismatchDiagnostics(actualEvents);
+ // If we have a sequence mismatch for a successful gesture, we want to provide all low-level
+ // details.
+ if (successfulGesture) {
+ return lowLevelDiags;
+ }
+
+ final String sequenceMismatchInEnglish = highLevelMismatchDiagnostics(actualEvents);
+
+ if (sequenceMismatchInEnglish != null) {
+ LauncherInstrumentation.log(lowLevelDiags);
+ return "Hint: " + sequenceMismatchInEnglish;
+ } else {
+ return lowLevelDiags;
+ }
+ }
+
+ private String lowLevelMismatchDiagnostics(ListMap<String> actualEvents) {
final StringBuilder sb = new StringBuilder();
boolean hasMismatches = false;
for (Map.Entry<String, List<Pattern>> expectedEvents : mExpectedEvents.entrySet()) {
@@ -118,6 +140,42 @@
return hasMismatches ? "Mismatching events: " + sb.toString() : null;
}
+ private String highLevelMismatchDiagnostics(ListMap<String> actualEvents) {
+ if (!mExpectedEvents.getNonNull(SEQUENCE_TIS).isEmpty()
+ && actualEvents.getNonNull(SEQUENCE_TIS).isEmpty()) {
+ return "TouchInteractionService didn't receive any of the touch events sent by the "
+ + "test";
+ }
+ if (getMismatchPosition(mExpectedEvents.getNonNull(SEQUENCE_TIS),
+ actualEvents.getNonNull(SEQUENCE_TIS)) != -1) {
+ // If TIS has a mismatch that we can't convert to high-level diags, don't convert
+ // other sequences either.
+ return null;
+ }
+
+ if (mExpectedEvents.getNonNull(SEQUENCE_PILFER).size() == 1
+ && actualEvents.getNonNull(SEQUENCE_PILFER).isEmpty()) {
+ return "Launcher didn't detect the navigation gesture sent by the test";
+ }
+ if (mExpectedEvents.getNonNull(SEQUENCE_PILFER).isEmpty()
+ && actualEvents.getNonNull(SEQUENCE_PILFER).size() == 1) {
+ return "Launcher detected a navigation gesture, but the test didn't send one";
+ }
+ if (getMismatchPosition(mExpectedEvents.getNonNull(SEQUENCE_PILFER),
+ actualEvents.getNonNull(SEQUENCE_PILFER)) != -1) {
+ // If Pilfer has a mismatch that we can't convert to high-level diags, don't analyze
+ // other sequences.
+ return null;
+ }
+
+ if (!mExpectedEvents.getNonNull(SEQUENCE_MAIN).isEmpty()
+ && actualEvents.getNonNull(SEQUENCE_MAIN).isEmpty()) {
+ return "None of the touch or keyboard events sent by the test was received by "
+ + "Launcher's main thread";
+ }
+ return null;
+ }
+
// If the list of actual events matches the list of expected events, returns -1, otherwise
// the position of the mismatch.
private static int getMismatchPosition(List<Pattern> expected, List<String> actual) {