mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-07 02:20:10 -05:00
Fix revoke and save
This commit is contained in:
parent
9a737c7318
commit
8614ff2ec7
@ -78,9 +78,9 @@ public class KeychainProvider extends ContentProvider {
|
||||
private static final int SECRET_KEY_RING_USER_ID = 221;
|
||||
private static final int SECRET_KEY_RING_USER_ID_BY_ROW_ID = 222;
|
||||
|
||||
private static final int CRYPTO_CONSUMERS = 301;
|
||||
private static final int CRYPTO_CONSUMERS_BY_ROW_ID = 302;
|
||||
private static final int CRYPTO_CONSUMERS_BY_PACKAGE_NAME = 303;
|
||||
private static final int API_APPS = 301;
|
||||
private static final int API_APPS_BY_ROW_ID = 302;
|
||||
private static final int API_APPS_BY_PACKAGE_NAME = 303;
|
||||
|
||||
// private static final int DATA_STREAM = 401;
|
||||
|
||||
@ -226,13 +226,12 @@ public class KeychainProvider extends ContentProvider {
|
||||
SECRET_KEY_RING_USER_ID_BY_ROW_ID);
|
||||
|
||||
/**
|
||||
* Crypto Consumers
|
||||
* API apps
|
||||
*/
|
||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS, CRYPTO_CONSUMERS);
|
||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/#",
|
||||
CRYPTO_CONSUMERS_BY_ROW_ID);
|
||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS, API_APPS);
|
||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/#", API_APPS_BY_ROW_ID);
|
||||
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/"
|
||||
+ KeychainContract.PATH_BY_PACKAGE_NAME + "/*", CRYPTO_CONSUMERS_BY_PACKAGE_NAME);
|
||||
+ KeychainContract.PATH_BY_PACKAGE_NAME + "/*", API_APPS_BY_PACKAGE_NAME);
|
||||
|
||||
/**
|
||||
* data stream
|
||||
@ -293,11 +292,11 @@ public class KeychainProvider extends ContentProvider {
|
||||
case SECRET_KEY_RING_USER_ID_BY_ROW_ID:
|
||||
return UserIds.CONTENT_ITEM_TYPE;
|
||||
|
||||
case CRYPTO_CONSUMERS:
|
||||
case API_APPS:
|
||||
return ApiApps.CONTENT_TYPE;
|
||||
|
||||
case CRYPTO_CONSUMERS_BY_ROW_ID:
|
||||
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
|
||||
case API_APPS_BY_ROW_ID:
|
||||
case API_APPS_BY_PACKAGE_NAME:
|
||||
return ApiApps.CONTENT_ITEM_TYPE;
|
||||
|
||||
default:
|
||||
@ -608,18 +607,18 @@ public class KeychainProvider extends ContentProvider {
|
||||
|
||||
break;
|
||||
|
||||
case CRYPTO_CONSUMERS:
|
||||
case API_APPS:
|
||||
qb.setTables(Tables.API_APPS);
|
||||
|
||||
break;
|
||||
case CRYPTO_CONSUMERS_BY_ROW_ID:
|
||||
case API_APPS_BY_ROW_ID:
|
||||
qb.setTables(Tables.API_APPS);
|
||||
|
||||
qb.appendWhere(BaseColumns._ID + " = ");
|
||||
qb.appendWhereEscapeString(uri.getLastPathSegment());
|
||||
|
||||
break;
|
||||
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
|
||||
case API_APPS_BY_PACKAGE_NAME:
|
||||
qb.setTables(Tables.API_APPS);
|
||||
qb.appendWhere(ApiApps.PACKAGE_NAME + " = ");
|
||||
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
|
||||
@ -711,7 +710,7 @@ public class KeychainProvider extends ContentProvider {
|
||||
rowUri = UserIds.buildSecretUserIdsUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case CRYPTO_CONSUMERS:
|
||||
case API_APPS:
|
||||
rowId = db.insertOrThrow(Tables.API_APPS, null, values);
|
||||
rowUri = ApiApps.buildIdUri(Long.toString(rowId));
|
||||
|
||||
@ -771,10 +770,13 @@ public class KeychainProvider extends ContentProvider {
|
||||
count = db.delete(Tables.KEYS, buildDefaultUserIdsSelection(uri, selection),
|
||||
selectionArgs);
|
||||
break;
|
||||
case CRYPTO_CONSUMERS_BY_ROW_ID:
|
||||
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
|
||||
count = db.delete(Tables.API_APPS,
|
||||
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
|
||||
case API_APPS_BY_ROW_ID:
|
||||
count = db.delete(Tables.API_APPS, buildDefaultApiAppsSelection(uri, false, selection),
|
||||
selectionArgs);
|
||||
break;
|
||||
case API_APPS_BY_PACKAGE_NAME:
|
||||
count = db.delete(Tables.API_APPS, buildDefaultApiAppsSelection(uri, true, selection),
|
||||
selectionArgs);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
@ -836,10 +838,13 @@ public class KeychainProvider extends ContentProvider {
|
||||
count = db.update(Tables.USER_IDS, values,
|
||||
buildDefaultUserIdsSelection(uri, selection), selectionArgs);
|
||||
break;
|
||||
case CRYPTO_CONSUMERS_BY_ROW_ID:
|
||||
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
|
||||
case API_APPS_BY_ROW_ID:
|
||||
count = db.update(Tables.API_APPS, values,
|
||||
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
|
||||
buildDefaultApiAppsSelection(uri, false, selection), selectionArgs);
|
||||
break;
|
||||
case API_APPS_BY_PACKAGE_NAME:
|
||||
count = db.update(Tables.API_APPS, values,
|
||||
buildDefaultApiAppsSelection(uri, true, selection), selectionArgs);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
@ -930,20 +935,26 @@ public class KeychainProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build default selection statement for Crypto Consumers. If no extra selection is specified
|
||||
* only build where clause with rowId
|
||||
* Build default selection statement for API apps. If no extra selection is specified only build
|
||||
* where clause with rowId
|
||||
*
|
||||
* @param uri
|
||||
* @param selection
|
||||
* @return
|
||||
*/
|
||||
private String buildDefaultCryptoConsumersSelection(Uri uri, String selection) {
|
||||
private String buildDefaultApiAppsSelection(Uri uri, boolean packageSelection, String selection) {
|
||||
String lastPathSegment = uri.getLastPathSegment();
|
||||
|
||||
String andSelection = "";
|
||||
if (!TextUtils.isEmpty(selection)) {
|
||||
andSelection = " AND (" + selection + ")";
|
||||
}
|
||||
|
||||
return selection + andSelection;
|
||||
if (packageSelection) {
|
||||
return ApiApps.PACKAGE_NAME + "=" + lastPathSegment + andSelection;
|
||||
} else {
|
||||
return BaseColumns._ID + "=" + lastPathSegment + andSelection;
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
@ -27,10 +27,8 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
|
||||
|
||||
// model
|
||||
Uri appUri;
|
||||
long id;
|
||||
String packageName;
|
||||
long keyId;
|
||||
boolean asciiArmor;
|
||||
|
||||
// model, derived
|
||||
String appName;
|
||||
@ -85,11 +83,8 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
|
||||
|
||||
private void loadData(Uri appUri) {
|
||||
Cursor cur = getContentResolver().query(appUri, null, null, null, null);
|
||||
id = ContentUris.parseId(appUri);
|
||||
if (cur.moveToFirst()) {
|
||||
do {
|
||||
packageName = cur.getString(cur
|
||||
.getColumnIndex(KeychainContract.ApiApps.PACKAGE_NAME));
|
||||
packageName = cur.getString(cur.getColumnIndex(KeychainContract.ApiApps.PACKAGE_NAME));
|
||||
// get application name
|
||||
try {
|
||||
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
|
||||
@ -98,33 +93,35 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
|
||||
} catch (final NameNotFoundException e) {
|
||||
appName = getString(R.string.api_unknown_app);
|
||||
}
|
||||
setTitle(appName);
|
||||
|
||||
try {
|
||||
asciiArmor = (cur.getInt(cur
|
||||
boolean asciiArmor = (cur.getInt(cur
|
||||
.getColumnIndexOrThrow(KeychainContract.ApiApps.ASCII_ARMOR)) == 1);
|
||||
|
||||
// display values
|
||||
asciiArmorCheckBox.setChecked(asciiArmor);
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(Constants.TAG, "AppSettingsActivity", e);
|
||||
}
|
||||
|
||||
} while (cur.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
private void revokeAccess() {
|
||||
Uri calUri = ContentUris.withAppendedId(appUri, id);
|
||||
getContentResolver().delete(calUri, null, null);
|
||||
if (getContentResolver().delete(appUri, null, null) <= 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void save() {
|
||||
Log.d(Constants.TAG, "saving");
|
||||
final ContentValues cv = new ContentValues();
|
||||
cv.put(KeychainContract.ApiApps.PACKAGE_NAME, packageName);
|
||||
cv.put(KeychainContract.ApiApps.ASCII_ARMOR, asciiArmor);
|
||||
// TODO: other parameter
|
||||
getContentResolver().update(appUri, cv, null, null);
|
||||
// cv.put(KeychainContract.ApiApps.PACKAGE_NAME, packageName);
|
||||
cv.put(KeychainContract.ApiApps.ASCII_ARMOR, asciiArmorCheckBox.isChecked());
|
||||
// TODO: other parameters
|
||||
if (getContentResolver().update(appUri, cv, null, null) <= 0) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ public class ServiceActivity extends SherlockFragmentActivity {
|
||||
if (ACTION_REGISTER.equals(action)) {
|
||||
final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
|
||||
|
||||
setContentView(R.layout.api_app_settings_activity);
|
||||
setContentView(R.layout.api_app_register_activity);
|
||||
|
||||
// TODO: handle if app is already registered
|
||||
// LinearLayout layoutRegister = (LinearLayout)
|
||||
|
Loading…
Reference in New Issue
Block a user