Loading services/core/java/com/android/server/rollback/RollbackStore.java +10 −3 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.content.rollback.PackageRollbackInfo; import android.content.rollback.PackageRollbackInfo.RestoreInfo; import android.content.rollback.RollbackInfo; import android.os.UserHandle; import android.util.AtomicFile; import android.util.Slog; import android.util.SparseIntArray; Loading @@ -37,6 +38,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; Loading Loading @@ -66,8 +68,6 @@ class RollbackStore { // // * XXX, YYY are the rollbackIds for the corresponding rollbacks. // * rollback.json contains all relevant metadata for the rollback. // // TODO: Use AtomicFile for all the .json files? private final File mRollbackDataDir; RollbackStore(File rollbackDataDir) { Loading Loading @@ -259,6 +259,8 @@ class RollbackStore { * Saves the given rollback to persistent storage. */ static void saveRollback(Rollback rollback) { FileOutputStream fos = null; AtomicFile file = new AtomicFile(new File(rollback.getBackupDir(), "rollback.json")); try { JSONObject dataJson = new JSONObject(); dataJson.put("info", rollbackInfoToJson(rollback.info)); Loading @@ -272,11 +274,16 @@ class RollbackStore { dataJson.putOpt( "extensionVersions", extensionVersionsToJson(rollback.getExtensionVersions())); PrintWriter pw = new PrintWriter(new File(rollback.getBackupDir(), "rollback.json")); fos = file.startWrite(); PrintWriter pw = new PrintWriter(fos); pw.println(dataJson.toString()); pw.close(); file.finishWrite(fos); } catch (JSONException | IOException e) { Slog.e(TAG, "Unable to save rollback for: " + rollback.info.getRollbackId(), e); if (fos != null) { file.failWrite(fos); } } } Loading tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.tests.rollback.host; import static com.android.tests.rollback.host.WatchdogEventLogger.watchdogEventOccurred; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -272,6 +274,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/rollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/rollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -358,6 +362,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -405,6 +411,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_de/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_de/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -450,6 +458,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -509,6 +519,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); // Expire all rollbacks and check CE snapshot directories are deleted runPhase("testCleanUp"); for (String dir : after) { Loading Loading
services/core/java/com/android/server/rollback/RollbackStore.java +10 −3 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.content.rollback.PackageRollbackInfo; import android.content.rollback.PackageRollbackInfo.RestoreInfo; import android.content.rollback.RollbackInfo; import android.os.UserHandle; import android.util.AtomicFile; import android.util.Slog; import android.util.SparseIntArray; Loading @@ -37,6 +38,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.nio.file.Files; Loading Loading @@ -66,8 +68,6 @@ class RollbackStore { // // * XXX, YYY are the rollbackIds for the corresponding rollbacks. // * rollback.json contains all relevant metadata for the rollback. // // TODO: Use AtomicFile for all the .json files? private final File mRollbackDataDir; RollbackStore(File rollbackDataDir) { Loading Loading @@ -259,6 +259,8 @@ class RollbackStore { * Saves the given rollback to persistent storage. */ static void saveRollback(Rollback rollback) { FileOutputStream fos = null; AtomicFile file = new AtomicFile(new File(rollback.getBackupDir(), "rollback.json")); try { JSONObject dataJson = new JSONObject(); dataJson.put("info", rollbackInfoToJson(rollback.info)); Loading @@ -272,11 +274,16 @@ class RollbackStore { dataJson.putOpt( "extensionVersions", extensionVersionsToJson(rollback.getExtensionVersions())); PrintWriter pw = new PrintWriter(new File(rollback.getBackupDir(), "rollback.json")); fos = file.startWrite(); PrintWriter pw = new PrintWriter(fos); pw.println(dataJson.toString()); pw.close(); file.finishWrite(fos); } catch (JSONException | IOException e) { Slog.e(TAG, "Unable to save rollback for: " + rollback.info.getRollbackId(), e); if (fos != null) { file.failWrite(fos); } } } Loading
tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.tests.rollback.host; import static com.android.tests.rollback.host.WatchdogEventLogger.watchdogEventOccurred; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; Loading Loading @@ -272,6 +274,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/rollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/rollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -358,6 +362,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -405,6 +411,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_de/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_de/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -450,6 +458,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); after.forEach(dir -> assertDirectoryIsEmpty(dir)); } Loading Loading @@ -509,6 +519,8 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { List<String> after = getSnapshotDirectories("/data/misc_ce/0/apexrollback"); // Only check directories newly created during the test after.removeAll(before); // There should be only one /data/misc_ce/0/apexrollback/<rollbackId> created during test assertThat(after).hasSize(1); // Expire all rollbacks and check CE snapshot directories are deleted runPhase("testCleanUp"); for (String dir : after) { Loading