Merge "Rename LoaderResults to LauncherBinder." into tm-qpr-dev

This commit is contained in:
Stefan Andonian
2023-01-11 22:47:34 +00:00
committed by Android (Google) Code Review
5 changed files with 37 additions and 26 deletions
@@ -22,11 +22,11 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.model.BgDataModel.Callbacks; 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) { AllAppsList allAppsList, Callbacks[] callbacks) {
super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR); super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR);
} }
+7 -7
View File
@@ -47,7 +47,7 @@ import com.android.launcher3.model.BgDataModel;
import com.android.launcher3.model.BgDataModel.Callbacks; import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.CacheDataUpdatedTask; import com.android.launcher3.model.CacheDataUpdatedTask;
import com.android.launcher3.model.ItemInstallQueue; 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.LoaderTask;
import com.android.launcher3.model.ModelDelegate; import com.android.launcher3.model.ModelDelegate;
import com.android.launcher3.model.ModelWriter; import com.android.launcher3.model.ModelWriter;
@@ -405,22 +405,22 @@ public class LauncherModel extends LauncherApps.Callback implements InstallSessi
MAIN_EXECUTOR.execute(cb::clearPendingBinds); MAIN_EXECUTOR.execute(cb::clearPendingBinds);
} }
LoaderResults loaderResults = new LoaderResults( LauncherBinder launcherBinder = new LauncherBinder(
mApp, mBgDataModel, mBgAllAppsList, callbacksList); mApp, mBgDataModel, mBgAllAppsList, callbacksList);
if (bindDirectly) { if (bindDirectly) {
// Divide the set of loaded items into those that we are binding synchronously, // Divide the set of loaded items into those that we are binding synchronously,
// and everything else that is to be bound normally (asynchronously). // 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 // For now, continue posting the binding of AllApps as there are other
// issues that arise from that. // issues that arise from that.
loaderResults.bindAllApps(); launcherBinder.bindAllApps();
loaderResults.bindDeepShortcuts(); launcherBinder.bindDeepShortcuts();
loaderResults.bindWidgets(); launcherBinder.bindWidgets();
return true; return true;
} else { } else {
stopLoader(); stopLoader();
mLoaderTask = new LoaderTask( mLoaderTask = new LoaderTask(
mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, loaderResults); mApp, mBgAllAppsList, mBgDataModel, mModelDelegate, launcherBinder);
// Always post the loader task, instead of running directly // Always post the loader task, instead of running directly
// (even on same thread) so that we exit any nested synchronized blocks // (even on same thread) so that we exit any nested synchronized blocks
@@ -47,12 +47,11 @@ import java.util.Objects;
import java.util.concurrent.Executor; 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 String TAG = "LauncherBinder";
protected static final int INVALID_SCREEN_ID = -1;
private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons
protected final LooperExecutor mUiExecutor; protected final LooperExecutor mUiExecutor;
@@ -65,7 +64,7 @@ public abstract class BaseLoaderResults {
private int mMyBindingId; private int mMyBindingId;
public BaseLoaderResults(LauncherAppState app, BgDataModel dataModel, public BaseLauncherBinder(LauncherAppState app, BgDataModel dataModel,
AllAppsList allAppsList, Callbacks[] callbacksList, LooperExecutor uiExecutor) { AllAppsList allAppsList, Callbacks[] callbacksList, LooperExecutor uiExecutor) {
mUiExecutor = uiExecutor; mUiExecutor = uiExecutor;
mApp = app; 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(); public abstract void bindDeepShortcuts();
/**
* Binds the all apps results from LoaderTask to the callbacks UX.
*/
public void bindAllApps() { public void bindAllApps() {
// shallow copy // shallow copy
AppInfo[] apps = mBgAllAppsList.copyData(); AppInfo[] apps = mBgAllAppsList.copyData();
@@ -110,6 +115,9 @@ public abstract class BaseLoaderResults {
executeCallbacksTask(c -> c.bindAllApplications(apps, flags), mUiExecutor); executeCallbacksTask(c -> c.bindAllApplications(apps, flags), mUiExecutor);
} }
/**
* bindWidgets is abstract because it is a no-op for the go launcher.
*/
public abstract void bindWidgets(); public abstract void bindWidgets();
/** /**
@@ -160,6 +168,9 @@ public abstract class BaseLoaderResults {
}); });
} }
/**
* Only used in LoaderTask.
*/
public LooperIdleLock newIdleLock(Object lock) { public LooperIdleLock newIdleLock(Object lock) {
LooperIdleLock idleLock = new LooperIdleLock(lock, mUiExecutor.getLooper()); 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 // If we are not binding or if the main looper is already idle, there is no reason to wait
@@ -125,7 +125,7 @@ public class LoaderTask implements Runnable {
private FirstScreenBroadcast mFirstScreenBroadcast; private FirstScreenBroadcast mFirstScreenBroadcast;
private final LoaderResults mResults; private final LauncherBinder mLauncherBinder;
private final LauncherApps mLauncherApps; private final LauncherApps mLauncherApps;
private final UserManager mUserManager; private final UserManager mUserManager;
@@ -145,12 +145,12 @@ public class LoaderTask implements Runnable {
private String mDbName; private String mDbName;
public LoaderTask(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel, public LoaderTask(LauncherAppState app, AllAppsList bgAllAppsList, BgDataModel dataModel,
ModelDelegate modelDelegate, LoaderResults results) { ModelDelegate modelDelegate, LauncherBinder launcherBinder) {
mApp = app; mApp = app;
mBgAllAppsList = bgAllAppsList; mBgAllAppsList = bgAllAppsList;
mBgDataModel = dataModel; mBgDataModel = dataModel;
mModelDelegate = modelDelegate; mModelDelegate = modelDelegate;
mResults = results; mLauncherBinder = launcherBinder;
mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class); mLauncherApps = mApp.getContext().getSystemService(LauncherApps.class);
mUserManager = mApp.getContext().getSystemService(UserManager.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. // 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 // This way we don't start loading all apps until the workspace has settled
// down. // down.
LooperIdleLock idleLock = mResults.newIdleLock(this); LooperIdleLock idleLock = mLauncherBinder.newIdleLock(this);
// Just in case mFlushingWorkerThread changes but we aren't woken up, // Just in case mFlushingWorkerThread changes but we aren't woken up,
// wait no longer than 1sec at a time // wait no longer than 1sec at a time
while (!mStopped && idleLock.awaitLocked(1000)); while (!mStopped && idleLock.awaitLocked(1000));
@@ -221,7 +221,7 @@ public class LoaderTask implements Runnable {
} }
verifyNotStopped(); verifyNotStopped();
mResults.bindWorkspace(true /* incrementBindId */); mLauncherBinder.bindWorkspace(true /* incrementBindId */);
logASplit(logger, "bindWorkspace"); logASplit(logger, "bindWorkspace");
mModelDelegate.workspaceLoadComplete(); mModelDelegate.workspaceLoadComplete();
@@ -245,7 +245,7 @@ public class LoaderTask implements Runnable {
logASplit(logger, "loadAllApps"); logASplit(logger, "loadAllApps");
verifyNotStopped(); verifyNotStopped();
mResults.bindAllApps(); mLauncherBinder.bindAllApps();
logASplit(logger, "bindAllApps"); logASplit(logger, "bindAllApps");
verifyNotStopped(); verifyNotStopped();
@@ -271,7 +271,7 @@ public class LoaderTask implements Runnable {
logASplit(logger, "loadDeepShortcuts"); logASplit(logger, "loadDeepShortcuts");
verifyNotStopped(); verifyNotStopped();
mResults.bindDeepShortcuts(); mLauncherBinder.bindDeepShortcuts();
logASplit(logger, "bindDeepShortcuts"); logASplit(logger, "bindDeepShortcuts");
verifyNotStopped(); verifyNotStopped();
@@ -290,7 +290,7 @@ public class LoaderTask implements Runnable {
logASplit(logger, "load widgets"); logASplit(logger, "load widgets");
verifyNotStopped(); verifyNotStopped();
mResults.bindWidgets(); mLauncherBinder.bindWidgets();
logASplit(logger, "bindWidgets"); logASplit(logger, "bindWidgets");
verifyNotStopped(); verifyNotStopped();
@@ -27,11 +27,11 @@ import java.util.HashMap;
import java.util.List; 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) { AllAppsList allAppsList, Callbacks[] callbacks) {
super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR); super(app, dataModel, allAppsList, callbacks, MAIN_EXECUTOR);
} }