feat: de-dupe attribute names during styles writing (#3404)

This commit is contained in:
Connor Tumbleson 2023-10-16 07:15:34 -04:00 committed by GitHub
parent 03fa70bd2a
commit 247735c434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,8 @@ import brut.util.Duo;
import org.xmlpull.v1.XmlSerializer; import org.xmlpull.v1.XmlSerializer;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializable { public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializable {
@ -47,6 +49,8 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
} else if (res.getResSpec().getName().indexOf('.') != -1) { } else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", ""); serializer.attribute(null, "parent", "");
} }
Set<String> processedNames = new HashSet<>();
for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) { for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) {
ResResSpec spec = mItem.m1.getReferent(); ResResSpec spec = mItem.m1.getReferent();
@ -70,6 +74,11 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false); name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
} }
// #3400 - Skip duplicate values, commonly seen are duplicate key-pairs on styles.
if (!isAnalysisMode() && processedNames.contains(name)) {
continue;
}
if (value == null) { if (value == null) {
value = mItem.m2.encodeAsResXmlValue(); value = mItem.m2.encodeAsResXmlValue();
} }
@ -82,8 +91,11 @@ public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializab
serializer.attribute(null, "name", name); serializer.attribute(null, "name", name);
serializer.text(value); serializer.text(value);
serializer.endTag(null, "item"); serializer.endTag(null, "item");
processedNames.add(name);
} }
serializer.endTag(null, "style"); serializer.endTag(null, "style");
processedNames.clear();
} }
private final Duo<ResReferenceValue, ResScalarValue>[] mItems; private final Duo<ResReferenceValue, ResScalarValue>[] mItems;

View File

@ -22,4 +22,8 @@ public class ResValue {
public boolean shouldRemoveUnknownRes() { public boolean shouldRemoveUnknownRes() {
return Config.getInstance().isDecodeResolveModeRemoving(); return Config.getInstance().isDecodeResolveModeRemoving();
} }
public boolean isAnalysisMode() {
return Config.getInstance().analysisMode;
}
} }