Don't back up / restore certain sync-related settings
In particular, this no longer attempts to back up the on/off state of specific
backend syncing [gmail/contacts/calendar], nor the "background data" toggle.
The former was causing a great deal of spurious trips through backup as the
notification was being tickled during general sync operation, and the latter
makes little sense at restore time.
Fixes these issues:
b/2097613 - frequent "backup_data_changed" messages in event log
b/2131662 - should not backup background data, master sync settings
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index f251984..6e312d2 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -346,16 +346,6 @@
}
}
}
- // Inform the backup manager about a data change
- IBackupManager ibm = IBackupManager.Stub.asInterface(
- ServiceManager.getService(Context.BACKUP_SERVICE));
- if (ibm != null) {
- try {
- ibm.dataChanged("com.android.providers.settings");
- } catch (RemoteException e) {
- // Try again later
- }
- }
}
public boolean getSyncAutomatically(Account account, String providerName) {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 1d41df2..6cf8db6 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2406,7 +2406,6 @@
WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
WIFI_NUM_ALLOWED_CHANNELS,
WIFI_NUM_OPEN_NETWORKS_KEPT,
- BACKGROUND_DATA,
};
/**
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
index 8cfd956..c4acf33 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsBackupAgent.java
@@ -54,15 +54,17 @@
private static final String KEY_SYSTEM = "system";
private static final String KEY_SECURE = "secure";
- private static final String KEY_SYNC = "sync_providers";
private static final String KEY_LOCALE = "locale";
+ // Versioning of the state file. Increment this version
+ // number any time the set of state items is altered.
+ private static final int STATE_VERSION = 1;
+
private static final int STATE_SYSTEM = 0;
private static final int STATE_SECURE = 1;
- private static final int STATE_SYNC = 2;
- private static final int STATE_LOCALE = 3;
- private static final int STATE_WIFI = 4;
- private static final int STATE_SIZE = 5; // The number of state items
+ private static final int STATE_LOCALE = 2;
+ private static final int STATE_WIFI = 3;
+ private static final int STATE_SIZE = 4; // The number of state items
private static String[] sortedSystemKeys = null;
private static String[] sortedSecureKeys = null;
@@ -101,7 +103,6 @@
byte[] systemSettingsData = getSystemSettings();
byte[] secureSettingsData = getSecureSettings();
- byte[] syncProviders = mSettingsHelper.getSyncProviders();
byte[] locale = mSettingsHelper.getLocaleData();
byte[] wifiData = getWifiSupplicant(FILE_WIFI_SUPPLICANT);
@@ -111,8 +112,6 @@
writeIfChanged(stateChecksums[STATE_SYSTEM], KEY_SYSTEM, systemSettingsData, data);
stateChecksums[STATE_SECURE] =
writeIfChanged(stateChecksums[STATE_SECURE], KEY_SECURE, secureSettingsData, data);
- stateChecksums[STATE_SYNC] =
- writeIfChanged(stateChecksums[STATE_SYNC], KEY_SYNC, syncProviders, data);
stateChecksums[STATE_LOCALE] =
writeIfChanged(stateChecksums[STATE_LOCALE], KEY_LOCALE, locale, data);
stateChecksums[STATE_WIFI] =
@@ -143,8 +142,6 @@
// retain the previous WIFI state.
enableWifi(retainedWifiState == WifiManager.WIFI_STATE_ENABLED ||
retainedWifiState == WifiManager.WIFI_STATE_ENABLING);
- } else if (KEY_SYNC.equals(key)) {
- mSettingsHelper.setSyncProviders(data);
} else if (KEY_LOCALE.equals(key)) {
byte[] localeData = new byte[size];
data.readEntityData(localeData, 0, size);
@@ -160,12 +157,17 @@
DataInputStream dataInput = new DataInputStream(
new FileInputStream(oldState.getFileDescriptor()));
- for (int i = 0; i < STATE_SIZE; i++) {
- try {
- stateChecksums[i] = dataInput.readLong();
- } catch (EOFException eof) {
- break;
+
+ try {
+ int stateVersion = dataInput.readInt();
+ if (stateVersion == STATE_VERSION) {
+ for (int i = 0; i < STATE_SIZE; i++) {
+ stateChecksums[i] = dataInput.readLong();
+ }
}
+ } catch (EOFException eof) {
+ // With the default 0 checksum we'll wind up forcing a backup of
+ // any unhandled data sets, which is appropriate.
}
dataInput.close();
return stateChecksums;
@@ -175,6 +177,8 @@
throws IOException {
DataOutputStream dataOutput = new DataOutputStream(
new FileOutputStream(newState.getFileDescriptor()));
+
+ dataOutput.writeInt(STATE_VERSION);
for (int i = 0; i < STATE_SIZE; i++) {
dataOutput.writeLong(checksums[i]);
}
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
index 39084a7..77da8f1 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -116,43 +116,6 @@
}
}
- byte[] getSyncProviders() {
- byte[] sync = new byte[1 + PROVIDERS.length];
- // TODO: Sync backup needs to be moved to SystemBackupAgent
- /*
- try {
- sync[0] = (byte) (mContentService.getListenForNetworkTickles() ? 1 : 0);
- for (int i = 0; i < PROVIDERS.length; i++) {
- sync[i + 1] = (byte)
- (mContentService.getSyncAutomatically(PROVIDERS[i]) ? 1 : 0);
- }
- } catch (RemoteException re) {
- Log.w(TAG, "Unable to backup sync providers");
- return sync;
- }
- */
- return sync;
- }
-
- void setSyncProviders(BackupDataInput backup) {
- byte[] sync = new byte[backup.getDataSize()];
-
- try {
- backup.readEntityData(sync, 0, sync.length);
- // TODO: Sync backup needs to be moved to SystemBackupAgent
- /*
- mContentService.setListenForNetworkTickles(sync[0] == 1);
- for (int i = 0; i < PROVIDERS.length; i++) {
- mContentService.setSyncProviderAutomatically(PROVIDERS[i], sync[i + 1] > 0);
- }
- } catch (RemoteException re) {
- Log.w(TAG, "Unable to restore sync providers");
- */
- } catch (java.io.IOException ioe) {
- Log.w(TAG, "Unable to read sync settings");
- }
- }
-
byte[] getLocaleData() {
Configuration conf = mContext.getResources().getConfiguration();
final Locale loc = conf.locale;