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

Commit eac832ae authored by Stefan Andonian's avatar Stefan Andonian Committed by Android (Google) Code Review
Browse files

Merge "Load Delegate Items in correct order when loading Launcher Data." into udc-dev

parents a61ac589 e4609a27
Loading
Loading
Loading
Loading
+66 −26
Original line number Original line Diff line number Diff line
@@ -48,11 +48,15 @@ import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
import android.util.StatsEvent;
import android.util.StatsEvent;


import androidx.annotation.AnyThread;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import androidx.annotation.WorkerThread;


import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logger.LauncherAtom;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceId;
import com.android.launcher3.logging.InstanceIdSequence;
import com.android.launcher3.logging.InstanceIdSequence;
@@ -62,6 +66,7 @@ import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.shortcuts.ShortcutKey;
import com.android.launcher3.util.Executors;
import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.PersistedItemArray;
import com.android.launcher3.util.PersistedItemArray;
import com.android.quickstep.logging.SettingsChangeLogger;
import com.android.quickstep.logging.SettingsChangeLogger;
@@ -111,45 +116,80 @@ public class QuickstepModelDelegate extends ModelDelegate {
        mStatsManager = context.getSystemService(StatsManager.class);
        mStatsManager = context.getSystemService(StatsManager.class);
    }
    }


    @CallSuper
    @Override
    @Override
    public void loadHotseatItems(UserManagerState ums,
    public void loadAndBindWorkspaceItems(@NonNull UserManagerState ums,
            Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) {
            @NonNull BgDataModel.Callbacks[] callbacks,
        // TODO: Implement caching and preloading
            @NonNull Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) {
        super.loadHotseatItems(ums, pinnedShortcuts);
        loadAndBindItems(ums, pinnedShortcuts, callbacks, mIDP.numDatabaseHotseatIcons,

                mHotseatState);
        WorkspaceItemFactory hotseatFactory = new WorkspaceItemFactory(mApp, ums, pinnedShortcuts,
                mIDP.numDatabaseHotseatIcons, mHotseatState.containerId);
        FixedContainerItems hotseatItems = new FixedContainerItems(mHotseatState.containerId,
                mHotseatState.storage.read(mApp.getContext(), hotseatFactory, ums.allUsers::get));
        mDataModel.extraItems.put(mHotseatState.containerId, hotseatItems);
    }
    }


    @CallSuper
    @Override
    @Override
    public void loadAllAppsItems(UserManagerState ums,
    public void loadAndBindAllAppsItems(@NonNull UserManagerState ums,
            Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) {
            @NonNull BgDataModel.Callbacks[] callbacks,
            @NonNull Map<ShortcutKey, ShortcutInfo> pinnedShortcuts) {
        loadAndBindItems(ums, pinnedShortcuts, callbacks, mIDP.numDatabaseAllAppsColumns,
                mAllAppsState);
    }

    @WorkerThread
    private void loadAndBindItems(@NonNull UserManagerState ums,
            @NonNull Map<ShortcutKey, ShortcutInfo> pinnedShortcuts,
            @NonNull BgDataModel.Callbacks[] callbacks,
            int numColumns, @NonNull PredictorState state) {
        // TODO: Implement caching and preloading
        // TODO: Implement caching and preloading
        super.loadAllAppsItems(ums, pinnedShortcuts);


        WorkspaceItemFactory allAppsFactory = new WorkspaceItemFactory(mApp, ums, pinnedShortcuts,
        WorkspaceItemFactory factory =
                mIDP.numDatabaseAllAppsColumns, mAllAppsState.containerId);
                new WorkspaceItemFactory(mApp, ums, pinnedShortcuts, numColumns, state.containerId);
        FixedContainerItems allAppsPredictionItems = new FixedContainerItems(
        FixedContainerItems fci = new FixedContainerItems(state.containerId,
                mAllAppsState.containerId, mAllAppsState.storage.read(mApp.getContext(),
                state.storage.read(mApp.getContext(), factory, ums.allUsers::get));
                allAppsFactory, ums.allUsers::get));
        if (FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
        mDataModel.extraItems.put(mAllAppsState.containerId, allAppsPredictionItems);
            bindPredictionItems(callbacks, fci);
        }
        mDataModel.extraItems.put(state.containerId, fci);
    }
    }


    @CallSuper
    @Override
    @Override
    public void loadWidgetsRecommendationItems() {
    public void loadAndBindOtherItems(@NonNull BgDataModel.Callbacks[] callbacks) {
        // TODO: Implement caching and preloading
        FixedContainerItems widgetPredictionFCI = new FixedContainerItems(
        super.loadWidgetsRecommendationItems();
                mWidgetsRecommendationState.containerId, new ArrayList<>());


        // Widgets prediction isn't used frequently. And thus, it is not persisted on disk.
        // Widgets prediction isn't used frequently. And thus, it is not persisted on disk.
        mDataModel.extraItems.put(mWidgetsRecommendationState.containerId,
        mDataModel.extraItems.put(mWidgetsRecommendationState.containerId, widgetPredictionFCI);
                new FixedContainerItems(mWidgetsRecommendationState.containerId,

                        new ArrayList<>()));
        bindPredictionItems(callbacks, widgetPredictionFCI);
        loadStringCache(mDataModel.stringCache);
    }

    @AnyThread
    private void bindPredictionItems(@NonNull BgDataModel.Callbacks[] callbacks,
            @NonNull FixedContainerItems fci) {
        Executors.MAIN_EXECUTOR.execute(() -> {
            for (BgDataModel.Callbacks c : callbacks) {
                c.bindExtraContainerItems(fci);
            }
        });
    }
    }


    @Override
    @Override
    @WorkerThread
    public void bindAllModelExtras(@NonNull BgDataModel.Callbacks[] callbacks) {
        Iterable<FixedContainerItems> containerItems;
        synchronized (mDataModel.extraItems) {
            containerItems = mDataModel.extraItems.clone();
        }
        Executors.MAIN_EXECUTOR.execute(() -> {
            for (BgDataModel.Callbacks c : callbacks) {
                for (FixedContainerItems fci : containerItems) {
                    c.bindExtraContainerItems(fci);
                }
            }
        });
    }

    public void markActive() {
    public void markActive() {
        super.markActive();
        super.markActive();
        mActive = true;
        mActive = true;
+3 −0
Original line number Original line Diff line number Diff line
@@ -421,6 +421,9 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
                    launcherBinder.bindAllApps();
                    launcherBinder.bindAllApps();
                    launcherBinder.bindDeepShortcuts();
                    launcherBinder.bindDeepShortcuts();
                    launcherBinder.bindWidgets();
                    launcherBinder.bindWidgets();
                    if (FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
                        mModelDelegate.bindAllModelExtras(callbacksList);
                    }
                    return true;
                    return true;
                } else {
                } else {
                    stopLoader();
                    stopLoader();
+5 −0
Original line number Original line Diff line number Diff line
@@ -349,6 +349,11 @@ public final class FeatureFlags {
            "load the current workspace screen visible to the user before the rest rather than "
            "load the current workspace screen visible to the user before the rest rather than "
                    + "loading all of them at once.");
                    + "loading all of them at once.");


    public static final BooleanFlag CHANGE_MODEL_DELEGATE_LOADING_ORDER = getDebugFlag(251502424,
            "CHANGE_MODEL_DELEGATE_LOADING_ORDER", DISABLED,
            "changes the timing of the loading and binding of delegate items during "
                    + "data preparation for loading the home screen");

    public static final BooleanFlag ENABLE_GRID_ONLY_OVERVIEW = getDebugFlag(270397206,
    public static final BooleanFlag ENABLE_GRID_ONLY_OVERVIEW = getDebugFlag(270397206,
            "ENABLE_GRID_ONLY_OVERVIEW", DISABLED,
            "ENABLE_GRID_ONLY_OVERVIEW", DISABLED,
            "Enable a grid-only overview without a focused task.");
            "Enable a grid-only overview without a focused task.");
+2 −2
Original line number Original line Diff line number Diff line
@@ -229,8 +229,8 @@ public class PreviewSurfaceRenderer {
                        query += " or " + LauncherSettings.Favorites.SCREEN + " = "
                        query += " or " + LauncherSettings.Favorites.SCREEN + " = "
                                + Workspace.SECOND_SCREEN_ID;
                                + Workspace.SECOND_SCREEN_ID;
                    }
                    }
                    loadWorkspace(new ArrayList<>(), LauncherSettings.Favorites.PREVIEW_CONTENT_URI,
                    loadWorkspaceForPreviewSurfaceRenderer(new ArrayList<>(),
                            query);
                            LauncherSettings.Favorites.PREVIEW_CONTENT_URI, query);


                    final SparseArray<Size> spanInfo =
                    final SparseArray<Size> spanInfo =
                            getLoadedLauncherWidgetInfo(previewContext.getBaseContext());
                            getLoadedLauncherWidgetInfo(previewContext.getBaseContext());
+13 −3
Original line number Original line Diff line number Diff line
@@ -63,7 +63,7 @@ public abstract class BaseLauncherBinder {
    protected final BgDataModel mBgDataModel;
    protected final BgDataModel mBgDataModel;
    private final AllAppsList mBgAllAppsList;
    private final AllAppsList mBgAllAppsList;


    private final Callbacks[] mCallbacksList;
    final Callbacks[] mCallbacksList;


    private int mMyBindingId;
    private int mMyBindingId;


@@ -293,8 +293,10 @@ public abstract class BaseLauncherBinder {
            // Load items on the current page.
            // Load items on the current page.
            bindWorkspaceItems(currentWorkspaceItems, mUiExecutor);
            bindWorkspaceItems(currentWorkspaceItems, mUiExecutor);
            bindAppWidgets(currentAppWidgets, mUiExecutor);
            bindAppWidgets(currentAppWidgets, mUiExecutor);
            if (!FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
                mExtraItems.forEach(item ->
                mExtraItems.forEach(item ->
                        executeCallbacksTask(c -> c.bindExtraContainerItems(item), mUiExecutor));
                        executeCallbacksTask(c -> c.bindExtraContainerItems(item), mUiExecutor));
            }


            RunnableList pendingTasks = new RunnableList();
            RunnableList pendingTasks = new RunnableList();
            Executor pendingExecutor = pendingTasks::add;
            Executor pendingExecutor = pendingTasks::add;
@@ -382,14 +384,22 @@ public abstract class BaseLauncherBinder {
            // Save a copy of all the bg-thread collections
            // Save a copy of all the bg-thread collections
            ArrayList<ItemInfo> workspaceItems;
            ArrayList<ItemInfo> workspaceItems;
            ArrayList<LauncherAppWidgetInfo> appWidgets;
            ArrayList<LauncherAppWidgetInfo> appWidgets;
            ArrayList<FixedContainerItems> fciList = new ArrayList<>();


            synchronized (mBgDataModel) {
            synchronized (mBgDataModel) {
                workspaceItems = new ArrayList<>(mBgDataModel.workspaceItems);
                workspaceItems = new ArrayList<>(mBgDataModel.workspaceItems);
                appWidgets = new ArrayList<>(mBgDataModel.appWidgets);
                appWidgets = new ArrayList<>(mBgDataModel.appWidgets);
                if (!FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
                    mBgDataModel.extraItems.forEach(fciList::add);
                }
            }
            }


            workspaceItems.forEach(it -> mBoundItemIds.add(it.id));
            workspaceItems.forEach(it -> mBoundItemIds.add(it.id));
            appWidgets.forEach(it -> mBoundItemIds.add(it.id));
            appWidgets.forEach(it -> mBoundItemIds.add(it.id));
            if (!FeatureFlags.CHANGE_MODEL_DELEGATE_LOADING_ORDER.get()) {
                fciList.forEach(item ->
                        executeCallbacksTask(c -> c.bindExtraContainerItems(item), mUiExecutor));
            }


            sortWorkspaceItemsSpatially(mApp.getInvariantDeviceProfile(), workspaceItems);
            sortWorkspaceItemsSpatially(mApp.getInvariantDeviceProfile(), workspaceItems);


Loading