From ccd359d76c7f42d4fc799f19d54a66c7c2fa462a Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 6 Jul 2023 22:01:49 +0000 Subject: [PATCH] Fix an issue with nav bar translations not being updated - There are flows where the shared taskbar state is updated prior to being destroyed, and not updated to the latest values when the taskbar is recreated. ie. unfolded -> lock screen -> LauncherTaskbarUiController's mTaskbarInAppDisplayProgress[SYSUI_SURFACE_PROGRESS_INDEX] is set to 1 due to the notif shade (lockscreen) showing. This is written into TaskbarSharedState's sysuiStateFlags and inAppDisplayProgressMultiPropValues. fold -> TaskbarActivityContext is destroyed unlock -> TaskbarManager and TaskbarSharedState's sysuiStateFlags are updated while the device is folded unfold -> TaskbarActivityContext is recreated and initialized which restores from the shared state's inAppDisplayProgressMultiPropValues. It also tries to reapply the shared state's sysuiStateFlags, but this doesn't update inAppDisplayProgressMultiPropValues because the state's "enabled" state is not updated (default is no flag set, and lockscreen sysui state is not set anymore). -> The restored inAppDisplayProgressMultiPropValues value results in the wrong translation. - Note that after the above, the NavbarButtonsViewController state is actually correct and reflects the SysUI state, but the LauncherTaskbarUiController state is wrong. This CL tries to manually update the ui controller to the correct state when it is recreated. - CL also fixes a separate issue where LauncherTaskbarUIController could potentially overwrite the saved state progresses while restoring them due to the state callback being called Bug: 283346744 Test: Unfold -> Lockscreen -> Fold -> Unlock -> Unfold and ensure the buttons are translated correctly Change-Id: I43e473faf4fa2a493b9705506e3755df8f6264e7 Signed-off-by: Winson Chung --- .../taskbar/LauncherTaskbarUIController.java | 5 +++++ .../taskbar/NavbarButtonsViewController.java | 9 +++++++++ .../launcher3/taskbar/TaskbarActivityContext.java | 4 +--- .../launcher3/taskbar/TaskbarControllers.java | 13 +++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java index ba6f1651ed..abf49eb195 100644 --- a/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java +++ b/quickstep/src/com/android/launcher3/taskbar/LauncherTaskbarUIController.java @@ -50,6 +50,7 @@ import com.android.quickstep.util.GroupTask; import com.android.quickstep.views.RecentsView; import java.io.PrintWriter; +import java.util.Arrays; /** * A data source which integrates with a Launcher instance @@ -105,6 +106,10 @@ public class LauncherTaskbarUIController extends TaskbarUIController { // Restore the in-app display progress from before Taskbar was recreated. float[] prevProgresses = mControllers.getSharedState().inAppDisplayProgressMultiPropValues; + // Make a copy of the previous progress to set since updating the multiprop will update + // the property which also calls onInAppDisplayProgressChanged() which writes the current + // values into the shared state + prevProgresses = Arrays.copyOf(prevProgresses, prevProgresses.length); for (int i = 0; i < prevProgresses.length; i++) { mTaskbarInAppDisplayProgressMultiProp.get(i).setValue(prevProgresses[i]); } diff --git a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java index 9a9e0ba70c..9c463cb68c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/NavbarButtonsViewController.java @@ -923,6 +923,15 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT insetsInfo.setTouchableInsets(TOUCHABLE_INSETS_REGION); } + /** + * Called whenever a new ui controller is set, and should update anything that depends on the + * ui controller. + */ + public void onUiControllerChanged() { + updateNavButtonInAppDisplayProgressForSysui(); + updateNavButtonTranslationY(); + } + @Override public void dumpLogs(String prefix, PrintWriter pw) { pw.println(prefix + "NavbarButtonsViewController:"); diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 43feec716d..a1390aeabb 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -591,9 +591,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { * Sets a new data-source for this taskbar instance */ public void setUIController(@NonNull TaskbarUIController uiController) { - mControllers.uiController.onDestroy(); - mControllers.uiController = uiController; - mControllers.uiController.init(mControllers); + mControllers.setUiController(uiController); } /** diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java index 66c2eb3314..d3f80e31cd 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarControllers.java @@ -196,6 +196,19 @@ public class TaskbarControllers { mPostInitCallbacks.clear(); } + /** + * Sets the ui controller. + */ + public void setUiController(@NonNull TaskbarUIController newUiController) { + uiController.onDestroy(); + uiController = newUiController; + uiController.init(this); + uiController.updateStateForSysuiFlags(mSharedState.sysuiStateFlags); + + // Notify that the ui controller has changed + navbarButtonsViewController.onUiControllerChanged(); + } + @Nullable public TaskbarSharedState getSharedState() { // This should only be null if called before init() and after destroy().