Skip to content

Commit

Permalink
(feature) add protection level parsing
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
strazzere committed Aug 7, 2024
1 parent 461da32 commit 469693f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/android/content/res/chunk/types/Attribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
*/
public class Attribute implements Chunk {

public static class Permission {
public static final int PROTECTION_MASK_BASE = 0xF;

public static final int PROTECTION_NORMAL = 0;
public static final int PROTECTION_DANGEROUS = 1;
public static final int PROTECTION_SIGNATURE = 2;
public static final int PROTECTION_SIGNATURE_OR_SYSTEM = 3;
public static final int PROTECTION_INTERNAL = 4;
}

private int uri;
private int name;
private int stringData;
Expand Down Expand Up @@ -133,6 +143,9 @@ public String toXML(StringSection stringSection, ResourceSection resourceSection
}

buffer.append(stringSection.getString(name));
if (stringSection.getString(name).equals("protectionLevel")) {
boolean derp = true;
}

buffer.append("=\"");

Expand All @@ -153,13 +166,32 @@ public String toXML(StringSection stringSection, ResourceSection resourceSection
} else {
buffer.append("ERROR");
}
} else if (attributeType == AttributeType.FLAGS.getIntType()) {
buffer.append(getProtectionString(data));
}

buffer.append("\"");

return buffer.toString();
}

private String getProtectionString(int level) {
switch (level & Permission.PROTECTION_MASK_BASE) {
case Permission.PROTECTION_DANGEROUS:
return "dangerous";
case Permission.PROTECTION_NORMAL:
return "normal";
case Permission.PROTECTION_SIGNATURE:
return "signature";
case Permission.PROTECTION_SIGNATURE_OR_SYSTEM:
return "signatureOrSystem";
case Permission.PROTECTION_INTERNAL:
return "internal";
default:
return "????";
}
}

/*
* (non-Javadoc)
*
Expand Down

0 comments on commit 469693f

Please sign in to comment.