1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-16 06:25:06 -05:00

Whitelist settings for export instead of blacklisting keys

Use GlobalSettings.SETTINGS an AccountSettings.SETTINGS to decide
which settings to export.
This commit is contained in:
cketti 2011-10-04 05:13:17 +02:00
parent 644571cfe5
commit 83ee4253d5

View File

@ -74,42 +74,6 @@ public class StorageExporter {
public static final String EMAIL_ELEMENT = "email"; public static final String EMAIL_ELEMENT = "email";
public static final String DESCRIPTION_ELEMENT = "description"; public static final String DESCRIPTION_ELEMENT = "description";
/**
* List of keys of global settings that don't need to or shouldn't be exported.
*/
private static final Set<String> SKIP_GLOBAL_SETTINGS;
/**
* List of keys of account settings that don't need to or shouldn't be exported.
*/
private static final Set<String> SKIP_ACCOUNT_SETTINGS;
static {
Set<String> skipGlobal = new HashSet<String>();
// No need to export the "accountUuids" field. It will be (re)created by the import code.
skipGlobal.add("accountUuids");
// "defaultAccountUuid" is also handled by the import code.
skipGlobal.add("defaultAccountUuid");
SKIP_GLOBAL_SETTINGS = skipGlobal;
Set<String> skipAccount = new HashSet<String>();
// No need to export the "accountNumber" field. It will be (re)created by the import code.
skipAccount.add("accountNumber");
// The values for the following keys get their own XML element in the export file and
// therefore don't need to be stored with the other account settings.
skipAccount.add(Account.ACCOUNT_DESCRIPTION_KEY);
skipAccount.add(Account.STORE_URI_KEY);
skipAccount.add(Account.TRANSPORT_URI_KEY);
SKIP_ACCOUNT_SETTINGS = skipAccount;
}
public static String exportToFile(Context context, boolean includeGlobals, public static String exportToFile(Context context, boolean includeGlobals,
Set<String> accountUuids, String encryptionKey) Set<String> accountUuids, String encryptionKey)
@ -218,14 +182,13 @@ public class StorageExporter {
private static void writeSettings(XmlSerializer serializer, private static void writeSettings(XmlSerializer serializer,
Map<String, Object> prefs) throws IOException { Map<String, Object> prefs) throws IOException {
for (Map.Entry<String, Object> entry : prefs.entrySet()) { for (String key : GlobalSettings.SETTINGS.keySet()) {
String key = entry.getKey(); Object value = prefs.get(key);
String value = entry.getValue().toString();
if (key.indexOf('.') != -1 || SKIP_GLOBAL_SETTINGS.contains(key)) { if (value != null) {
// Skip account entries and keys we don't want/need to export String outputValue = value.toString();
continue; writeKeyValue(serializer, key, outputValue);
} }
writeKeyValue(serializer, key, value);
} }
} }
@ -307,14 +270,22 @@ public class StorageExporter {
String key = entry.getKey(); String key = entry.getKey();
String value = entry.getValue().toString(); String value = entry.getValue().toString();
String[] comps = key.split("\\."); String[] comps = key.split("\\.");
if (comps.length >= 2) {
if (comps.length < 2) {
// Skip global settings
continue;
}
String keyUuid = comps[0]; String keyUuid = comps[0];
String secondPart = comps[1]; String secondPart = comps[1];
if (!keyUuid.equals(accountUuid) || SKIP_ACCOUNT_SETTINGS.contains(secondPart)) { if (!keyUuid.equals(accountUuid)) {
// Setting doesn't belong to the account we're currently writing.
continue; continue;
} }
if (comps.length == 3) {
String keyPart;
if (comps.length >= 3) {
String thirdPart = comps[2]; String thirdPart = comps[2];
if (Account.IDENTITY_KEYS.contains(secondPart)) { if (Account.IDENTITY_KEYS.contains(secondPart)) {
@ -332,17 +303,18 @@ public class StorageExporter {
// ... but don't write it now. // ... but don't write it now.
continue; continue;
} }
}
} else {
// Skip global config entries and identity entries
continue;
}
// Strip account UUID from key // Strip account UUID from key
String keyPart = key.substring(comps[0].length() + 1); keyPart = key.substring(comps[0].length() + 1);
} else {
keyPart = secondPart;
}
if (AccountSettings.SETTINGS.containsKey(keyPart)) {
// Only export account settings that can be found in AccountSettings.SETTINGS
writeKeyValue(serializer, keyPart, value); writeKeyValue(serializer, keyPart, value);
} }
}
serializer.endTag(null, SETTINGS_ELEMENT); serializer.endTag(null, SETTINGS_ELEMENT);
if (identities.size() > 0) { if (identities.size() > 0) {