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
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 810a521..ce7addc 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -1554,10 +1554,15 @@
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 @@
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(