list trust ids in ShowKeyFragment

This commit is contained in:
Vincent Breitmoser
2016-11-16 15:52:40 +01:00
parent c7bb6a7bc0
commit 31ef4c4789
10 changed files with 418 additions and 16 deletions

View File

@@ -128,6 +128,9 @@ public class KeychainContract {
public static final String BASE_API_APPS = "api_apps";
public static final String PATH_ALLOWED_KEYS = "allowed_keys";
public static final String PATH_BY_PACKAGE_NAME = "by_package_name";
public static final String PATH_BY_KEY_ID = "by_key_id";
public static final String BASE_TRUST_IDENTITIES = "trust_ids";
public static class KeyRings implements BaseColumns, KeysColumns, UserPacketsColumns {
@@ -345,24 +348,12 @@ public class KeychainContract {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_TRUST_IDENTITIES).build();
/**
* Use if multiple items get returned
*/
public static final String CONTENT_TYPE
= "vnd.android.cursor.dir/vnd.org.sufficientlysecure.keychain.provider.trust_ids";
/**
* Use if a single item is returned
*/
public static final String CONTENT_ITEM_TYPE
= "vnd.android.cursor.item/vnd.org.sufficientlysecure.keychain.provider.trust_ids";
public static Uri buildByPackageNameUri(String packageName) {
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).build();
public static Uri buildByKeyUri(Uri uri) {
return CONTENT_URI.buildUpon().appendPath(PATH_BY_KEY_ID).appendPath(uri.getPathSegments().get(1)).build();
}
public static Uri buildByPackageNameAndTrustIdUri(String packageName, String trustId) {
return CONTENT_URI.buildUpon().appendEncodedPath(packageName).appendEncodedPath(trustId).build();
public static Uri buildByPackageNameAndTrustId(String packageName, String trustId) {
return CONTENT_URI.buildUpon().appendPath(PATH_BY_PACKAGE_NAME).appendPath(packageName).appendPath(trustId).build();
}
}

View File

@@ -79,6 +79,10 @@ public class KeychainProvider extends ContentProvider {
private static final int UPDATED_KEYS = 500;
private static final int UPDATED_KEYS_SPECIFIC = 501;
private static final int TRUST_IDS_BY_MASTER_KEY_ID = 601;
private static final int TRUST_IDS_BY_PACKAGE_NAME = 602;
private static final int TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID = 603;
protected UriMatcher mUriMatcher;
/**
@@ -191,6 +195,22 @@ public class KeychainProvider extends ContentProvider {
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/*/"
+ KeychainContract.PATH_ALLOWED_KEYS, API_ALLOWED_KEYS);
/**
* Trust Identity access
*
* <pre>
* trust_ids/by_key_id/_
*
* </pre>
*/
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" +
KeychainContract.PATH_BY_KEY_ID + "/*", TRUST_IDS_BY_MASTER_KEY_ID);
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" +
KeychainContract.PATH_BY_PACKAGE_NAME + "/*", TRUST_IDS_BY_PACKAGE_NAME);
matcher.addURI(authority, KeychainContract.BASE_TRUST_IDENTITIES + "/" +
KeychainContract.PATH_BY_PACKAGE_NAME + "/*/*", TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID);
/**
* to access table containing last updated dates of keys
*/
@@ -636,6 +656,45 @@ public class KeychainProvider extends ContentProvider {
break;
}
case TRUST_IDS_BY_MASTER_KEY_ID:
case TRUST_IDS_BY_PACKAGE_NAME:
case TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID: {
if (selection != null || selectionArgs != null) {
throw new UnsupportedOperationException();
}
HashMap<String, String> projectionMap = new HashMap<>();
projectionMap.put(ApiTrustIdentity._ID, "oid AS " + ApiTrustIdentity._ID);
projectionMap.put(ApiTrustIdentity.PACKAGE_NAME, ApiTrustIdentity.PACKAGE_NAME);
projectionMap.put(ApiTrustIdentity.IDENTIFIER, ApiTrustIdentity.IDENTIFIER);
projectionMap.put(ApiTrustIdentity.MASTER_KEY_ID, ApiTrustIdentity.MASTER_KEY_ID);
projectionMap.put(ApiTrustIdentity.LAST_UPDATED, ApiTrustIdentity.LAST_UPDATED);
qb.setProjectionMap(projectionMap);
qb.setTables(Tables.API_TRUST_IDENTITIES);
if (match == TRUST_IDS_BY_MASTER_KEY_ID) {
long masterKeyId = Long.parseLong(uri.getLastPathSegment());
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.MASTER_KEY_ID + " = ?";
selectionArgs = new String[] { Long.toString(masterKeyId) };
} else if (match == TRUST_IDS_BY_PACKAGE_NAME) {
String packageName = uri.getPathSegments().get(2);
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + " = ?";
selectionArgs = new String[] { packageName };
} else { // TRUST_IDS_BY_PACKAGE_NAME_AND_TRUST_ID
String packageName = uri.getPathSegments().get(2);
String trustId = uri.getPathSegments().get(3);
selection = Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.PACKAGE_NAME + " = ? AND " +
Tables.API_TRUST_IDENTITIES + "." + ApiTrustIdentity.IDENTIFIER + " = ?";
selectionArgs = new String[] { packageName, trustId };
}
break;
}
case UPDATED_KEYS:
case UPDATED_KEYS_SPECIFIC: {
HashMap<String, String> projectionMap = new HashMap<>();