OMS: Remove old overlays.xml versions
In order to allow the default theme to take effect, older
versions of overlays.xml need to be purged.
Bug: 35757608
Test: manual
Change-Id: Ib8719567455038e8d61bf75968a1842edc34edee
diff --git a/services/core/java/com/android/server/om/OverlayManagerSettings.java b/services/core/java/com/android/server/om/OverlayManagerSettings.java
index ff5c594..2262a2e 100644
--- a/services/core/java/com/android/server/om/OverlayManagerSettings.java
+++ b/services/core/java/com/android/server/om/OverlayManagerSettings.java
@@ -360,7 +360,7 @@
private static final String ATTR_USER_ID = "userId";
private static final String ATTR_VERSION = "version";
- private static final int CURRENT_VERSION = 1;
+ private static final int CURRENT_VERSION = 2;
public static void restore(@NonNull final ArrayList<SettingsItem> table,
@NonNull final InputStream is) throws IOException, XmlPullParserException {
@@ -372,7 +372,7 @@
XmlUtils.beginDocument(parser, TAG_OVERLAYS);
int version = XmlUtils.readIntAttribute(parser, ATTR_VERSION);
if (version != CURRENT_VERSION) {
- throw new XmlPullParserException("unrecognized version " + version);
+ upgrade(version);
}
int depth = parser.getDepth();
@@ -387,6 +387,18 @@
}
}
+ private static void upgrade(int oldVersion) throws XmlPullParserException {
+ switch (oldVersion) {
+ case 0:
+ case 1:
+ // Throw an exception which will cause the overlay file to be ignored
+ // and overwritten.
+ throw new XmlPullParserException("old version " + oldVersion + "; ignoring");
+ default:
+ throw new XmlPullParserException("unrecognized version " + oldVersion);
+ }
+ }
+
private static SettingsItem restoreRow(@NonNull final XmlPullParser parser, final int depth)
throws IOException {
final String packageName = XmlUtils.readStringAttribute(parser, ATTR_PACKAGE_NAME);