]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
Updated backup to handle package access.
authorrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Mon, 19 Jan 2009 20:59:54 +0000 (20:59 +0000)
committerrmceoin <rmceoin@72b678ce-9140-0410-bee8-679b907dd61a>
Mon, 19 Jan 2009 20:59:54 +0000 (20:59 +0000)
git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1787 72b678ce-9140-0410-bee8-679b907dd61a

src/org/openintents/safe/Backup.java
src/org/openintents/safe/DBHelper.java

index cf9b91d65207bd7ba961eb89d3db1d7d80a42005..31a9e625294c2b14666c1d3a5122cb820b64e687 100644 (file)
@@ -19,7 +19,9 @@ package org.openintents.safe;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.DateFormat;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import android.content.Context;
 import android.util.Log;
@@ -73,7 +75,8 @@ public class Backup {
                        
                        List<CategoryEntry> crows;
                        crows = dbHelper.fetchAllCategoryRows();
-
+                       HashMap<Long, ArrayList<String>> packageAccess=dbHelper.fetchPackageAccessAll();
+                       
                        int totalPasswords=0;
 
                        for (CategoryEntry crow : crows) {
@@ -88,7 +91,11 @@ public class Backup {
                                        totalPasswords++;
                                        
                                        serializer.startTag(null, "Entry");
-                                       
+
+                                       serializer.startTag(null, "RowID");
+                                       serializer.text(Long.toString(row.id));
+                                       serializer.endTag(null, "RowID");
+
                                        serializer.startTag(null, "Description");
                                        serializer.text(row.description);
                                        serializer.endTag(null, "Description");
@@ -109,9 +116,17 @@ public class Backup {
                                        serializer.text(row.note);
                                        serializer.endTag(null, "Note");
 
-                                       serializer.startTag(null, "UniqueName");
-                                       serializer.text(row.uniqueName);
-                                       serializer.endTag(null, "UniqueName");
+                                       if (row.uniqueName!=null) {
+                                               serializer.startTag(null, "UniqueName");
+                                               serializer.text(row.uniqueName);
+                                               serializer.endTag(null, "UniqueName");
+                                       }
+                                       
+                                       if(packageAccess.containsKey(row.id)) {
+                                               serializer.startTag(null, "PackageAccess");
+                                               serializer.text(packageAccess.get(row.id).toString());
+                                               serializer.endTag(null, "PackageAccess");
+                                       }
 
                                        serializer.endTag(null, "Entry");
                                }
index 7e6db5726e63186ef71c456b4d310a68230fd5f3..4308ebde864bc2c79e8bc384d34ce16eed624fd7 100644 (file)
@@ -17,9 +17,9 @@
 package org.openintents.safe;
 
 import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import android.content.ContentValues;
 import android.content.Context;
@@ -532,6 +532,40 @@ public class DBHelper {
                return pkgs;
        }
        
+       /**
+        * Fetch all the package access data into one HashMap.
+        * 
+        * @return  HashMap&lt;Long id, ArrayList&lt;String> package>
+        */
+       public HashMap<Long, ArrayList<String>> fetchPackageAccessAll() {
+               HashMap<Long, ArrayList<String>> pkgsAll=new HashMap<Long, ArrayList<String>>();
+
+               Cursor c = null;
+               try {
+                       c =
+                               db.query(true, TABLE_PACKAGE_ACCESS, new String[] {
+                                       "id"}, null, null, null, null, null, null);
+                       if (c.getCount() > 0) {
+                               c.moveToFirst();
+                               while (! c.isAfterLast()) {
+                                       Long id=c.getLong(0);
+                                       ArrayList <String> pkgs = fetchPackageAccess(id);
+                                       if (pkgs!=null) {
+                                               pkgsAll.put(id, pkgs);
+                                       }
+                                       c.moveToNext();
+                               }
+                       }
+               } catch (SQLException e)
+               {
+                       Log.d(TAG,"SQLite exception: " + e.getLocalizedMessage());
+               } finally {
+                       if (c != null) c.close();
+               }
+               
+               return pkgsAll;
+       }
+       
        public void addPackageAccess (long passwordID, String packageToAdd) {
                ContentValues packageAccessValues = new ContentValues ();
                packageAccessValues.put("id", passwordID);
@@ -556,10 +590,11 @@ public class DBHelper {
            args.put("website", entry.website);
            args.put("note", entry.note);
            args.put("unique_name", entry.uniqueName);
-           DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); 
-           Date date = new Date();
-        String timeNow = dateFormat.format(date); 
-           args.put("lastdatetimeedit", timeNow);
+               DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.DEFAULT,
+                               DateFormat.FULL);
+               Date today = new Date();
+               String dateOut = dateFormatter.format(today);
+           args.put("lastdatetimeedit", dateOut);
            try {
                        db.update(TABLE_PASSWORDS, args, "id=" + Id, null);
                } catch (SQLException e)