From dfb334f1e16e35a745d8ff03edc06f3ae14e7cfc Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Wed, 31 Jan 2024 13:24:11 -0800 Subject: [PATCH] Hide task bar when folding before the new config renders the correct task bar Currently on folding, onConfigurationChange doesn't return about 0.5sec after the small screen turns on. The old bar is visible on the new screen before a visual jump from rendering the new bar. While the ideal solution is to figure out what causes the delay, we can mitigate the visual jump by dimming the old bar when folded listener returns folded Test: repeatedly fold and unfold, observe that there is no glare task bar change in task bar area after folding Bug: 291562764 Change-Id: Ic6834d2d3b7df01a8ef841dde601cdb6a3e481b0 --- .../taskbar/TaskbarActivityContext.java | 20 +++++++++++ .../taskbar/TaskbarDragLayerController.java | 6 ++++ .../launcher3/taskbar/TaskbarManager.java | 33 ++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 55deca884b..b69f657183 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -36,12 +36,14 @@ import static com.android.launcher3.config.FeatureFlags.enableTaskbarPinning; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_OPEN; import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_DRAGGING; import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_FULLSCREEN; +import static com.android.launcher3.taskbar.TaskbarDragLayerController.TASKBAR_REAPPEAR_DELAY_MS; import static com.android.launcher3.testing.shared.ResourceUtils.getBoolByName; import static com.android.quickstep.util.AnimUtils.completeRunnableListCallback; import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE; import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_VOICE_INTERACTION_WINDOW_SHOWING; import android.animation.AnimatorSet; +import android.animation.ObjectAnimator; import android.animation.ValueAnimator; import android.app.ActivityOptions; import android.content.ActivityNotFoundException; @@ -77,6 +79,7 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.LauncherPrefs; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.R; +import com.android.launcher3.anim.AnimatedFloat; import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.apppairs.AppPairIcon; import com.android.launcher3.config.FeatureFlags; @@ -1377,6 +1380,23 @@ public class TaskbarActivityContext extends BaseTaskbarContext { }); } + public void hideTaskbarWhenFolding() { + AnimatedFloat alphaAnim = mControllers.taskbarDragLayerController.getTaskbarAlpha(); + alphaAnim.cancelAnimation(); + alphaAnim.updateValue(0); + ObjectAnimator animator = alphaAnim.animateToValue(1).setDuration(0); + animator.setStartDelay(TASKBAR_REAPPEAR_DELAY_MS); + animator.start(); + } + + public void cancelHideTaskbarWhenFolding() { + mControllers.taskbarDragLayerController.getTaskbarAlpha().cancelAnimation(); + } + + public void resetHideTaskbarWhenUnfolding() { + mControllers.taskbarDragLayerController.getTaskbarAlpha().updateValue(1); + } + protected boolean isUserSetupComplete() { return mIsUserSetupComplete; } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java index 3f5402fc16..74eda24e6e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDragLayerController.java @@ -44,6 +44,12 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa private static final boolean DEBUG = SystemProperties.getBoolean( "persist.debug.draw_taskbar_debug_ui", false); + // Delay to reset the task bar alpha back to 1 after fading it for transition from unfold to + // fold. Normally this is not needed since the new task bar is recreated after fading, but in + // case something goes wrong this provides a fallback mechanism to make sure the task bar is + // visible after the transition finishes. + public static final long TASKBAR_REAPPEAR_DELAY_MS = 2000; + private final TaskbarActivityContext mActivity; private final TaskbarDragLayer mTaskbarDragLayer; private final int mFolderMargin; diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index 7c7c426d19..4dd2f4485b 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -30,6 +30,7 @@ import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING; import static com.android.launcher3.util.DisplayController.TASKBAR_NOT_DESTROYED_TAG; +import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; import static com.android.quickstep.util.SystemActionConstants.ACTION_SHOW_TASKBAR; @@ -43,6 +44,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.res.Configuration; +import android.hardware.devicestate.DeviceStateManager; import android.hardware.display.DisplayManager; import android.net.Uri; import android.os.Handler; @@ -109,6 +111,7 @@ public class TaskbarManager { private final Context mContext; private final @Nullable Context mNavigationBarPanelContext; + private final DeviceStateManager mDeviceStateManager; private WindowManager mWindowManager; private FrameLayout mTaskbarRootLayout; private boolean mAddedWindow; @@ -175,7 +178,8 @@ public class TaskbarManager { } }; - UnfoldTransitionProgressProvider.TransitionProgressListener mUnfoldTransitionProgressListener = + private final UnfoldTransitionProgressProvider.TransitionProgressListener + mUnfoldTransitionProgressListener = new UnfoldTransitionProgressProvider.TransitionProgressListener() { @Override public void onTransitionStarted() { @@ -204,6 +208,9 @@ public class TaskbarManager { } }; + private final DeviceStateManager.FoldStateListener mFoldStateListener; + private Boolean mFolded; + @SuppressLint("WrongConstant") public TaskbarManager(TouchInteractionService service) { Display display = @@ -229,6 +236,29 @@ public class TaskbarManager { } }; } + // Temporary solution to mitigate the visual jump from folding the device. Currently, the + // screen turns on much earlier than we receive the onConfigurationChanged callback or + // receiving the correct device profile. While the ideal the solution is to align turning + // the screen on after onConfigurationChanged (by either delaying turning on the screen or + // figuring out what is causing the delay in getting onConfigurationChanged callback), one + // easy temporary mitigation is to dimming the bar so that the visual jump isn't as glaring. + mFoldStateListener = new DeviceStateManager.FoldStateListener(mContext, folded -> { + boolean firstTime = mFolded == null; + if (mTaskbarActivityContext == null) { + return; + } + if (!firstTime && mFolded.booleanValue() != folded) { + mTaskbarActivityContext.cancelHideTaskbarWhenFolding(); + } + mFolded = folded; + if (folded && !firstTime) { + mTaskbarActivityContext.hideTaskbarWhenFolding(); + } else { + mTaskbarActivityContext.resetHideTaskbarWhenUnfolding(); + } + }); + mDeviceStateManager = mContext.getSystemService(DeviceStateManager.class); + mDeviceStateManager.registerCallback(MAIN_EXECUTOR, mFoldStateListener); mNavButtonController = new TaskbarNavButtonController(service, SystemUiProxy.INSTANCE.get(mContext), new Handler(), AssistUtils.newInstance(mContext)); @@ -588,6 +618,7 @@ public class TaskbarManager { Log.d(TASKBAR_NOT_DESTROYED_TAG, "unregistering component callbacks from destroy()."); mContext.unregisterComponentCallbacks(mComponentCallbacks); mContext.unregisterReceiver(mShutdownReceiver); + mDeviceStateManager.unregisterCallback(mFoldStateListener); } public @Nullable TaskbarActivityContext getCurrentActivityContext() {