diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java index 1da864819..aecede0c1 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java @@ -56,8 +56,7 @@ public class AccountSettings { new V(1, new StringSetting("INBOX")) )); s.put("automaticCheckIntervalMinutes", Settings.versions( - new V(1, new IntegerResourceSetting(-1, - R.array.account_settings_check_frequency_values)) + new V(1, new IntegerResourceSetting(-1, R.array.account_settings_check_frequency_values)) )); s.put("chipColor", Settings.versions( new V(1, new ColorSetting(0xFF0000FF)) @@ -120,16 +119,13 @@ public class AccountSettings { new V(1, new IntegerRangeSetting(0, 100, 10)) )); s.put("maximumAutoDownloadMessageSize", Settings.versions( - new V(1, new IntegerResourceSetting(32768, - R.array.account_settings_autodownload_message_size_values)) + new V(1, new IntegerResourceSetting(32768, R.array.account_settings_autodownload_message_size_values)) )); s.put("maximumPolledMessageAge", Settings.versions( - new V(1, new IntegerResourceSetting(-1, - R.array.account_settings_message_age_values)) + new V(1, new IntegerResourceSetting(-1, R.array.account_settings_message_age_values)) )); s.put("messageFormat", Settings.versions( - new V(1, new EnumSetting<>( - MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)) + new V(1, new EnumSetting<>(MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)) )); s.put("messageFormatAuto", Settings.versions( new V(2, new BooleanSetting(Account.DEFAULT_MESSAGE_FORMAT_AUTO)) @@ -213,12 +209,10 @@ public class AccountSettings { new V(1, new BooleanSetting(false)) )); s.put("vibratePattern", Settings.versions( - new V(1, new IntegerResourceSetting(0, - R.array.account_settings_vibrate_pattern_values)) + new V(1, new IntegerResourceSetting(0, R.array.account_settings_vibrate_pattern_values)) )); s.put("vibrateTimes", Settings.versions( - new V(1, new IntegerResourceSetting(5, - R.array.account_settings_vibrate_times_label)) + new V(1, new IntegerResourceSetting(5, R.array.account_settings_vibrate_times_label)) )); s.put("allowRemoteSearch", Settings.versions( new V(18, new BooleanSetting(true)) @@ -241,8 +235,7 @@ public class AccountSettings { UPGRADERS = Collections.unmodifiableMap(u); } - static Map validate(int version, Map importedSettings, - boolean useDefaultValues) { + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java index d9f97044e..d3219e592 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/FolderSettings.java @@ -48,8 +48,7 @@ class FolderSettings { UPGRADERS = Collections.unmodifiableMap(u); } - static Map validate(int version, Map importedSettings, - boolean useDefaultValues) { + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } @@ -61,8 +60,7 @@ class FolderSettings { return Settings.convert(settings, SETTINGS); } - static Map getFolderSettings(Storage storage, String uuid, - String folderName) { + static Map getFolderSettings(Storage storage, String uuid, String folderName) { Map result = new HashMap<>(); String prefix = uuid + "." + folderName + "."; for (String key : SETTINGS.keySet()) { diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java index 89bcc5d2e..77618b62d 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/GlobalSettings.java @@ -56,8 +56,7 @@ public class GlobalSettings { Environment.DIRECTORY_DOWNLOADS))) )); s.put("backgroundOperations", Settings.versions( - new V(1, new EnumSetting<>( - K9.BACKGROUND_OPS.class, K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC)) + new V(1, new EnumSetting<>(K9.BACKGROUND_OPS.class, K9.BACKGROUND_OPS.WHEN_CHECKED_AUTO_SYNC)) )); s.put("changeRegisteredNameColor", Settings.versions( new V(1, new BooleanSetting(false)) @@ -214,8 +213,7 @@ public class GlobalSettings { new V(22, new BooleanSetting(false)) )); s.put("notificationHideSubject", Settings.versions( - new V(12, new EnumSetting<>( - NotificationHideSubject.class, NotificationHideSubject.NEVER)) + new V(12, new EnumSetting<>(NotificationHideSubject.class, NotificationHideSubject.NEVER)) )); s.put("useBackgroundAsUnreadIndicator", Settings.versions( new V(19, new BooleanSetting(true)) @@ -276,8 +274,7 @@ public class GlobalSettings { new V(38, new BooleanSetting(false)) )); s.put("notificationQuickDelete", Settings.versions( - new V(38, new EnumSetting<>(NotificationQuickDelete.class, - NotificationQuickDelete.NEVER)) + new V(38, new EnumSetting<>(NotificationQuickDelete.class, NotificationQuickDelete.NEVER)) )); s.put("notificationDuringQuietTimeEnabled", Settings.versions( new V(39, new BooleanSetting(true)) @@ -287,7 +284,7 @@ public class GlobalSettings { )); s.put("pgpInlineDialogCounter", Settings.versions( new V(43, new IntegerRangeSetting(0, Integer.MAX_VALUE, 0)) - )); + )); SETTINGS = Collections.unmodifiableMap(s); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java index fa82f6f62..ad7804a9d 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/IdentitySettings.java @@ -17,8 +17,7 @@ class IdentitySettings { private static final Map UPGRADERS; static { - Map> s = - new LinkedHashMap<>(); + Map> s = new LinkedHashMap<>(); /** * When adding new settings here, be sure to increment {@link Settings.VERSION} @@ -42,8 +41,7 @@ class IdentitySettings { UPGRADERS = Collections.unmodifiableMap(u); } - static Map validate(int version, Map importedSettings, - boolean useDefaultValues) { + static Map validate(int version, Map importedSettings, boolean useDefaultValues) { return Settings.validate(version, SETTINGS, importedSettings, useDefaultValues); } @@ -55,8 +53,7 @@ class IdentitySettings { return Settings.convert(settings, SETTINGS); } - static Map getIdentitySettings(Storage storage, String uuid, - int identityIndex) { + static Map getIdentitySettings(Storage storage, String uuid, int identityIndex) { Map result = new HashMap<>(); String prefix = uuid + "."; String suffix = "." + Integer.toString(identityIndex); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java index e77176780..2d0d1ceff 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/Settings.java @@ -38,13 +38,11 @@ public class Settings { */ public static final int VERSION = 44; - static Map validate(int version, Map> settings, + static Map validate(int version, Map> settings, Map importedSettings, boolean useDefaultValues) { Map validatedSettings = new HashMap<>(); - for (Map.Entry> versionedSetting : - settings.entrySet()) { + for (Map.Entry> versionedSetting : settings.entrySet()) { // Get the setting description with the highest version lower than or equal to the // supplied content version. @@ -112,8 +110,7 @@ public class Settings { * if none were removed. */ public static Set upgrade(int version, Map customUpgraders, - Map> settings, - Map validatedSettingsMutable) { + Map> settings, Map validatedSettingsMutable) { Set deletedSettings = null; for (int toVersion = version + 1; toVersion <= VERSION; toVersion++) { @@ -201,8 +198,7 @@ public class Settings { String settingName = setting.getKey(); Object internalValue = setting.getValue(); - TreeMap versionedSetting = - settingDescriptions.get(settingName); + TreeMap versionedSetting = settingDescriptions.get(settingName); Integer highestVersion = versionedSetting.lastKey(); SettingsDescription settingDesc = versionedSetting.get(highestVersion); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java index 7427dd87e..cc6976395 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java @@ -76,8 +76,7 @@ public class SettingsExporter { static final String DESCRIPTION_ELEMENT = "description"; - public static String exportToFile(Context context, boolean includeGlobals, - Set accountUuids) + public static String exportToFile(Context context, boolean includeGlobals, Set accountUuids) throws SettingsImportExportException { OutputStream os = null; @@ -110,8 +109,8 @@ public class SettingsExporter { } } - static void exportPreferences(Context context, OutputStream os, boolean includeGlobals, - Set accountUuids) throws SettingsImportExportException { + static void exportPreferences(Context context, OutputStream os, boolean includeGlobals, Set accountUuids) + throws SettingsImportExportException { try { XmlSerializer serializer = Xml.newSerializer(); @@ -124,8 +123,7 @@ public class SettingsExporter { serializer.startTag(null, ROOT_ELEMENT); serializer.attribute(null, VERSION_ATTRIBUTE, Integer.toString(Settings.VERSION)); - serializer.attribute(null, FILE_FORMAT_ATTRIBUTE, - Integer.toString(FILE_FORMAT_VERSION)); + serializer.attribute(null, FILE_FORMAT_ATTRIBUTE, Integer.toString(FILE_FORMAT_VERSION)); Log.i(K9.LOG_TAG, "Exporting preferences"); @@ -167,10 +165,9 @@ public class SettingsExporter { } } - private static void writeSettings(XmlSerializer serializer, - Map prefs) throws IOException { + private static void writeSettings(XmlSerializer serializer, Map prefs) throws IOException { - for (Entry> versionedSetting : + for (Entry> versionedSetting : GlobalSettings.SETTINGS.entrySet()) { String key = versionedSetting.getKey(); @@ -192,8 +189,7 @@ public class SettingsExporter { } } else { if (K9.DEBUG) { - Log.d(K9.LOG_TAG, "Couldn't find key \"" + key + "\" in preference storage." + - "Using default value."); + Log.d(K9.LOG_TAG, "Couldn't find key \"" + key + "\" in preference storage. Using default value."); } writeKeyAndDefaultValueFromSetting(serializer, key, setting); @@ -201,8 +197,8 @@ public class SettingsExporter { } } - private static void writeAccount(XmlSerializer serializer, Account account, - Map prefs) throws IOException { + private static void writeAccount(XmlSerializer serializer, Account account, Map prefs) + throws IOException { Set identities = new HashSet<>(); Set folders = new HashSet<>(); @@ -218,7 +214,6 @@ public class SettingsExporter { serializer.endTag(null, NAME_ELEMENT); } - // Write incoming server settings ServerSettings incoming = RemoteStore.decodeStoreUri(account.getStoreUri()); serializer.startTag(null, INCOMING_SERVER_ELEMENT); @@ -326,8 +321,7 @@ public class SettingsExporter { } } - TreeMap versionedSetting = - AccountSettings.SETTINGS.get(keyPart); + TreeMap versionedSetting = AccountSettings.SETTINGS.get(keyPart); if (versionedSetting != null) { Integer highestVersion = versionedSetting.lastKey(); @@ -371,8 +365,8 @@ public class SettingsExporter { serializer.endTag(null, ACCOUNT_ELEMENT); } - private static void writeIdentity(XmlSerializer serializer, String accountUuid, - String identity, Map prefs) throws IOException { + private static void writeIdentity(XmlSerializer serializer, String accountUuid, String identity, + Map prefs) throws IOException { serializer.startTag(null, IDENTITY_ELEMENT); @@ -419,8 +413,7 @@ public class SettingsExporter { continue; } - TreeMap versionedSetting = - IdentitySettings.SETTINGS.get(identityKey); + TreeMap versionedSetting = IdentitySettings.SETTINGS.get(identityKey); if (versionedSetting != null) { Integer highestVersion = versionedSetting.lastKey(); @@ -431,9 +424,8 @@ public class SettingsExporter { try { writeKeyAndPrettyValueFromSetting(serializer, identityKey, setting, valueString); } catch (InvalidSettingValueException e) { - Log.w(K9.LOG_TAG, "Identity setting \"" + identityKey + - "\" has invalid value \"" + valueString + - "\" in preference storage. This shouldn't happen!"); + Log.w(K9.LOG_TAG, "Identity setting \"" + identityKey + "\" has invalid value \"" + + valueString + "\" in preference storage. This shouldn't happen!"); } } } @@ -443,8 +435,8 @@ public class SettingsExporter { serializer.endTag(null, IDENTITY_ELEMENT); } - private static void writeFolder(XmlSerializer serializer, String accountUuid, - String folder, Map prefs) throws IOException { + private static void writeFolder(XmlSerializer serializer, String accountUuid, String folder, + Map prefs) throws IOException { serializer.startTag(null, FOLDER_ELEMENT); serializer.attribute(null, NAME_ATTRIBUTE, folder); @@ -470,8 +462,7 @@ public class SettingsExporter { continue; } - TreeMap versionedSetting = - FolderSettings.SETTINGS.get(folderKey); + TreeMap versionedSetting = FolderSettings.SETTINGS.get(folderKey); if (versionedSetting != null) { Integer highestVersion = versionedSetting.lastKey(); @@ -482,8 +473,7 @@ public class SettingsExporter { try { writeKeyAndPrettyValueFromSetting(serializer, folderKey, setting, valueString); } catch (InvalidSettingValueException e) { - Log.w(K9.LOG_TAG, "Folder setting \"" + folderKey + - "\" has invalid value \"" + valueString + + Log.w(K9.LOG_TAG, "Folder setting \"" + folderKey + "\" has invalid value \"" + valueString + "\" in preference storage. This shouldn't happen!"); } } @@ -502,8 +492,8 @@ public class SettingsExporter { } } - private static void writeKeyAndPrettyValueFromSetting(XmlSerializer serializer, - String key, SettingsDescription setting, String valueString) + private static void writeKeyAndPrettyValueFromSetting(XmlSerializer serializer, String key, + SettingsDescription setting, String valueString) throws IllegalArgumentException, IllegalStateException, IOException, InvalidSettingValueException { A value = setting.fromString(valueString); String outputValue = setting.toPrettyString(value); @@ -511,9 +501,8 @@ public class SettingsExporter { writeKeyAndPrettyValueFromSetting(serializer, key, outputValue); } - private static void writeKeyAndDefaultValueFromSetting(XmlSerializer serializer, - String key, SettingsDescription setting) - throws IllegalArgumentException, IllegalStateException, IOException { + private static void writeKeyAndDefaultValueFromSetting(XmlSerializer serializer, String key, + SettingsDescription setting) throws IllegalArgumentException, IllegalStateException, IOException { A value = setting.getDefaultValue(); String outputValue = setting.toPrettyString(value); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java index e1837ced3..744a1d89c 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsImporter.java @@ -83,8 +83,7 @@ public class SettingsImporter { public final AccountDescription imported; public final boolean overwritten; - private AccountDescriptionPair(AccountDescription original, AccountDescription imported, - boolean overwritten) { + private AccountDescriptionPair(AccountDescription original, AccountDescription imported, boolean overwritten) { this.original = original; this.imported = imported; this.overwritten = overwritten; @@ -96,8 +95,7 @@ public class SettingsImporter { public final List importedAccounts; public final List errorneousAccounts; - private ImportResults(boolean globalSettings, - List importedAccounts, + private ImportResults(boolean globalSettings, List importedAccounts, List errorneousAccounts) { this.globalSettings = globalSettings; this.importedAccounts = importedAccounts; @@ -174,9 +172,8 @@ public class SettingsImporter { * @throws SettingsImportExportException * In case of an error. */ - public static ImportResults importSettings(Context context, InputStream inputStream, - boolean globalSettings, List accountUuids, boolean overwrite) - throws SettingsImportExportException { + public static ImportResults importSettings(Context context, InputStream inputStream, boolean globalSettings, + List accountUuids, boolean overwrite) throws SettingsImportExportException { try { @@ -193,21 +190,18 @@ public class SettingsImporter { try { StorageEditor editor = storage.edit(); if (imported.globalSettings != null) { - importGlobalSettings(storage, editor, imported.contentVersion, - imported.globalSettings); + importGlobalSettings(storage, editor, imported.contentVersion, imported.globalSettings); } else { Log.w(K9.LOG_TAG, "Was asked to import global settings but none found."); } if (editor.commit()) { if (K9.DEBUG) { - Log.v(K9.LOG_TAG, "Committed global settings to the preference " + - "storage."); + Log.v(K9.LOG_TAG, "Committed global settings to the preference storage."); } globalSettingsImported = true; } else { if (K9.DEBUG) { - Log.v(K9.LOG_TAG, "Failed to commit global settings to the " + - "preference storage"); + Log.v(K9.LOG_TAG, "Failed to commit global settings to the preference storage"); } } } catch (Exception e) { @@ -223,14 +217,13 @@ public class SettingsImporter { try { StorageEditor editor = storage.edit(); - AccountDescriptionPair importResult = importAccount(context, - editor, imported.contentVersion, account, overwrite); + AccountDescriptionPair importResult = importAccount(context, editor, + imported.contentVersion, account, overwrite); if (editor.commit()) { if (K9.DEBUG) { Log.v(K9.LOG_TAG, "Committed settings for account \"" + - importResult.imported.name + - "\" to the settings database."); + importResult.imported.name + "\" to the settings database."); } // Add UUID of the account we just imported to the list of @@ -256,9 +249,8 @@ public class SettingsImporter { importedAccounts.add(importResult); } else { if (K9.DEBUG) { - Log.w(K9.LOG_TAG, "Error while committing settings for " + - "account \"" + importResult.original.name + - "\" to the settings database."); + Log.w(K9.LOG_TAG, "Error while committing settings for account \"" + + importResult.original.name + "\" to the settings database."); } errorneousAccounts.add(importResult.original); } @@ -269,13 +261,12 @@ public class SettingsImporter { } errorneousAccounts.add(new AccountDescription(account.name, account.uuid)); } catch (Exception e) { - Log.e(K9.LOG_TAG, "Exception while importing account \"" + - account.name + "\"", e); + Log.e(K9.LOG_TAG, "Exception while importing account \"" + account.name + "\"", e); errorneousAccounts.add(new AccountDescription(account.name, account.uuid)); } } else { - Log.w(K9.LOG_TAG, "Was asked to import account with UUID " + - accountUuid + ". But this account wasn't found."); + Log.w(K9.LOG_TAG, "Was asked to import account with UUID " + accountUuid + + ". But this account wasn't found."); } } @@ -307,12 +298,11 @@ public class SettingsImporter { } } - private static void importGlobalSettings(Storage storage, - StorageEditor editor, int contentVersion, ImportedSettings settings) { + private static void importGlobalSettings(Storage storage, StorageEditor editor, int contentVersion, + ImportedSettings settings) { // Validate global settings - Map validatedSettings = GlobalSettings.validate(contentVersion, - settings.settings); + Map validatedSettings = GlobalSettings.validate(contentVersion, settings.settings); // Upgrade global settings to current content version if (contentVersion != Settings.VERSION) { @@ -322,10 +312,8 @@ public class SettingsImporter { // Convert global settings to the string representation used in preference storage Map stringSettings = GlobalSettings.convert(validatedSettings); - // Use current global settings as base and overwrite with validated settings read from the - // import file. - Map mergedSettings = - new HashMap<>(GlobalSettings.getGlobalSettings(storage)); + // Use current global settings as base and overwrite with validated settings read from the import file. + Map mergedSettings = new HashMap<>(GlobalSettings.getGlobalSettings(storage)); mergedSettings.putAll(stringSettings); for (Map.Entry setting : mergedSettings.entrySet()) { @@ -335,9 +323,8 @@ public class SettingsImporter { } } - private static AccountDescriptionPair importAccount(Context context, - StorageEditor editor, int contentVersion, ImportedAccount account, - boolean overwrite) throws InvalidSettingValueException { + private static AccountDescriptionPair importAccount(Context context, StorageEditor editor, int contentVersion, + ImportedAccount account, boolean overwrite) throws InvalidSettingValueException { AccountDescription original = new AccountDescription(account.name, account.uuid); @@ -357,8 +344,8 @@ public class SettingsImporter { // Make sure the account name is unique String accountName = account.name; if (isAccountNameUsed(accountName, accounts)) { - // Account name is already in use. So generate a new one by appending " (x)", where x - // is the first number >= 1 that results in an unused account name. + // Account name is already in use. So generate a new one by appending " (x)", where x is the first + // number >= 1 that results in an unused account name. for (int i = 1; i <= accounts.size(); i++) { accountName = account.name + " (" + i + ")"; if (!isAccountNameUsed(accountName, accounts)) { @@ -398,11 +385,9 @@ public class SettingsImporter { putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Base64.encode(transportUri)); /* - * Mark account as disabled if the settings file contained a - * username but no password. However, no password is required for - * the outgoing server for WebDAV accounts, because incoming and - * outgoing servers are identical for this account type. Nor is a - * password required if the AuthType is EXTERNAL. + * Mark account as disabled if the settings file contained a username but no password. However, no password + * is required for the outgoing server for WebDAV accounts, because incoming and outgoing servers are + * identical for this account type. Nor is a password required if the AuthType is EXTERNAL. */ boolean outgoingPasswordNeeded = AuthType.EXTERNAL != outgoing.authenticationType && !(ServerSettings.Type.WebDAV == outgoing.type) && @@ -419,8 +404,7 @@ public class SettingsImporter { // Validate account settings Map validatedSettings = - AccountSettings.validate(contentVersion, account.settings.settings, - !mergeImportedAccount); + AccountSettings.validate(contentVersion, account.settings.settings, !mergeImportedAccount); // Upgrade account settings to current content version if (contentVersion != Settings.VERSION) { @@ -433,8 +417,7 @@ public class SettingsImporter { // Merge account settings if necessary Map writeSettings; if (mergeImportedAccount) { - writeSettings = new HashMap<>( - AccountSettings.getAccountSettings(prefs.getStorage(), uuid)); + writeSettings = new HashMap<>(AccountSettings.getAccountSettings(prefs.getStorage(), uuid)); writeSettings.putAll(stringSettings); } else { writeSettings = stringSettings; @@ -455,8 +438,7 @@ public class SettingsImporter { // Write identities if (account.identities != null) { - importIdentities(editor, contentVersion, uuid, account, overwrite, existingAccount, - prefs); + importIdentities(editor, contentVersion, uuid, account, overwrite, existingAccount, prefs); } else if (!mergeImportedAccount) { // Require accounts to at least have one identity throw new InvalidSettingValueException(); @@ -475,8 +457,8 @@ public class SettingsImporter { return new AccountDescriptionPair(original, imported, mergeImportedAccount); } - private static void importFolder(StorageEditor editor, int contentVersion, - String uuid, ImportedFolder folder, boolean overwrite, Preferences prefs) { + private static void importFolder(StorageEditor editor, int contentVersion, String uuid, ImportedFolder folder, + boolean overwrite, Preferences prefs) { // Validate folder settings Map validatedSettings = @@ -493,8 +475,7 @@ public class SettingsImporter { // Merge folder settings if necessary Map writeSettings; if (overwrite) { - writeSettings = FolderSettings.getFolderSettings(prefs.getStorage(), - uuid, folder.name); + writeSettings = FolderSettings.getFolderSettings(prefs.getStorage(), uuid, folder.name); writeSettings.putAll(stringSettings); } else { writeSettings = stringSettings; @@ -509,9 +490,8 @@ public class SettingsImporter { } } - private static void importIdentities(StorageEditor editor, int contentVersion, - String uuid, ImportedAccount account, boolean overwrite, Account existingAccount, - Preferences prefs) throws InvalidSettingValueException { + private static void importIdentities(StorageEditor editor, int contentVersion, String uuid, ImportedAccount account, + boolean overwrite, Account existingAccount, Preferences prefs) throws InvalidSettingValueException { String accountKeyPrefix = uuid + "."; @@ -540,8 +520,7 @@ public class SettingsImporter { nextIdentityIndex++; } - String identityDescription = (identity.description == null) ? - "Imported" : identity.description; + String identityDescription = (identity.description == null) ? "Imported" : identity.description; if (isIdentityDescriptionUsed(identityDescription, existingIdentities)) { // Identity description is already in use. So generate a new one by appending // " (x)", where x is the first number >= 1 that results in an unused identity @@ -558,8 +537,7 @@ public class SettingsImporter { // Write name used in identity String identityName = (identity.name == null) ? "" : identity.name; - putString(editor, accountKeyPrefix + Account.IDENTITY_NAME_KEY + identitySuffix, - identityName); + putString(editor, accountKeyPrefix + Account.IDENTITY_NAME_KEY + identitySuffix, identityName); // Validate email address if (!IdentitySettings.isEmailAddressValid(identity.email)) { @@ -567,8 +545,7 @@ public class SettingsImporter { } // Write email address - putString(editor, accountKeyPrefix + Account.IDENTITY_EMAIL_KEY + identitySuffix, - identity.email); + putString(editor, accountKeyPrefix + Account.IDENTITY_EMAIL_KEY + identitySuffix, identity.email); // Write identity description putString(editor, accountKeyPrefix + Account.IDENTITY_DESCRIPTION_KEY + identitySuffix, @@ -629,8 +606,7 @@ public class SettingsImporter { return false; } - private static int findIdentity(ImportedIdentity identity, - List identities) { + private static int findIdentity(ImportedIdentity identity, List identities) { for (int i = 0; i < identities.size(); i++) { Identity existingIdentity = identities.get(i); if (existingIdentity.getName().equals(identity.name) && @@ -655,8 +631,7 @@ public class SettingsImporter { private static void putString(StorageEditor editor, String key, String value) { if (K9.DEBUG) { String outputValue = value; - if (!K9.DEBUG_SENSITIVE && - (key.endsWith(".transportUri") || key.endsWith(".storeUri"))) { + if (!K9.DEBUG_SENSITIVE && (key.endsWith(".transportUri") || key.endsWith(".storeUri"))) { outputValue = "*sensitive*"; } Log.v(K9.LOG_TAG, "Setting " + key + "=" + outputValue); @@ -665,9 +640,8 @@ public class SettingsImporter { } @VisibleForTesting - static Imported parseSettings(InputStream inputStream, boolean globalSettings, - List accountUuids, boolean overview) - throws SettingsImportExportException { + static Imported parseSettings(InputStream inputStream, boolean globalSettings, List accountUuids, + boolean overview) throws SettingsImportExportException { if (!overview && accountUuids == null) { throw new IllegalArgumentException("Argument 'accountUuids' must not be null."); @@ -694,8 +668,7 @@ public class SettingsImporter { eventType = xpp.next(); } - if (imported == null || (overview && imported.globalSettings == null && - imported.accounts == null)) { + if (imported == null || (overview && imported.globalSettings == null && imported.accounts == null)) { throw new SettingsImportExportException("Invalid import data"); } @@ -705,18 +678,14 @@ public class SettingsImporter { } } - private static void skipToEndTag(XmlPullParser xpp, String endTag) - throws XmlPullParserException, IOException { - + private static void skipToEndTag(XmlPullParser xpp, String endTag) throws XmlPullParserException, IOException { int eventType = xpp.next(); while (!(eventType == XmlPullParser.END_TAG && endTag.equals(xpp.getName()))) { eventType = xpp.next(); } } - private static String getText(XmlPullParser xpp) - throws XmlPullParserException, IOException { - + private static String getText(XmlPullParser xpp) throws XmlPullParserException, IOException { int eventType = xpp.next(); if (eventType != XmlPullParser.TEXT) { return ""; @@ -724,24 +693,19 @@ public class SettingsImporter { return xpp.getText(); } - private static Imported parseRoot(XmlPullParser xpp, boolean globalSettings, - List accountUuids, boolean overview) - throws XmlPullParserException, IOException, SettingsImportExportException { + private static Imported parseRoot(XmlPullParser xpp, boolean globalSettings, List accountUuids, + boolean overview) throws XmlPullParserException, IOException, SettingsImportExportException { Imported result = new Imported(); - String fileFormatVersionString = xpp.getAttributeValue(null, - SettingsExporter.FILE_FORMAT_ATTRIBUTE); + String fileFormatVersionString = xpp.getAttributeValue(null, SettingsExporter.FILE_FORMAT_ATTRIBUTE); validateFileFormatVersion(fileFormatVersionString); - String contentVersionString = xpp.getAttributeValue(null, - SettingsExporter.VERSION_ATTRIBUTE); + String contentVersionString = xpp.getAttributeValue(null, SettingsExporter.VERSION_ATTRIBUTE); result.contentVersion = validateContentVersion(contentVersionString); int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.ROOT_ELEMENT.equals(xpp.getName()))) { - + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.ROOT_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); if (SettingsExporter.GLOBAL_ELEMENT.equals(element)) { @@ -777,9 +741,7 @@ public class SettingsImporter { return result; } - private static int validateFileFormatVersion(String versionString) - throws SettingsImportExportException { - + private static int validateFileFormatVersion(String versionString) throws SettingsImportExportException { if (versionString == null) { throw new SettingsImportExportException("Missing file format version"); } @@ -788,21 +750,17 @@ public class SettingsImporter { try { version = Integer.parseInt(versionString); } catch (NumberFormatException e) { - throw new SettingsImportExportException("Invalid file format version: " + - versionString); + throw new SettingsImportExportException("Invalid file format version: " + versionString); } if (version != SettingsExporter.FILE_FORMAT_VERSION) { - throw new SettingsImportExportException("Unsupported file format version: " + - versionString); + throw new SettingsImportExportException("Unsupported file format version: " + versionString); } return version; } - private static int validateContentVersion(String versionString) - throws SettingsImportExportException { - + private static int validateContentVersion(String versionString) throws SettingsImportExportException { if (versionString == null) { throw new SettingsImportExportException("Missing content version"); } @@ -811,8 +769,7 @@ public class SettingsImporter { try { version = Integer.parseInt(versionString); } catch (NumberFormatException e) { - throw new SettingsImportExportException("Invalid content version: " + - versionString); + throw new SettingsImportExportException("Invalid content version: " + versionString); } if (version < 1) { @@ -822,8 +779,8 @@ public class SettingsImporter { return version; } - private static ImportedSettings parseSettings(XmlPullParser xpp, String endTag) - throws XmlPullParserException, IOException { + private static ImportedSettings parseSettings(XmlPullParser xpp, String endTag) + throws XmlPullParserException, IOException { ImportedSettings result = null; @@ -855,16 +812,13 @@ public class SettingsImporter { return result; } - private static Map parseAccounts(XmlPullParser xpp, - List accountUuids, boolean overview) - throws XmlPullParserException, IOException { + private static Map parseAccounts(XmlPullParser xpp, List accountUuids, + boolean overview) throws XmlPullParserException, IOException { Map accounts = null; int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.ACCOUNTS_ELEMENT.equals(xpp.getName()))) { - + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.ACCOUNTS_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); if (SettingsExporter.ACCOUNT_ELEMENT.equals(element)) { @@ -879,8 +833,7 @@ public class SettingsImporter { } else if (!accounts.containsKey(account.uuid)) { accounts.put(account.uuid, account); } else { - Log.w(K9.LOG_TAG, "Duplicate account entries with UUID " + account.uuid + - ". Ignoring!"); + Log.w(K9.LOG_TAG, "Duplicate account entries with UUID " + account.uuid + ". Ignoring!"); } } else { Log.w(K9.LOG_TAG, "Unexpected start tag: " + xpp.getName()); @@ -892,9 +845,8 @@ public class SettingsImporter { return accounts; } - private static ImportedAccount parseAccount(XmlPullParser xpp, List accountUuids, - boolean overview) - throws XmlPullParserException, IOException { + private static ImportedAccount parseAccount(XmlPullParser xpp, List accountUuids, boolean overview) + throws XmlPullParserException, IOException { String uuid = xpp.getAttributeValue(null, SettingsExporter.UUID_ATTRIBUTE); @@ -911,9 +863,7 @@ public class SettingsImporter { if (overview || accountUuids.contains(uuid)) { int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.ACCOUNT_ELEMENT.equals(xpp.getName()))) { - + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.ACCOUNT_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); if (SettingsExporter.NAME_ELEMENT.equals(element)) { @@ -964,7 +914,7 @@ public class SettingsImporter { } private static ImportedServer parseServerSettings(XmlPullParser xpp, String endTag) - throws XmlPullParserException, IOException { + throws XmlPullParserException, IOException { ImportedServer server = new ImportedServer(); server.type = xpp.getAttributeValue(null, SettingsExporter.TYPE_ATTRIBUTE); @@ -1000,14 +950,12 @@ public class SettingsImporter { return server; } - private static List parseIdentities(XmlPullParser xpp) - throws XmlPullParserException, IOException { + private static List parseIdentities(XmlPullParser xpp) + throws XmlPullParserException, IOException { List identities = null; int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.IDENTITIES_ELEMENT.equals(xpp.getName()))) { - + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.IDENTITIES_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); if (SettingsExporter.IDENTITY_ELEMENT.equals(element)) { @@ -1027,13 +975,11 @@ public class SettingsImporter { return identities; } - private static ImportedIdentity parseIdentity(XmlPullParser xpp) - throws XmlPullParserException, IOException { + private static ImportedIdentity parseIdentity(XmlPullParser xpp) throws XmlPullParserException, IOException { ImportedIdentity identity = new ImportedIdentity(); int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.IDENTITY_ELEMENT.equals(xpp.getName()))) { + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.IDENTITY_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); @@ -1055,14 +1001,11 @@ public class SettingsImporter { return identity; } - private static List parseFolders(XmlPullParser xpp) - throws XmlPullParserException, IOException { + private static List parseFolders(XmlPullParser xpp) throws XmlPullParserException, IOException { List folders = null; int eventType = xpp.next(); - while (!(eventType == XmlPullParser.END_TAG && - SettingsExporter.FOLDERS_ELEMENT.equals(xpp.getName()))) { - + while (!(eventType == XmlPullParser.END_TAG && SettingsExporter.FOLDERS_ELEMENT.equals(xpp.getName()))) { if(eventType == XmlPullParser.START_TAG) { String element = xpp.getName(); if (SettingsExporter.FOLDER_ELEMENT.equals(element)) { @@ -1082,8 +1025,7 @@ public class SettingsImporter { return folders; } - private static ImportedFolder parseFolder(XmlPullParser xpp) - throws XmlPullParserException, IOException { + private static ImportedFolder parseFolder(XmlPullParser xpp) throws XmlPullParserException, IOException { ImportedFolder folder = new ImportedFolder(); String name = xpp.getAttributeValue(null, SettingsExporter.NAME_ATTRIBUTE);