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

Commit 3231ba01 authored by Brian Isganitis's avatar Brian Isganitis
Browse files

Add tests for TaskbarStashController.

Test: TaskbarStashControllerTest
Bug: 346394503
Flag: TEST_ONLY
Change-Id: I930e745826f2512d04434ad689a3e42cac7e9901
parent c2c79131
Loading
Loading
Loading
Loading
+38 −12
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
    private static final String TAG = "TaskbarStashController";
    private static final boolean DEBUG = false;

    private static boolean sEnableSoftwareImeForTests = false;

    /**
     * Def. value for @param shouldBubblesFollow in
     * {@link #updateAndAnimateTransientTaskbar(boolean)} */
@@ -131,19 +133,22 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
     *
     * Use {@link #getStashDuration()} to query duration
     */
    private static final long TASKBAR_STASH_DURATION = InsetsController.ANIMATION_DURATION_RESIZE;
    @VisibleForTesting
    static final long TASKBAR_STASH_DURATION = InsetsController.ANIMATION_DURATION_RESIZE;

    /**
     * How long to stash/unstash transient taskbar.
     *
     * Use {@link #getStashDuration()} to query duration.
     */
    private static final long TRANSIENT_TASKBAR_STASH_DURATION = 417;
    @VisibleForTesting
    static final long TRANSIENT_TASKBAR_STASH_DURATION = 417;

    /**
     * How long to stash/unstash when keyboard is appearing/disappearing.
     */
    private static final long TASKBAR_STASH_DURATION_FOR_IME = 80;
    @VisibleForTesting
    static final long TASKBAR_STASH_DURATION_FOR_IME = 80;

    /**
     * The scale TaskbarView animates to when being stashed.
@@ -164,7 +169,7 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
    /**
     * How long the icon/stash handle alpha animation plays.
     */
    public static final long TASKBAR_STASH_ALPHA_DURATION = 50;
    public static final long TRANSIENT_TASKBAR_STASH_ALPHA_DURATION = 50;

    /**
     * How long to delay the icon/stash handle alpha for the home to app taskbar animation.
@@ -254,7 +259,7 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
    private boolean mEnableBlockingTimeoutDuringTests = false;

    private Animator mTaskbarBackgroundAlphaAnimator;
    private long mTaskbarBackgroundDuration;
    private final long mTaskbarBackgroundDuration;
    private boolean mUserIsNotGoingHome = false;

    // Evaluate whether the handle should be stashed
@@ -801,14 +806,14 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
            if (animationType == TRANSITION_HANDLE_FADE) {
                // When fading, the handle fades in/out at the beginning of the transition with
                // TASKBAR_STASH_ALPHA_DURATION.
                backgroundAndHandleAlphaDuration = TASKBAR_STASH_ALPHA_DURATION;
                backgroundAndHandleAlphaDuration = TRANSIENT_TASKBAR_STASH_ALPHA_DURATION;
                // The iconAlphaDuration must be set to duration for the skippable interpolators
                // below to work.
                iconAlphaDuration = duration;
            } else {
                iconAlphaStartDelay = TASKBAR_STASH_ALPHA_START_DELAY;
                iconAlphaDuration = TASKBAR_STASH_ALPHA_DURATION;
                backgroundAndHandleAlphaDuration = TASKBAR_STASH_ALPHA_DURATION;
                iconAlphaDuration = TRANSIENT_TASKBAR_STASH_ALPHA_DURATION;
                backgroundAndHandleAlphaDuration = TRANSIENT_TASKBAR_STASH_ALPHA_DURATION;

                if (isStashed) {
                    if (animationType == TRANSITION_HOME_TO_APP) {
@@ -1084,7 +1089,8 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
    /**
     * When hiding the IME, delay the unstash animation to align with the end of the transition.
     */
    private long getTaskbarStashStartDelayForIme() {
    @VisibleForTesting
    long getTaskbarStashStartDelayForIme() {
        if (mIsImeShowing) {
            // Only delay when IME is exiting, not entering.
            return 0;
@@ -1144,13 +1150,13 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
        }

        // Do not stash if pinned taskbar, hardware keyboard is attached and no IME is docked
        if (mActivity.isHardwareKeyboard() && DisplayController.isPinnedTaskbar(mActivity)
        if (isHardwareKeyboard() && DisplayController.isPinnedTaskbar(mActivity)
                && !mActivity.isImeDocked()) {
            return false;
        }

        // Do not stash if hardware keyboard is attached, in 3 button nav and desktop windowing mode
        if (mActivity.isHardwareKeyboard()
        if (isHardwareKeyboard()
                && mActivity.isThreeButtonNav()
                && mControllers.taskbarDesktopModeController.getAreDesktopTasksVisible()) {
            return false;
@@ -1164,6 +1170,21 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
        return mIsImeShowing || mIsImeSwitcherShowing;
    }

    private boolean isHardwareKeyboard() {
        return mActivity.isHardwareKeyboard() && !sEnableSoftwareImeForTests;
    }

    /**
     * Overrides {@link #isHardwareKeyboard()} to {@code false} for testing, if enabled.
     * <p>
     * Virtual devices are sometimes in hardware keyboard mode, leading to an inconsistent
     * testing environment.
     */
    @VisibleForTesting
    static void enableSoftwareImeForTests(boolean enable) {
        sEnableSoftwareImeForTests = enable;
    }

    /**
     * Updates the proper flag to indicate whether the task bar should be stashed.
     *
@@ -1289,7 +1310,7 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
    /**
     * Attempts to start timer to auto hide the taskbar based on time.
     */
    public void tryStartTaskbarTimeout() {
    private void tryStartTaskbarTimeout() {
        if (!DisplayController.isTransientTaskbar(mActivity)
                || mIsStashed
                || mEnableBlockingTimeoutDuringTests) {
@@ -1317,6 +1338,11 @@ public class TaskbarStashController implements TaskbarControllers.LoggableTaskba
        updateAndAnimateTransientTaskbarForTimeout();
    }

    @VisibleForTesting
    Alarm getTimeoutAlarm() {
        return mTimeoutAlarm;
    }

    @Override
    public void dumpLogs(String prefix, PrintWriter pw) {
        pw.println(prefix + "TaskbarStashController:");
+4 −3
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ import com.android.launcher3.R
import com.android.launcher3.anim.AnimatedFloat
import com.android.launcher3.anim.SpringAnimationBuilder
import com.android.launcher3.taskbar.TaskbarInsetsController
import com.android.launcher3.taskbar.TaskbarStashController.TASKBAR_STASH_ALPHA_DURATION
import com.android.launcher3.taskbar.TaskbarStashController.TASKBAR_STASH_ALPHA_START_DELAY
import com.android.launcher3.taskbar.TaskbarStashController.TRANSIENT_TASKBAR_STASH_ALPHA_DURATION
import com.android.launcher3.taskbar.bubbles.BubbleBarViewController
import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController
import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Companion.BAR_STASH_DURATION
@@ -305,7 +305,8 @@ class TransientBubbleStashController(

        animatorSet.play(
            createBackgroundAlphaAnimator(isStashed).apply {
                val alphaDuration = if (isStashed) duration else TASKBAR_STASH_ALPHA_DURATION
                val alphaDuration =
                    if (isStashed) duration else TRANSIENT_TASKBAR_STASH_ALPHA_DURATION
                val alphaDelay = if (isStashed) TASKBAR_STASH_ALPHA_START_DELAY else 0L
                this.duration = max(0L, alphaDuration - alphaDelay)
                this.startDelay = alphaDelay
@@ -317,7 +318,7 @@ class TransientBubbleStashController(
            bubbleBarBubbleAlpha
                .animateToValue(getBarAlphaStart(isStashed), getBarAlphaEnd(isStashed))
                .apply {
                    this.duration = TASKBAR_STASH_ALPHA_DURATION
                    this.duration = TRANSIENT_TASKBAR_STASH_ALPHA_DURATION
                    this.startDelay = TASKBAR_STASH_ALPHA_START_DELAY
                    this.interpolator = LINEAR
                }
+681 −0

File added.

Preview size limit exceeded, changes collapsed.

+11 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;

import androidx.annotation.VisibleForTesting;

public class Alarm implements Runnable{
    // if we reach this time and the alarm hasn't been cancelled, call the listener
    private long mAlarmTriggerTime;
@@ -96,4 +98,13 @@ public class Alarm implements Runnable{
    public long getLastSetTimeout() {
        return mLastSetTimeout;
    }

    /** Simulates the alarm firing for tests. */
    @VisibleForTesting
    public void finishAlarm() {
        if (!mAlarmPending) return;
        mAlarmPending = false;
        mHandler.removeCallbacks(this);
        mAlarmListener.onAlarm(this);
    }
}