From: rmceoin Date: Mon, 19 Jan 2009 19:45:37 +0000 (+0000) Subject: Updated backup/restore to use OISafe for naming. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=e3d3ce42892c591288f580ec679be250d25b2aba;p=android-vcpass-oisafe Updated backup/restore to use OISafe for naming. Updated filenames to use OISafe. git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1785 72b678ce-9140-0410-bee8-679b907dd61a --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 534d2bc..ab4d471 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -52,7 +52,8 @@ Cannot decrypt password Error exporting database Export Database - Export to 'passwordsafe.csv' successful. Warning! The file is not encrypted. + Export to ' + ' successful. Warning! The file is not encrypted. Unable to create export file 'passwordsafe.csv' on SDCARD. You might try disconnecting USB from computer. Import Database Import file is missing: @@ -125,9 +126,9 @@ OI Safe: Another application requests access. Allow other applications to secure your data with OI Safe. This can also be set in OI Safe\'s Menu / Preferences. - Lock timeout + Auto lock timeout Minutes before timeout occurs and safe is locked. - Lock timeout + Auto lock timeout Decrypt (OI Safe) Encrypt (OI Safe) Get password (OI Safe) diff --git a/src/org/openintents/safe/Backup.java b/src/org/openintents/safe/Backup.java index ab3ef95..20d377d 100644 --- a/src/org/openintents/safe/Backup.java +++ b/src/org/openintents/safe/Backup.java @@ -30,7 +30,7 @@ public class Backup { private static boolean debug = false; private static final String TAG = "Backup"; - public static int CURRENT_VERSION = 2; + public static int CURRENT_VERSION = 1; private String result=""; @@ -49,7 +49,7 @@ public class Backup { serializer.setOutput(str, "utf-8"); serializer.startDocument(null, Boolean.valueOf(true)); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); - serializer.startTag(null, "AndroidPasswordSafe"); + serializer.startTag(null, "OISafe"); serializer.attribute(null, "version", Integer.toString(CURRENT_VERSION)); @@ -114,7 +114,7 @@ public class Backup { serializer.endTag(null, "Category"); } - serializer.endTag(null, "AndroidPasswordSafe"); + serializer.endTag(null, "OISafe"); serializer.endDocument(); dbHelper.close(); diff --git a/src/org/openintents/safe/CategoryList.java b/src/org/openintents/safe/CategoryList.java index 0cb90a1..eb2c17a 100644 --- a/src/org/openintents/safe/CategoryList.java +++ b/src/org/openintents/safe/CategoryList.java @@ -101,8 +101,8 @@ public class CategoryList extends ListActivity { public static final int MAX_CATEGORIES = 256; - private static final String EXPORT_FILENAME = "/sdcard/passwordsafe.csv"; - public static final String BACKUP_FILENAME = "/sdcard/passwordsafe.xml"; + private static final String EXPORT_FILENAME = "/sdcard/oisafe.csv"; + public static final String BACKUP_FILENAME = "/sdcard/oisafe.xml"; public static final String KEY_ID = "id"; // Intent keys @@ -113,6 +113,7 @@ public class CategoryList extends ListActivity { private int importedEntries=0; private Thread importThread=null; private boolean importDeletedDatabase=false; + private String importedFilename=""; private Thread backupThread=null; @@ -148,24 +149,27 @@ public class CategoryList extends ListActivity { Toast.makeText(CategoryList.this, importMessage, Toast.LENGTH_LONG).show(); } - String deleteMsg=getString(R.string.import_delete_csv) + - " " + EXPORT_FILENAME + "?"; - Dialog about = new AlertDialog.Builder(CategoryList.this) - .setIcon(R.drawable.passicon) - .setTitle(R.string.import_complete) - .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - File csvFile=new File(EXPORT_FILENAME); - csvFile.delete(); - } - }) - .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - } - }) - .setMessage(deleteMsg) - .create(); - about.show(); + if (importedFilename != "") { + String deleteMsg=getString(R.string.import_delete_csv) + + " " + importedFilename + "?"; + Dialog about = new AlertDialog.Builder(CategoryList.this) + .setIcon(R.drawable.passicon) + .setTitle(R.string.import_complete) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + File csvFile=new File(importedFilename); + csvFile.delete(); + importedFilename=""; + } + }) + .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + } + }) + .setMessage(deleteMsg) + .create(); + about.show(); + } if ((importedEntries!=0) || (importDeletedDatabase)) { @@ -647,8 +651,9 @@ public class CategoryList extends ListActivity { } public boolean exportDatabase(){ + String filename=EXPORT_FILENAME; try { - CSVWriter writer = new CSVWriter(new FileWriter(EXPORT_FILENAME), ','); + CSVWriter writer = new CSVWriter(new FileWriter(filename), ','); String[] header = { getString(R.string.category), getString(R.string.description), @@ -726,7 +731,9 @@ public class CategoryList extends ListActivity { Toast.LENGTH_SHORT).show(); return false; } - Toast.makeText(CategoryList.this, R.string.export_success, + String msg=getString(R.string.export_success)+filename+ + getString(R.string.export_success2); + Toast.makeText(CategoryList.this, msg, Toast.LENGTH_LONG).show(); return true; } @@ -735,7 +742,7 @@ public class CategoryList extends ListActivity { dbHelper.deleteDatabase(); } - public void deleteDatabase4Import(){ + public void deleteDatabase4Import(final String filename){ // Log.i(TAG,"deleteDatabase4Import"); Dialog about = new AlertDialog.Builder(this) .setIcon(R.drawable.passicon) @@ -744,7 +751,7 @@ public class CategoryList extends ListActivity { public void onClick(DialogInterface dialog, int whichButton) { deleteDatabaseNow(); importDeletedDatabase=true; - importDatabaseThreadStart(); + importDatabaseThreadStart(filename); } }) .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @@ -757,10 +764,11 @@ public class CategoryList extends ListActivity { } public void importDatabase(){ - File csvFile=new File(EXPORT_FILENAME); + final String filename=EXPORT_FILENAME; + File csvFile=new File(filename); if (!csvFile.exists()) { String msg=getString(R.string.import_file_missing) + " " + - EXPORT_FILENAME; + filename; Toast.makeText(CategoryList.this, msg, Toast.LENGTH_LONG).show(); return; @@ -770,13 +778,13 @@ public class CategoryList extends ListActivity { .setTitle(R.string.dialog_import_title) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - deleteDatabase4Import(); + deleteDatabase4Import(filename); } }) .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { importDeletedDatabase=false; - importDatabaseThreadStart(); + importDatabaseThreadStart(filename); } }) .setMessage(R.string.dialog_import_msg) @@ -789,11 +797,11 @@ public class CategoryList extends ListActivity { * the import in a thread it allows the main UI thread to return * and permit the updating of the progress dialog. */ - private void importDatabaseThreadStart(){ + private void importDatabaseThreadStart(final String filename){ showDialog(IMPORT_PROGRESS_KEY); importThread = new Thread(new Runnable() { public void run() { - importDatabaseFromCSV(); + importDatabaseFromCSV(filename); dismissDialog(IMPORT_PROGRESS_KEY); Message m = new Message(); @@ -810,13 +818,13 @@ public class CategoryList extends ListActivity { * While running inside a thread, read from a CSV and import * into the database. */ - private void importDatabaseFromCSV(){ + private void importDatabaseFromCSV(String filename){ try { importMessage=""; importedEntries=0; final int recordLength=6; - CSVReader reader= new CSVReader(new FileReader(EXPORT_FILENAME)); + CSVReader reader= new CSVReader(new FileReader(filename)); String [] nextLine; nextLine = reader.readNext(); if (nextLine==null) { @@ -888,7 +896,7 @@ public class CategoryList extends ListActivity { // // read the whole file again to import the actual fields // - reader = new CSVReader(new FileReader(EXPORT_FILENAME)); + reader = new CSVReader(new FileReader(filename)); nextLine = reader.readNext(); int newEntries=0; int lineNumber=0; @@ -972,6 +980,7 @@ public class CategoryList extends ListActivity { }else{ importMessage=getString(R.string.added)+ " "+ newEntries + " "+ getString(R.string.entries); + importedFilename=filename; } } catch (IOException e) { e.printStackTrace(); diff --git a/src/org/openintents/safe/RestoreHandler.java b/src/org/openintents/safe/RestoreHandler.java index 9112297..0dc766c 100644 --- a/src/org/openintents/safe/RestoreHandler.java +++ b/src/org/openintents/safe/RestoreHandler.java @@ -31,7 +31,7 @@ public class RestoreHandler extends DefaultHandler { // Fields // =========================================================== - private boolean in_apws = false; + private boolean in_oisafe = false; private boolean in_masterkey = false; private boolean in_category = false; private boolean in_entry = false; @@ -73,8 +73,8 @@ public class RestoreHandler extends DefaultHandler { public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { - if (localName.equals("AndroidPasswordSafe")) { - in_apws = true; + if (localName.equals("OISafe")) { + in_oisafe = true; String attrValue = atts.getValue("version"); int version = Integer.parseInt(attrValue); @@ -83,14 +83,14 @@ public class RestoreHandler extends DefaultHandler { myRestoreDataSet.setVersion(version); myRestoreDataSet.setDate(date); - if (debug) Log.d(TAG,"found APWS "+version+" date "+date); + if (debug) Log.d(TAG,"found OISafe "+version+" date "+date); - }else if (in_apws && localName.equals("MasterKey")) { + }else if (in_oisafe && localName.equals("MasterKey")) { in_masterkey = true; if (debug) Log.d(TAG,"found MasterKey"); - }else if (in_apws && localName.equals("Category")) { + }else if (in_oisafe && localName.equals("Category")) { in_category = true; String name = atts.getValue("name"); @@ -125,11 +125,11 @@ public class RestoreHandler extends DefaultHandler { public void endElement(String namespaceURI, String localName, String qName) throws SAXException { - if (localName.equals("AndroidPasswordSafe")) { - in_apws = false; - }else if (in_apws && localName.equals("MasterKey")) { + if (localName.equals("OISafe")) { + in_oisafe = false; + }else if (in_oisafe && localName.equals("MasterKey")) { in_masterkey = false; - }else if (in_apws && localName.equals("Category")) { + }else if (in_oisafe && localName.equals("Category")) { in_category = false; myRestoreDataSet.storyCategory();