Fix create duplicated custom bug
It's existing in old picker, not a regression. See analysis: b/157723282#comment3
Video of fixing, create same theme as custom1: https://drive.google.com/file/d/1m7RvAIs-EY8Um5BHUfRHSK2yzpHfozFF/view?usp=sharing
Test: Manually
Fixes: 157723282
Change-Id: I6dfbc7655e5de563b49b92fad075e185f2a92017
diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java
index 8cb2865..43b07ff 100644
--- a/src/com/android/customization/model/theme/ThemeBundle.java
+++ b/src/com/android/customization/model/theme/ThemeBundle.java
@@ -62,6 +62,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
/**
* Represents a Theme component available in the system as a "persona" bundle.
@@ -87,7 +88,7 @@
mTitle = title;
mIsDefault = isDefault;
mPreviewInfo = previewInfo;
- mPackagesByCategory = Collections.unmodifiableMap(overlayPackages);
+ mPackagesByCategory = Collections.unmodifiableMap(removeNullValues(overlayPackages));
}
@Override
@@ -214,6 +215,13 @@
}
}
+ private Map<String, String> removeNullValues(Map<String, String> map) {
+ return map.entrySet()
+ .stream()
+ .filter(entry -> entry.getValue() != null)
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+ }
+
protected CharSequence getContentDescription(Context context) {
if (mContentDescription == null) {
CharSequence defaultName = context.getString(R.string.default_theme_title);