Search in sources :

Example 46 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.

the class PopupDataProvider method onNotificationFullRefresh.

@Override
public void onNotificationFullRefresh(List<StatusBarNotification> activeNotifications) {
    if (activeNotifications == null)
        return;
    // This will contain the PackageUserKeys which have updated dots.
    HashMap<PackageUserKey, DotInfo> updatedDots = new HashMap<>(mPackageUserToDotInfos);
    mPackageUserToDotInfos.clear();
    for (StatusBarNotification notification : activeNotifications) {
        PackageUserKey packageUserKey = PackageUserKey.fromNotification(notification);
        DotInfo dotInfo = mPackageUserToDotInfos.get(packageUserKey);
        if (dotInfo == null) {
            dotInfo = new DotInfo();
            mPackageUserToDotInfos.put(packageUserKey, dotInfo);
        }
        dotInfo.addOrUpdateNotificationKey(NotificationKeyData.fromNotification(notification));
    }
    // Add and remove from updatedDots so it contains the PackageUserKeys of updated dots.
    for (PackageUserKey packageUserKey : mPackageUserToDotInfos.keySet()) {
        DotInfo prevDot = updatedDots.get(packageUserKey);
        DotInfo newDot = mPackageUserToDotInfos.get(packageUserKey);
        if (prevDot == null || prevDot.getNotificationCount() != newDot.getNotificationCount()) {
            updatedDots.put(packageUserKey, newDot);
        } else {
            // No need to update the dot if it already existed (no visual change).
            // Note that if the dot was removed entirely, we wouldn't reach this point because
            // this loop only includes active notifications added above.
            updatedDots.remove(packageUserKey);
        }
    }
    if (!updatedDots.isEmpty()) {
        updateNotificationDots(updatedDots::containsKey);
    }
    trimNotifications(updatedDots);
}
Also used : DotInfo(com.android.launcher3.dot.DotInfo) StatusBarNotification(android.service.notification.StatusBarNotification) HashMap(java.util.HashMap) PackageUserKey(com.android.launcher3.util.PackageUserKey)

Example 47 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.

the class BindWidgetTest method getInvalidWidgetInfo.

/**
 * Returns a LauncherAppWidgetInfo with package name which is not present on the device
 */
private LauncherAppWidgetInfo getInvalidWidgetInfo() {
    String invalidPackage = "com.invalidpackage";
    int count = 0;
    String pkg = invalidPackage;
    Set<String> activePackage = getOnUiThread(() -> {
        Set<String> packages = new HashSet<>();
        PackageInstallerCompat.getInstance(mTargetContext).updateAndGetActiveSessionCache().keySet().forEach(packageUserKey -> packages.add(packageUserKey.mPackageName));
        return packages;
    });
    while (true) {
        try {
            mTargetContext.getPackageManager().getPackageInfo(pkg, PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (Exception e) {
            if (!activePackage.contains(pkg)) {
                break;
            }
        }
        pkg = invalidPackage + count;
        count++;
    }
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(10, new ComponentName(pkg, "com.test.widgetprovider"));
    item.spanX = 2;
    item.spanY = 2;
    item.minSpanX = 2;
    item.minSpanY = 2;
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
    return item;
}
Also used : LauncherAppWidgetInfo(com.android.launcher3.LauncherAppWidgetInfo) ComponentName(android.content.ComponentName) HashSet(java.util.HashSet)

Example 48 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.

the class WidgetsModel method setWidgetsAndShortcuts.

private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts, LauncherAppState app, @Nullable PackageUserKey packageUser) {
    if (DEBUG) {
        Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
    }
    // Temporary list for {@link PackageItemInfos} to avoid having to go through
    // {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
    HashMap<String, PackageItemInfo> tmpPackageItemInfos = new HashMap<>();
    // clear the lists.
    if (packageUser == null) {
        mWidgetsList.clear();
    } else {
        // Only clear the widgets for the given package/user.
        PackageItemInfo packageItem = null;
        for (PackageItemInfo item : mWidgetsList.keySet()) {
            if (item.packageName.equals(packageUser.mPackageName)) {
                packageItem = item;
                break;
            }
        }
        if (packageItem != null) {
            // We want to preserve the user that was on the packageItem previously,
            // so add it to tmpPackageItemInfos here to avoid creating a new entry.
            tmpPackageItemInfos.put(packageItem.packageName, packageItem);
            Iterator<WidgetItem> widgetItemIterator = mWidgetsList.get(packageItem).iterator();
            while (widgetItemIterator.hasNext()) {
                WidgetItem nextWidget = widgetItemIterator.next();
                if (nextWidget.componentName.getPackageName().equals(packageUser.mPackageName) && nextWidget.user.equals(packageUser.mUser)) {
                    widgetItemIterator.remove();
                }
            }
        }
    }
    InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
    UserHandle myUser = Process.myUserHandle();
    // add and update.
    for (WidgetItem item : rawWidgetsShortcuts) {
        if (item.widgetInfo != null) {
            if ((item.widgetInfo.getWidgetFeatures() & WIDGET_FEATURE_HIDE_FROM_PICKER) != 0) {
                // Widget is hidden from picker
                continue;
            }
            // Ensure that all widgets we show can be added on a workspace of this size
            int minSpanX = Math.min(item.widgetInfo.spanX, item.widgetInfo.minSpanX);
            int minSpanY = Math.min(item.widgetInfo.spanY, item.widgetInfo.minSpanY);
            if (minSpanX > idp.numColumns || minSpanY > idp.numRows) {
                if (DEBUG) {
                    Log.d(TAG, String.format("Widget %s : (%d X %d) can't fit on this device", item.componentName, minSpanX, minSpanY));
                }
                continue;
            }
        }
        if (mAppFilter == null) {
            mAppFilter = AppFilter.newInstance(app.getContext());
        }
        if (!mAppFilter.shouldShowApp(item.componentName, item.user)) {
            if (DEBUG) {
                Log.d(TAG, String.format("%s is filtered and not added to the widget tray.", item.componentName));
            }
            continue;
        }
        String packageName = item.componentName.getPackageName();
        PackageItemInfo pInfo = tmpPackageItemInfos.get(packageName);
        if (pInfo == null) {
            pInfo = new PackageItemInfo(packageName);
            pInfo.user = item.user;
            tmpPackageItemInfos.put(packageName, pInfo);
        } else if (!myUser.equals(pInfo.user)) {
            // Keep updating the user, until we get the primary user.
            pInfo.user = item.user;
        }
        mWidgetsList.addToList(pInfo, item);
    }
    // Update each package entry
    IconCache iconCache = app.getIconCache();
    for (PackageItemInfo p : tmpPackageItemInfos.values()) {
        iconCache.getTitleAndIconForApp(p, true);
    }
}
Also used : HashMap(java.util.HashMap) MultiHashMap(com.android.launcher3.util.MultiHashMap) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache)

Example 49 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabel> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabel> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : LauncherAppsCompat.getInstance(context).getCustomShortcutActivityList(packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) AppWidgetManagerCompat(com.android.launcher3.compat.AppWidgetManagerCompat) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.compat.ShortcutConfigActivityInfo) ComponentWithLabel(com.android.launcher3.icons.ComponentWithLabel)

Example 50 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_Launcher3 by ArrowOS.

the class Workspace method updateNotificationDots.

public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
    final PackageUserKey packageUserKey = new PackageUserKey(null, null);
    Predicate<ItemInfo> matcher = info -> !packageUserKey.updateFromItemInfo(info) || updatedDots.test(packageUserKey);
    ItemOperator op = (info, v) -> {
        if (info instanceof WorkspaceItemInfo && v instanceof BubbleTextView) {
            if (matcher.test(info)) {
                ((BubbleTextView) v).applyDotState(info, true);
            }
        } else if (info instanceof FolderInfo && v instanceof FolderIcon) {
            FolderInfo fi = (FolderInfo) info;
            if (fi.contents.stream().anyMatch(matcher)) {
                FolderDotInfo folderDotInfo = new FolderDotInfo();
                for (WorkspaceItemInfo si : fi.contents) {
                    folderDotInfo.addDotInfo(mLauncher.getDotInfoForItem(si));
                }
                ((FolderIcon) v).setDotInfo(folderDotInfo);
            }
        }
        // process all the shortcuts
        return false;
    };
    mapOverItems(op);
    Folder folder = Folder.getOpen(mLauncher);
    if (folder != null) {
        folder.iterateOverItems(op);
    }
}
Also used : BitmapRenderer(com.android.launcher3.icons.BitmapRenderer) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) LAUNCHER_SWIPELEFT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPELEFT) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Drawable(android.graphics.drawable.Drawable) DraggableView(com.android.launcher3.dragndrop.DraggableView) WallpaperManager(android.app.WallpaperManager) FolderDotInfo(com.android.launcher3.dot.FolderDotInfo) LayoutTransition(android.animation.LayoutTransition) Interpolators(com.android.launcher3.anim.Interpolators) LauncherAtom(com.android.launcher3.logger.LauncherAtom) Handler(android.os.Handler) Log(android.util.Log) WallpaperOffsetInterpolator(com.android.launcher3.util.WallpaperOffsetInterpolator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) OverlayEdgeEffect(com.android.launcher3.util.OverlayEdgeEffect) Nullable(androidx.annotation.Nullable) Message(android.os.Message) LauncherAppWidgetHostView(com.android.launcher3.widget.LauncherAppWidgetHostView) ItemInfoMatcher(com.android.launcher3.util.ItemInfoMatcher) NORMAL(com.android.launcher3.LauncherState.NORMAL) AccessibleDragListenerAdapter(com.android.launcher3.accessibility.AccessibleDragListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) AppWidgetHostViewDragListener(com.android.launcher3.widget.dragndrop.AppWidgetHostViewDragListener) ITEM_TYPE_APPLICATION(com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) SpringLoadedDragController(com.android.launcher3.dragndrop.SpringLoadedDragController) ArrayList(java.util.ArrayList) FLAG_MULTI_PAGE(com.android.launcher3.LauncherState.FLAG_MULTI_PAGE) PreviewBackground(com.android.launcher3.folder.PreviewBackground) AppWidgetHostView(android.appwidget.AppWidgetHostView) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) AnimatorListeners.forSuccessCallback(com.android.launcher3.anim.AnimatorListeners.forSuccessCallback) UserHandle(android.os.UserHandle) Toast(android.widget.Toast) IntArray(com.android.launcher3.util.IntArray) ProviderChangedListener(com.android.launcher3.widget.LauncherAppWidgetHost.ProviderChangedListener) Parcelable(android.os.Parcelable) InstanceId(com.android.launcher3.logging.InstanceId) FastBitmapDrawable(com.android.launcher3.icons.FastBitmapDrawable) DragController(com.android.launcher3.dragndrop.DragController) LauncherAppWidgetInfo(com.android.launcher3.model.data.LauncherAppWidgetInfo) StateManager(com.android.launcher3.statemanager.StateManager) FeatureFlags(com.android.launcher3.config.FeatureFlags) IntSet(com.android.launcher3.util.IntSet) LauncherAppWidgetHost(com.android.launcher3.widget.LauncherAppWidgetHost) LAUNCHER_SWIPERIGHT(com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SWIPERIGHT) WorkspaceTouchListener(com.android.launcher3.touch.WorkspaceTouchListener) RunnableList(com.android.launcher3.util.RunnableList) DragPreviewProvider(com.android.launcher3.graphics.DragPreviewProvider) ValueAnimator(android.animation.ValueAnimator) WorkspaceAccessibilityHelper(com.android.launcher3.accessibility.WorkspaceAccessibilityHelper) Rect(android.graphics.Rect) SPRING_LOADED_EXIT_DELAY(com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY) Animator(android.animation.Animator) SPRING_LOADED(com.android.launcher3.LauncherState.SPRING_LOADED) FLAG_WORKSPACE_INACCESSIBLE(com.android.launcher3.LauncherState.FLAG_WORKSPACE_INACCESSIBLE) AttributeSet(android.util.AttributeSet) FolderInfo(com.android.launcher3.model.data.FolderInfo) View(android.view.View) LauncherEvent(com.android.launcher3.logging.StatsLogManager.LauncherEvent) Predicate(java.util.function.Predicate) EdgeEffectCompat(com.android.launcher3.util.EdgeEffectCompat) PendingAppWidgetHostView(com.android.launcher3.widget.PendingAppWidgetHostView) Collectors(java.util.stream.Collectors) ViewGroup(android.view.ViewGroup) DragOptions(com.android.launcher3.dragndrop.DragOptions) SparseArray(android.util.SparseArray) WidgetSizes(com.android.launcher3.widget.util.WidgetSizes) List(java.util.List) ALL_APPS(com.android.launcher3.LauncherState.ALL_APPS) LAUNCHER_STATE_HOME(com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME) StateAnimationConfig(com.android.launcher3.states.StateAnimationConfig) ALPHA_INDEX_OVERLAY(com.android.launcher3.dragndrop.DragLayer.ALPHA_INDEX_OVERLAY) Folder(com.android.launcher3.folder.Folder) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AppInfo(com.android.launcher3.model.data.AppInfo) LauncherOverlay(com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay) ItemInfo(com.android.launcher3.model.data.ItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) PopupContainerWithArrow(com.android.launcher3.popup.PopupContainerWithArrow) LauncherBindableItemsContainer(com.android.launcher3.util.LauncherBindableItemsContainer) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED(com.android.launcher3.LauncherState.FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED) DragLayer(com.android.launcher3.dragndrop.DragLayer) Executors(com.android.launcher3.util.Executors) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) PackageUserKey(com.android.launcher3.util.PackageUserKey) Point(android.graphics.Point) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper) Consumer(java.util.function.Consumer) StatsLogManager(com.android.launcher3.logging.StatsLogManager) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) Bitmap(android.graphics.Bitmap) WorkspacePageIndicator(com.android.launcher3.pageindicators.WorkspacePageIndicator) StateHandler(com.android.launcher3.statemanager.StateManager.StateHandler) ViewTreeObserver(android.view.ViewTreeObserver) IntSparseArrayMap(com.android.launcher3.util.IntSparseArrayMap) Thunk(com.android.launcher3.util.Thunk) HINT_STATE(com.android.launcher3.LauncherState.HINT_STATE) Collections(java.util.Collections) PendingAnimation(com.android.launcher3.anim.PendingAnimation) DragView(com.android.launcher3.dragndrop.DragView) Resources(android.content.res.Resources) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) ItemInfo(com.android.launcher3.model.data.ItemInfo) SearchActionItemInfo(com.android.launcher3.model.data.SearchActionItemInfo) FolderIcon(com.android.launcher3.folder.FolderIcon) PackageUserKey(com.android.launcher3.util.PackageUserKey) FolderDotInfo(com.android.launcher3.dot.FolderDotInfo) Folder(com.android.launcher3.folder.Folder) FolderInfo(com.android.launcher3.model.data.FolderInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

PackageUserKey (com.android.launcher3.util.PackageUserKey)94 ArrayList (java.util.ArrayList)53 Context (android.content.Context)42 ComponentName (android.content.ComponentName)39 UserHandle (android.os.UserHandle)35 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)31 HashMap (java.util.HashMap)31 HashSet (java.util.HashSet)31 List (java.util.List)29 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)26 IconCache (com.android.launcher3.icons.IconCache)24 LauncherAppWidgetInfo (com.android.launcher3.model.data.LauncherAppWidgetInfo)24 WidgetsListBaseEntry (com.android.launcher3.widget.model.WidgetsListBaseEntry)24 DotInfo (com.android.launcher3.dot.DotInfo)22 Log (android.util.Log)21 FeatureFlags (com.android.launcher3.config.FeatureFlags)21 PackageItemInfo (com.android.launcher3.model.data.PackageItemInfo)21 IntSet (com.android.launcher3.util.IntSet)21 Predicate (java.util.function.Predicate)21 Test (org.junit.Test)21