summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/SyncStorageEngine.java
diff options
context:
space:
mode:
authorFred Quintana <fredq@google.com>2010-03-15 16:10:44 -0700
committerFred Quintana <fredq@google.com>2010-03-16 10:01:54 -0700
commitc2e4691d788088b22eadc9b2d35e9bdf0b6a0ffc (patch)
tree9e2dabf9dde89a18360c5d4ce08a2e9648e3284f /core/java/android/content/SyncStorageEngine.java
parent74d4843641ca1f810e27989873697cba1f41338a (diff)
downloadframeworks_base-c2e4691d788088b22eadc9b2d35e9bdf0b6a0ffc.zip
frameworks_base-c2e4691d788088b22eadc9b2d35e9bdf0b6a0ffc.tar.gz
frameworks_base-c2e4691d788088b22eadc9b2d35e9bdf0b6a0ffc.tar.bz2
- make the SyncManager add periodic syncs when it upgrades from a
version of the accounts.xml file that pre-dated periodic syncs, e.g. eclair or early froyo. http://b/2515823 - make the AccountManagerService dump() use a getAccounts call that doesn't check the GET_ACCOUNTS permission to make it useful in "adb bugreport" - add some logging to SyncManager to help track down a problem Change-Id: Icb646909074e2d327d71f6bb39cf06b6fac29e77
Diffstat (limited to 'core/java/android/content/SyncStorageEngine.java')
-rw-r--r--core/java/android/content/SyncStorageEngine.java38
1 files changed, 33 insertions, 5 deletions
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index 240da72..0ec2453 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -121,6 +121,9 @@ public class SyncStorageEngine extends Handler {
private static final boolean SYNC_ENABLED_DEFAULT = false;
+ // the version of the accounts xml file format
+ private static final int ACCOUNTS_VERSION = 1;
+
public static class PendingOperation {
final Account account;
final int syncSource;
@@ -1322,6 +1325,7 @@ public class SyncStorageEngine extends Handler {
* Read all account information back in to the initial engine state.
*/
private void readAccountInfoLocked() {
+ boolean writeNeeded = false;
FileInputStream fis = null;
try {
fis = mAccountInfoFile.openRead();
@@ -1336,6 +1340,16 @@ public class SyncStorageEngine extends Handler {
if ("accounts".equals(tagName)) {
String listen = parser.getAttributeValue(
null, "listen-for-tickles");
+ String versionString = parser.getAttributeValue(null, "version");
+ int version;
+ try {
+ version = (versionString == null) ? 0 : Integer.parseInt(versionString);
+ } catch (NumberFormatException e) {
+ version = 0;
+ }
+ if (version < ACCOUNTS_VERSION) {
+ writeNeeded = true;
+ }
mMasterSyncAutomatically = listen == null
|| Boolean.parseBoolean(listen);
eventType = parser.next();
@@ -1346,7 +1360,7 @@ public class SyncStorageEngine extends Handler {
tagName = parser.getName();
if (parser.getDepth() == 2) {
if ("authority".equals(tagName)) {
- authority = parseAuthority(parser);
+ authority = parseAuthority(parser, version);
periodicSync = null;
}
} else if (parser.getDepth() == 3) {
@@ -1364,9 +1378,11 @@ public class SyncStorageEngine extends Handler {
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Error reading accounts", e);
+ return;
} catch (java.io.IOException e) {
if (fis == null) Log.i(TAG, "No initial accounts");
else Log.w(TAG, "Error reading accounts", e);
+ return;
} finally {
if (fis != null) {
try {
@@ -1375,9 +1391,13 @@ public class SyncStorageEngine extends Handler {
}
}
}
+
+ if (writeNeeded) {
+ writeAccountInfoLocked();
+ }
}
- private AuthorityInfo parseAuthority(XmlPullParser parser) {
+ private AuthorityInfo parseAuthority(XmlPullParser parser, int version) {
AuthorityInfo authority = null;
int id = -1;
try {
@@ -1406,8 +1426,14 @@ public class SyncStorageEngine extends Handler {
if (DEBUG_FILE) Log.v(TAG, "Creating entry");
authority = getOrCreateAuthorityLocked(
new Account(accountName, accountType), authorityName, id, false);
- // clear this since we will read these later on
- authority.periodicSyncs.clear();
+ // If the version is 0 then we are upgrading from a file format that did not
+ // know about periodic syncs. In that case don't clear the list since we
+ // want the default, which is a daily periodioc sync.
+ // Otherwise clear out this default list since we will populate it later with
+ // the periodic sync descriptions that are read from the configuration file.
+ if (version > 0) {
+ authority.periodicSyncs.clear();
+ }
}
if (authority != null) {
authority.enabled = enabled == null || Boolean.parseBoolean(enabled);
@@ -1443,6 +1469,7 @@ public class SyncStorageEngine extends Handler {
}
final Pair<Bundle, Long> periodicSync = Pair.create(extras, period);
authority.periodicSyncs.add(periodicSync);
+
return periodicSync;
}
@@ -1491,6 +1518,7 @@ public class SyncStorageEngine extends Handler {
out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
out.startTag(null, "accounts");
+ out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
if (!mMasterSyncAutomatically) {
out.attribute(null, "listen-for-tickles", "false");
}
@@ -1505,7 +1533,7 @@ public class SyncStorageEngine extends Handler {
out.attribute(null, "authority", authority.authority);
if (!authority.enabled) {
out.attribute(null, "enabled", "false");
- }
+ }
if (authority.syncable < 0) {
out.attribute(null, "syncable", "unknown");
} else if (authority.syncable == 0) {