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

Commit f217079a authored by Sebastián Franco's avatar Sebastián Franco Committed by Android (Google) Code Review
Browse files

Merge "Move onInitialBindComplete to ModelCallbacks" into main

parents 04e04456 0b461efe
Loading
Loading
Loading
Loading
+13 −36
Original line number Diff line number Diff line
@@ -80,7 +80,6 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent.LAUNCHER_LATENCY_STARTUP_ACTIVITY_ON_CREATE;
import static com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent.LAUNCHER_LATENCY_STARTUP_TOTAL_DURATION;
import static com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent.LAUNCHER_LATENCY_STARTUP_VIEW_INFLATION;
import static com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent.LAUNCHER_LATENCY_STARTUP_WORKSPACE_LOADER_ASYNC;
import static com.android.launcher3.logging.StatsLogManager.StatsLatencyLogger.LatencyType.COLD;
import static com.android.launcher3.logging.StatsLogManager.StatsLatencyLogger.LatencyType.COLD_DEVICE_REBOOTING;
import static com.android.launcher3.logging.StatsLogManager.StatsLatencyLogger.LatencyType.WARM;
@@ -139,7 +138,6 @@ import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.view.WindowManager.LayoutParams;
import android.view.accessibility.AccessibilityEvent;
@@ -159,7 +157,6 @@ import com.android.launcher3.DropTarget.DragObject;
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.allapps.AllAppsRecyclerView;
import com.android.launcher3.allapps.AllAppsStore;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.allapps.DiscoveryBounce;
import com.android.launcher3.anim.AnimationSuccessListener;
@@ -189,6 +186,7 @@ import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.logging.StartupLatencyLogger;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.model.ModelWriter;
@@ -2475,39 +2473,20 @@ public class Launcher extends StatefulActivity<LauncherState>
        }
    }

    @Override
    /**
     * Call back when ModelCallbacks finish binding the Launcher data.
     */
    @TargetApi(Build.VERSION_CODES.S)
    public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks,
            int workspaceItemCount, boolean isBindSync) {
        mModelCallbacks.setSynchronouslyBoundPages(boundPages);
        mModelCallbacks.setPagesToBindSynchronously(new IntSet());

        mModelCallbacks.clearPendingBinds();
        ViewOnDrawExecutor executor = new ViewOnDrawExecutor(pendingTasks);
        mModelCallbacks.setPendingExecutor(executor);
        if (!isInState(ALL_APPS)) {
            mAppsView.getAppsStore().enableDeferUpdates(AllAppsStore.DEFER_UPDATES_NEXT_DRAW);
            pendingTasks.add(() -> mAppsView.getAppsStore().disableDeferUpdates(
                    AllAppsStore.DEFER_UPDATES_NEXT_DRAW));
        }

    public void bindComplete(int workspaceItemCount, boolean isBindSync) {
        if (mOnInitialBindListener != null) {
            getRootView().getViewTreeObserver().removeOnPreDrawListener(mOnInitialBindListener);
            mOnInitialBindListener = null;
        }

        executor.onLoadAnimationCompleted();
        executor.attachTo(this);
        if (Utilities.ATLEAST_S) {
            Trace.endAsyncSection(DISPLAY_WORKSPACE_TRACE_METHOD_NAME,
                    DISPLAY_WORKSPACE_TRACE_COOKIE);
        }
        if (!isBindSync) {
            mStartupLatencyLogger
                    .logCardinality(workspaceItemCount)
                    .logEnd(LAUNCHER_LATENCY_STARTUP_WORKSPACE_LOADER_ASYNC);
                    .logEnd(LauncherLatencyEvent.LAUNCHER_LATENCY_STARTUP_WORKSPACE_LOADER_ASYNC);
        }

        MAIN_EXECUTOR.getHandler().postAtFrontOfQueue(() -> {
            mStartupLatencyLogger
                    .logEnd(LAUNCHER_LATENCY_STARTUP_TOTAL_DURATION)
@@ -2518,15 +2497,13 @@ public class Launcher extends StatefulActivity<LauncherState>
                        COLD_STARTUP_TRACE_COOKIE);
            }
        });
        getRootView().getViewTreeObserver().addOnDrawListener(
                new ViewTreeObserver.OnDrawListener() {
                    @Override
                    public void onDraw() {
                        MAIN_EXECUTOR.getHandler().postAtFrontOfQueue(
                                () -> getRootView().getViewTreeObserver()
                                        .removeOnDrawListener(this));
    }
                });

    @Override
    public void onInitialBindComplete(IntSet boundPages, RunnableList pendingTasks,
            int workspaceItemCount, boolean isBindSync) {
        mModelCallbacks.onInitialBindComplete(boundPages, pendingTasks, workspaceItemCount,
                isBindSync);
    }

    /**
+50 −4
Original line number Diff line number Diff line
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
import com.android.launcher3.allapps.AllAppsStore
import com.android.launcher3.config.FeatureFlags
@@ -13,11 +18,12 @@ 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.IntSet
import com.android.launcher3.util.PackageUserKey
import com.android.launcher3.util.Preconditions
import com.android.launcher3.util.RunnableList
import com.android.launcher3.util.TraceHelper
import com.android.launcher3.util.ViewOnDrawExecutor
import com.android.launcher3.widget.PendingAddWidgetInfo
@@ -64,6 +70,46 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
        TraceHelper.INSTANCE.endSection()
    }

    @TargetApi(Build.VERSION_CODES.S)
    override fun onInitialBindComplete(
        boundPages: LIntSet,
        pendingTasks: RunnableList,
        workspaceItemCount: Int,
        isBindSync: Boolean
    ) {
        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 {
                launcher.appsView.appsStore.disableDeferUpdates(
                    AllAppsStore.DEFER_UPDATES_NEXT_DRAW
                )
            }
        }
        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)
                    }
                }
            }
        )
    }

    /**
     * Callback saying that there aren't any more items to bind.
     *
@@ -83,7 +129,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
        // Since we are just resetting the current page without user interaction,
        // override the previous page so we don't log the page switch.
        launcher.workspace.setCurrentPage(currentPage, currentPage /* overridePrevPage */)
        pagesToBindSynchronously = IntSet()
        pagesToBindSynchronously = LIntSet()

        // Cache one page worth of icons
        launcher.viewCache.setCacheSize(
@@ -319,7 +365,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
            } else {
                // Some empty pages might have been removed while the phone was in a single panel
                // mode, so we want to add those empty pages back.
                val screenIds = IntSet.wrap(orderedScreenIds)
                val screenIds = LIntSet.wrap(orderedScreenIds)
                orderedScreenIds.forEach { screenId: Int ->
                    screenIds.add(launcher.workspace.getScreenPair(screenId))
                }
@@ -343,7 +389,7 @@ class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks {
     * if not present.
     */
    private fun filterTwoPanelScreenIds(orderedScreenIds: LIntArray): LIntArray {
        val screenIds = IntSet.wrap(orderedScreenIds)
        val screenIds = LIntSet.wrap(orderedScreenIds)
        orderedScreenIds
            .filter { screenId -> screenId % 2 == 1 }
            .forEach { screenId ->