From: peli0101 Date: Fri, 1 May 2009 13:55:41 +0000 (+0000) Subject: OI Safe: Fix crash when trying to "Restore" from a backup file without any categories. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=8ac722680f75c0078ff2ee81cf0143dbd2929f6f;p=android-vcpass-oisafe OI Safe: Fix crash when trying to "Restore" from a backup file without any categories. git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@2060 72b678ce-9140-0410-bee8-679b907dd61a --- diff --git a/src/org/openintents/safe/Restore.java b/src/org/openintents/safe/Restore.java index 4c8873c..7246b38 100644 --- a/src/org/openintents/safe/Restore.java +++ b/src/org/openintents/safe/Restore.java @@ -202,11 +202,14 @@ public class Restore extends Activity { Toast.LENGTH_LONG).show(); return false; } - CategoryEntry firstCatEntry=restoreDataSet.getCategories().get(0); - if (firstCatEntry==null) { - Toast.makeText(Restore.this, getString(R.string.restore_error), - Toast.LENGTH_LONG).show(); - return false; + CategoryEntry firstCatEntry= null; + if (restoreDataSet.getCategories().size() > 0) { + firstCatEntry = restoreDataSet.getCategories().get(0); + if (firstCatEntry==null) { + Toast.makeText(Restore.this, getString(R.string.restore_error), + Toast.LENGTH_LONG).show(); + return false; + } } CryptoHelper ch=new CryptoHelper(); @@ -243,19 +246,21 @@ public class Restore extends Activity { return false; } - String firstCategory=""; - try { - firstCategory = ch.decrypt(firstCatEntry.name); - } catch (CryptoHelperException e) { - Log.e(TAG,e.toString()); - } - if (ch.getStatus() == false) { - Toast.makeText(Restore.this, getString(R.string.restore_decrypt_error), - Toast.LENGTH_LONG).show(); - return false; + if (firstCatEntry != null) { + String firstCategory=""; + try { + firstCategory = ch.decrypt(firstCatEntry.name); + } catch (CryptoHelperException e) { + Log.e(TAG,e.toString()); + } + if (ch.getStatus() == false) { + Toast.makeText(Restore.this, getString(R.string.restore_decrypt_error), + Toast.LENGTH_LONG).show(); + return false; + } + if (debug) Log.d(TAG,"firstCategory="+firstCategory); } - if (debug) Log.d(TAG,"firstCategory="+firstCategory); - + dbHelper=new DBHelper(Restore.this); String msg=getString(R.string.restore_found,