Skip to content

Commit

Permalink
[XML] handle type '^attr-private'
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Feb 14, 2023
1 parent 37df67c commit 6a83ddd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/apk/ApkModuleXmlDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void decodeValues(EntryStore entryStore, File outDir, TypeBlock typeBloc
xmlDocument.save(file, false);
}
private XMLElement decodeValue(EntryStore entryStore, Entry entry){
XMLElement element=new XMLElement(entry.getTypeName());
XMLElement element=new XMLElement(XmlHelper.toXMLTagName(entry.getTypeName()));
int resourceId= entry.getResourceId();
XMLAttribute attribute=new XMLAttribute("name", entry.getName());
element.addAttribute(attribute);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/reandroid/apk/XmlHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ public static void setTextContent(XMLElement element, StringItem stringItem){
element.setSpannableText(stringItem.getXml());
}
}
public static String toXMLTagName(String typeName){
// e.g ^attr-private
if(typeName.length()>0 && typeName.charAt(0)=='^'){
typeName = typeName.substring(1);
}
return typeName;
}
}
10 changes: 9 additions & 1 deletion src/main/java/com/reandroid/apk/xmlencoder/EncodeMaterials.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ public SpecString getSpecString(String name){
.get(0);
}
public Entry getAttributeBlock(String refString){
String packageName = null;
String type = "attr";
Entry entry = getAttributeBlock(type, refString);
if(entry == null){
type = "^attr-private";
entry = getAttributeBlock(type, refString);
}
return entry;
}
private Entry getAttributeBlock(String type, String refString){
String packageName = null;
String name = refString;
int i=refString.lastIndexOf(':');
if(i>=0){
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/reandroid/apk/xmlencoder/EncodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ public static String getTypeNameFromValuesXml(File valuesXml){
return name;
}
public static String sanitizeType(String type){
if(type.startsWith("^attr")){
return type;
}
Matcher matcher=PATTERN_TYPE.matcher(type);
if(!matcher.find()){
return "";
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/reandroid/apk/xmlencoder/ValuesEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public ValuesEncoder(EncodeMaterials materials){
this.commonEncoder=new XMLValuesEncoderCommon(materials);

Map<String, XMLValuesEncoderBag> mapBag=new HashMap<>();
mapBag.put("attr", new XMLValuesEncoderAttr(materials));
XMLValuesEncoderAttr encoderAttr = new XMLValuesEncoderAttr(materials);
mapBag.put("attr", encoderAttr);
mapBag.put("^attr-private", encoderAttr);
mapBag.put("plurals", new XMLValuesEncoderPlurals(materials));
mapBag.put("array", new XMLValuesEncoderArray(materials));
mapBag.put("style", new XMLValuesEncoderStyle(materials));
Expand Down Expand Up @@ -79,6 +81,9 @@ private boolean isBag(XMLDocument xmlDocument, String type){
if(type.startsWith("attr")){
return true;
}
if(type.startsWith("^attr")){
return true;
}
if(type.startsWith("style")){
return true;
}
Expand Down Expand Up @@ -117,6 +122,9 @@ private String getType(XMLDocument xmlDocument, String def){
if(type.endsWith("-array")){
return "array";
}
if(type.startsWith("attr-private")){
return "^attr-private";
}
if(type.equals("item")){
return def;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.reandroid.arsc.array.ResValueMapArray;
import com.reandroid.arsc.decoder.ValueDecoder;
import com.reandroid.arsc.value.EntryHeaderMap;
import com.reandroid.arsc.value.ResTableMapEntry;
import com.reandroid.arsc.value.ResValueMap;
import com.reandroid.arsc.value.ValueType;
Expand All @@ -42,8 +43,10 @@ int getChildesCount(XMLElement element){
void encodeChildes(XMLElement parentElement, ResTableMapEntry mapEntry){
encodeAttributes(parentElement, mapEntry);
encodeEnumOrFlag(parentElement, mapEntry);
// TODO: re-check if this is necessary
mapEntry.getHeader().setPublic(true);
EntryHeaderMap header = mapEntry.getHeader();
boolean is_public = !mapEntry.getParentEntry()
.getTypeName().contains("private");
header.setPublic(is_public);
}
private void encodeAttributes(XMLElement parentElement, ResTableMapEntry mapEntry){
ResValueMapArray mapArray = mapEntry.getValue();
Expand Down

0 comments on commit 6a83ddd

Please sign in to comment.