Added general handling of invalid config flags.

This commit is contained in:
Ryszard Wiśniewski 2010-08-30 15:13:38 +02:00
parent 2064de6a19
commit 31e987fa12
2 changed files with 24 additions and 6 deletions

View File

@ -43,6 +43,8 @@ public class ResConfigFlags {
public final byte screenLayout;
public final byte uiMode;
public final boolean isInvalid;
private final String mQualifiers;
public ResConfigFlags() {
@ -61,6 +63,7 @@ public class ResConfigFlags {
sdkVersion = 0;
screenLayout = SCREENLONG_ANY | SCREENSIZE_ANY;
uiMode = UI_MODE_TYPE_ANY | UI_MODE_NIGHT_ANY;
isInvalid = false;
mQualifiers = "";
}
@ -68,7 +71,7 @@ public class ResConfigFlags {
byte orientation, byte touchscreen, short density, byte keyboard,
byte navigation, byte inputFlags, short screenWidth,
short screenHeight, short sdkVersion, byte screenLayout,
byte uiMode) {
byte uiMode, boolean isInvalid) {
this.mcc = mcc;
this.mnc = mnc;
this.language = language;
@ -84,6 +87,7 @@ public class ResConfigFlags {
this.sdkVersion = sdkVersion;
this.screenLayout = screenLayout;
this.uiMode = uiMode;
this.isInvalid = isInvalid;
mQualifiers = generateQualifiers();
}
@ -234,6 +238,9 @@ public class ResConfigFlags {
if (sdkVersion > getNaturalSdkVersionRequirement()) {
ret.append("-v").append(sdkVersion);
}
if (isInvalid) {
ret.append("-[ERR]");
}
return ret.toString();
}

View File

@ -143,7 +143,11 @@ public class ARSCDecoder {
int[] entryOffsets = mIn.readIntArray(entryCount);
ResConfig config;
if (mPkg.hasConfig(flags)) {
if (flags.isInvalid) {
config = null;
LOGGER.warning(
"Invalid config flags detected. Dropping resources: " + mType.getName() + flags.getQualifiers());
} else if (mPkg.hasConfig(flags)) {
config = mPkg.getConfig(flags);
} else {
config = new ResConfig(flags);
@ -167,6 +171,13 @@ public class ARSCDecoder {
short flags = mIn.readShort();
int specNamesId = mIn.readInt();
ResValue value = (flags & ENTRY_FLAG_COMPLEX) == 0 ?
readValue() : readComplexEntry();
if (mConfig == null) {
return;
}
ResID resId = new ResID(mResId);
ResResSpec spec;
if (mPkg.hasResSpec(resId)) {
@ -177,9 +188,6 @@ public class ARSCDecoder {
mPkg.addResSpec(spec);
mType.addResSpec(spec);
}
ResValue value = (flags & ENTRY_FLAG_COMPLEX) == 0 ?
readValue() : readComplexEntry();
ResResource res = new ResResource(mConfig, spec, value);
mConfig.addResource(res);
@ -219,6 +227,8 @@ public class ARSCDecoder {
throw new AndrolibException("Config size < 28");
}
boolean isInvalid = false;
short mcc = mIn.readShort();
short mnc = mIn.readShort();
@ -262,7 +272,8 @@ public class ARSCDecoder {
return new ResConfigFlags(mcc, mnc, language, country, orientation,
touchscreen, density, keyboard, navigation, inputFlags,
screenWidth, screenHeight, sdkVersion, screenLayout, uiMode);
screenWidth, screenHeight, sdkVersion, screenLayout, uiMode,
isInvalid);
}
private void addMissingResSpecs() throws AndrolibException {