Revert "When getting a widget provider by name, check all categories"

This reverts commit 1f69351310.

Reason for revert: Testing odd behavior between google app and pixel weather and duplicate items issue
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:7e5ed568b9f14570a67293827c5c7248b2ac975d)
Merged-In: If181aa3e86969e8821b7e1cc765c3801f04489d2
Change-Id: If181aa3e86969e8821b7e1cc765c3801f04489d2
This commit is contained in:
Shamali Patwa
2024-04-18 18:16:38 +00:00
committed by Android Build Coastguard Worker
parent 398ba7a42c
commit 140124334a
6 changed files with 18 additions and 40 deletions
@@ -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.get(this).get(targetApp.widgetCategory);
: WidgetSections.getWidgetSections(this).get(targetApp.widgetCategory);
widgetAppName.setText(section == null ? info.loadLabel(getPackageManager())
: getString(section.mSectionTitle));
@@ -419,7 +419,7 @@ public class LauncherPreviewRenderer extends ContextWrapper
private void inflateAndAddWidgets(LauncherAppWidgetInfo info, WidgetsModel widgetsModel) {
WidgetItem widgetItem = widgetsModel.getWidgetProviderInfoByProviderName(
info.providerName, info.user, mContext);
info.providerName, info.user);
if (widgetItem == null) {
return;
}
@@ -559,7 +559,7 @@ public class IconCache extends BaseIconCache {
return;
}
WidgetSection widgetSection = WidgetSections.get(mContext)
WidgetSection widgetSection = WidgetSections.getWidgetSections(mContext)
.get(infoInOut.widgetCategory);
infoInOut.title = mContext.getString(widgetSection.mSectionTitle);
infoInOut.contentDescription = getUserBadgedLabel(infoInOut.title, infoInOut.user);
@@ -18,7 +18,6 @@ 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;
@@ -202,16 +201,8 @@ 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
@@ -249,26 +240,19 @@ public class WidgetsModel {
}
public WidgetItem getWidgetProviderInfoByProviderName(
ComponentName providerName, UserHandle user, Context context) {
SparseArray<WidgetSections.WidgetSection> sections = WidgetSections.get(
context);
ComponentName providerName, UserHandle user) {
if (!WIDGETS_ENABLED) {
return null;
}
List<WidgetItem> widgetsList = mWidgetsList.get(
new PackageItemInfo(providerName.getPackageName(), user));
if (widgetsList == null) {
return null;
}
// 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);
for (WidgetItem item : widgetsList) {
if (item.componentName.equals(providerName)) {
return item;
}
}
return null;
@@ -302,12 +286,10 @@ 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(item.componentName.getPackageName(), category, item.user)
);
packageUserKeys.add(new PackageUserKey(category, item.user));
}
});
return packageUserKeys;
@@ -48,10 +48,6 @@ 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);
}
@@ -50,7 +50,7 @@ public final class WidgetSections {
private static Map<ComponentName, IntSet> sWidgetsToCategories;
/** Returns a list of widget sections that are shown in the widget picker. */
public static synchronized SparseArray<WidgetSection> get(Context context) {
public static synchronized SparseArray<WidgetSection> getWidgetSections(Context context) {
if (sWidgetSections != null) {
return sWidgetSections;
}