Merge "Make read/write from/to XML persistent state more robust."

This commit is contained in:
Svet Ganov
2015-04-22 20:44:19 +00:00
committed by Android (Google) Code Review
2 changed files with 15 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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);
}