Search in sources :

Example 86 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_404Launcher by P-404.

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.
}
Also used : CONTAINER_WIDGETS_PREDICTION(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION) ComponentName(android.content.ComponentName) LauncherAppState(com.android.launcher3.LauncherAppState) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) PackageUserKey(com.android.launcher3.util.PackageUserKey) Set(java.util.Set) TextUtils(android.text.TextUtils) FeatureFlags(com.android.launcher3.config.FeatureFlags) Collectors(java.util.stream.Collectors) AppTarget(android.app.prediction.AppTarget) List(java.util.List) ComponentKey(com.android.launcher3.util.ComponentKey) Map(java.util.Map) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) PredictorState(com.android.launcher3.model.QuickstepModelDelegate.PredictorState) ComponentKey(com.android.launcher3.util.ComponentKey) PackageUserKey(com.android.launcher3.util.PackageUserKey) FixedContainerItems(com.android.launcher3.model.BgDataModel.FixedContainerItems) AppTarget(android.app.prediction.AppTarget) PendingAddWidgetInfo(com.android.launcher3.widget.PendingAddWidgetInfo) List(java.util.List) ComponentName(android.content.ComponentName)

Example 87 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_404Launcher by P-404.

the class SdCardAvailableReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    final LauncherApps launcherApps = context.getSystemService(LauncherApps.class);
    final PackageManagerHelper pmHelper = new PackageManagerHelper(context);
    for (PackageUserKey puk : mPackages) {
        UserHandle user = puk.mUser;
        final ArrayList<String> packagesRemoved = new ArrayList<>();
        final ArrayList<String> packagesUnavailable = new ArrayList<>();
        if (!launcherApps.isPackageEnabled(puk.mPackageName, user)) {
            if (pmHelper.isAppOnSdcard(puk.mPackageName, user)) {
                packagesUnavailable.add(puk.mPackageName);
            } else {
                packagesRemoved.add(puk.mPackageName);
            }
        }
        if (!packagesRemoved.isEmpty()) {
            mModel.onPackagesRemoved(user, packagesRemoved.toArray(new String[packagesRemoved.size()]));
        }
        if (!packagesUnavailable.isEmpty()) {
            mModel.onPackagesUnavailable(packagesUnavailable.toArray(new String[packagesUnavailable.size()]), user, false);
        }
    }
    // Unregister the broadcast receiver, just in case
    mContext.unregisterReceiver(this);
}
Also used : UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) LauncherApps(android.content.pm.LauncherApps) PackageManagerHelper(com.android.launcher3.util.PackageManagerHelper) PackageUserKey(com.android.launcher3.util.PackageUserKey)

Example 88 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_404Launcher by P-404.

the class PopupDataProvider method onNotificationRemoved.

@Override
public void onNotificationRemoved(PackageUserKey removedPackageUserKey, NotificationKeyData notificationKey) {
    DotInfo oldDotInfo = mPackageUserToDotInfos.get(removedPackageUserKey);
    if (oldDotInfo != null && oldDotInfo.removeNotificationKey(notificationKey)) {
        if (oldDotInfo.getNotificationKeys().size() == 0) {
            mPackageUserToDotInfos.remove(removedPackageUserKey);
        }
        updateNotificationDots(removedPackageUserKey::equals);
        trimNotifications(mPackageUserToDotInfos);
    }
}
Also used : DotInfo(com.android.launcher3.dot.DotInfo)

Example 89 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_404Launcher by P-404.

the class InstallSessionTracker method onFinished.

@Override
public void onFinished(int sessionId, boolean success) {
    InstallSessionHelper helper = mWeakHelper.get();
    Callback callback = mWeakCallback.get();
    if (callback == null || helper == null) {
        return;
    }
    // For a finished session, we can't get the session info. So use the
    // packageName from our local cache.
    SparseArray<PackageUserKey> activeSessions = getActiveSessionMap(helper);
    PackageUserKey key = activeSessions.get(sessionId);
    activeSessions.remove(sessionId);
    if (key != null && key.mPackageName != null) {
        String packageName = key.mPackageName;
        PackageInstallInfo info = PackageInstallInfo.fromState(success ? STATUS_INSTALLED : STATUS_FAILED, packageName, key.mUser);
        callback.onPackageStateChanged(info);
        if (!success && helper.promiseIconAddedForId(sessionId)) {
            callback.onSessionFailure(packageName, key.mUser);
            // If it is successful, the id is removed in the the package added flow.
            helper.removePromiseIconId(sessionId);
        }
    }
}
Also used : PackageUserKey(com.android.launcher3.util.PackageUserKey)

Example 90 with PackageUserKey

use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_404Launcher by P-404.

the class WidgetsListAdapterTest method headerClick_expanded_shouldNotifyItemChange.

@Test
public void headerClick_expanded_shouldNotifyItemChange() {
    // GIVEN a list of widgets entries:
    // [com.google.test0, com.google.test0 content,
    // com.google.test1, com.google.test1 content,
    // com.google.test2, com.google.test2 content]
    // The visible widgets entries: [com.google.test0, com.google.test1, com.google.test2].
    mAdapter.setWidgets(generateSampleMap(3));
    // WHEN com.google.test.1 header is expanded.
    mAdapter.onHeaderClicked(/* showWidgets= */
    true, new PackageUserKey(TEST_PACKAGE_PLACEHOLDER + 1, mUserHandle));
    // THEN the visible entries list becomes:
    // [com.google.test0, com.google.test1, com.google.test1 content, com.google.test2]
    // com.google.test.1 content is inserted into position 2.
    verify(mListener).onItemRangeInserted(eq(3), eq(1));
}
Also used : PackageUserKey(com.android.launcher3.util.PackageUserKey) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

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