diff options
| author | 2015-08-25 18:06:15 +0000 | |
|---|---|---|
| committer | 2015-08-25 18:06:15 +0000 | |
| commit | 91b3d8bf24f10c7d545f54fcc4e3fd670aa1842b (patch) | |
| tree | 1cae2761e96d9e9c265ac2036eb1606f4c2a39c6 | |
| parent | e188fcc2836d3495b471d61121071f4bb063ea9f (diff) | |
| parent | 80e8db3d9cbdd6f42ca83b535abd26d761dc26ee (diff) | |
Merge "[Backup] Special handling for sharedpref files in backup config"
| -rw-r--r-- | core/java/android/app/backup/FullBackup.java | 14 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/app/backup/FullBackupTest.java | 39 |
2 files changed, 43 insertions, 10 deletions
diff --git a/core/java/android/app/backup/FullBackup.java b/core/java/android/app/backup/FullBackup.java index 7718a3615464..9ea2ba286754 100644 --- a/core/java/android/app/backup/FullBackup.java +++ b/core/java/android/app/backup/FullBackup.java @@ -401,7 +401,19 @@ public class FullBackup { activeSet.add(canonicalJournalPath); if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) { Log.v(TAG_XML_PARSER, "...automatically generated " - + canonicalJournalPath + ". Ignore if nonexistant."); + + canonicalJournalPath + ". Ignore if nonexistent."); + } + } + + // Special case for sharedpref files (not dirs) also add ".xml" suffix file. + if ("sharedpref".equals(domainFromXml) && !canonicalFile.isDirectory() && + !canonicalFile.getCanonicalPath().endsWith(".xml")) { + final String canonicalXmlPath = + canonicalFile.getCanonicalPath() + ".xml"; + activeSet.add(canonicalXmlPath); + if (Log.isLoggable(TAG_XML_PARSER, Log.VERBOSE)) { + Log.v(TAG_XML_PARSER, "...automatically generated " + + canonicalXmlPath + ". Ignore if nonexistent."); } } } diff --git a/core/tests/coretests/src/android/app/backup/FullBackupTest.java b/core/tests/coretests/src/android/app/backup/FullBackupTest.java index 8c9c63ca1d08..c3afbf672ae2 100644 --- a/core/tests/coretests/src/android/app/backup/FullBackupTest.java +++ b/core/tests/coretests/src/android/app/backup/FullBackupTest.java @@ -114,12 +114,14 @@ public class FullBackupTest extends AndroidTestCase { public void testparseBackupSchemeFromXml_lotsOfIncludesAndExcludes() throws Exception { mXpp.setInput(new StringReader( "<full-backup-content>" + - "<exclude path=\"exclude1.txt\" domain=\"file\"/>" + + "<exclude path=\"exclude1.txt\" domain=\"file\"/>" + "<include path=\"include1.txt\" domain=\"file\"/>" + "<exclude path=\"exclude2.txt\" domain=\"database\"/>" + "<include path=\"include2.txt\" domain=\"database\"/>" + - "<exclude path=\"exclude3.txt\" domain=\"sharedpref\"/>" + - "<include path=\"include3.txt\" domain=\"sharedpref\"/>" + + "<exclude path=\"exclude3\" domain=\"sharedpref\"/>" + + "<include path=\"include3\" domain=\"sharedpref\"/>" + + "<exclude path=\"exclude4.xml\" domain=\"sharedpref\"/>" + + "<include path=\"include4.xml\" domain=\"sharedpref\"/>" + "</full-backup-content>")); @@ -146,16 +148,27 @@ public class FullBackupTest extends AndroidTestCase { "include2.txt-journal") .getCanonicalPath())); - Set<String> sharedPrefDomainIncludes = includeMap.get(FullBackup.SHAREDPREFS_TREE_TOKEN); + List<String> sharedPrefDomainIncludes = new ArrayList<String>( + includeMap.get(FullBackup.SHAREDPREFS_TREE_TOKEN)); + Collections.sort(sharedPrefDomainIncludes); + assertEquals("Didn't find expected sharedpref domain include.", - 1, sharedPrefDomainIncludes.size()); + 3, sharedPrefDomainIncludes.size()); + assertEquals("Invalid path parsed for <include/>", + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include3") + .getCanonicalPath(), + sharedPrefDomainIncludes.get(0)); + assertEquals("Invalid path parsed for <include/>", + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include3.xml") + .getCanonicalPath(), + sharedPrefDomainIncludes.get(1)); assertEquals("Invalid path parsed for <include/>", - new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include3.txt") + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include4.xml") .getCanonicalPath(), - sharedPrefDomainIncludes.iterator().next()); + sharedPrefDomainIncludes.get(2)); - assertEquals("Unexpected number of <exclude/>s", 4, excludesSet.size()); + assertEquals("Unexpected number of <exclude/>s", 6, excludesSet.size()); // Sets are annoying to iterate over b/c order isn't enforced - convert to an array and // sort lexicographically. List<String> arrayedSet = new ArrayList<String>(excludesSet); @@ -173,9 +186,17 @@ public class FullBackupTest extends AndroidTestCase { new File(mContext.getFilesDir(), "exclude1.txt").getCanonicalPath(), arrayedSet.get(2)); assertEquals("Invalid path parsed for <exclude/>", - new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude3.txt") + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude3") .getCanonicalPath(), arrayedSet.get(3)); + assertEquals("Invalid path parsed for <exclude/>", + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude3.xml") + .getCanonicalPath(), + arrayedSet.get(4)); + assertEquals("Invalid path parsed for <exclude/>", + new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude4.xml") + .getCanonicalPath(), + arrayedSet.get(5)); } public void testParseBackupSchemeFromXml_invalidXmlFails() throws Exception { |