use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class PackageInstallStateChangedTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
if (mInstallInfo.state == PackageInstallInfo.STATUS_INSTALLED) {
try {
// For instant apps we do not get package-add. Use setting events to update
// any pinned icons.
ApplicationInfo ai = app.getContext().getPackageManager().getApplicationInfo(mInstallInfo.packageName, 0);
if (InstantAppResolver.newInstance(app.getContext()).isInstantApp(ai)) {
app.getModel().onPackageAdded(ai.packageName, mInstallInfo.user);
}
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
// Ignore install success events as they are handled by Package add events.
return;
}
synchronized (apps) {
List<AppInfo> updatedAppInfos = apps.updatePromiseInstallInfo(mInstallInfo);
if (!updatedAppInfos.isEmpty()) {
for (AppInfo appInfo : updatedAppInfos) {
scheduleCallbackTask(c -> c.bindIncrementalDownloadProgressUpdated(appInfo));
}
}
bindApplicationsIfNeeded();
}
synchronized (dataModel) {
final HashSet<ItemInfo> updates = new HashSet<>();
dataModel.forAllWorkspaceItemInfos(mInstallInfo.user, si -> {
if (si.hasPromiseIconUi() && mInstallInfo.packageName.equals(si.getTargetPackage())) {
si.setProgressLevel(mInstallInfo);
updates.add(si);
}
});
for (LauncherAppWidgetInfo widget : dataModel.appWidgets) {
if (widget.providerName.getPackageName().equals(mInstallInfo.packageName)) {
widget.installProgress = mInstallInfo.progress;
updates.add(widget);
}
}
if (!updates.isEmpty()) {
scheduleCallbackTask(callbacks -> callbacks.bindRestoreItemsChange(updates));
}
}
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class AddWorkspaceItemsTask method execute.
@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
if (mItemList.isEmpty()) {
return;
}
final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
final IntArray addedWorkspaceScreensFinal = new IntArray();
synchronized (dataModel) {
IntArray workspaceScreens = dataModel.collectWorkspaceScreens();
List<ItemInfo> filteredItems = new ArrayList<>();
for (Pair<ItemInfo, Object> entry : mItemList) {
ItemInfo item = entry.first;
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION || item.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) {
// Short-circuit this logic if the icon exists somewhere on the workspace
if (shortcutExists(dataModel, item.getIntent(), item.user)) {
continue;
}
// b/139663018 Short-circuit this logic if the icon is a system app
if (PackageManagerHelper.isSystemApp(app.getContext(), item.getIntent())) {
continue;
}
}
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
if (item instanceof AppInfo) {
item = ((AppInfo) item).makeWorkspaceItem();
}
}
if (item != null) {
filteredItems.add(item);
}
}
InstallSessionHelper packageInstaller = InstallSessionHelper.INSTANCE.get(app.getContext());
LauncherApps launcherApps = app.getContext().getSystemService(LauncherApps.class);
for (ItemInfo item : filteredItems) {
// Find appropriate space for the item.
int[] coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY);
int screenId = coords[0];
ItemInfo itemInfo;
if (item instanceof WorkspaceItemInfo || item instanceof FolderInfo || item instanceof LauncherAppWidgetInfo) {
itemInfo = item;
} else if (item instanceof AppInfo) {
itemInfo = ((AppInfo) item).makeWorkspaceItem();
} else {
throw new RuntimeException("Unexpected info type");
}
if (item instanceof WorkspaceItemInfo && ((WorkspaceItemInfo) item).isPromise()) {
WorkspaceItemInfo workspaceInfo = (WorkspaceItemInfo) item;
String packageName = item.getTargetComponent() != null ? item.getTargetComponent().getPackageName() : null;
if (packageName == null) {
continue;
}
SessionInfo sessionInfo = packageInstaller.getActiveSessionInfo(item.user, packageName);
if (!packageInstaller.verifySessionInfo(sessionInfo)) {
FileLog.d(LOG, "Item info failed session info verification. " + "Skipping : " + workspaceInfo);
continue;
}
List<LauncherActivityInfo> activities = launcherApps.getActivityList(packageName, item.user);
boolean hasActivity = activities != null && !activities.isEmpty();
if (sessionInfo == null) {
if (!hasActivity) {
// Session was cancelled, do not add.
continue;
}
} else {
workspaceInfo.setProgressLevel((int) (sessionInfo.getProgress() * 100), PackageInstallInfo.STATUS_INSTALLING);
}
if (hasActivity) {
// App was installed while launcher was in the background,
// or app was already installed for another user.
itemInfo = new AppInfo(app.getContext(), activities.get(0), item.user).makeWorkspaceItem();
if (shortcutExists(dataModel, itemInfo.getIntent(), itemInfo.user)) {
// Icon already exists on the workspace and should not be auto-added.
continue;
}
WorkspaceItemInfo wii = (WorkspaceItemInfo) itemInfo;
wii.title = "";
wii.bitmap = app.getIconCache().getDefaultIcon(item.user);
app.getIconCache().getTitleAndIcon(wii, ((WorkspaceItemInfo) itemInfo).usingLowResIcon());
}
}
// Add the shortcut to the db
getModelWriter().addItemToDatabase(itemInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, screenId, coords[1], coords[2]);
// Save the WorkspaceItemInfo for binding in the workspace
addedItemsFinal.add(itemInfo);
// log bitmap and label
FileLog.d(LOG, "Adding item info to workspace: " + itemInfo);
}
}
if (!addedItemsFinal.isEmpty()) {
scheduleCallbackTask(new CallbackTask() {
@Override
public void execute(Callbacks callbacks) {
final ArrayList<ItemInfo> addAnimated = new ArrayList<>();
final ArrayList<ItemInfo> addNotAnimated = new ArrayList<>();
if (!addedItemsFinal.isEmpty()) {
ItemInfo info = addedItemsFinal.get(addedItemsFinal.size() - 1);
int lastScreenId = info.screenId;
for (ItemInfo i : addedItemsFinal) {
if (i.screenId == lastScreenId) {
addAnimated.add(i);
} else {
addNotAnimated.add(i);
}
}
}
callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated);
}
});
}
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class LauncherPreviewRenderer method populate.
private void populate(BgDataModel dataModel, Map<ComponentKey, AppWidgetProviderInfo> widgetProviderInfoMap) {
// Separate the items that are on the current screen, and the other remaining items.
ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<>();
ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<>();
ArrayList<LauncherAppWidgetInfo> currentAppWidgets = new ArrayList<>();
ArrayList<LauncherAppWidgetInfo> otherAppWidgets = new ArrayList<>();
IntSet currentScreenIds = IntSet.wrap(mWorkspaceScreens.keySet());
filterCurrentWorkspaceItems(currentScreenIds, dataModel.workspaceItems, currentWorkspaceItems, otherWorkspaceItems);
filterCurrentWorkspaceItems(currentScreenIds, dataModel.appWidgets, currentAppWidgets, otherAppWidgets);
sortWorkspaceItemsSpatially(mIdp, currentWorkspaceItems);
for (ItemInfo itemInfo : currentWorkspaceItems) {
switch(itemInfo.itemType) {
case Favorites.ITEM_TYPE_APPLICATION:
case Favorites.ITEM_TYPE_SHORTCUT:
case Favorites.ITEM_TYPE_DEEP_SHORTCUT:
inflateAndAddIcon((WorkspaceItemInfo) itemInfo);
break;
case Favorites.ITEM_TYPE_FOLDER:
inflateAndAddFolder((FolderInfo) itemInfo);
break;
default:
break;
}
}
for (ItemInfo itemInfo : currentAppWidgets) {
switch(itemInfo.itemType) {
case Favorites.ITEM_TYPE_APPWIDGET:
case Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
if (widgetProviderInfoMap != null) {
inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, widgetProviderInfoMap);
} else {
inflateAndAddWidgets((LauncherAppWidgetInfo) itemInfo, dataModel.widgetsModel);
}
break;
default:
break;
}
}
IntArray ranks = getMissingHotseatRanks(currentWorkspaceItems, mDp.numShownHotseatIcons);
FixedContainerItems hotseatpredictions = dataModel.extraItems.get(CONTAINER_HOTSEAT_PREDICTION);
List<ItemInfo> predictions = hotseatpredictions == null ? Collections.emptyList() : hotseatpredictions.items;
int count = Math.min(ranks.size(), predictions.size());
for (int i = 0; i < count; i++) {
int rank = ranks.get(i);
WorkspaceItemInfo itemInfo = new WorkspaceItemInfo((WorkspaceItemInfo) predictions.get(i));
itemInfo.container = CONTAINER_HOTSEAT_PREDICTION;
itemInfo.rank = rank;
itemInfo.cellX = mHotseat.getCellXFromOrder(rank);
itemInfo.cellY = mHotseat.getCellYFromOrder(rank);
itemInfo.screenId = rank;
inflateAndAddPredictedIcon(itemInfo);
}
// Add first page QSB
if (FeatureFlags.QSB_ON_FIRST_SCREEN) {
CellLayout firstScreen = mWorkspaceScreens.get(FIRST_SCREEN_ID);
View qsb = mHomeElementInflater.inflate(R.layout.qsb_preview, firstScreen, false);
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstScreen.getCountX(), 1);
lp.canReorder = false;
firstScreen.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true);
}
measureView(mRootView, mDp.widthPx, mDp.heightPx);
dispatchVisibilityAggregated(mRootView, true);
measureView(mRootView, mDp.widthPx, mDp.heightPx);
// Additional measure for views which use auto text size API
measureView(mRootView, mDp.widthPx, mDp.heightPx);
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ArrowOS.
the class LauncherModelHelper method initializeData.
/**
* Initializes mock data for the test.
*/
public void initializeData(String resourceName) throws Exception {
BgDataModel bgDataModel = getBgDataModel();
AllAppsList allAppsList = getAllAppsList();
MODEL_EXECUTOR.submit(() -> {
// Copy apk from resources to a local file and install from there.
Resources resources = testContext().getResources();
int resId = resources.getIdentifier(resourceName, "raw", testContext().getPackageName());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resources.openRawResource(resId)))) {
String line;
HashMap<String, Class> classMap = new HashMap<>();
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("#") || line.isEmpty()) {
continue;
}
String[] commands = line.split(" ");
switch(commands[0]) {
case "classMap":
classMap.put(commands[1], Class.forName(commands[2]));
break;
case "bgItem":
bgDataModel.addItem(sandboxContext, (ItemInfo) initItem(classMap.get(commands[1]), commands, 2), false);
break;
case "allApps":
allAppsList.add((AppInfo) initItem(AppInfo.class, commands, 1), null);
break;
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}).get();
}
use of com.android.launcher3.model.BgDataModel in project android_packages_apps_Launcher3 by ProtonAOSP.
the class WidgetsPredictionUpdateTask method execute.
/**
* Uses the app predication result to infer widgets that the user may want to use.
*
* <p>The algorithm uses the app prediction ranking to create a widgets ranking which only
* includes one widget per app and excludes widgets that have already been added to the
* workspace.
*/
@Override
public void execute(LauncherAppState appState, BgDataModel dataModel, AllAppsList apps) {
Set<ComponentKey> widgetsInWorkspace = dataModel.appWidgets.stream().map(widget -> new ComponentKey(widget.providerName, widget.user)).collect(Collectors.toSet());
Map<PackageUserKey, List<WidgetItem>> allWidgets = dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
FixedContainerItems fixedContainerItems = mPredictorState.items;
fixedContainerItems.items.clear();
if (FeatureFlags.ENABLE_LOCAL_RECOMMENDED_WIDGETS_FILTER.get()) {
for (AppTarget app : mTargets) {
PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
if (allWidgets.containsKey(packageUserKey)) {
List<WidgetItem> notAddedWidgets = allWidgets.get(packageUserKey).stream().filter(item -> !widgetsInWorkspace.contains(new ComponentKey(item.componentName, item.user))).collect(Collectors.toList());
if (notAddedWidgets.size() > 0) {
// Even an apps have more than one widgets, we only include one widget.
fixedContainerItems.items.add(new PendingAddWidgetInfo(notAddedWidgets.get(0).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
}
}
}
} else {
Map<ComponentKey, WidgetItem> widgetItems = allWidgets.values().stream().flatMap(List::stream).distinct().collect(Collectors.toMap(widget -> (ComponentKey) widget, widget -> widget));
for (AppTarget app : mTargets) {
if (TextUtils.isEmpty(app.getClassName())) {
continue;
}
ComponentKey targetWidget = new ComponentKey(new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
if (widgetItems.containsKey(targetWidget)) {
fixedContainerItems.items.add(new PendingAddWidgetInfo(widgetItems.get(targetWidget).widgetInfo, CONTAINER_WIDGETS_PREDICTION));
}
}
}
bindExtraContainerItems(fixedContainerItems);
// Don't store widgets prediction to disk because it is not used frequently.
}
Aggregations