Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f693513 authored by Sebastian Franco's avatar Sebastian Franco
Browse files

When getting a widget provider by name, check all categories

Some widgets have different categories for special cases for Pixel
widgets and because of that, some times we can't find the provider,
so we need to go through all of the categories.

Flag: NA
Test: Manaul testing =(
Test: All widgets in widget_section.xml with alsoKeepInApp set to false will previously dissapear on the preview.
Fix: 331628371
Change-Id: Iffbb788cbb27c79a215d06d21c9d623462d6f7e6
parent 2a6ce152
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ public class AddItemActivity extends BaseActivity
        // user sees
        TextView widgetAppName = findViewById(R.id.widget_appName);
        WidgetSections.WidgetSection section = targetApp.widgetCategory == NO_CATEGORY ? null
                : WidgetSections.getWidgetSections(this).get(targetApp.widgetCategory);
                : WidgetSections.get(this).get(targetApp.widgetCategory);
        widgetAppName.setText(section == null ? info.loadLabel(getPackageManager())
                : getString(section.mSectionTitle));

+1 −1
Original line number Diff line number Diff line
@@ -419,7 +419,7 @@ public class LauncherPreviewRenderer extends ContextWrapper

    private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
        WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(
                info.providerName, info.user);
                info.providerName, info.user, mContext);
        if (widgetItem == null) {
            return;
        }
+1 −1
Original line number Diff line number Diff line
@@ -559,7 +559,7 @@ public class IconCache extends BaseIconCache {
            return;
        }

        WidgetSection widgetSection = WidgetSections.getWidgetSections(mContext)
        WidgetSection widgetSection = WidgetSections.get(mContext)
                .get(infoInOut.widgetCategory);
        infoInOut.title = mContext.getString(widgetSection.mSectionTitle);
        infoInOut.contentDescription = getUserBadgedLabel(infoInOut.title, infoInOut.user);
+32 −14
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.content.pm.PackageManager;
import android.os.UserHandle;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;

import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
@@ -201,8 +202,16 @@ public class WidgetsModel {
        // add and update.
        mWidgetsList.putAll(rawWidgetsShortcuts.stream()
                .filter(new WidgetValidityCheck(app))
                .flatMap(widgetItem -> getPackageUserKeys(app.getContext(), widgetItem).stream()
                        .map(key -> new Pair<>(packageItemInfoCache.getOrCreate(key), widgetItem)))
                .flatMap(
                        widgetItem -> getPackageUserKeys(app.getContext(), widgetItem)
                                .stream()
                                .map(
                                        key -> new Pair<>(
                                                packageItemInfoCache.getOrCreate(key),
                                                widgetItem
                                        )
                                )
                )
                .collect(groupingBy(pair -> pair.first, mapping(pair -> pair.second, toList()))));

        // Update each package entry
@@ -240,19 +249,26 @@ public class WidgetsModel {
    }

    public WidgetItem getWidgetProviderInfoByProviderName(
            ComponentName providerName, UserHandle user) {
            ComponentName providerName, UserHandle user, Context context) {
        SparseArray<WidgetSections.WidgetSection> sections = WidgetSections.get(
                context);
        if (!WIDGETS_ENABLED) {
            return null;
        }
        List<WidgetItem> widgetsList = mWidgetsList.get(
                new PackageItemInfo(providerName.getPackageName(), user));
        if (widgetsList == null) {
            return null;
        }

        for (WidgetItem item : widgetsList) {
            if (item.componentName.equals(providerName)) {
                return item;
        // Checking if we hav ea provider in any of the categories.
        for (int i = 0; i < sections.size(); i++) {
            PackageItemInfo key = new PackageItemInfo(
                    providerName.getPackageName(),
                    sections.get(i).mCategory,
                    user
            );
            if (mWidgetsList.containsKey(key)) {
                return mWidgetsList.get(key).stream().filter(
                                item -> item.componentName.equals(providerName)
                        )
                        .findFirst()
                        .orElse(null);
            }
        }
        return null;
@@ -286,10 +302,12 @@ public class WidgetsModel {
        categories.forEach(category -> {
            if (category == NO_CATEGORY) {
                packageUserKeys.add(
                        new PackageUserKey(item.componentName.getPackageName(),
                                item.user));
                        new PackageUserKey(item.componentName.getPackageName(), item.user)
                );
            } else {
                packageUserKeys.add(new PackageUserKey(category, item.user));
                packageUserKeys.add(
                        new PackageUserKey(item.componentName.getPackageName(), category, item.user)
                );
            }
        });
        return packageUserKeys;
+4 −0
Original line number Diff line number Diff line
@@ -48,6 +48,10 @@ public class PackageUserKey {
        update(/* packageName= */ "", widgetCategory, user);
    }

    public PackageUserKey(String packageName, int widgetCategory, UserHandle user) {
        update(packageName, widgetCategory, user);
    }

    public void update(String packageName, UserHandle user) {
        update(packageName, NO_CATEGORY, user);
    }
Loading