Separating apps list callback from model callback and simplifying various events

Bug: 137568159
Change-Id: I4d8bb5c01cabe642731ebd3f57fe15bdc5a569b7
This commit is contained in:
Sunny Goyal
2019-07-17 20:35:56 -07:00
parent b33dc7d8fb
commit 87dcde6d6c
23 changed files with 210 additions and 265 deletions

View File

@@ -23,23 +23,19 @@ import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import com.android.launcher3.AllAppsList;
import com.android.launcher3.AppInfo;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.InstallShortcutReceiver;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetInfo;
import com.android.launcher3.LauncherModel.CallbackTask;
import com.android.launcher3.LauncherModel.Callbacks;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.SessionCommitReceiver;
import com.android.launcher3.Utilities;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.BitmapInfo;
import com.android.launcher3.icons.IconCache;
import com.android.launcher3.icons.LauncherIcons;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.shortcuts.DeepShortcutManager;
@@ -48,6 +44,7 @@ import com.android.launcher3.util.IntSparseArrayMap;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.SafeCloseable;
import java.util.ArrayList;
import java.util.Arrays;
@@ -93,6 +90,8 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
FlagOp flagOp = FlagOp.NO_OP;
final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packages));
ItemInfoMatcher matcher = ItemInfoMatcher.ofPackages(packageSet, mUser);
final HashSet<ComponentName> removedComponents = new HashSet<>();
switch (mOp) {
case OP_ADD: {
for (int i = 0; i < N; i++) {
@@ -112,11 +111,14 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
break;
}
case OP_UPDATE:
for (int i = 0; i < N; i++) {
if (DEBUG) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
iconCache.updateIconsForPkg(packages[i], mUser);
appsList.updatePackage(context, packages[i], mUser);
app.getWidgetCache().removePackage(packages[i], mUser);
try (SafeCloseable t =
appsList.trackRemoves(a -> removedComponents.add(a.componentName))) {
for (int i = 0; i < N; i++) {
if (DEBUG) Log.d(TAG, "mAllAppsList.updatePackage " + packages[i]);
iconCache.updateIconsForPkg(packages[i], mUser);
appsList.updatePackage(context, packages[i], mUser);
app.getWidgetCache().removePackage(packages[i], mUser);
}
}
// Since package was just updated, the target must be available now.
flagOp = FlagOp.removeFlag(WorkspaceItemInfo.FLAG_DISABLED_NOT_AVAILABLE);
@@ -153,23 +155,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
break;
}
final ArrayList<AppInfo> addedOrModified = new ArrayList<>();
addedOrModified.addAll(appsList.added);
appsList.added.clear();
addedOrModified.addAll(appsList.modified);
appsList.modified.clear();
if (!addedOrModified.isEmpty()) {
scheduleCallbackTask((callbacks) -> callbacks.bindAppsAddedOrUpdated(addedOrModified));
}
final ArrayList<AppInfo> removedApps = new ArrayList<>(appsList.removed);
appsList.removed.clear();
final HashSet<ComponentName> removedComponents = new HashSet<>();
if (mOp == OP_UPDATE) {
for (AppInfo ai : removedApps) {
removedComponents.add(ai.componentName);
}
}
bindApplicationsIfNeeded();
final IntSparseArrayMap<Boolean> removedShortcuts = new IntSparseArrayMap<>();
@@ -296,12 +282,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
}
if (!widgets.isEmpty()) {
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
callbacks.bindWidgetsRestored(widgets);
}
});
scheduleCallbackTask(c -> c.bindWidgetsRestored(widgets));
}
}
@@ -332,16 +313,6 @@ public class PackageUpdatedTask extends BaseModelUpdateTask {
InstallShortcutReceiver.removeFromInstallQueue(context, removedPackages, mUser);
}
if (!removedApps.isEmpty()) {
// Remove corresponding apps from All-Apps
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
callbacks.bindAppInfosRemoved(removedApps);
}
});
}
if (Utilities.ATLEAST_OREO && mOp == OP_ADD) {
// Load widgets for the new package. Changes due to app updates are handled through
// AppWidgetHost events, this is just to initialize the long-press options.