Add tests for TaskbarStashController.

Test: TaskbarStashControllerTest
Bug: 346394503
Flag: TEST_ONLY
Change-Id: I930e745826f2512d04434ad689a3e42cac7e9901
This commit is contained in:
Brian Isganitis committed 2024-09-24 18:51:46 -04:00
1 parent c2c7913134
commit 3231ba01e6
4 files changed
+734 -15

No files matched your search

@@ -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:");
@@ -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
}