summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Svet Ganov <svetoslavganov@google.com> 2015-04-22 13:34:31 -0700
committer Svet Ganov <svetoslavganov@google.com> 2015-04-22 13:42:54 -0700
commitba0821ed3bc2536be02df1ae850619b111cbd6f4 (patch)
treeb608df12b48268882137d233fdac43a26021d6be
parent4f2dcfd48010a338dc9a2f5870ed12b382c30cd7 (diff)
Make read/write from/to XML persistent state more robust.
When writing critical state to XML an excpetion can lead to creating a malformed XML that is later parsed and may put the device in a bad state. Hence, on any error while writing we should bail out and drop the partially write state on the floor. Corollary, any error on parsing can lead to having a partially read state that is not consistent which may lead to writing this bad state back to disk. Hence, on any error while parsing we should bail as our current state may be unrecoverable. Change-Id: Ia050c16198cb583f8a51263ad2035dbb948052b8
-rw-r--r--packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java11
-rw-r--r--services/core/java/com/android/server/pm/Settings.java12
2 files changed, 15 insertions, 8 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
index c7092b386b49..0385d1eb02fd 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsState.java
@@ -383,8 +383,9 @@ final class SettingsState {
Slog.i(LOG_TAG, "[PERSIST END]");
}
- } catch (IOException e) {
- Slog.wtf(LOG_TAG, "Failed to write settings, restoring backup", e);
+ // Any error while writing is fatal.
+ } catch (Throwable t) {
+ Slog.wtf(LOG_TAG, "Failed to write settings, restoring backup", t);
destination.failWrite(out);
} finally {
IoUtils.closeQuietly(out);
@@ -406,9 +407,11 @@ final class SettingsState {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
parseStateLocked(parser);
- } catch (XmlPullParserException | IOException ise) {
+
+ // Any error while parsing is fatal.
+ } catch (Throwable t) {
throw new IllegalStateException("Failed parsing settings file: "
- + mStatePersistFile , ise);
+ + mStatePersistFile , t);
} finally {
IoUtils.closeQuietly(in);
}
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index f3fdb0d409fd..b3aa966e37a8 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -4269,9 +4269,11 @@ final class Settings {
serializer.endTag(null, TAG_RUNTIME_PERMISSIONS);
serializer.endDocument();
destination.finishWrite(out);
- } catch (IOException e) {
+
+ // Any error while writing is fatal.
+ } catch (Throwable t) {
Slog.wtf(PackageManagerService.TAG,
- "Failed to write settings, restoring backup", e);
+ "Failed to write settings, restoring backup", t);
destination.failWrite(out);
} finally {
IoUtils.closeQuietly(out);
@@ -4319,9 +4321,11 @@ final class Settings {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(in, null);
parseRuntimePermissionsLPr(parser, userId);
- } catch (XmlPullParserException | IOException ise) {
+
+ // Any error while parsing is fatal.
+ } catch (Throwable t) {
throw new IllegalStateException("Failed parsing permissions file: "
- + permissionsFile , ise);
+ + permissionsFile , t);
} finally {
IoUtils.closeQuietly(in);
}