blob: 465fa674d166aecd49e44b43dc47da60dda168af [file] [log] [blame]
Craig Mautner21d24a22014-04-23 11:45:37 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.am;
18
Suprabh Shukla4bccb462016-02-10 18:45:12 -080019import android.annotation.NonNull;
Craig Mautner21d24a22014-04-23 11:45:37 -070020import android.graphics.Bitmap;
21import android.graphics.BitmapFactory;
22import android.os.Debug;
Suprabh Shukla23593142015-11-03 17:31:15 -080023import android.os.Environment;
24import android.os.FileUtils;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080025import android.os.Process;
Craig Mautner21d24a22014-04-23 11:45:37 -070026import android.os.SystemClock;
27import android.util.ArraySet;
28import android.util.AtomicFile;
29import android.util.Slog;
Suprabh Shukla4bccb462016-02-10 18:45:12 -080030import android.util.SparseArray;
31import android.util.SparseBooleanArray;
Craig Mautner21d24a22014-04-23 11:45:37 -070032import android.util.Xml;
Wale Ogunwale18795a22014-12-03 11:38:33 -080033
Suprabh Shukla4bccb462016-02-10 18:45:12 -080034import com.android.internal.annotations.VisibleForTesting;
Craig Mautner21d24a22014-04-23 11:45:37 -070035import com.android.internal.util.FastXmlSerializer;
36import com.android.internal.util.XmlUtils;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080037import libcore.io.IoUtils;
38
Craig Mautner21d24a22014-04-23 11:45:37 -070039import org.xmlpull.v1.XmlPullParser;
40import org.xmlpull.v1.XmlPullParserException;
41import org.xmlpull.v1.XmlSerializer;
42
43import java.io.BufferedReader;
Suprabh Shukla4bccb462016-02-10 18:45:12 -080044import java.io.BufferedWriter;
Craig Mautner21d24a22014-04-23 11:45:37 -070045import java.io.File;
Suprabh Shukla4bccb462016-02-10 18:45:12 -080046import java.io.FileNotFoundException;
Craig Mautner21d24a22014-04-23 11:45:37 -070047import java.io.FileOutputStream;
48import java.io.FileReader;
Suprabh Shukla4bccb462016-02-10 18:45:12 -080049import java.io.FileWriter;
Craig Mautner21d24a22014-04-23 11:45:37 -070050import java.io.IOException;
51import java.io.StringWriter;
52import java.util.ArrayList;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080053import java.util.Collections;
Craig Mautner21d24a22014-04-23 11:45:37 -070054import java.util.Comparator;
Suprabh Shukla23593142015-11-03 17:31:15 -080055import java.util.List;
Wale Ogunwale18795a22014-12-03 11:38:33 -080056
Winson Chung7900bee2017-03-10 08:59:25 -080057import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS;
Wale Ogunwale625ed0c2016-10-18 08:50:31 -070058
Craig Mautner21d24a22014-04-23 11:45:37 -070059public class TaskPersister {
60 static final String TAG = "TaskPersister";
Stefan Kuhnee88d1e52015-05-18 10:33:45 -070061 static final boolean DEBUG = false;
Craig Mautner21d24a22014-04-23 11:45:37 -070062
Craig Mautnerf4f8bb72014-07-29 10:41:40 -070063 /** When not flushing don't write out files faster than this */
64 private static final long INTER_WRITE_DELAY_MS = 500;
65
Suprabh Shukla23593142015-11-03 17:31:15 -080066 /**
67 * When not flushing delay this long before writing the first file out. This gives the next task
68 * being launched a chance to load its resources without this occupying IO bandwidth.
69 */
Craig Mautnerf4f8bb72014-07-29 10:41:40 -070070 private static final long PRE_TASK_DELAY_MS = 3000;
Craig Mautner21d24a22014-04-23 11:45:37 -070071
Craig Mautner63f10902014-09-16 23:57:21 -070072 /** The maximum number of entries to keep in the queue before draining it automatically. */
73 private static final int MAX_WRITE_QUEUE_LENGTH = 6;
74
75 /** Special value for mWriteTime to mean don't wait, just write */
76 private static final long FLUSH_QUEUE = -1;
77
Craig Mautner21d24a22014-04-23 11:45:37 -070078 private static final String TASKS_DIRNAME = "recent_tasks";
Daichi Hirono4cb941e2017-03-31 14:30:41 +090079 private static final String TASK_FILENAME_SUFFIX = "_task.xml";
Craig Mautner21d24a22014-04-23 11:45:37 -070080 private static final String IMAGES_DIRNAME = "recent_images";
Suprabh Shukla4bccb462016-02-10 18:45:12 -080081 private static final String PERSISTED_TASK_IDS_FILENAME = "persisted_taskIds.txt";
Craig Mautnerc0ffce52014-07-01 12:38:52 -070082 static final String IMAGE_EXTENSION = ".png";
Craig Mautner21d24a22014-04-23 11:45:37 -070083
Winson Chung36f3f032016-09-08 23:29:43 +000084 private static final String TAG_TASK = "task";
Craig Mautner21d24a22014-04-23 11:45:37 -070085
Wale Ogunwale16e505a2018-05-07 15:00:49 -070086 private final ActivityTaskManagerService mService;
Craig Mautner21d24a22014-04-23 11:45:37 -070087 private final ActivityStackSupervisor mStackSupervisor;
Wale Ogunwalec82f2f52014-12-09 09:32:50 -080088 private final RecentTasks mRecentTasks;
Suprabh Shukla4bccb462016-02-10 18:45:12 -080089 private final SparseArray<SparseBooleanArray> mTaskIdsInFile = new SparseArray<>();
Suprabh Shuklaf50b4582016-02-23 17:44:22 -080090 private final File mTaskIdsDir;
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -070091 // To lock file operations in TaskPersister
92 private final Object mIoLock = new Object();
Craig Mautner21d24a22014-04-23 11:45:37 -070093
Suprabh Shukla23593142015-11-03 17:31:15 -080094 /**
95 * Value determines write delay mode as follows: < 0 We are Flushing. No delays between writes
96 * until the image queue is drained and all tasks needing persisting are written to disk. There
97 * is no delay between writes. == 0 We are Idle. Next writes will be delayed by
98 * #PRE_TASK_DELAY_MS. > 0 We are Actively writing. Next write will be at this time. Subsequent
99 * writes will be delayed by #INTER_WRITE_DELAY_MS.
100 */
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700101 private long mNextWriteTime = 0;
Craig Mautner21d24a22014-04-23 11:45:37 -0700102
103 private final LazyTaskWriterThread mLazyTaskWriterThread;
104
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700105 private static class WriteQueueItem {}
Suprabh Shukla23593142015-11-03 17:31:15 -0800106
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700107 private static class TaskWriteQueueItem extends WriteQueueItem {
108 final TaskRecord mTask;
Winsonc809cbb2015-11-02 12:06:15 -0800109
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700110 TaskWriteQueueItem(TaskRecord task) {
111 mTask = task;
112 }
113 }
Suprabh Shukla23593142015-11-03 17:31:15 -0800114
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700115 private static class ImageWriteQueueItem extends WriteQueueItem {
Suprabh Shukla23593142015-11-03 17:31:15 -0800116 final String mFilePath;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700117 Bitmap mImage;
Winsonc809cbb2015-11-02 12:06:15 -0800118
Suprabh Shukla23593142015-11-03 17:31:15 -0800119 ImageWriteQueueItem(String filePath, Bitmap image) {
120 mFilePath = filePath;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700121 mImage = image;
122 }
123 }
124
125 ArrayList<WriteQueueItem> mWriteQueue = new ArrayList<WriteQueueItem>();
126
Wale Ogunwalec82f2f52014-12-09 09:32:50 -0800127 TaskPersister(File systemDir, ActivityStackSupervisor stackSupervisor,
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700128 ActivityTaskManagerService service, RecentTasks recentTasks) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800129
130 final File legacyImagesDir = new File(systemDir, IMAGES_DIRNAME);
131 if (legacyImagesDir.exists()) {
132 if (!FileUtils.deleteContents(legacyImagesDir) || !legacyImagesDir.delete()) {
133 Slog.i(TAG, "Failure deleting legacy images directory: " + legacyImagesDir);
Craig Mautner21d24a22014-04-23 11:45:37 -0700134 }
135 }
136
Suprabh Shukla23593142015-11-03 17:31:15 -0800137 final File legacyTasksDir = new File(systemDir, TASKS_DIRNAME);
138 if (legacyTasksDir.exists()) {
139 if (!FileUtils.deleteContents(legacyTasksDir) || !legacyTasksDir.delete()) {
140 Slog.i(TAG, "Failure deleting legacy tasks directory: " + legacyTasksDir);
Craig Mautner21d24a22014-04-23 11:45:37 -0700141 }
142 }
143
Suprabh Shuklaf50b4582016-02-23 17:44:22 -0800144 mTaskIdsDir = new File(Environment.getDataDirectory(), "system_de");
Craig Mautner21d24a22014-04-23 11:45:37 -0700145 mStackSupervisor = stackSupervisor;
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800146 mService = service;
Wale Ogunwalec82f2f52014-12-09 09:32:50 -0800147 mRecentTasks = recentTasks;
Craig Mautner21d24a22014-04-23 11:45:37 -0700148 mLazyTaskWriterThread = new LazyTaskWriterThread("LazyTaskWriterThread");
149 }
150
Suprabh Shuklaf50b4582016-02-23 17:44:22 -0800151 @VisibleForTesting
152 TaskPersister(File workingDir) {
153 mTaskIdsDir = workingDir;
154 mStackSupervisor = null;
155 mService = null;
156 mRecentTasks = null;
157 mLazyTaskWriterThread = new LazyTaskWriterThread("LazyTaskWriterThreadTest");
158 }
159
Craig Mautner21d24a22014-04-23 11:45:37 -0700160 void startPersisting() {
Wale Ogunwalec82f2f52014-12-09 09:32:50 -0800161 if (!mLazyTaskWriterThread.isAlive()) {
162 mLazyTaskWriterThread.start();
163 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700164 }
165
Craig Mautner63f10902014-09-16 23:57:21 -0700166 private void removeThumbnails(TaskRecord task) {
167 final String taskString = Integer.toString(task.taskId);
168 for (int queueNdx = mWriteQueue.size() - 1; queueNdx >= 0; --queueNdx) {
169 final WriteQueueItem item = mWriteQueue.get(queueNdx);
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800170 if (item instanceof ImageWriteQueueItem) {
171 final File thumbnailFile = new File(((ImageWriteQueueItem) item).mFilePath);
172 if (thumbnailFile.getName().startsWith(taskString)) {
173 if (DEBUG) {
174 Slog.d(TAG, "Removing " + ((ImageWriteQueueItem) item).mFilePath +
175 " from write queue");
176 }
177 mWriteQueue.remove(queueNdx);
178 }
Craig Mautner63f10902014-09-16 23:57:21 -0700179 }
180 }
181 }
182
183 private void yieldIfQueueTooDeep() {
184 boolean stall = false;
185 synchronized (this) {
186 if (mNextWriteTime == FLUSH_QUEUE) {
187 stall = true;
188 }
189 }
190 if (stall) {
191 Thread.yield();
192 }
193 }
194
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800195 @NonNull
196 SparseBooleanArray loadPersistedTaskIdsForUser(int userId) {
197 if (mTaskIdsInFile.get(userId) != null) {
198 return mTaskIdsInFile.get(userId).clone();
199 }
200 final SparseBooleanArray persistedTaskIds = new SparseBooleanArray();
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700201 synchronized (mIoLock) {
202 BufferedReader reader = null;
203 String line;
204 try {
205 reader = new BufferedReader(new FileReader(getUserPersistedTaskIdsFile(userId)));
206 while ((line = reader.readLine()) != null) {
207 for (String taskIdString : line.split("\\s+")) {
208 int id = Integer.parseInt(taskIdString);
209 persistedTaskIds.put(id, true);
210 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800211 }
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700212 } catch (FileNotFoundException e) {
213 // File doesn't exist. Ignore.
214 } catch (Exception e) {
215 Slog.e(TAG, "Error while reading taskIds file for user " + userId, e);
216 } finally {
217 IoUtils.closeQuietly(reader);
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800218 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800219 }
220 mTaskIdsInFile.put(userId, persistedTaskIds);
221 return persistedTaskIds.clone();
222 }
223
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700224
Suprabh Shuklaf50b4582016-02-23 17:44:22 -0800225 @VisibleForTesting
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700226 void writePersistedTaskIdsForUser(@NonNull SparseBooleanArray taskIds, int userId) {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800227 if (userId < 0) {
228 return;
229 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800230 final File persistedTaskIdsFile = getUserPersistedTaskIdsFile(userId);
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700231 synchronized (mIoLock) {
232 BufferedWriter writer = null;
233 try {
234 writer = new BufferedWriter(new FileWriter(persistedTaskIdsFile));
235 for (int i = 0; i < taskIds.size(); i++) {
236 if (taskIds.valueAt(i)) {
237 writer.write(String.valueOf(taskIds.keyAt(i)));
238 writer.newLine();
239 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800240 }
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700241 } catch (Exception e) {
242 Slog.e(TAG, "Error while writing taskIds file for user " + userId, e);
243 } finally {
244 IoUtils.closeQuietly(writer);
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800245 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800246 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800247 }
248
249 void unloadUserDataFromMemory(int userId) {
250 mTaskIdsInFile.delete(userId);
251 }
252
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700253 void wakeup(TaskRecord task, boolean flush) {
Craig Mautner21d24a22014-04-23 11:45:37 -0700254 synchronized (this) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700255 if (task != null) {
256 int queueNdx;
257 for (queueNdx = mWriteQueue.size() - 1; queueNdx >= 0; --queueNdx) {
258 final WriteQueueItem item = mWriteQueue.get(queueNdx);
259 if (item instanceof TaskWriteQueueItem &&
260 ((TaskWriteQueueItem) item).mTask == task) {
Craig Mautner63f10902014-09-16 23:57:21 -0700261 if (!task.inRecents) {
262 // This task is being removed.
263 removeThumbnails(task);
264 }
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700265 break;
266 }
267 }
Wale Ogunwalebe23ff42014-10-21 16:29:51 -0700268 if (queueNdx < 0 && task.isPersistable) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700269 mWriteQueue.add(new TaskWriteQueueItem(task));
270 }
271 } else {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800272 // Dummy. Ensures removeObsoleteFiles is called when LazyTaskThreadWriter is
273 // notified.
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700274 mWriteQueue.add(new WriteQueueItem());
275 }
Craig Mautner63f10902014-09-16 23:57:21 -0700276 if (flush || mWriteQueue.size() > MAX_WRITE_QUEUE_LENGTH) {
277 mNextWriteTime = FLUSH_QUEUE;
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700278 } else if (mNextWriteTime == 0) {
279 mNextWriteTime = SystemClock.uptimeMillis() + PRE_TASK_DELAY_MS;
280 }
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700281 if (DEBUG) Slog.d(TAG, "wakeup: task=" + task + " flush=" + flush + " mNextWriteTime="
282 + mNextWriteTime + " mWriteQueue.size=" + mWriteQueue.size()
283 + " Callers=" + Debug.getCallers(4));
Craig Mautner21d24a22014-04-23 11:45:37 -0700284 notifyAll();
285 }
Craig Mautner63f10902014-09-16 23:57:21 -0700286
287 yieldIfQueueTooDeep();
Craig Mautner21d24a22014-04-23 11:45:37 -0700288 }
289
Dianne Hackbornce0fd762014-09-19 12:58:15 -0700290 void flush() {
291 synchronized (this) {
292 mNextWriteTime = FLUSH_QUEUE;
293 notifyAll();
294 do {
295 try {
296 wait();
297 } catch (InterruptedException e) {
298 }
299 } while (mNextWriteTime == FLUSH_QUEUE);
300 }
301 }
302
Suprabh Shukla23593142015-11-03 17:31:15 -0800303 void saveImage(Bitmap image, String filePath) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700304 synchronized (this) {
305 int queueNdx;
306 for (queueNdx = mWriteQueue.size() - 1; queueNdx >= 0; --queueNdx) {
307 final WriteQueueItem item = mWriteQueue.get(queueNdx);
308 if (item instanceof ImageWriteQueueItem) {
309 ImageWriteQueueItem imageWriteQueueItem = (ImageWriteQueueItem) item;
Suprabh Shukla23593142015-11-03 17:31:15 -0800310 if (imageWriteQueueItem.mFilePath.equals(filePath)) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700311 // replace the Bitmap with the new one.
312 imageWriteQueueItem.mImage = image;
313 break;
314 }
315 }
316 }
317 if (queueNdx < 0) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800318 mWriteQueue.add(new ImageWriteQueueItem(filePath, image));
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700319 }
Craig Mautner63f10902014-09-16 23:57:21 -0700320 if (mWriteQueue.size() > MAX_WRITE_QUEUE_LENGTH) {
321 mNextWriteTime = FLUSH_QUEUE;
322 } else if (mNextWriteTime == 0) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700323 mNextWriteTime = SystemClock.uptimeMillis() + PRE_TASK_DELAY_MS;
324 }
Suprabh Shukla23593142015-11-03 17:31:15 -0800325 if (DEBUG) Slog.d(TAG, "saveImage: filePath=" + filePath + " now=" +
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700326 SystemClock.uptimeMillis() + " mNextWriteTime=" +
327 mNextWriteTime + " Callers=" + Debug.getCallers(4));
328 notifyAll();
329 }
Craig Mautner63f10902014-09-16 23:57:21 -0700330
331 yieldIfQueueTooDeep();
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700332 }
333
Suprabh Shukla23593142015-11-03 17:31:15 -0800334 Bitmap getTaskDescriptionIcon(String filePath) {
Craig Mautner648f69b2014-09-18 14:16:26 -0700335 // See if it is in the write queue
Suprabh Shukla23593142015-11-03 17:31:15 -0800336 final Bitmap icon = getImageFromWriteQueue(filePath);
Craig Mautner648f69b2014-09-18 14:16:26 -0700337 if (icon != null) {
338 return icon;
339 }
Suprabh Shukla23593142015-11-03 17:31:15 -0800340 return restoreImage(filePath);
Craig Mautner648f69b2014-09-18 14:16:26 -0700341 }
342
Suprabh Shukla23593142015-11-03 17:31:15 -0800343 Bitmap getImageFromWriteQueue(String filePath) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700344 synchronized (this) {
345 for (int queueNdx = mWriteQueue.size() - 1; queueNdx >= 0; --queueNdx) {
346 final WriteQueueItem item = mWriteQueue.get(queueNdx);
347 if (item instanceof ImageWriteQueueItem) {
348 ImageWriteQueueItem imageWriteQueueItem = (ImageWriteQueueItem) item;
Suprabh Shukla23593142015-11-03 17:31:15 -0800349 if (imageWriteQueueItem.mFilePath.equals(filePath)) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700350 return imageWriteQueueItem.mImage;
351 }
352 }
353 }
354 return null;
355 }
356 }
357
Craig Mautner21d24a22014-04-23 11:45:37 -0700358 private StringWriter saveToXml(TaskRecord task) throws IOException, XmlPullParserException {
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700359 if (DEBUG) Slog.d(TAG, "saveToXml: task=" + task);
Craig Mautner21d24a22014-04-23 11:45:37 -0700360 final XmlSerializer xmlSerializer = new FastXmlSerializer();
361 StringWriter stringWriter = new StringWriter();
362 xmlSerializer.setOutput(stringWriter);
363
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700364 if (DEBUG) xmlSerializer.setFeature(
Suprabh Shukla23593142015-11-03 17:31:15 -0800365 "http://xmlpull.org/v1/doc/features.html#indent-output", true);
Craig Mautner21d24a22014-04-23 11:45:37 -0700366
367 // save task
368 xmlSerializer.startDocument(null, true);
369
370 xmlSerializer.startTag(null, TAG_TASK);
371 task.saveToXml(xmlSerializer);
372 xmlSerializer.endTag(null, TAG_TASK);
373
374 xmlSerializer.endDocument();
375 xmlSerializer.flush();
376
377 return stringWriter;
378 }
379
Craig Mautner77b04262014-06-27 15:22:12 -0700380 private String fileToString(File file) {
381 final String newline = System.lineSeparator();
382 try {
383 BufferedReader reader = new BufferedReader(new FileReader(file));
384 StringBuffer sb = new StringBuffer((int) file.length() * 2);
385 String line;
386 while ((line = reader.readLine()) != null) {
387 sb.append(line + newline);
388 }
389 reader.close();
390 return sb.toString();
391 } catch (IOException ioe) {
392 Slog.e(TAG, "Couldn't read file " + file.getName());
393 return null;
394 }
395 }
396
Craig Mautnera228ae92014-07-09 05:44:55 -0700397 private TaskRecord taskIdToTask(int taskId, ArrayList<TaskRecord> tasks) {
398 if (taskId < 0) {
399 return null;
400 }
401 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
402 final TaskRecord task = tasks.get(taskNdx);
403 if (task.taskId == taskId) {
404 return task;
405 }
406 }
407 Slog.e(TAG, "Restore affiliation error looking for taskId=" + taskId);
408 return null;
409 }
410
Daichi Hirono4cb941e2017-03-31 14:30:41 +0900411 List<TaskRecord> restoreTasksForUserLocked(final int userId, SparseBooleanArray preaddedTasks) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800412 final ArrayList<TaskRecord> tasks = new ArrayList<TaskRecord>();
Craig Mautner21d24a22014-04-23 11:45:37 -0700413 ArraySet<Integer> recoveredTaskIds = new ArraySet<Integer>();
414
Suprabh Shukla23593142015-11-03 17:31:15 -0800415 File userTasksDir = getUserTasksDir(userId);
Winson Chung36f3f032016-09-08 23:29:43 +0000416
Suprabh Shukla23593142015-11-03 17:31:15 -0800417 File[] recentFiles = userTasksDir.listFiles();
Craig Mautner21d24a22014-04-23 11:45:37 -0700418 if (recentFiles == null) {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800419 Slog.e(TAG, "restoreTasksForUserLocked: Unable to list files from " + userTasksDir);
Craig Mautner21d24a22014-04-23 11:45:37 -0700420 return tasks;
421 }
422
423 for (int taskNdx = 0; taskNdx < recentFiles.length; ++taskNdx) {
424 File taskFile = recentFiles[taskNdx];
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800425 if (DEBUG) {
426 Slog.d(TAG, "restoreTasksForUserLocked: userId=" + userId
427 + ", taskFile=" + taskFile.getName());
428 }
Daichi Hirono4cb941e2017-03-31 14:30:41 +0900429
430 if (!taskFile.getName().endsWith(TASK_FILENAME_SUFFIX)) {
431 continue;
432 }
433 try {
434 final int taskId = Integer.parseInt(taskFile.getName().substring(
435 0 /* beginIndex */,
436 taskFile.getName().length() - TASK_FILENAME_SUFFIX.length()));
437 if (preaddedTasks.get(taskId, false)) {
438 Slog.w(TAG, "Task #" + taskId +
439 " has already been created so we don't restore again");
440 continue;
441 }
442 } catch (NumberFormatException e) {
443 Slog.w(TAG, "Unexpected task file name", e);
444 continue;
445 }
446
Craig Mautner21d24a22014-04-23 11:45:37 -0700447 BufferedReader reader = null;
Craig Mautnere0129b32014-05-25 16:41:09 -0700448 boolean deleteFile = false;
Craig Mautner21d24a22014-04-23 11:45:37 -0700449 try {
450 reader = new BufferedReader(new FileReader(taskFile));
451 final XmlPullParser in = Xml.newPullParser();
452 in.setInput(reader);
453
454 int event;
455 while (((event = in.next()) != XmlPullParser.END_DOCUMENT) &&
456 event != XmlPullParser.END_TAG) {
457 final String name = in.getName();
458 if (event == XmlPullParser.START_TAG) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800459 if (DEBUG) Slog.d(TAG, "restoreTasksForUserLocked: START_TAG name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -0700460 if (TAG_TASK.equals(name)) {
Winson Chung36f3f032016-09-08 23:29:43 +0000461 final TaskRecord task = TaskRecord.restoreFromXml(in, mStackSupervisor);
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800462 if (DEBUG) Slog.d(TAG, "restoreTasksForUserLocked: restored task="
Suprabh Shukla23593142015-11-03 17:31:15 -0800463 + task);
Craig Mautner21d24a22014-04-23 11:45:37 -0700464 if (task != null) {
Winson Chung36f3f032016-09-08 23:29:43 +0000465 // XXX Don't add to write queue... there is no reason to write
466 // out the stuff we just read, if we don't write it we will
467 // read the same thing again.
468 // mWriteQueue.add(new TaskWriteQueueItem(task));
469
Craig Mautner21d24a22014-04-23 11:45:37 -0700470 final int taskId = task.taskId;
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800471 if (mStackSupervisor.anyTaskForIdLocked(taskId,
Wale Ogunwale0568aed2017-09-08 13:29:37 -0700472 MATCH_TASK_IN_STACKS_OR_RECENT_TASKS) != null) {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800473 // Should not happen.
474 Slog.wtf(TAG, "Existing task with taskId " + taskId + "found");
475 } else if (userId != task.userId) {
476 // Should not happen.
477 Slog.wtf(TAG, "Task with userId " + task.userId + " found in "
478 + userTasksDir.getAbsolutePath());
479 } else {
480 // Looks fine.
481 mStackSupervisor.setNextTaskIdForUserLocked(taskId, userId);
Amith Yamasani515d4062015-09-28 11:30:06 -0700482 task.isPersistable = true;
483 tasks.add(task);
484 recoveredTaskIds.add(taskId);
485 }
Craig Mautner77b04262014-06-27 15:22:12 -0700486 } else {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800487 Slog.e(TAG, "restoreTasksForUserLocked: Unable to restore taskFile="
Suprabh Shukla23593142015-11-03 17:31:15 -0800488 + taskFile + ": " + fileToString(taskFile));
Craig Mautner21d24a22014-04-23 11:45:37 -0700489 }
490 } else {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800491 Slog.wtf(TAG, "restoreTasksForUserLocked: Unknown xml event=" + event
Suprabh Shukla23593142015-11-03 17:31:15 -0800492 + " name=" + name);
Craig Mautner21d24a22014-04-23 11:45:37 -0700493 }
494 }
495 XmlUtils.skipCurrentTag(in);
496 }
Craig Mautnere0129b32014-05-25 16:41:09 -0700497 } catch (Exception e) {
Craig Mautnera228ae92014-07-09 05:44:55 -0700498 Slog.wtf(TAG, "Unable to parse " + taskFile + ". Error ", e);
Craig Mautner77b04262014-06-27 15:22:12 -0700499 Slog.e(TAG, "Failing file: " + fileToString(taskFile));
Craig Mautnere0129b32014-05-25 16:41:09 -0700500 deleteFile = true;
Craig Mautner21d24a22014-04-23 11:45:37 -0700501 } finally {
Wale Ogunwale18795a22014-12-03 11:38:33 -0800502 IoUtils.closeQuietly(reader);
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700503 if (deleteFile) {
504 if (DEBUG) Slog.d(TAG, "Deleting file=" + taskFile.getName());
Craig Mautnere0129b32014-05-25 16:41:09 -0700505 taskFile.delete();
506 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700507 }
508 }
509
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700510 if (!DEBUG) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800511 removeObsoleteFiles(recoveredTaskIds, userTasksDir.listFiles());
512 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700513
Suprabh Shukla23593142015-11-03 17:31:15 -0800514 // Fix up task affiliation from taskIds
Craig Mautnera228ae92014-07-09 05:44:55 -0700515 for (int taskNdx = tasks.size() - 1; taskNdx >= 0; --taskNdx) {
516 final TaskRecord task = tasks.get(taskNdx);
517 task.setPrevAffiliate(taskIdToTask(task.mPrevAffiliateTaskId, tasks));
518 task.setNextAffiliate(taskIdToTask(task.mNextAffiliateTaskId, tasks));
519 }
520
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800521 Collections.sort(tasks, new Comparator<TaskRecord>() {
Craig Mautner21d24a22014-04-23 11:45:37 -0700522 @Override
523 public int compare(TaskRecord lhs, TaskRecord rhs) {
Craig Mautner43e52ed2014-06-16 17:18:52 -0700524 final long diff = rhs.mLastTimeMoved - lhs.mLastTimeMoved;
Craig Mautner21d24a22014-04-23 11:45:37 -0700525 if (diff < 0) {
526 return -1;
527 } else if (diff > 0) {
528 return +1;
529 } else {
530 return 0;
531 }
532 }
533 });
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800534 return tasks;
Craig Mautner21d24a22014-04-23 11:45:37 -0700535 }
536
Craig Mautnere0129b32014-05-25 16:41:09 -0700537 private static void removeObsoleteFiles(ArraySet<Integer> persistentTaskIds, File[] files) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800538 if (DEBUG) Slog.d(TAG, "removeObsoleteFiles: persistentTaskIds=" + persistentTaskIds +
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700539 " files=" + files);
Craig Mautnera5badf02014-09-11 12:47:03 -0700540 if (files == null) {
Suprabh Shukladc4b80d2016-04-20 15:24:31 -0700541 Slog.e(TAG, "File error accessing recents directory (directory doesn't exist?).");
Craig Mautnera5badf02014-09-11 12:47:03 -0700542 return;
543 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700544 for (int fileNdx = 0; fileNdx < files.length; ++fileNdx) {
545 File file = files[fileNdx];
546 String filename = file.getName();
Craig Mautnerffcfcaa2014-06-05 09:54:38 -0700547 final int taskIdEnd = filename.indexOf('_');
Craig Mautner21d24a22014-04-23 11:45:37 -0700548 if (taskIdEnd > 0) {
549 final int taskId;
550 try {
Narayan Kamatha09b4d22016-04-15 18:32:45 +0100551 taskId = Integer.parseInt(filename.substring(0, taskIdEnd));
Suprabh Shukla23593142015-11-03 17:31:15 -0800552 if (DEBUG) Slog.d(TAG, "removeObsoleteFiles: Found taskId=" + taskId);
Craig Mautner21d24a22014-04-23 11:45:37 -0700553 } catch (Exception e) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800554 Slog.wtf(TAG, "removeObsoleteFiles: Can't parse file=" + file.getName());
Craig Mautner21d24a22014-04-23 11:45:37 -0700555 file.delete();
556 continue;
557 }
558 if (!persistentTaskIds.contains(taskId)) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800559 if (DEBUG) Slog.d(TAG, "removeObsoleteFiles: deleting file=" + file.getName());
Craig Mautner21d24a22014-04-23 11:45:37 -0700560 file.delete();
561 }
562 }
563 }
564 }
565
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800566 private void writeTaskIdsFiles() {
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700567 SparseArray<SparseBooleanArray> changedTaskIdsPerUser = new SparseArray<>();
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700568 synchronized (mService.mGlobalLock) {
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700569 for (int userId : mRecentTasks.usersWithRecentsLoadedLocked()) {
Winson Chung1dbc8112017-09-28 18:05:31 -0700570 SparseBooleanArray taskIdsToSave = mRecentTasks.getTaskIdsForUser(userId);
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700571 SparseBooleanArray persistedIdsInFile = mTaskIdsInFile.get(userId);
572 if (persistedIdsInFile != null && persistedIdsInFile.equals(taskIdsToSave)) {
573 continue;
574 } else {
575 SparseBooleanArray taskIdsToSaveCopy = taskIdsToSave.clone();
576 mTaskIdsInFile.put(userId, taskIdsToSaveCopy);
577 changedTaskIdsPerUser.put(userId, taskIdsToSaveCopy);
578 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800579 }
Suprabh Shuklafd0bd4f2016-08-24 14:08:29 -0700580 }
581 for (int i = 0; i < changedTaskIdsPerUser.size(); i++) {
582 writePersistedTaskIdsForUser(changedTaskIdsPerUser.valueAt(i),
583 changedTaskIdsPerUser.keyAt(i));
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800584 }
585 }
586
Craig Mautner21d24a22014-04-23 11:45:37 -0700587 private void removeObsoleteFiles(ArraySet<Integer> persistentTaskIds) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800588 int[] candidateUserIds;
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700589 synchronized (mService.mGlobalLock) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -0800590 // Remove only from directories of the users who have recents in memory synchronized
591 // with persistent storage.
592 candidateUserIds = mRecentTasks.usersWithRecentsLoadedLocked();
593 }
594 for (int userId : candidateUserIds) {
Suprabh Shukla23593142015-11-03 17:31:15 -0800595 removeObsoleteFiles(persistentTaskIds, getUserImagesDir(userId).listFiles());
596 removeObsoleteFiles(persistentTaskIds, getUserTasksDir(userId).listFiles());
597 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700598 }
599
600 static Bitmap restoreImage(String filename) {
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700601 if (DEBUG) Slog.d(TAG, "restoreImage: restoring " + filename);
Suprabh Shukla23593142015-11-03 17:31:15 -0800602 return BitmapFactory.decodeFile(filename);
603 }
604
Suprabh Shuklaf50b4582016-02-23 17:44:22 -0800605 private File getUserPersistedTaskIdsFile(int userId) {
606 File userTaskIdsDir = new File(mTaskIdsDir, String.valueOf(userId));
607 if (!userTaskIdsDir.exists() && !userTaskIdsDir.mkdirs()) {
608 Slog.e(TAG, "Error while creating user directory: " + userTaskIdsDir);
609 }
610 return new File(userTaskIdsDir, PERSISTED_TASK_IDS_FILENAME);
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800611 }
612
Suprabh Shukla23593142015-11-03 17:31:15 -0800613 static File getUserTasksDir(int userId) {
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800614 File userTasksDir = new File(Environment.getDataSystemCeDirectory(userId), TASKS_DIRNAME);
Suprabh Shukla23593142015-11-03 17:31:15 -0800615
616 if (!userTasksDir.exists()) {
617 if (!userTasksDir.mkdir()) {
618 Slog.e(TAG, "Failure creating tasks directory for user " + userId + ": "
619 + userTasksDir);
620 }
621 }
622 return userTasksDir;
623 }
624
625 static File getUserImagesDir(int userId) {
Suprabh Shukladc4b80d2016-04-20 15:24:31 -0700626 return new File(Environment.getDataSystemCeDirectory(userId), IMAGES_DIRNAME);
627 }
Suprabh Shukla23593142015-11-03 17:31:15 -0800628
Suprabh Shukladc4b80d2016-04-20 15:24:31 -0700629 private static boolean createParentDirectory(String filePath) {
630 File parentDir = new File(filePath).getParentFile();
631 return parentDir.exists() || parentDir.mkdirs();
Craig Mautner21d24a22014-04-23 11:45:37 -0700632 }
633
634 private class LazyTaskWriterThread extends Thread {
Craig Mautner21d24a22014-04-23 11:45:37 -0700635
636 LazyTaskWriterThread(String name) {
637 super(name);
638 }
639
640 @Override
641 public void run() {
Riley Andrewsf16c2e82015-06-02 18:24:48 -0700642 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
Winson Chung1dbc8112017-09-28 18:05:31 -0700643 ArraySet<Integer> persistentTaskIds = new ArraySet<>();
Craig Mautner21d24a22014-04-23 11:45:37 -0700644 while (true) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700645 // We can't lock mService while holding TaskPersister.this, but we don't want to
646 // call removeObsoleteFiles every time through the loop, only the last time before
647 // going to sleep. The risk is that we call removeObsoleteFiles() successively.
648 final boolean probablyDone;
Craig Mautner21d24a22014-04-23 11:45:37 -0700649 synchronized (TaskPersister.this) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700650 probablyDone = mWriteQueue.isEmpty();
651 }
652 if (probablyDone) {
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700653 if (DEBUG) Slog.d(TAG, "Looking for obsolete files.");
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700654 persistentTaskIds.clear();
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700655 synchronized (mService.mGlobalLock) {
Stefan Kuhnee88d1e52015-05-18 10:33:45 -0700656 if (DEBUG) Slog.d(TAG, "mRecents=" + mRecentTasks);
Winson Chung1dbc8112017-09-28 18:05:31 -0700657 mRecentTasks.getPersistableTaskIds(persistentTaskIds);
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700658 mService.mAm.mWindowManager.removeObsoleteTaskFiles(persistentTaskIds,
Jorim Jaggif9084ec2017-01-16 13:16:59 +0100659 mRecentTasks.usersWithRecentsLoadedLocked());
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700660 }
661 removeObsoleteFiles(persistentTaskIds);
662 }
Suprabh Shukla4bccb462016-02-10 18:45:12 -0800663 writeTaskIdsFiles();
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700664
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700665 processNextItem();
666 }
667 }
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700668
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700669 private void processNextItem() {
670 // This part is extracted into a method so that the GC can clearly see the end of the
671 // scope of the variable 'item'. If this part was in the loop above, the last item
672 // it processed would always "leak".
673 // See https://b.corp.google.com/issues/64438652#comment7
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700674
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700675 // If mNextWriteTime, then don't delay between each call to saveToXml().
676 final WriteQueueItem item;
677 synchronized (TaskPersister.this) {
678 if (mNextWriteTime != FLUSH_QUEUE) {
679 // The next write we don't have to wait so long.
680 mNextWriteTime = SystemClock.uptimeMillis() + INTER_WRITE_DELAY_MS;
681 if (DEBUG) Slog.d(TAG, "Next write time may be in " +
682 INTER_WRITE_DELAY_MS + " msec. (" + mNextWriteTime + ")");
Craig Mautner21d24a22014-04-23 11:45:37 -0700683 }
684
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700685 while (mWriteQueue.isEmpty()) {
686 if (mNextWriteTime != 0) {
687 mNextWriteTime = 0; // idle.
688 TaskPersister.this.notifyAll(); // wake up flush() if needed.
Suprabh Shukladc4b80d2016-04-20 15:24:31 -0700689 }
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700690 try {
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700691 if (DEBUG) Slog.d(TAG, "LazyTaskWriter: waiting indefinitely.");
692 TaskPersister.this.wait();
693 } catch (InterruptedException e) {
Craig Mautnerc0ffce52014-07-01 12:38:52 -0700694 }
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700695 // Invariant: mNextWriteTime is either FLUSH_QUEUE or PRE_WRITE_DELAY_MS
696 // from now.
697 }
698 item = mWriteQueue.remove(0);
699
700 long now = SystemClock.uptimeMillis();
701 if (DEBUG) Slog.d(TAG, "LazyTaskWriter: now=" + now + " mNextWriteTime=" +
702 mNextWriteTime + " mWriteQueue.size=" + mWriteQueue.size());
703 while (now < mNextWriteTime) {
704 try {
705 if (DEBUG) Slog.d(TAG, "LazyTaskWriter: waiting " +
706 (mNextWriteTime - now));
707 TaskPersister.this.wait(mNextWriteTime - now);
708 } catch (InterruptedException e) {
Dianne Hackborn852975d2014-08-22 17:42:43 -0700709 }
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700710 now = SystemClock.uptimeMillis();
711 }
712
713 // Got something to do.
714 }
715
716 if (item instanceof ImageWriteQueueItem) {
717 ImageWriteQueueItem imageWriteQueueItem = (ImageWriteQueueItem) item;
718 final String filePath = imageWriteQueueItem.mFilePath;
719 if (!createParentDirectory(filePath)) {
720 Slog.e(TAG, "Error while creating images directory for file: " + filePath);
721 return;
722 }
723 final Bitmap bitmap = imageWriteQueueItem.mImage;
724 if (DEBUG) Slog.d(TAG, "writing bitmap: filename=" + filePath);
725 FileOutputStream imageFile = null;
726 try {
727 imageFile = new FileOutputStream(new File(filePath));
728 bitmap.compress(Bitmap.CompressFormat.PNG, 100, imageFile);
729 } catch (Exception e) {
730 Slog.e(TAG, "saveImage: unable to save " + filePath, e);
731 } finally {
732 IoUtils.closeQuietly(imageFile);
733 }
734 } else if (item instanceof TaskWriteQueueItem) {
735 // Write out one task.
736 StringWriter stringWriter = null;
737 TaskRecord task = ((TaskWriteQueueItem) item).mTask;
738 if (DEBUG) Slog.d(TAG, "Writing task=" + task);
Wale Ogunwale16e505a2018-05-07 15:00:49 -0700739 synchronized (mService.mGlobalLock) {
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700740 if (task.inRecents) {
741 // Still there.
Dianne Hackborn852975d2014-08-22 17:42:43 -0700742 try {
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700743 if (DEBUG) Slog.d(TAG, "Saving task=" + task);
744 stringWriter = saveToXml(task);
Dianne Hackborn852975d2014-08-22 17:42:43 -0700745 } catch (IOException e) {
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700746 } catch (XmlPullParserException e) {
Craig Mautnerf4f8bb72014-07-29 10:41:40 -0700747 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700748 }
749 }
Makoto Onuki62a93aa2017-08-08 10:24:59 -0700750 if (stringWriter != null) {
751 // Write out xml file while not holding mService lock.
752 FileOutputStream file = null;
753 AtomicFile atomicFile = null;
754 try {
755 atomicFile = new AtomicFile(new File(
756 getUserTasksDir(task.userId),
757 String.valueOf(task.taskId) + TASK_FILENAME_SUFFIX));
758 file = atomicFile.startWrite();
759 file.write(stringWriter.toString().getBytes());
760 file.write('\n');
761 atomicFile.finishWrite(file);
762 } catch (IOException e) {
763 if (file != null) {
764 atomicFile.failWrite(file);
765 }
766 Slog.e(TAG,
767 "Unable to open " + atomicFile + " for persisting. " + e);
768 }
769 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700770 }
771 }
772 }
Craig Mautner21d24a22014-04-23 11:45:37 -0700773}