Binding Taskbar directly from Launcher model
This allows taskbar to be loaded even in case of 3P Launchers
and removes dependency on LauncherActivity lifecycle
Bug: 187353581
Bug: 188788621
Test: Manual
Change-Id: I5a0988e0697b41677d4c58f0213aef14ec0c0972
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index eef3980..6966abf 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -144,9 +144,10 @@
enqueueModelUpdateTask(new AddWorkspaceItemsTask(itemList));
}
- public ModelWriter getWriter(boolean hasVerticalHotseat, boolean verifyChanges) {
+ public ModelWriter getWriter(boolean hasVerticalHotseat, boolean verifyChanges,
+ @Nullable Callbacks owner) {
return new ModelWriter(mApp.getContext(), this, mBgDataModel,
- hasVerticalHotseat, verifyChanges);
+ hasVerticalHotseat, verifyChanges, owner);
}
@Override
@@ -329,7 +330,7 @@
public boolean addCallbacksAndLoad(Callbacks callbacks) {
synchronized (mLock) {
addCallbacks(callbacks);
- return startLoader();
+ return startLoader(new Callbacks[] { callbacks });
}
}
@@ -349,26 +350,32 @@
* @return true if the page could be bound synchronously.
*/
public boolean startLoader() {
+ return startLoader(new Callbacks[0]);
+ }
+
+ private boolean startLoader(Callbacks[] newCallbacks) {
// Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
ItemInstallQueue.INSTANCE.get(mApp.getContext())
.pauseModelPush(ItemInstallQueue.FLAG_LOADER_RUNNING);
synchronized (mLock) {
- // Don't bother to start the thread if we know it's not going to do anything
- final Callbacks[] callbacksList = getCallbacks();
+ // If there is already one running, tell it to stop.
+ boolean wasRunning = stopLoader();
+ boolean bindDirectly = mModelLoaded && !mIsLoaderTaskRunning;
+ boolean bindAllCallbacks = wasRunning || !bindDirectly || newCallbacks.length == 0;
+ final Callbacks[] callbacksList = bindAllCallbacks ? getCallbacks() : newCallbacks;
+
if (callbacksList.length > 0) {
// Clear any pending bind-runnables from the synchronized load process.
for (Callbacks cb : callbacksList) {
MAIN_EXECUTOR.execute(cb::clearPendingBinds);
}
- // If there is already one running, tell it to stop.
- stopLoader();
LoaderResults loaderResults = new LoaderResults(
mApp, mBgDataModel, mBgAllAppsList, callbacksList);
- if (mModelLoaded && !mIsLoaderTaskRunning) {
+ 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();
+ loaderResults.bindWorkspace(bindAllCallbacks);
// For now, continue posting the binding of AllApps as there are other
// issues that arise from that.
loaderResults.bindAllApps();
@@ -387,7 +394,7 @@
* If there is already a loader task running, tell it to stop.
* @return true if an existing loader was stopped.
*/
- public boolean stopLoader() {
+ private boolean stopLoader() {
synchronized (mLock) {
LoaderTask oldTask = mLoaderTask;
mLoaderTask = null;