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

Commit 7e858498 authored by Massimo Carli's avatar Massimo Carli
Browse files

[31/n] Introduce source for rechability to easily fix tests

Current tests implementations consider double-tap for surfaces in
Core. The new logic in Shell is covered with specific tests. To
keep the existing tests unchanged, a ReachabilitySource is
introduced to define a specific code path for the Core case.

Flag: com.android.window.flags.app_compat_refactoring
Bug: 407731267
Test: atest WmTests:AppCompatReachabilityPolicyTest

Change-Id: I114afb8583c4d871fb9070fa768bdba986b53fd4
parent 36c330df
Loading
Loading
Loading
Loading
+47 −14
Original line number Diff line number Diff line
@@ -27,14 +27,16 @@ import static com.android.internal.util.FrameworkStatsLog.LETTERBOX_POSITION_CHA
import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_HORIZONTAL_REACHABILITY_POSITION_CENTER;
import static com.android.server.wm.AppCompatConfiguration.LETTERBOX_VERTICAL_REACHABILITY_POSITION_CENTER;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.Rect;

import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Supplier;

/**
@@ -50,6 +52,26 @@ class AppCompatReachabilityPolicy {
    @VisibleForTesting
    Supplier<Rect> mLetterboxInnerBoundsSupplier;

    /** @hide */
    @IntDef(prefix = { "REACHABILITY_SOURCE_" }, value = {
            REACHABILITY_SOURCE_CORE,
            REACHABILITY_SOURCE_SHELL,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ReachabilitySource {}

    /**
     * This is the value used when the double tap is coming from the Letterbox surfaces in Core.
     * @hide
     */
    public static final int REACHABILITY_SOURCE_CORE = 0;

    /**
     * This is the value used when the double tap is coming from the Letterbox surfaces in Shell.
     * @hide
     */
    public static final int REACHABILITY_SOURCE_SHELL = 1;

    AppCompatReachabilityPolicy(@NonNull ActivityRecord activityRecord,
            @NonNull AppCompatConfiguration appCompatConfiguration) {
        mActivityRecord = activityRecord;
@@ -66,14 +88,25 @@ class AppCompatReachabilityPolicy {
    }

    /**
     * Handles double tap events for reachability.
     * Handles double tap events for reachability from Core.
     * <p/>
     * @param x Double tap x coordinate.
     * @param y Double tap y coordinate.
     */
    void handleDoubleTap(int x, int y) {
        handleHorizontalDoubleTap(x);
        handleVerticalDoubleTap(y);
        handleDoubleTap(x, y, REACHABILITY_SOURCE_CORE);
    }

    /**
     * Handles double tap events for reachability.
     * <p/>
     * @param x Double tap x coordinate.
     * @param y Double tap y coordinate.
     * @param source The Source of the double-tap event.
     */
    void handleDoubleTap(int x, int y, @ReachabilitySource int source) {
        handleHorizontalDoubleTap(x, source);
        handleVerticalDoubleTap(y, source);
    }

    void dump(@NonNull PrintWriter pw, @NonNull String prefix) {
@@ -95,14 +128,14 @@ class AppCompatReachabilityPolicy {
                mActivityRecord.getParent().getConfiguration()));
    }

    private void handleHorizontalDoubleTap(int x) {
    private void handleHorizontalDoubleTap(int x, @ReachabilitySource int source) {
        final AppCompatReachabilityOverrides reachabilityOverrides =
                mActivityRecord.mAppCompatController.getReachabilityOverrides();
        // We don't return early when the Shell letterbox implementation is enabled because
        // double tap is always sent via transitions.
        final boolean isInTransition = !Flags.appCompatRefactoring()
        // The check on the transition state only makes sense if the event is coming from core.
        // In case the event is coming from Shell, the transition should not be considered.
        final boolean skipWhenOnTransition = source == REACHABILITY_SOURCE_CORE
                && mActivityRecord.isInTransition();
        if (!reachabilityOverrides.isHorizontalReachabilityEnabled() || isInTransition) {
        if (!reachabilityOverrides.isHorizontalReachabilityEnabled() || skipWhenOnTransition) {
            return;
        }
        final Rect letterboxInnerFrame = getLetterboxInnerFrame();
@@ -144,14 +177,14 @@ class AppCompatReachabilityPolicy {
        mActivityRecord.recomputeConfiguration();
    }

    private void handleVerticalDoubleTap(int y) {
    private void handleVerticalDoubleTap(int y, @ReachabilitySource int source) {
        final AppCompatReachabilityOverrides reachabilityOverrides =
                mActivityRecord.mAppCompatController.getReachabilityOverrides();
        // We don't return early when the Shell letterbox implementation is enabled because
        // double tap is always sent via transitions.
        final boolean isInTransition = !Flags.appCompatRefactoring()
        // The check on the transition state only makes sense if the event is coming from core.
        // In case the event is coming from Shell, the transition should not be considered.
        final boolean skipWhenOnTransition = source == REACHABILITY_SOURCE_CORE
                && mActivityRecord.isInTransition();
        if (!reachabilityOverrides.isVerticalReachabilityEnabled() || isInTransition) {
        if (!reachabilityOverrides.isVerticalReachabilityEnabled() || skipWhenOnTransition) {
            return;
        }
        final Rect letterboxInnerFrame = getLetterboxInnerFrame();
+3 −1
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import static com.android.server.wm.ActivityRecord.State.RESUMED;
import static com.android.server.wm.ActivityTaskManagerService.enforceTaskPermission;
import static com.android.server.wm.ActivityTaskManagerService.isPip2ExperimentEnabled;
import static com.android.server.wm.ActivityTaskSupervisor.REMOVE_FROM_RECENTS;
import static com.android.server.wm.AppCompatReachabilityPolicy.REACHABILITY_SOURCE_SHELL;
import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_PINNED_TASK;
import static com.android.server.wm.Task.FLAG_FORCE_HIDDEN_FOR_TASK_ORG;
import static com.android.server.wm.TaskFragment.EMBEDDED_DIM_AREA_PARENT_TASK;
@@ -1239,7 +1240,8 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                            final int doubleTapX = bundle.getInt(REACHABILITY_EVENT_X);
                            final int doubleTapY = bundle.getInt(REACHABILITY_EVENT_Y);
                            topOpaqueActivity.mAppCompatController.getReachabilityPolicy()
                                    .handleDoubleTap(doubleTapX, doubleTapY);
                                    .handleDoubleTap(doubleTapX, doubleTapY,
                                            REACHABILITY_SOURCE_SHELL);
                        }
                    }
                }