extract deletion of keys from ContentProvider
This commit is contained in:
@@ -38,6 +38,7 @@ import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.sufficientlysecure.keychain.KeyRingsPublicModel.DeleteByMasterKeyId;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
@@ -593,7 +594,10 @@ public class KeyWritableRepository extends KeyRepository {
|
||||
return false;
|
||||
}
|
||||
autocryptPeerDao.deleteByMasterKeyId(masterKeyId);
|
||||
int deletedRows = contentResolver.delete(KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null);
|
||||
|
||||
DeleteByMasterKeyId deleteStatement = new DeleteByMasterKeyId(db);
|
||||
deleteStatement.bind(masterKeyId);
|
||||
int deletedRows = deleteStatement.executeUpdateDelete();
|
||||
|
||||
databaseNotifyManager.notifyKeyChange(masterKeyId);
|
||||
|
||||
|
||||
@@ -634,39 +634,8 @@ public class KeychainProvider extends ContentProvider implements SimpleContentRe
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int delete(Uri uri, String additionalSelection, String[] selectionArgs) {
|
||||
Timber.v("delete(uri=" + uri + ")");
|
||||
|
||||
final SupportSQLiteDatabase db = getDb().getWritableDatabase();
|
||||
|
||||
int count;
|
||||
final int match = mUriMatcher.match(uri);
|
||||
|
||||
ContentResolver contentResolver = getContext().getContentResolver();
|
||||
switch (match) {
|
||||
// dangerous
|
||||
case KEY_RINGS_UNIFIED: {
|
||||
count = db.delete(Tables.KEY_RINGS_PUBLIC, null, null);
|
||||
break;
|
||||
}
|
||||
|
||||
case KEY_RING_PUBLIC: {
|
||||
@SuppressWarnings("ConstantConditions") // ensured by uriMatcher above
|
||||
String selection = KeyRings.MASTER_KEY_ID + " = " + uri.getPathSegments().get(1);
|
||||
if (!TextUtils.isEmpty(additionalSelection)) {
|
||||
selection += " AND (" + additionalSelection + ")";
|
||||
}
|
||||
// corresponding keys and userIds are deleted by ON DELETE CASCADE
|
||||
count = db.delete(Tables.KEY_RINGS_PUBLIC, selection, selectionArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
public int delete(@NonNull Uri uri, String additionalSelection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,3 +7,7 @@ selectByMasterKeyId:
|
||||
SELECT *
|
||||
FROM keyrings_public
|
||||
WHERE master_key_id = ?;
|
||||
|
||||
deleteByMasterKeyId:
|
||||
DELETE FROM keyrings_public
|
||||
WHERE master_key_id = ?;
|
||||
Reference in New Issue
Block a user