Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,34 +135,34 @@ protected void serializeBody(XmlSerializer serializer, ResResource res)
}

protected String getTypeAsString() {
String s = "";
StringBuilder sb = new StringBuilder();
if ((mType & TYPE_REFERENCE) != 0) {
s += "|reference";
sb.append("|reference");
}
if ((mType & TYPE_STRING) != 0) {
s += "|string";
sb.append("|string");
}
if ((mType & TYPE_INT) != 0) {
s += "|integer";
sb.append("|integer");
}
if ((mType & TYPE_BOOL) != 0) {
s += "|boolean";
sb.append("|boolean");
}
if ((mType & TYPE_COLOR) != 0) {
s += "|color";
sb.append("|color");
}
if ((mType & TYPE_FLOAT) != 0) {
s += "|float";
sb.append("|float");
}
if ((mType & TYPE_DIMEN) != 0) {
s += "|dimension";
sb.append("|dimension");
}
if ((mType & TYPE_FRACTION) != 0) {
s += "|fraction";
sb.append("|fraction");
}
if (s.isEmpty()) {
if (sb.length() == 0) {
return null;
}
return s.substring(1);
return sb.substring(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,70 @@ public String convertToResXmlFormat(ResScalarValue value) throws AndrolibExcepti
return super.convertToResXmlFormat(value);
}
loadFlags();
int intVal = ((ResIntValue) value).getValue();

int intVal = ((ResIntValue) value).getValue();
if (intVal == 0) {
return renderFlags(mZeroFlags);
}

FlagItem[] flagItems = new FlagItem[mFlags.length];
int[] flags = new int[mFlags.length];
FlagItem[] flags = new FlagItem[mFlags.length];
int flagsCount = 0;
for (FlagItem flagItem : mFlags) {
int flag = flagItem.flag;
int flagsInt = 0;

for (FlagItem item : mFlags) {
int flag = item.flag;

if ((intVal & flag) != flag) {
if ((intVal & flag) != flag || (flagsInt & flag) == flag) {
continue;
}

if (!isSubpartOf(flag, flags)) {
flags[flagsCount] = flag;
flagItems[flagsCount++] = flagItem;
flags[flagsCount++] = item;
flagsInt |= flag;

if (intVal == flagsInt) {
break;
}
}
return renderFlags(Arrays.copyOf(flagItems, flagsCount));

if (flagsCount == 0) {
throw new AndrolibException(String.format("invalid flags in value: 0x%08x", intVal));
}

// Filter out redundant flags
if (flagsCount > 2) {
FlagItem[] filtered = new FlagItem[flagsCount];
int filteredCount = 0;

for (int i = 0; i < flagsCount; i++) {
FlagItem item = flags[i];
int mask = 0;

// Combine the other flags
for (int j = 0; j < flagsCount; j++) {
FlagItem other = flags[j];

if (j != i && other != null) {
mask |= other.flag;
}
}

// Keep only if it adds at least one unique bit
if ((item.flag & ~mask) != 0) {
filtered[filteredCount++] = item;
} else {
flags[i] = null;
}
}

flags = filtered;
flagsCount = filteredCount;
}

if (flagsCount != flags.length) {
flags = Arrays.copyOf(flags, flagsCount);
}

return renderFlags(flags);
}

@Override
Expand All @@ -98,15 +140,6 @@ protected void serializeBody(XmlSerializer serializer, ResResource res)
}
}

private boolean isSubpartOf(int flag, int[] flags) {
for (int f : flags) {
if ((f & flag) == flag) {
return true;
}
}
return false;
}

private String renderFlags(FlagItem[] flags) throws AndrolibException {
StringBuilder sb = new StringBuilder();
for (FlagItem flag : flags) {
Expand Down Expand Up @@ -139,6 +172,8 @@ private void loadFlags() {
mZeroFlags = Arrays.copyOf(zeroFlags, zeroFlagsCount);
mFlags = Arrays.copyOf(flags, flagsCount);

Arrays.sort(mFlags, Comparator.comparingInt((FlagItem item) -> Integer.bitCount(item.flag)).reversed());
Arrays.sort(mFlags,
Comparator.comparingInt((FlagItem item) -> Integer.bitCount(item.flag)).reversed()
.thenComparingInt((FlagItem item) -> item.flag));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public void netSecConfGeneric() throws BrutException {
Document doc = loadDocument(new File(sTestNewDir, "res/xml/network_security_config.xml"));

// Check if 'system' certificate exists
String systemCertExpr = "//base-config//certificates[@src='system']";
String systemCertExpr = "/network-security-config/base-config/trust-anchors/certificates[@src='system']";
NodeList systemCertNodes = evaluateXPath(doc, systemCertExpr, NodeList.class);
assertTrue(systemCertNodes.getLength() > 0);

// Check if 'user' certificate exists
String userCertExpr = "//base-config//certificates[@src='user']";
String userCertExpr = "/network-security-config/base-config/trust-anchors/certificates[@src='user']";
NodeList userCertNodes = evaluateXPath(doc, userCertExpr, NodeList.class);
assertTrue(userCertNodes.getLength() > 0);
}
Expand Down