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

Commit 82f7b5ad authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix onUserInteraction not called with 3-button-nav and enableOnBackInvokedCallback=true

We should ignore KeyEvents with the FLAG_CANCELED flag in log analysis for Launcher tests as these KeyEvents should not have any effect.

Bug: 346943119
Flag: com.android.window.flags.predictive_back_system_anims
Test: atest BackNavigationTests
Test: atest OnBackInvokedCallbackGestureTest
Test: Manual, i.e. verifying in a test app that onUserInteraction is called when pressing back key in 3-button-nav and when enableOnBackInvokedCallback=true
Change-Id: Icff47009757c49cdd8998244dd3e9459cc6ee085
parent b15dce1e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ import java.util.concurrent.TimeoutException;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@@ -2402,6 +2403,16 @@ public final class LauncherInstrumentation {
        disableSensorRotation();
        final Integer initialPid = getPid();
        final LogEventChecker eventChecker = new LogEventChecker(this);
        eventChecker.setLogExclusionRule(event -> {
            Matcher matcher = Pattern.compile("KeyEvent.*flags=0x([0-9a-fA-F]+)").matcher(event);
            if (matcher.find()) {
                int keyEventFlags = Integer.parseInt(matcher.group(1), 16);
                // ignore KeyEvents with FLAG_CANCELED
                return (keyEventFlags & KeyEvent.FLAG_CANCELED) != 0;
            }
            return false;
        });

        if (eventChecker.start()) mEventChecker = eventChecker;

        return () -> {
+13 −1
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public class LogEventChecker {
    // Map from an event sequence name to an ordered list of expected events in that sequence.
    private final ListMap<Pattern> mExpectedEvents = new ListMap<>();

    private LogExclusionRule mLogExclusionRule = null;

    LogEventChecker(LauncherInstrumentation launcher) {
        mLauncher = launcher;
    }
@@ -48,6 +50,10 @@ public class LogEventChecker {
        mExpectedEvents.add(sequence, pattern);
    }

    void setLogExclusionRule(LogExclusionRule logExclusionRule) {
        mLogExclusionRule = logExclusionRule;
    }

    // Waits for the expected number of events and returns them.
    private ListMap<String> finishSync(long waitForExpectedCountMs) {
        final long startTime = SystemClock.uptimeMillis();
@@ -74,8 +80,10 @@ public class LogEventChecker {
        final ListMap<String> eventSequences = new ListMap<>();
        for (String rawEvent : rawEvents) {
            final String[] split = rawEvent.split("/");
            if (mLogExclusionRule == null || !mLogExclusionRule.shouldExclude(split[1])) {
                eventSequences.add(split[0], split[1]);
            }
        }
        return eventSequences;
    }

@@ -175,4 +183,8 @@ public class LogEventChecker {
            return list;
        }
    }

    interface LogExclusionRule {
        boolean shouldExclude(String event);
    }
}