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