KeySets: better rejection for badly-formed manifest

During testing, I typed in a <publicKey> tag incorrectly and it
clobbered the previously defined key entry since it still parsed the
subsequent <keyset> tag defining an alias.

This gives more information in the log when running into such parsing
errors.

Change-Id: Id3c8e85530b1a5e39f4a2cb6ea8bd5521cb6918f
This commit is contained in:
Kenny Root
2013-07-10 14:01:49 -07:00
parent 47e36c3cfe
commit 37dca155aa

View File

@@ -1554,10 +1554,15 @@ public class PackageParser {
int type;
PublicKey currentKey = null;
int currentKeyDepth = -1;
Map<PublicKey, Set<String>> definedKeySets = new HashMap<PublicKey, Set<String>>();
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG) {
if (parser.getDepth() == currentKeyDepth) {
currentKey = null;
currentKeyDepth = -1;
}
continue;
}
String tagname = parser.getName();
@@ -1567,9 +1572,21 @@ public class PackageParser {
final String encodedKey = sa.getNonResourceString(
com.android.internal.R.styleable.PublicKey_value);
currentKey = parsePublicKey(encodedKey);
if (currentKey == null) {
Slog.w(TAG, "No valid key in 'publicKey' tag at "
+ parser.getPositionDescription());
sa.recycle();
continue;
}
currentKeyDepth = parser.getDepth();
definedKeySets.put(currentKey, new HashSet<String>());
sa.recycle();
} else if (tagname.equals("keyset")) {
if (currentKey == null) {
Slog.i(TAG, "'keyset' not in 'publicKey' tag at "
+ parser.getPositionDescription());
continue;
}
final TypedArray sa = res.obtainAttributes(attrs,
com.android.internal.R.styleable.KeySet);
final String name = sa.getNonResourceString(