mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -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:
parent
644571cfe5
commit
83ee4253d5
@ -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,41 +270,50 @@ 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) {
|
|
||||||
String keyUuid = comps[0];
|
|
||||||
String secondPart = comps[1];
|
|
||||||
|
|
||||||
if (!keyUuid.equals(accountUuid) || SKIP_ACCOUNT_SETTINGS.contains(secondPart)) {
|
if (comps.length < 2) {
|
||||||
continue;
|
// Skip global settings
|
||||||
}
|
|
||||||
if (comps.length == 3) {
|
|
||||||
String thirdPart = comps[2];
|
|
||||||
|
|
||||||
if (Account.IDENTITY_KEYS.contains(secondPart)) {
|
|
||||||
// This is an identity key. Save identity index for later...
|
|
||||||
try {
|
|
||||||
identities.add(Integer.parseInt(thirdPart));
|
|
||||||
} catch (NumberFormatException e) { /* ignore */ }
|
|
||||||
// ... but don't write it now.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LocalStore.FOLDER_SETTINGS_KEYS.contains(thirdPart)) {
|
|
||||||
// This is a folder key. Save folder name for later...
|
|
||||||
folders.add(secondPart);
|
|
||||||
// ... but don't write it now.
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Skip global config entries and identity entries
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strip account UUID from key
|
String keyUuid = comps[0];
|
||||||
String keyPart = key.substring(comps[0].length() + 1);
|
String secondPart = comps[1];
|
||||||
|
|
||||||
writeKeyValue(serializer, keyPart, value);
|
if (!keyUuid.equals(accountUuid)) {
|
||||||
|
// Setting doesn't belong to the account we're currently writing.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String keyPart;
|
||||||
|
if (comps.length >= 3) {
|
||||||
|
String thirdPart = comps[2];
|
||||||
|
|
||||||
|
if (Account.IDENTITY_KEYS.contains(secondPart)) {
|
||||||
|
// This is an identity key. Save identity index for later...
|
||||||
|
try {
|
||||||
|
identities.add(Integer.parseInt(thirdPart));
|
||||||
|
} catch (NumberFormatException e) { /* ignore */ }
|
||||||
|
// ... but don't write it now.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (LocalStore.FOLDER_SETTINGS_KEYS.contains(thirdPart)) {
|
||||||
|
// This is a folder key. Save folder name for later...
|
||||||
|
folders.add(secondPart);
|
||||||
|
// ... but don't write it now.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip account UUID from key
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
serializer.endTag(null, SETTINGS_ELEMENT);
|
serializer.endTag(null, SETTINGS_ELEMENT);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user