From 8c6cb8b0ab9e89f9d575af829e0dd1dd9e82e401 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Sat, 8 Mar 2014 11:19:34 +0100 Subject: working unified list (no actions yet) --- .../keychain/provider/KeychainProvider.java | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java') diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 781f36758..85e01ae53 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -81,6 +81,8 @@ public class KeychainProvider extends ContentProvider { private static final int API_APPS_BY_ROW_ID = 302; private static final int API_APPS_BY_PACKAGE_NAME = 303; + private static final int UNIFIED_KEY_RING = 401; + // private static final int DATA_STREAM = 401; protected UriMatcher mUriMatcher; @@ -226,6 +228,16 @@ public class KeychainProvider extends ContentProvider { matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/" + KeychainContract.PATH_BY_PACKAGE_NAME + "/*", API_APPS_BY_PACKAGE_NAME); + /** + * unified key rings + *
+         *
+         * key_rings/unified
+         *
+         */
+        matcher.addURI(authority, KeychainContract.BASE_KEY_RINGS + "/"
+                + KeychainContract.PATH_UNIFIED, UNIFIED_KEY_RING);
+
         /**
          * data stream
          *
@@ -455,6 +467,69 @@ public class KeychainProvider extends ContentProvider {
 
         int match = mUriMatcher.match(uri);
 
+        // screw that switch
+        if(match == UNIFIED_KEY_RING) {
+
+            // join keyrings with keys and userIds
+            // Only get user id and key with rank 0 (main user id and main key)
+            qb.setTables(Tables.KEY_RINGS + " INNER JOIN " + Tables.KEYS + " ON " + "("
+                    + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
+                    + KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
+                    + KeysColumns.RANK + " = '0') " + " INNER JOIN " + Tables.USER_IDS + " ON "
+                    + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.USER_IDS + "."
+                    + UserIdsColumns.KEY_RING_ROW_ID + " AND " + Tables.USER_IDS + "."
+                    + UserIdsColumns.RANK + " = '0')");
+
+            {
+                HashMap projectionMap = new HashMap();
+
+                projectionMap.put(KeyRingsColumns.TYPE, "MAX(" + Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + ")");
+
+                projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
+                projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
+                        + KeyRingsColumns.KEY_RING_DATA);
+                projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID);
+                // TODO: deprecated master key id
+                //projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEYS + "." + KeysColumns.KEY_ID);
+
+                projectionMap.put(KeysColumns.FINGERPRINT, Tables.KEYS + "." + KeysColumns.FINGERPRINT);
+                projectionMap.put(KeysColumns.IS_REVOKED, Tables.KEYS + "." + KeysColumns.IS_REVOKED);
+
+                projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID);
+
+                qb.setProjectionMap(projectionMap);
+            }
+
+            if (TextUtils.isEmpty(sortOrder)) {
+                sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
+            }
+
+            // If no sort order is specified use the default
+            String orderBy;
+            if (TextUtils.isEmpty(sortOrder)) {
+                orderBy = Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " DESC";
+            } else {
+                orderBy = Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " DESC, " + sortOrder;
+            }
+
+            Cursor c = qb.query(db, projection, selection, selectionArgs,
+                    Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID,
+                    null, orderBy);
+
+            // Tell the cursor what uri to watch, so it knows when its source data changes
+            c.setNotificationUri(getContext().getContentResolver(), uri);
+
+            if (Constants.DEBUG) {
+                Log.d(Constants.TAG,
+                        "Query: "
+                                + qb.buildQuery(projection, selection, selectionArgs, Tables.KEY_RINGS + "." + KeyRingsColumns.MASTER_KEY_ID, null,
+                                orderBy, null));
+                Log.d(Constants.TAG, "Cursor: " + DatabaseUtils.dumpCursorToString(c));
+            }
+
+            return c;
+        }
+
         switch (match) {
             case PUBLIC_KEY_RING:
             case SECRET_KEY_RING:
-- 
cgit v1.2.3