Search in sources :

Example 1 with ITEM_TYPE_DEEP_SHORTCUT

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT in project android_packages_apps_Launcher3 by crdroidandroid.

the class ItemInfo method buildProto.

/**
 * Creates {@link LauncherAtom.ItemInfo} with important fields and parent container info.
 */
public LauncherAtom.ItemInfo buildProto(FolderInfo fInfo) {
    LauncherAtom.ItemInfo.Builder itemBuilder = getDefaultItemInfoBuilder();
    Optional<ComponentName> nullableComponent = Optional.ofNullable(getTargetComponent());
    switch(itemType) {
        case ITEM_TYPE_APPLICATION:
            itemBuilder.setApplication(nullableComponent.map(component -> LauncherAtom.Application.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Application.newBuilder()));
            break;
        case ITEM_TYPE_DEEP_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> {
                Shortcut.Builder lsb = Shortcut.newBuilder().setShortcutName(component.flattenToShortString());
                Optional.ofNullable(getIntent()).map(i -> i.getStringExtra(EXTRA_SHORTCUT_ID)).ifPresent(lsb::setShortcutId);
                return lsb;
            }).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_SHORTCUT:
            itemBuilder.setShortcut(nullableComponent.map(component -> LauncherAtom.Shortcut.newBuilder().setShortcutName(component.flattenToShortString())).orElse(LauncherAtom.Shortcut.newBuilder()));
            break;
        case ITEM_TYPE_APPWIDGET:
            itemBuilder.setWidget(nullableComponent.map(component -> LauncherAtom.Widget.newBuilder().setComponentName(component.flattenToShortString()).setPackageName(component.getPackageName())).orElse(LauncherAtom.Widget.newBuilder()).setSpanX(spanX).setSpanY(spanY));
            break;
        case ITEM_TYPE_TASK:
            itemBuilder.setTask(LauncherAtom.Task.newBuilder().setComponentName(getTargetComponent().flattenToShortString()).setIndex(screenId));
            break;
        default:
            break;
    }
    if (fInfo != null) {
        LauncherAtom.FolderContainer.Builder folderBuilder = LauncherAtom.FolderContainer.newBuilder();
        folderBuilder.setGridX(cellX).setGridY(cellY).setPageIndex(screenId);
        switch(fInfo.container) {
            case CONTAINER_HOTSEAT:
            case CONTAINER_HOTSEAT_PREDICTION:
                folderBuilder.setHotseat(LauncherAtom.HotseatContainer.newBuilder().setIndex(fInfo.screenId));
                break;
            case CONTAINER_DESKTOP:
                folderBuilder.setWorkspace(LauncherAtom.WorkspaceContainer.newBuilder().setPageIndex(fInfo.screenId).setGridX(fInfo.cellX).setGridY(fInfo.cellY));
                break;
        }
        itemBuilder.setContainerInfo(ContainerInfo.newBuilder().setFolder(folderBuilder));
    } else {
        ContainerInfo containerInfo = getContainerInfo();
        if (!containerInfo.getContainerCase().equals(CONTAINER_NOT_SET)) {
            itemBuilder.setContainerInfo(containerInfo);
        }
    }
    return itemBuilder.build();
}
Also used : ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) CONTAINER_WIDGETS_TRAY(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_TRAY) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) Intent(android.content.Intent) LauncherSettings(com.android.launcher3.LauncherSettings) Process(android.os.Process) AllAppsContainer(com.android.launcher3.logger.LauncherAtom.AllAppsContainer) SearchResultContainer(com.android.launcher3.logger.LauncherAtom.SearchResultContainer) CONTAINER_TASKSWITCHER(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_TASKSWITCHER) CONTAINER_HOTSEAT(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT) LauncherAtom(com.android.launcher3.logger.LauncherAtom) ITEM_TYPE_APPWIDGET(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) UserHandle(android.os.UserHandle) TaskSwitcherContainer(com.android.launcher3.logger.LauncherAtom.TaskSwitcherContainer) ExtendedContainers(com.android.launcher3.logger.LauncherAtomExtensions.ExtendedContainers) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) EXTRA_SHORTCUT_ID(com.android.launcher3.shortcuts.ShortcutKey.EXTRA_SHORTCUT_ID) Favorites(com.android.launcher3.LauncherSettings.Favorites) ComponentName(android.content.ComponentName) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) ITEM_TYPE_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) CONTAINER_DESKTOP(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP) CONTAINER_SEARCH_RESULTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SEARCH_RESULTS) CONTAINER_HOTSEAT_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION) ShortcutsContainer(com.android.launcher3.logger.LauncherAtom.ShortcutsContainer) Nullable(androidx.annotation.Nullable) PredictionContainer(com.android.launcher3.logger.LauncherAtom.PredictionContainer) ITEM_TYPE_TASK(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_TASK) ContentWriter(com.android.launcher3.util.ContentWriter) EXTENDED_CONTAINERS(com.android.launcher3.LauncherSettings.Favorites.EXTENDED_CONTAINERS) CONTAINER_SETTINGS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SETTINGS) CONTAINER_NOT_SET(com.android.launcher3.logger.LauncherAtom.ContainerInfo.ContainerCase.CONTAINER_NOT_SET) Optional(java.util.Optional) Workspace(com.android.launcher3.Workspace) CONTAINER_ALL_APPS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS) ContentValues(android.content.ContentValues) CONTAINER_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_PREDICTION) SettingsContainer(com.android.launcher3.logger.LauncherAtom.SettingsContainer) ModelWriter(com.android.launcher3.model.ModelWriter) Shortcut(com.android.launcher3.logger.LauncherAtom.Shortcut) ContainerInfo(com.android.launcher3.logger.LauncherAtom.ContainerInfo) ComponentName(android.content.ComponentName)

Example 2 with ITEM_TYPE_DEEP_SHORTCUT

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT in project android_packages_apps_Launcher3 by crdroidandroid.

the class PredictionUpdateTask method execute.

@Override
public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    Context context = app.getContext();
    // TODO: remove this
    Utilities.getDevicePrefs(context).edit().putBoolean(LAST_PREDICTION_ENABLED_STATE, !mTargets.isEmpty()).apply();
    FixedContainerItems fci = mPredictorState.items;
    Set<UserHandle> usersForChangedShortcuts = new HashSet<>(fci.items.stream().filter(info -> info.itemType == ITEM_TYPE_DEEP_SHORTCUT).map(info -> info.user).collect(Collectors.toSet()));
    fci.items.clear();
    for (AppTarget target : mTargets) {
        WorkspaceItemInfo itemInfo;
        ShortcutInfo si = target.getShortcutInfo();
        if (si != null) {
            usersForChangedShortcuts.add(si.getUserHandle());
            itemInfo = new WorkspaceItemInfo(si, context);
            app.getIconCache().getShortcutIcon(itemInfo, si);
        } else {
            String className = target.getClassName();
            if (COMPONENT_CLASS_MARKER.equals(className)) {
                // TODO: Implement this
                continue;
            }
            ComponentName cn = new ComponentName(target.getPackageName(), className);
            UserHandle user = target.getUser();
            itemInfo = apps.data.stream().filter(info -> user.equals(info.user) && cn.equals(info.componentName)).map(ai -> {
                app.getIconCache().getTitleAndIcon(ai, false);
                return ai.makeWorkspaceItem();
            }).findAny().orElseGet(() -> {
                LauncherActivityInfo lai = context.getSystemService(LauncherApps.class).resolveActivity(AppInfo.makeLaunchIntent(cn), user);
                if (lai == null) {
                    return null;
                }
                AppInfo ai = new AppInfo(context, lai, user);
                app.getIconCache().getTitleAndIcon(ai, lai, false);
                return ai.makeWorkspaceItem();
            });
            if (itemInfo == null) {
                continue;
            }
        }
        itemInfo.container = fci.containerId;
        fci.items.add(itemInfo);
    }
    bindExtraContainerItems(fci);
    usersForChangedShortcuts.forEach(u -> dataModel.updateShortcutPinnedState(app.getContext(), u));
    // Save to disk
    mPredictorState.storage.write(context, fci.items);
}
Also used : Context(android.content.Context) Utilities(com.android.launcher3.Utilities) Context(android.content.Context) AppInfo(com.android.launcher3.model.data.AppInfo) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) ITEM_TYPE_DEEP_SHORTCUT(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) LauncherAppState(com.android.launcher3.LauncherAppState) Set(java.util.Set) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) LauncherApps(android.content.pm.LauncherApps) HashSet(java.util.HashSet) List(java.util.List) COMPONENT_CLASS_MARKER(com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) LAST_PREDICTION_ENABLED_STATE(com.android.launcher3.model.QuickstepModelDelegate.LAST_PREDICTION_ENABLED_STATE) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ShortcutInfo(android.content.pm.ShortcutInfo) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppInfo(com.android.launcher3.model.data.AppInfo) AppTarget(android.app.prediction.AppTarget) UserHandle(android.os.UserHandle) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Example 3 with ITEM_TYPE_DEEP_SHORTCUT

use of com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT in project android_packages_apps_Launcher3 by crdroidandroid.

the class QuickstepLauncher method logAppLaunch.

@Override
protected void logAppLaunch(ItemInfo info, InstanceId instanceId) {
    // LiveSearchManager to recreate the AllApps session on the server side.
    if (mAllAppsSessionLogId != null && ALL_APPS.equals(getStateManager().getCurrentStableState())) {
        instanceId = mAllAppsSessionLogId;
    }
    StatsLogger logger = getStatsLogManager().logger().withItemInfo(info).withInstanceId(instanceId);
    if (mAllAppsPredictions != null && (info.itemType == ITEM_TYPE_APPLICATION || info.itemType == ITEM_TYPE_SHORTCUT || info.itemType == ITEM_TYPE_DEEP_SHORTCUT)) {
        int count = mAllAppsPredictions.items.size();
        for (int i = 0; i < count; i++) {
            ItemInfo targetInfo = mAllAppsPredictions.items.get(i);
            if (targetInfo.itemType == info.itemType && targetInfo.user.equals(info.user) && Objects.equals(targetInfo.getIntent(), info.getIntent())) {
                logger.withRank(i);
                break;
            }
        }
    }
    logger.log(LAUNCHER_APP_LAUNCH_TAP);
    mHotseatPredictionController.logLaunchedAppRankingInfo(info, instanceId);
}
Also used : StatsLogger(com.android.launcher3.logging.StatsLogManager.StatsLogger) ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

ComponentName (android.content.ComponentName)2 UserHandle (android.os.UserHandle)2 ITEM_TYPE_DEEP_SHORTCUT (com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2 AppTarget (android.app.prediction.AppTarget)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)1 LauncherApps (android.content.pm.LauncherApps)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 Process (android.os.Process)1 Nullable (androidx.annotation.Nullable)1 LauncherAppState (com.android.launcher3.LauncherAppState)1 LauncherSettings (com.android.launcher3.LauncherSettings)1 Favorites (com.android.launcher3.LauncherSettings.Favorites)1 CONTAINER_ALL_APPS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_ALL_APPS)1 CONTAINER_DESKTOP (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP)1 CONTAINER_HOTSEAT (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT)1 CONTAINER_HOTSEAT_PREDICTION (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT_PREDICTION)1