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

Commit e82476ad authored by Stefan Andonian's avatar Stefan Andonian
Browse files

Rename LoaderResults to LauncherBinder.

LoaderResults implies a data object, not binding code specific to
Launcher UX containers. This CL merely renames this class and its
usages. It also adds a comment that explains why the functionality is
split into a base class and an implementing class.

Bug: 251502424
Test: Compilation worked correctly.
Change-Id: I01b5ac2f717e9b20612538d5c1e0ca947beb593f
parent 616de308
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.model.BgDataModel.Callbacks;

/**
 * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}.
 * Binds the results of {@link com.android.launcher3.model.LoaderTask} to the Callbacks objects.
 */
public class LoaderResults extends BaseLoaderResults {
public class LauncherBinder extends BaseLauncherBinder {

    public LoaderResults(LauncherAppState app, BgDataModel dataModel,
    public LauncherBinder(LauncherAppState app, BgDataModel dataModel,
            AllAppsList allAppsList, Callbacks[] callbacks) {
        super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR);
    }
+7 −7
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.CacheDataUpdatedTask;
import com.android.launcher3.model.ItemInstallQueue;
import com.android.launcher3.model.LoaderResults;
import com.android.launcher3.model.LauncherBinder;
import com.android.launcher3.model.LoaderTask;
import com.android.launcher3.model.ModelDelegate;
import com.android.launcher3.model.ModelWriter;
@@ -405,22 +405,22 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
                    MAIN_EXECUTOR.execute(cb::clearPendingBinds);
                }

                LoaderResults loaderResults = new LoaderResults(
                LauncherBinder launcherBinder = new LauncherBinder(
                        mApp, mBgDataModel, mBgAllAppsList, callbacksList);
                if (bindDirectly) {
                    // Divide the set of loaded items into those that we are binding synchronously,
                    // and everything else that is to be bound normally (asynchronously).
                    loaderResults.bindWorkspace(bindAllCallbacks);
                    launcherBinder.bindWorkspace(bindAllCallbacks);
                    // For now, continue posting the binding of AllApps as there are other
                    // issues that arise from that.
                    loaderResults.bindAllApps();
                    loaderResults.bindDeepShortcuts();
                    loaderResults.bindWidgets();
                    launcherBinder.bindAllApps();
                    launcherBinder.bindDeepShortcuts();
                    launcherBinder.bindWidgets();
                    return true;
                } else {
                    stopLoader();
                    mLoaderTask = new LoaderTask(
                            mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults);
                            mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, launcherBinder);

                    // Always post the loader task, instead of running directly
                    // (even on same thread) so that we exit any nested synchronized blocks
+16 −5
Original line number Diff line number Diff line
@@ -47,12 +47,11 @@ import java.util.Objects;
import java.util.concurrent.Executor;

/**
 * Base Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}.
 * Binds the results of {@link com.android.launcher3.model.LoaderTask} to the Callbacks objects.
 */
public abstract class BaseLoaderResults {
public abstract class BaseLauncherBinder {

    protected static final String TAG = "LoaderResults";
    protected static final int INVALID_SCREEN_ID = -1;
    protected static final String TAG = "LauncherBinder";
    private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons

    protected final LooperExecutor mUiExecutor;
@@ -65,7 +64,7 @@ public abstract class BaseLoaderResults {

    private int mMyBindingId;

    public BaseLoaderResults(LauncherAppState app, BgDataModel dataModel,
    public BaseLauncherBinder(LauncherAppState app, BgDataModel dataModel,
            AllAppsList allAppsList, Callbacks[] callbacksList, LooperExecutor uiExecutor) {
        mUiExecutor = uiExecutor;
        mApp = app;
@@ -101,8 +100,14 @@ public abstract class BaseLoaderResults {
        }
    }

    /**
     * BindDeepShortcuts is abstract because it is a no-op for the go launcher.
     */
    public abstract void bindDeepShortcuts();

    /**
     * Binds the all apps results from LoaderTask to the callbacks UX.
     */
    public void bindAllApps() {
        // shallow copy
        AppInfo[] apps = mBgAllAppsList.copyData();
@@ -110,6 +115,9 @@ public abstract class BaseLoaderResults {
        executeCallbacksTask(c -> c.bindAllApplications(apps, flags), mUiExecutor);
    }

    /**
     * bindWidgets is abstract because it is a no-op for the go launcher.
     */
    public abstract void bindWidgets();

    /**
@@ -160,6 +168,9 @@ public abstract class BaseLoaderResults {
        });
    }

    /**
     * Only used in LoaderTask.
     */
    public LooperIdleLock newIdleLock(Object lock) {
        LooperIdleLock idleLock = new LooperIdleLock(lock, mUiExecutor.getLooper());
        // If we are not binding or if the main looper is already idle, there is no reason to wait
+8 −8
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public class LoaderTask implements Runnable {

    private FirstScreenBroadcast mFirstScreenBroadcast;

    private final LoaderResults mResults;
    private final LauncherBinder mLauncherBinder;

    private final LauncherApps mLauncherApps;
    private final UserManager mUserManager;
@@ -145,12 +145,12 @@ public class LoaderTask implements Runnable {
    private String mDbName;

    public LoaderTask(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel,
            ModelDelegate modelDelegate, LoaderResults results) {
            ModelDelegate modelDelegate, LauncherBinder launcherBinder) {
        mApp = app;
        mBgAllAppsList = bgAllAppsList;
        mBgDataModel = dataModel;
        mModelDelegate = modelDelegate;
        mResults = results;
        mLauncherBinder = launcherBinder;

        mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class);
        mUserManager = mApp.getContext().getSystemService(UserManager.class);
@@ -163,7 +163,7 @@ public class LoaderTask implements Runnable {
        // Wait until the either we're stopped or the other threads are done.
        // This way we don't start loading all apps until the workspace has settled
        // down.
        LooperIdleLock idleLock = mResults.newIdleLock(this);
        LooperIdleLock idleLock = mLauncherBinder.newIdleLock(this);
        // Just in case mFlushingWorkerThread changes but we aren't woken up,
        // wait no longer than 1sec at a time
        while (!mStopped && idleLock.awaitLocked(1000));
@@ -221,7 +221,7 @@ public class LoaderTask implements Runnable {
            }

            verifyNotStopped();
            mResults.bindWorkspace(true /* incrementBindId */);
            mLauncherBinder.bindWorkspace(true /* incrementBindId */);
            logASplit(logger, "bindWorkspace");

            mModelDelegate.workspaceLoadComplete();
@@ -245,7 +245,7 @@ public class LoaderTask implements Runnable {
            logASplit(logger, "loadAllApps");

            verifyNotStopped();
            mResults.bindAllApps();
            mLauncherBinder.bindAllApps();
            logASplit(logger, "bindAllApps");

            verifyNotStopped();
@@ -271,7 +271,7 @@ public class LoaderTask implements Runnable {
            logASplit(logger, "loadDeepShortcuts");

            verifyNotStopped();
            mResults.bindDeepShortcuts();
            mLauncherBinder.bindDeepShortcuts();
            logASplit(logger, "bindDeepShortcuts");

            verifyNotStopped();
@@ -290,7 +290,7 @@ public class LoaderTask implements Runnable {
            logASplit(logger, "load widgets");

            verifyNotStopped();
            mResults.bindWidgets();
            mLauncherBinder.bindWidgets();
            logASplit(logger, "bindWidgets");
            verifyNotStopped();

+3 −3
Original line number Diff line number Diff line
@@ -27,11 +27,11 @@ import java.util.HashMap;
import java.util.List;

/**
 * Helper class to handle results of {@link com.android.launcher3.model.LoaderTask}.
 * Binds the results of {@link com.android.launcher3.model.LoaderTask} to the Callbacks objects.
 */
public class LoaderResults extends BaseLoaderResults {
public class LauncherBinder extends BaseLauncherBinder {

    public LoaderResults(LauncherAppState app, BgDataModel dataModel,
    public LauncherBinder(LauncherAppState app, BgDataModel dataModel,
            AllAppsList allAppsList, Callbacks[] callbacks) {
        super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR);
    }