From e0129b3c672f5555deb75366b1a7159f41737874 Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Sun, 25 May 2014 16:41:09 -0700 Subject: Add more error checking to xml restore Bad files and OS updates can cause the restore to throw an NPE. Rather than bring down the server process over this, just delete the persistent file and keep going. Fixes bug 15219594. Change-Id: Id9cd39988ff93a26def036a05c46209364f2a4c0 --- .../core/java/com/android/server/am/ActivityRecord.java | 6 ++++-- .../core/java/com/android/server/am/TaskPersister.java | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'services') diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java index b948c41..b429b93 100755 --- a/services/core/java/com/android/server/am/ActivityRecord.java +++ b/services/core/java/com/android/server/am/ActivityRecord.java @@ -1154,13 +1154,15 @@ final class ActivityRecord { } if (intent == null) { - Slog.e(TAG, "restoreActivity error intent=" + intent); - return null; + throw new XmlPullParserException("restoreActivity error intent=" + intent); } final ActivityManagerService service = stackSupervisor.mService; final ActivityInfo aInfo = stackSupervisor.resolveActivity(intent, resolvedType, 0, null, null, userId); + if (aInfo == null) { + throw new XmlPullParserException("restoreActivity resolver error."); + } final ActivityRecord r = new ActivityRecord(service, /*caller*/null, launchedFromUid, launchedFromPackage, intent, resolvedType, aInfo, service.getConfiguration(), null, null, 0, componentSpecified, stackSupervisor, null, null); diff --git a/services/core/java/com/android/server/am/TaskPersister.java b/services/core/java/com/android/server/am/TaskPersister.java index ba3f2fe..3bfaca9 100644 --- a/services/core/java/com/android/server/am/TaskPersister.java +++ b/services/core/java/com/android/server/am/TaskPersister.java @@ -155,6 +155,7 @@ public class TaskPersister { File taskFile = recentFiles[taskNdx]; if (DEBUG) Slog.d(TAG, "restoreTasksLocked: taskFile=" + taskFile.getName()); BufferedReader reader = null; + boolean deleteFile = false; try { reader = new BufferedReader(new FileReader(taskFile)); final XmlPullParser in = Xml.newPullParser(); @@ -183,10 +184,9 @@ public class TaskPersister { } XmlUtils.skipCurrentTag(in); } - } catch (IOException e) { - Slog.e(TAG, "Unable to parse " + taskFile + ". Error " + e); - } catch (XmlPullParserException e) { - Slog.e(TAG, "Unable to parse " + taskFile + ". Error " + e); + } catch (Exception e) { + Slog.wtf(TAG, "Unable to parse " + taskFile + ". Error " + e); + deleteFile = true; } finally { if (reader != null) { try { @@ -194,6 +194,9 @@ public class TaskPersister { } catch (IOException e) { } } + if (!DEBUG && deleteFile) { + taskFile.delete(); + } } } @@ -220,7 +223,7 @@ public class TaskPersister { return new ArrayList(Arrays.asList(tasksArray)); } - private void removeObsoleteFiles(ArraySet persistentTaskIds, File[] files) { + private static void removeObsoleteFiles(ArraySet persistentTaskIds, File[] files) { for (int fileNdx = 0; fileNdx < files.length; ++fileNdx) { File file = files[fileNdx]; String filename = file.getName(); @@ -285,8 +288,7 @@ public class TaskPersister { synchronized(mService) { final ArrayList tasks = mService.mRecentTasks; persistentTaskIds.clear(); - int taskNdx; - for (taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { + for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) { task = tasks.get(taskNdx); if (DEBUG) Slog.d(TAG, "LazyTaskWriter: task=" + task + " persistable=" + task.isPersistable + " needsPersisting=" + task.needsPersisting); -- cgit v1.1