From b9525aa0f78405dcaba8dbf0338055e5a722b34f Mon Sep 17 00:00:00 2001 From: Oli Lan Date: Fri, 24 Jan 2020 10:24:28 +0000 Subject: [PATCH] Add test for DE (user) snapshot and restore. This adds a test for rolling back device encrypted (user) apex data, similar to the tests previously added for DE_sys and CE data. Bug: 141148175 Test: atest StagedRollbackTest#testRollbackApexDataDirectories_DeUser Change-Id: I632957449e4aa4f93df2e8bf0ae541937472d9fe --- .../rollback/host/StagedRollbackTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java index ce2f7c50e5813..82a524be5c1e0 100644 --- a/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java +++ b/tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java @@ -328,6 +328,46 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { assertNull(getDevice().pullFile(newFilePath4)); } + /** + * Tests that data in DE (user) apex data directory is restored when apex is rolled back. + */ + @Test + public void testRollbackApexDataDirectories_DeUser() throws Exception { + pushTestApex(); + + // Push files to apex data directory + String oldFilePath1 = apexDataDirDeUser( + APK_IN_APEX_TESTAPEX_NAME, 0) + "/" + TEST_FILENAME_1; + String oldFilePath2 = + apexDataDirDeUser(APK_IN_APEX_TESTAPEX_NAME, 0) + TEST_SUBDIR + TEST_FILENAME_2; + assertTrue(getDevice().pushString(TEST_STRING_1, oldFilePath1)); + assertTrue(getDevice().pushString(TEST_STRING_2, oldFilePath2)); + + // Install new version of the APEX with rollback enabled + runPhase("testRollbackApexDataDirectories_Phase1"); + getDevice().reboot(); + + // Replace files in data directory + getDevice().deleteFile(oldFilePath1); + getDevice().deleteFile(oldFilePath2); + String newFilePath3 = + apexDataDirDeUser(APK_IN_APEX_TESTAPEX_NAME, 0) + "/" + TEST_FILENAME_3; + String newFilePath4 = + apexDataDirDeUser(APK_IN_APEX_TESTAPEX_NAME, 0) + TEST_SUBDIR + TEST_FILENAME_4; + assertTrue(getDevice().pushString(TEST_STRING_3, newFilePath3)); + assertTrue(getDevice().pushString(TEST_STRING_4, newFilePath4)); + + // Roll back the APEX + runPhase("testRollbackApexDataDirectories_Phase2"); + getDevice().reboot(); + + // Verify that old files have been restored and new files are gone + assertEquals(TEST_STRING_1, getDevice().pullFileContents(oldFilePath1)); + assertEquals(TEST_STRING_2, getDevice().pullFileContents(oldFilePath2)); + assertNull(getDevice().pullFile(newFilePath3)); + assertNull(getDevice().pullFile(newFilePath4)); + } + /** * Tests that data in CE apex data directory is restored when apex is rolled back. */ @@ -382,6 +422,10 @@ public class StagedRollbackTest extends BaseHostJUnit4Test { return String.format("/data/misc/apexdata/%s", apexName); } + private static String apexDataDirDeUser(String apexName, int userId) { + return String.format("/data/misc_de/%d/apexdata/%s", userId, apexName); + } + private static String apexDataDirCe(String apexName, int userId) { return String.format("/data/misc_ce/%d/apexdata/%s", userId, apexName); }