Skip to content

Commit a23bb38

Browse files
author
Amith Yamasani
committed
Don't migrate accounts.db if already migrated.
Some developers accidentally create a blank accounts.db and this was causing accounts to vanish. This safeguards the case where both old and new files exist. Bug: 6168813 Change-Id: I79cf211acc5422ff1c17fe0c9af80c49227b60ac
1 parent d3ce6f5 commit a23bb38

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/java/android/accounts/AccountManagerService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,9 +1844,12 @@ private static String getDatabaseName(int userId) {
18441844
File systemDir = Environment.getSystemSecureDirectory();
18451845
File databaseFile = new File(systemDir, "users/" + userId + "/" + DATABASE_NAME);
18461846
if (userId == 0) {
1847-
// Migrate old file, if it exists, to the new location
1847+
// Migrate old file, if it exists, to the new location.
1848+
// Make sure the new file doesn't already exist. A dummy file could have been
1849+
// accidentally created in the old location, causing the new one to become corrupted
1850+
// as well.
18481851
File oldFile = new File(systemDir, DATABASE_NAME);
1849-
if (oldFile.exists()) {
1852+
if (oldFile.exists() && !databaseFile.exists()) {
18501853
// Check for use directory; create if it doesn't exist, else renameTo will fail
18511854
File userDir = new File(systemDir, "users/" + userId);
18521855
if (!userDir.exists()) {

0 commit comments

Comments
 (0)