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

Commit bc776832 authored by Mateusz Cicheński's avatar Mateusz Cicheński Committed by Android (Google) Code Review
Browse files

Merge "Support going home from immersive fullscreen in 3 button nav" into main

parents adf1df2e 5f8124ad
Loading
Loading
Loading
Loading
+64 −12
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.KeyEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_SCROLL;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.MotionEvent.AXIS_GESTURE_SWIPE_FINGER_COUNT;
import static android.view.Surface.ROTATION_90;

import static com.android.launcher3.tapl.Folder.FOLDER_CONTENT_RES_ID;
import static com.android.launcher3.tapl.TestHelpers.getOverviewPackageName;
@@ -474,12 +475,25 @@ public final class LauncherInstrumentation {
        logShellCommand(cmd);
    }

    /**
     * Retrieves a resource value from context that defines if nav bar can change position or if it
     * is fixed position regardless of device orientation.
     */
    private boolean getNavBarCanMove() {
        final Context baseContext = mInstrumentation.getTargetContext();
        try {
            final Context ctx = getLauncherContext(baseContext);
            return getNavBarCanMove(ctx);
        } catch (Exception e) {
            fail(e.toString());
        }
        return false;
    }

    public NavigationModel getNavigationModel() {
        final Context baseContext = mInstrumentation.getTargetContext();
        try {
            // 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(getLauncherPackageName(), 0);
            final Context ctx = getLauncherContext(baseContext);
            for (int i = 0; i < 100; ++i) {
                final int currentInteractionMode = getCurrentInteractionMode(ctx);
                final NavigationModel model = getNavigationModel(currentInteractionMode);
@@ -1101,19 +1115,31 @@ public final class LauncherInstrumentation {
    /**
     * Goes to home from immersive fullscreen app by first swiping up to bring navbar, and then
     * performing {@code goHome()} action.
     * Currently only supports gesture navigation mode.
     *
     * @return the Workspace object.
     */
    public Workspace goHomeFromImmersiveFullscreenApp() {
        assertTrue("expected gesture navigation mode",
                getNavigationModel() == NavigationModel.ZERO_BUTTON);
        final boolean navBarCanMove = getNavBarCanMove();
        if (getNavigationModel() == NavigationModel.ZERO_BUTTON || !navBarCanMove) {
            // in gesture nav we can swipe up at the bottom to bring the navbar handle
            final Point displaySize = getRealDisplaySize();
            linearGesture(
                    displaySize.x / 2, displaySize.y - 1,
                    displaySize.x / 2, 0,
                    ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME,
                    false, GestureScope.EXPECT_PILFER);
        } else {
            // in 3 button nav we swipe up on the side edge of the screen to bring the navbar
            final boolean rotated90degrees = mDevice.getDisplayRotation() == ROTATION_90;
            final Point displaySize = getRealDisplaySize();
            final int startX = rotated90degrees ? displaySize.x : 0;
            final int endX = rotated90degrees ? 0 : displaySize.x;
            linearGesture(
                    startX, displaySize.y / 2,
                    endX, displaySize.y / 2,
                    ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME,
                    false, GestureScope.EXPECT_PILFER);
        }
        return goHome();
    }

@@ -2126,6 +2152,13 @@ public final class LauncherInstrumentation {
        return getSystemIntegerRes(context, "config_navBarInteractionMode");
    }

    /**
     * Retrieve the resource value that defines if nav bar can moved or if it is fixed position.
     */
    private static boolean getNavBarCanMove(Context context) {
        return getSystemBooleanRes(context, "config_navBarCanMove");
    }

    @NonNull
    UiObject2 clickAndGet(
            @NonNull final UiObject2 target, @NonNull String resName, Pattern longClickEvent) {
@@ -2166,6 +2199,18 @@ public final class LauncherInstrumentation {
        }
    }

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

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

    private static int getSystemIntegerRes(Context context, String resName) {
        Resources res = context.getResources();
        int resId = res.getIdentifier(resName, "integer", "android");
@@ -2431,6 +2476,13 @@ public final class LauncherInstrumentation {
        return Math.max(topRadius, bottomRadius) + tmpBuffer;
    }

    private Context getLauncherContext(Context baseContext)
            throws PackageManager.NameNotFoundException {
        // Workaround, use constructed context because both the instrumentation context and the
        // app context are not constructed with resources that take overlays into account
        return baseContext.createPackageContext(getLauncherPackageName(), 0);
    }

    private static boolean supportsRoundedCornersOnWindows(Resources resources) {
        return ResourceUtils.getBoolByName(
                "config_supportsRoundedCornersOnWindows", resources, false);