mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 17:18:50 -05:00
Move the generation of the XML envelope to a common place since it
would be used in all storageFormats. StorageImporter uses the header to figure out which specific import implementation to use.
This commit is contained in:
parent
0bded12843
commit
e5ef068c15
@ -1,12 +1,12 @@
|
|||||||
package com.fsck.k9.preferences;
|
package com.fsck.k9.preferences;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public interface IStorageExporter {
|
public interface IStorageExporter {
|
||||||
public boolean needsKey();
|
public boolean needsKey();
|
||||||
|
// exportPreferences must be sure to flush all data to the OutputStream before returning
|
||||||
public void exportPreferences(Context context, boolean includeGlobals, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException;
|
public void exportPreferences(Context context, boolean includeGlobals, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@ package com.fsck.k9.preferences;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@ -22,9 +24,9 @@ public class StorageExporter {
|
|||||||
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
|
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
|
||||||
}
|
}
|
||||||
if (storageExporter.needsKey() && encryptionKey == null) {
|
if (storageExporter.needsKey() && encryptionKey == null) {
|
||||||
gatherPassword(activity, storageExporter, includeGlobals, accountUuids, fileName, os, listener);
|
gatherPassword(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, listener);
|
||||||
} else {
|
} else {
|
||||||
finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener);
|
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +45,7 @@ public class StorageExporter {
|
|||||||
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, null, os, encryptionKey, listener);
|
exportPreferences(activity, storageFormat, includeGlobals, accountUuids, null, os, encryptionKey, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final boolean includeGlobals, final Set<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
|
private static void gatherPassword(final Activity activity, final String storageFormat, final IStorageExporter storageExporter, final boolean includeGlobals, final Set<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -57,7 +59,7 @@ public class StorageExporter {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener);
|
finishExport(activity, storageFormat, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(K9.LOG_TAG, "Exception while finishing export", e);
|
Log.w(K9.LOG_TAG, "Exception while finishing export", e);
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
@ -81,7 +83,7 @@ public class StorageExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void finishExport(Activity activity, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException {
|
private static void finishExport(Activity activity, String storageFormat, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException {
|
||||||
boolean needToClose = false;
|
boolean needToClose = false;
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.started();
|
listener.started();
|
||||||
@ -95,7 +97,18 @@ public class StorageExporter {
|
|||||||
os = new FileOutputStream(outFile);
|
os = new FileOutputStream(outFile);
|
||||||
}
|
}
|
||||||
if (os != null) {
|
if (os != null) {
|
||||||
|
|
||||||
|
OutputStreamWriter sw = new OutputStreamWriter(os);
|
||||||
|
PrintWriter pf = new PrintWriter(sw);
|
||||||
|
pf.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||||
|
|
||||||
|
pf.println("<k9settings version=\"" + storageFormat + "\">");
|
||||||
|
pf.flush();
|
||||||
|
|
||||||
storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey);
|
storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey);
|
||||||
|
|
||||||
|
pf.println("</k9settings>");
|
||||||
|
pf.flush();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
listener.success(fileName);
|
listener.success(fileName);
|
||||||
|
@ -24,10 +24,6 @@ public class StorageExporterEncryptedXml implements IStorageExporter {
|
|||||||
PrintWriter pf = new PrintWriter(sw);
|
PrintWriter pf = new PrintWriter(sw);
|
||||||
long keysEvaluated = 0;
|
long keysEvaluated = 0;
|
||||||
long keysExported = 0;
|
long keysExported = 0;
|
||||||
pf.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
||||||
|
|
||||||
pf.print("<k9settings version=\"1\"");
|
|
||||||
pf.println(">");
|
|
||||||
|
|
||||||
Preferences preferences = Preferences.getPreferences(context);
|
Preferences preferences = Preferences.getPreferences(context);
|
||||||
SharedPreferences storage = preferences.getPreferences();
|
SharedPreferences storage = preferences.getPreferences();
|
||||||
@ -66,7 +62,6 @@ public class StorageExporterEncryptedXml implements IStorageExporter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pf.println("</k9settings>");
|
|
||||||
pf.flush();
|
pf.flush();
|
||||||
|
|
||||||
Log.i(K9.LOG_TAG, "Exported " + keysExported + " of " + keysEvaluated + " settings.");
|
Log.i(K9.LOG_TAG, "Exported " + keysExported + " of " + keysEvaluated + " settings.");
|
||||||
|
Loading…
Reference in New Issue
Block a user