use of android.content.PeriodicSync in project platform_frameworks_base by android.
the class SyncStorageEngine method parsePeriodicSync.
/**
* Parse a periodic sync from accounts.xml. Sets the bundle to be empty.
*/
private PeriodicSync parsePeriodicSync(XmlPullParser parser, AuthorityInfo authorityInfo) {
// Gets filled in later.
Bundle extras = new Bundle();
String periodValue = parser.getAttributeValue(null, "period");
String flexValue = parser.getAttributeValue(null, "flex");
final long period;
long flextime;
try {
period = Long.parseLong(periodValue);
} catch (NumberFormatException e) {
Slog.e(TAG, "error parsing the period of a periodic sync", e);
return null;
} catch (NullPointerException e) {
Slog.e(TAG, "the period of a periodic sync is null", e);
return null;
}
try {
flextime = Long.parseLong(flexValue);
} catch (NumberFormatException e) {
flextime = calculateDefaultFlexTime(period);
Slog.e(TAG, "Error formatting value parsed for periodic sync flex: " + flexValue + ", using default: " + flextime);
} catch (NullPointerException expected) {
flextime = calculateDefaultFlexTime(period);
Slog.d(TAG, "No flex time specified for this sync, using a default. period: " + period + " flex: " + flextime);
}
PeriodicSync periodicSync;
periodicSync = new PeriodicSync(authorityInfo.target.account, authorityInfo.target.provider, extras, period, flextime);
authorityInfo.periodicSyncs.add(periodicSync);
return periodicSync;
}
use of android.content.PeriodicSync in project platform_frameworks_base by android.
the class SyncStorageEngine method restoreAllPeriodicSyncs.
/**
* Restore all periodic syncs read from persisted files. Used to restore periodic syncs
* after an OS update.
*/
boolean restoreAllPeriodicSyncs() {
if (mPeriodicSyncAddedListener == null) {
return false;
}
synchronized (mAuthorities) {
for (int i = 0; i < mAuthorities.size(); i++) {
AuthorityInfo authority = mAuthorities.valueAt(i);
for (PeriodicSync periodicSync : authority.periodicSyncs) {
mPeriodicSyncAddedListener.onPeriodicSyncAdded(authority.target, periodicSync.extras, periodicSync.period, periodicSync.flexTime);
}
authority.periodicSyncs.clear();
}
writeAccountInfoLocked();
}
return true;
}
use of android.content.PeriodicSync in project android_frameworks_base by DirtyUnicorns.
the class SyncStorageEngine method parsePeriodicSync.
/**
* Parse a periodic sync from accounts.xml. Sets the bundle to be empty.
*/
private PeriodicSync parsePeriodicSync(XmlPullParser parser, AuthorityInfo authorityInfo) {
// Gets filled in later.
Bundle extras = new Bundle();
String periodValue = parser.getAttributeValue(null, "period");
String flexValue = parser.getAttributeValue(null, "flex");
final long period;
long flextime;
try {
period = Long.parseLong(periodValue);
} catch (NumberFormatException e) {
Slog.e(TAG, "error parsing the period of a periodic sync", e);
return null;
} catch (NullPointerException e) {
Slog.e(TAG, "the period of a periodic sync is null", e);
return null;
}
try {
flextime = Long.parseLong(flexValue);
} catch (NumberFormatException e) {
flextime = calculateDefaultFlexTime(period);
Slog.e(TAG, "Error formatting value parsed for periodic sync flex: " + flexValue + ", using default: " + flextime);
} catch (NullPointerException expected) {
flextime = calculateDefaultFlexTime(period);
Slog.d(TAG, "No flex time specified for this sync, using a default. period: " + period + " flex: " + flextime);
}
PeriodicSync periodicSync;
periodicSync = new PeriodicSync(authorityInfo.target.account, authorityInfo.target.provider, extras, period, flextime);
authorityInfo.periodicSyncs.add(periodicSync);
return periodicSync;
}
use of android.content.PeriodicSync in project android_frameworks_base by DirtyUnicorns.
the class SyncStorageEngine method restoreAllPeriodicSyncs.
/**
* Restore all periodic syncs read from persisted files. Used to restore periodic syncs
* after an OS update.
*/
boolean restoreAllPeriodicSyncs() {
if (mPeriodicSyncAddedListener == null) {
return false;
}
synchronized (mAuthorities) {
for (int i = 0; i < mAuthorities.size(); i++) {
AuthorityInfo authority = mAuthorities.valueAt(i);
for (PeriodicSync periodicSync : authority.periodicSyncs) {
mPeriodicSyncAddedListener.onPeriodicSyncAdded(authority.target, periodicSync.extras, periodicSync.period, periodicSync.flexTime);
}
authority.periodicSyncs.clear();
}
writeAccountInfoLocked();
}
return true;
}
use of android.content.PeriodicSync in project android_frameworks_base by ResurrectionRemix.
the class SyncStorageEngine method readAccountInfoLocked.
/**
* Read all account information back in to the initial engine state.
*/
private void readAccountInfoLocked() {
int highestAuthorityId = -1;
FileInputStream fis = null;
try {
fis = mAccountInfoFile.openRead();
if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
Slog.v(TAG_FILE, "Reading " + mAccountInfoFile.getBaseFile());
}
XmlPullParser parser = Xml.newPullParser();
parser.setInput(fis, StandardCharsets.UTF_8.name());
int eventType = parser.getEventType();
while (eventType != XmlPullParser.START_TAG && eventType != XmlPullParser.END_DOCUMENT) {
eventType = parser.next();
}
if (eventType == XmlPullParser.END_DOCUMENT) {
Slog.i(TAG, "No initial accounts");
return;
}
String tagName = parser.getName();
if ("accounts".equals(tagName)) {
String listen = parser.getAttributeValue(null, XML_ATTR_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 < 3) {
mGrantSyncAdaptersAccountAccess = true;
}
String nextIdString = parser.getAttributeValue(null, XML_ATTR_NEXT_AUTHORITY_ID);
try {
int id = (nextIdString == null) ? 0 : Integer.parseInt(nextIdString);
mNextAuthorityId = Math.max(mNextAuthorityId, id);
} catch (NumberFormatException e) {
// don't care
}
String offsetString = parser.getAttributeValue(null, XML_ATTR_SYNC_RANDOM_OFFSET);
try {
mSyncRandomOffset = (offsetString == null) ? 0 : Integer.parseInt(offsetString);
} catch (NumberFormatException e) {
mSyncRandomOffset = 0;
}
if (mSyncRandomOffset == 0) {
Random random = new Random(System.currentTimeMillis());
mSyncRandomOffset = random.nextInt(86400);
}
mMasterSyncAutomatically.put(0, listen == null || Boolean.parseBoolean(listen));
eventType = parser.next();
AuthorityInfo authority = null;
PeriodicSync periodicSync = null;
do {
if (eventType == XmlPullParser.START_TAG) {
tagName = parser.getName();
if (parser.getDepth() == 2) {
if ("authority".equals(tagName)) {
authority = parseAuthority(parser, version);
periodicSync = null;
if (authority != null) {
if (authority.ident > highestAuthorityId) {
highestAuthorityId = authority.ident;
}
} else {
EventLog.writeEvent(0x534e4554, "26513719", -1, "Malformed authority");
}
} else if (XML_TAG_LISTEN_FOR_TICKLES.equals(tagName)) {
parseListenForTickles(parser);
}
} else if (parser.getDepth() == 3) {
if ("periodicSync".equals(tagName) && authority != null) {
periodicSync = parsePeriodicSync(parser, authority);
}
} else if (parser.getDepth() == 4 && periodicSync != null) {
if ("extra".equals(tagName)) {
parseExtra(parser, periodicSync.extras);
}
}
}
eventType = parser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
}
} catch (XmlPullParserException e) {
Slog.w(TAG, "Error reading accounts", e);
return;
} catch (java.io.IOException e) {
if (fis == null)
Slog.i(TAG, "No initial accounts");
else
Slog.w(TAG, "Error reading accounts", e);
return;
} finally {
mNextAuthorityId = Math.max(highestAuthorityId + 1, mNextAuthorityId);
if (fis != null) {
try {
fis.close();
} catch (java.io.IOException e1) {
}
}
}
maybeMigrateSettingsForRenamedAuthorities();
}
Aggregations