From e337a80ef2a6b3fe3c81f99d911fd6afd3aff314 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 14 Feb 2024 15:07:26 -0800 Subject: [PATCH] Cleaning up some no-op calls during workspace binding Bug: 318539160 Flag: None Test: Manual Change-Id: Ida21d849a06ed9c0ebf5671214dd9ee8525288d3 --- .../uioverrides/QuickstepLauncher.java | 20 +++-------- src/com/android/launcher3/Launcher.java | 7 ---- src/com/android/launcher3/ModelCallbacks.kt | 33 ++++++++----------- .../launcher3/util/ViewOnDrawExecutor.java | 29 ++++++---------- 4 files changed, 28 insertions(+), 61 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index c2a248db6e..f3f36c5abb 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -21,6 +21,7 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_OPTIMIZE_MEAS import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED; import static com.android.app.animation.Interpolators.EMPHASIZED; +import static com.android.launcher3.Flags.enablePredictiveBackGesture; import static com.android.launcher3.Flags.enableUnfoldStateAnimation; import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.PENDING_SPLIT_SELECT_INFO; import static com.android.launcher3.LauncherConstants.SavedInstanceKeys.RUNTIME_STATE; @@ -61,7 +62,6 @@ import static com.android.quickstep.util.SplitAnimationTimings.TABLET_HOME_TO_SP import static com.android.quickstep.views.DesktopTaskView.isDesktopModeSupported; import static com.android.systemui.shared.system.ActivityManagerWrapper.CLOSE_SYSTEM_WINDOWS_REASON_HOME_KEY; import static com.android.wm.shell.common.split.SplitScreenConstants.SNAP_TO_50_50; -import static com.android.launcher3.Flags.enablePredictiveBackGesture; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -1103,21 +1103,11 @@ public class QuickstepLauncher extends Launcher { // populating workspace. // TODO: Find a better place for this WellbeingModel.INSTANCE.get(this); - } - @Override - public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks, - int workspaceItemCount, boolean isBindSync) { - pendingTasks.add(() -> { - // This is added in pending task as we need to wait for views to be positioned - // correctly before registering them for the animation. - if (mLauncherUnfoldAnimationController != null) { - // This is needed in case items are rebound while the unfold animation is in - // progress. - mLauncherUnfoldAnimationController.updateRegisteredViewsIfNeeded(); - } - }); - super.onInitialBindComplete(boundPages, pendingTasks, workspaceItemCount, isBindSync); + if (mLauncherUnfoldAnimationController != null) { + // This is needed in case items are rebound while the unfold animation is in progress. + mLauncherUnfoldAnimationController.updateRegisteredViewsIfNeeded(); + } } @Override diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 2b203e110f..247125469f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -237,7 +237,6 @@ import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.TouchController; import com.android.launcher3.util.TraceHelper; -import com.android.launcher3.util.ViewOnDrawExecutor; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.views.ComposeInitializer; import com.android.launcher3.views.FloatingIconView; @@ -2233,12 +2232,6 @@ public class Launcher extends StatefulActivity return info; } - public void clearPendingExecutor(ViewOnDrawExecutor executor) { - if (mModelCallbacks.getPendingExecutor() == executor) { - mModelCallbacks.setPendingExecutor(null); - } - } - /** * Call back when ModelCallbacks finish binding the Launcher data. */ diff --git a/src/com/android/launcher3/ModelCallbacks.kt b/src/com/android/launcher3/ModelCallbacks.kt index f6bc1f14cb..0e3800701a 100644 --- a/src/com/android/launcher3/ModelCallbacks.kt +++ b/src/com/android/launcher3/ModelCallbacks.kt @@ -3,7 +3,6 @@ package com.android.launcher3 import android.annotation.TargetApi import android.os.Build import android.os.Trace -import android.view.ViewTreeObserver.OnDrawListener import androidx.annotation.UiThread import com.android.launcher3.LauncherConstants.TraceEvents import com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID @@ -18,7 +17,6 @@ import com.android.launcher3.model.data.LauncherAppWidgetInfo import com.android.launcher3.model.data.WorkspaceItemInfo import com.android.launcher3.popup.PopupContainerWithArrow import com.android.launcher3.util.ComponentKey -import com.android.launcher3.util.Executors import com.android.launcher3.util.IntArray as LIntArray import com.android.launcher3.util.IntSet as LIntSet import com.android.launcher3.util.PackageUserKey @@ -77,11 +75,15 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { workspaceItemCount: Int, isBindSync: Boolean ) { + if (Utilities.ATLEAST_S) { + Trace.endAsyncSection( + TraceEvents.DISPLAY_WORKSPACE_TRACE_METHOD_NAME, + TraceEvents.DISPLAY_WORKSPACE_TRACE_COOKIE + ) + } synchronouslyBoundPages = boundPages pagesToBindSynchronously = LIntSet() clearPendingBinds() - val executor = ViewOnDrawExecutor(pendingTasks) - pendingExecutor = executor if (!launcher.isInState(LauncherState.ALL_APPS)) { launcher.appsView.appsStore.enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW) pendingTasks.add { @@ -90,24 +92,15 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { ) } } - executor.onLoadAnimationCompleted() - executor.attachTo(launcher) - if (Utilities.ATLEAST_S) { - Trace.endAsyncSection( - TraceEvents.DISPLAY_WORKSPACE_TRACE_METHOD_NAME, - TraceEvents.DISPLAY_WORKSPACE_TRACE_COOKIE - ) - } - launcher.bindComplete(workspaceItemCount, isBindSync) - launcher.rootView.viewTreeObserver.addOnDrawListener( - object : OnDrawListener { - override fun onDraw() { - Executors.MAIN_EXECUTOR.handler.postAtFrontOfQueue { - launcher.rootView.getViewTreeObserver().removeOnDrawListener(this) - } + val executor = + ViewOnDrawExecutor(pendingTasks) { + if (pendingExecutor == it) { + pendingExecutor = null } } - ) + pendingExecutor = executor + executor.attachTo(launcher) + launcher.bindComplete(workspaceItemCount, isBindSync) } /** diff --git a/src/com/android/launcher3/util/ViewOnDrawExecutor.java b/src/com/android/launcher3/util/ViewOnDrawExecutor.java index fada4a3f01..26bfd36dcf 100644 --- a/src/com/android/launcher3/util/ViewOnDrawExecutor.java +++ b/src/com/android/launcher3/util/ViewOnDrawExecutor.java @@ -20,6 +20,8 @@ import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.ViewTreeObserver.OnDrawListener; +import androidx.annotation.NonNull; + import com.android.launcher3.Launcher; import java.util.function.Consumer; @@ -31,26 +33,23 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable, OnAttachStateChangeListener { private final RunnableList mTasks; - - private Consumer mOnClearCallback; + private final Consumer mOnClearCallback; private View mAttachedView; private boolean mCompleted; - private boolean mLoadAnimationCompleted; private boolean mFirstDrawCompleted; private boolean mCancelled; - public ViewOnDrawExecutor(RunnableList tasks) { + public ViewOnDrawExecutor(RunnableList tasks, + @NonNull Consumer onClearCallback) { mTasks = tasks; + mOnClearCallback = onClearCallback; } public void attachTo(Launcher launcher) { - mOnClearCallback = launcher::clearPendingExecutor; mAttachedView = launcher.getWorkspace(); - mAttachedView.addOnAttachStateChangeListener(this); - if (mAttachedView.isAttachedToWindow()) { attachObserver(); } @@ -77,17 +76,10 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable, mAttachedView.post(this); } - public void onLoadAnimationCompleted() { - mLoadAnimationCompleted = true; - if (mAttachedView != null) { - mAttachedView.post(this); - } - } - @Override public void run() { - // Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called. - if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) { + // Post the pending tasks after first draw + if (mFirstDrawCompleted && !mCompleted) { markCompleted(); } } @@ -104,9 +96,8 @@ public class ViewOnDrawExecutor implements OnDrawListener, Runnable, mAttachedView.getViewTreeObserver().removeOnDrawListener(this); mAttachedView.removeOnAttachStateChangeListener(this); } - if (mOnClearCallback != null) { - mOnClearCallback.accept(this); - } + + mOnClearCallback.accept(this); } public void cancel() {