add database structure for remembering overridden warnings
This commit is contained in:
@@ -90,6 +90,10 @@ public class KeychainContract {
|
|||||||
String PACKAGE_NAME = "package_name"; // foreign key to api_apps.package_name
|
String PACKAGE_NAME = "package_name"; // foreign key to api_apps.package_name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface OverriddenWarnings {
|
||||||
|
String IDENTIFIER = "identifier";
|
||||||
|
}
|
||||||
|
|
||||||
public static final String CONTENT_AUTHORITY = Constants.PROVIDER_AUTHORITY;
|
public static final String CONTENT_AUTHORITY = Constants.PROVIDER_AUTHORITY;
|
||||||
|
|
||||||
private static final Uri BASE_CONTENT_URI_INTERNAL = Uri
|
private static final Uri BASE_CONTENT_URI_INTERNAL = Uri
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.CertsColumns;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract.OverriddenWarnings;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeysColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeysColumns;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPacketsColumns;
|
||||||
import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity;
|
import org.sufficientlysecure.keychain.ui.ConsolidateDialogActivity;
|
||||||
@@ -51,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
*/
|
*/
|
||||||
public class KeychainDatabase extends SQLiteOpenHelper {
|
public class KeychainDatabase extends SQLiteOpenHelper {
|
||||||
private static final String DATABASE_NAME = "openkeychain.db";
|
private static final String DATABASE_NAME = "openkeychain.db";
|
||||||
private static final int DATABASE_VERSION = 20;
|
private static final int DATABASE_VERSION = 21;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
public interface Tables {
|
public interface Tables {
|
||||||
@@ -63,6 +64,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
String CERTS = "certs";
|
String CERTS = "certs";
|
||||||
String API_APPS = "api_apps";
|
String API_APPS = "api_apps";
|
||||||
String API_ALLOWED_KEYS = "api_allowed_keys";
|
String API_ALLOWED_KEYS = "api_allowed_keys";
|
||||||
|
String OVERRIDDEN_WARNINGS = "overridden_warnings";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String CREATE_KEYRINGS_PUBLIC =
|
private static final String CREATE_KEYRINGS_PUBLIC =
|
||||||
@@ -172,6 +174,12 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
+ Tables.API_APPS + "(" + ApiAppsAllowedKeysColumns.PACKAGE_NAME + ") ON DELETE CASCADE"
|
+ Tables.API_APPS + "(" + ApiAppsAllowedKeysColumns.PACKAGE_NAME + ") ON DELETE CASCADE"
|
||||||
+ ")";
|
+ ")";
|
||||||
|
|
||||||
|
private static final String CREATE_OVERRIDDEN_WARNINGS =
|
||||||
|
"CREATE TABLE IF NOT EXISTS " + Tables.OVERRIDDEN_WARNINGS + " ("
|
||||||
|
+ BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||||
|
+ OverriddenWarnings.IDENTIFIER + " TEXT NOT NULL UNIQUE "
|
||||||
|
+ ")";
|
||||||
|
|
||||||
public KeychainDatabase(Context context) {
|
public KeychainDatabase(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -306,6 +314,11 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
case 20:
|
||||||
|
db.execSQL(CREATE_OVERRIDDEN_WARNINGS);
|
||||||
|
if (oldVersion == 20) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: don't depend on consolidate! make migrations inline!
|
// TODO: don't depend on consolidate! make migrations inline!
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package org.sufficientlysecure.keychain.provider;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract.OverriddenWarnings;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||||
|
|
||||||
|
|
||||||
|
public class OverriddenWarningsRepository {
|
||||||
|
private final Context context;
|
||||||
|
private KeychainDatabase keychainDatabase;
|
||||||
|
|
||||||
|
public static OverriddenWarningsRepository createOverriddenWarningsRepository(Context context) {
|
||||||
|
return new OverriddenWarningsRepository(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private OverriddenWarningsRepository(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeychainDatabase getDb() {
|
||||||
|
if (keychainDatabase == null) {
|
||||||
|
keychainDatabase = new KeychainDatabase(context);
|
||||||
|
}
|
||||||
|
return keychainDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWarningOverridden(String identifier) {
|
||||||
|
SQLiteDatabase db = getDb().getReadableDatabase();
|
||||||
|
Cursor cursor = db.query(
|
||||||
|
Tables.OVERRIDDEN_WARNINGS,
|
||||||
|
new String[] { "COUNT(*)" },
|
||||||
|
OverriddenWarnings.IDENTIFIER + " = ?",
|
||||||
|
new String[] { identifier },
|
||||||
|
null, null, null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursor.moveToFirst();
|
||||||
|
return cursor.getInt(0) > 0;
|
||||||
|
} finally {
|
||||||
|
cursor.close();
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putOverride(String identifier) {
|
||||||
|
SQLiteDatabase db = getDb().getWritableDatabase();
|
||||||
|
ContentValues cv = new ContentValues();
|
||||||
|
cv.put(OverriddenWarnings.IDENTIFIER, identifier);
|
||||||
|
db.replace(Tables.OVERRIDDEN_WARNINGS, null, cv);
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteOverride(String identifier) {
|
||||||
|
SQLiteDatabase db = getDb().getWritableDatabase();
|
||||||
|
db.delete(Tables.OVERRIDDEN_WARNINGS, OverriddenWarnings.IDENTIFIER + " = ?", new String[] { identifier });
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user