mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-05 16:55:05 -05:00
fully removed old DataProvider for now, manage queries, clean up old database stuff
This commit is contained in:
parent
b943f706b6
commit
eed42b2e34
@ -106,10 +106,6 @@
|
||||
android:label="@string/title_preferences"
|
||||
android:configChanges="keyboardHidden|orientation|keyboard"/>
|
||||
|
||||
<provider
|
||||
android:name="org.thialfihar.android.apg.provider.DataProvider"
|
||||
android:authorities="org.thialfihar.android.apg.provider" />
|
||||
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
|
||||
|
||||
|
@ -81,7 +81,6 @@ import org.bouncycastle2.openpgp.PGPSignatureSubpacketVector;
|
||||
import org.bouncycastle2.openpgp.PGPUtil;
|
||||
import org.thialfihar.android.apg.provider.Database;
|
||||
import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.PublicKeys;
|
||||
import org.thialfihar.android.apg.ui.widget.KeyEditor;
|
||||
import org.thialfihar.android.apg.ui.widget.SectionView;
|
||||
import org.thialfihar.android.apg.ui.widget.UserIdEditor;
|
||||
@ -132,19 +131,6 @@ public class Apg {
|
||||
Pattern.compile(".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
|
||||
Pattern.DOTALL);
|
||||
|
||||
public static final String PUBLIC_KEY_PROJECTION[] =
|
||||
new String[] {
|
||||
PublicKeys._ID,
|
||||
PublicKeys.KEY_ID,
|
||||
PublicKeys.KEY_DATA,
|
||||
PublicKeys.WHO_ID, };
|
||||
public static final String SECRET_KEY_PROJECTION[] =
|
||||
new String[] {
|
||||
PublicKeys._ID,
|
||||
PublicKeys.KEY_ID,
|
||||
PublicKeys.KEY_DATA,
|
||||
PublicKeys.WHO_ID, };
|
||||
|
||||
private static HashMap<Long, CachedPassPhrase> mPassPhraseCache =
|
||||
new HashMap<Long, CachedPassPhrase>();
|
||||
private static String mEditPassPhrase = null;
|
||||
|
@ -424,15 +424,10 @@ public class KeyListActivity extends BaseActivity {
|
||||
Id.database.type_public : Id.database.type_secret) },
|
||||
null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC");
|
||||
|
||||
startManagingCursor(mCursor);
|
||||
rebuild(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
mCursor.deactivate();
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public void rebuild(boolean requery) {
|
||||
if (requery) {
|
||||
mCursor.requery();
|
||||
|
@ -47,6 +47,8 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||
|
||||
public class MainActivity extends BaseActivity {
|
||||
private ListView mAccounts = null;
|
||||
private AccountListAdapter mListAdapter = null;
|
||||
private Cursor mAccountCursor;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -95,22 +97,22 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
Cursor accountCursor = managedQuery(Accounts.CONTENT_URI, null, null, null, null);
|
||||
mAccountCursor =
|
||||
Apg.getDatabase().db().query(Accounts.TABLE_NAME,
|
||||
new String[] {
|
||||
Accounts._ID,
|
||||
Accounts.NAME,
|
||||
}, null, null, null, null, Accounts.NAME + " ASC");
|
||||
startManagingCursor(mAccountCursor);
|
||||
|
||||
mAccounts.setAdapter(new AccountListAdapter(this, accountCursor));
|
||||
mListAdapter = new AccountListAdapter(this, mAccountCursor);
|
||||
mAccounts.setAdapter(mListAdapter);
|
||||
mAccounts.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View view, int index, long id) {
|
||||
Cursor cursor =
|
||||
managedQuery(Uri.withAppendedPath(Accounts.CONTENT_URI, "" + id), null,
|
||||
null, null, null);
|
||||
if (cursor != null && cursor.getCount() > 0) {
|
||||
cursor.moveToFirst();
|
||||
int nameIndex = cursor.getColumnIndex(Accounts.NAME);
|
||||
String accountName = cursor.getString(nameIndex);
|
||||
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
||||
String accountName = (String) mAccounts.getSelectedItem();
|
||||
startActivity(new Intent(MainActivity.this, MailListActivity.class)
|
||||
.putExtra("account", accountName));
|
||||
}
|
||||
}
|
||||
});
|
||||
registerForContextMenu(mAccounts);
|
||||
@ -154,9 +156,10 @@ public class MainActivity extends BaseActivity {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Accounts.NAME, accountName);
|
||||
try {
|
||||
MainActivity.this.getContentResolver()
|
||||
.insert(Accounts.CONTENT_URI,
|
||||
values);
|
||||
Apg.getDatabase().db().insert(Accounts.TABLE_NAME,
|
||||
Accounts.NAME, values);
|
||||
mAccountCursor.requery();
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
} catch (SQLException e) {
|
||||
Toast.makeText(MainActivity.this,
|
||||
getString(R.string.errorMessage,
|
||||
@ -277,8 +280,11 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
switch (menuItem.getItemId()) {
|
||||
case Id.menu.delete: {
|
||||
Uri uri = Uri.withAppendedPath(Accounts.CONTENT_URI, "" + info.id);
|
||||
this.getContentResolver().delete(uri, null, null);
|
||||
Apg.getDatabase().db().delete(Accounts.TABLE_NAME,
|
||||
Accounts._ID + " = ?",
|
||||
new String[] { "" + info.id });
|
||||
mAccountCursor.requery();
|
||||
mListAdapter.notifyDataSetChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -297,6 +303,13 @@ public class MainActivity extends BaseActivity {
|
||||
minflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
Cursor c = getCursor();
|
||||
c.moveToPosition(position);
|
||||
return c.getString(c.getColumnIndex(Accounts.NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return super.getCount();
|
||||
|
@ -45,7 +45,7 @@ public class SelectPublicKeyListActivity extends BaseActivity {
|
||||
// needed in Android 1.5, where the XML attribute gets ignored
|
||||
mList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
|
||||
SelectPublicKeyListAdapter adapter = new SelectPublicKeyListAdapter(mList);
|
||||
SelectPublicKeyListAdapter adapter = new SelectPublicKeyListAdapter(this, mList);
|
||||
mList.setAdapter(adapter);
|
||||
|
||||
if (selectedKeyIds != null) {
|
||||
|
@ -22,6 +22,7 @@ import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
@ -39,7 +40,7 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
||||
protected SQLiteDatabase mDatabase;
|
||||
protected Cursor mCursor;
|
||||
|
||||
public SelectPublicKeyListAdapter(ListView parent) {
|
||||
public SelectPublicKeyListAdapter(Activity activity, ListView parent) {
|
||||
mParent = parent;
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
@ -75,13 +76,8 @@ public class SelectPublicKeyListAdapter extends BaseAdapter {
|
||||
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
||||
new String[] { "" + Id.database.type_public },
|
||||
null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
// TODO: this doesn't seem to work...
|
||||
mCursor.close();
|
||||
super.finalize();
|
||||
activity.startManagingCursor(mCursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ public class SelectSecretKeyListActivity extends BaseActivity {
|
||||
setContentView(R.layout.select_secret_key);
|
||||
|
||||
mList = (ListView) findViewById(R.id.list);
|
||||
mListAdapter = new SelectSecretKeyListAdapter(mList);
|
||||
mListAdapter = new SelectSecretKeyListAdapter(this, mList);
|
||||
mList.setAdapter(mListAdapter);
|
||||
|
||||
mList.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
@ -6,6 +6,7 @@ import org.thialfihar.android.apg.provider.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.Keys;
|
||||
import org.thialfihar.android.apg.provider.UserIds;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
@ -22,7 +23,7 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
||||
protected SQLiteDatabase mDatabase;
|
||||
protected Cursor mCursor;
|
||||
|
||||
public SelectSecretKeyListAdapter(ListView parent) {
|
||||
public SelectSecretKeyListAdapter(Activity activity, ListView parent) {
|
||||
mParent = parent;
|
||||
mDatabase = Apg.getDatabase().db();
|
||||
mInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
@ -58,13 +59,8 @@ public class SelectSecretKeyListAdapter extends BaseAdapter {
|
||||
KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
|
||||
new String[] { "" + Id.database.type_secret },
|
||||
null, null, UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
// TODO: this doesn't seem to work...
|
||||
mCursor.close();
|
||||
super.finalize();
|
||||
activity.startManagingCursor(mCursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,12 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
public class Accounts extends Accounts1 {
|
||||
private Accounts() {
|
||||
}
|
||||
}
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class Accounts implements BaseColumns {
|
||||
public static final String TABLE_NAME = "accounts";
|
||||
|
||||
public static final String _ID_type = "INTEGER PRIMARY KEY";
|
||||
public static final String NAME = "c_name";
|
||||
public static final String NAME_type = "TEXT";
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
class Accounts1 implements BaseColumns {
|
||||
public static final String TABLE_NAME = "accounts";
|
||||
|
||||
public static final String _ID_type = "INTEGER PRIMARY KEY";
|
||||
public static final String NAME = "c_name";
|
||||
public static final String NAME_type = "TEXT";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/accounts");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.account";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.account";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
@ -1,452 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.thialfihar.android.apg.Apg;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentUris;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.SQLException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
public class DataProvider extends ContentProvider {
|
||||
public static final String AUTHORITY = "org.thialfihar.android.apg.provider";
|
||||
|
||||
private static final int PUBLIC_KEYS = 101;
|
||||
private static final int PUBLIC_KEY_ID = 102;
|
||||
private static final int PUBLIC_KEY_BY_KEY_ID = 103;
|
||||
|
||||
private static final int SECRET_KEYS = 201;
|
||||
private static final int SECRET_KEY_ID = 202;
|
||||
private static final int SECRET_KEY_BY_KEY_ID = 203;
|
||||
|
||||
private static final int ACCOUNTS = 301;
|
||||
private static final int ACCOUNT_ID = 302;
|
||||
|
||||
private static final UriMatcher mUriMatcher;
|
||||
private static final HashMap<String, String> mPublicKeysProjectionMap;
|
||||
private static final HashMap<String, String> mSecretKeysProjectionMap;
|
||||
private static final HashMap<String, String> mAccountsProjectionMap;
|
||||
|
||||
private Database mdbHelper;
|
||||
|
||||
static {
|
||||
mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "public_keys", PUBLIC_KEYS);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "public_keys/#", PUBLIC_KEY_ID);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "public_keys/key_id/*", PUBLIC_KEY_BY_KEY_ID);
|
||||
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "secret_keys", SECRET_KEYS);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "secret_keys/#", SECRET_KEY_ID);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "secret_keys/key_id/*", SECRET_KEY_BY_KEY_ID);
|
||||
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "accounts", ACCOUNTS);
|
||||
mUriMatcher.addURI(DataProvider.AUTHORITY, "accounts/#", ACCOUNT_ID);
|
||||
|
||||
mPublicKeysProjectionMap = new HashMap<String, String>();
|
||||
mPublicKeysProjectionMap.put(PublicKeys._ID, PublicKeys._ID);
|
||||
mPublicKeysProjectionMap.put(PublicKeys.KEY_ID, PublicKeys.KEY_ID);
|
||||
mPublicKeysProjectionMap.put(PublicKeys.KEY_DATA, PublicKeys.KEY_DATA);
|
||||
mPublicKeysProjectionMap.put(PublicKeys.WHO_ID, PublicKeys.WHO_ID);
|
||||
|
||||
mSecretKeysProjectionMap = new HashMap<String, String>();
|
||||
mSecretKeysProjectionMap.put(PublicKeys._ID, PublicKeys._ID);
|
||||
mSecretKeysProjectionMap.put(PublicKeys.KEY_ID, PublicKeys.KEY_ID);
|
||||
mSecretKeysProjectionMap.put(PublicKeys.KEY_DATA, PublicKeys.KEY_DATA);
|
||||
mSecretKeysProjectionMap.put(PublicKeys.WHO_ID, PublicKeys.WHO_ID);
|
||||
|
||||
mAccountsProjectionMap = new HashMap<String, String>();
|
||||
mAccountsProjectionMap.put(Accounts._ID, Accounts._ID);
|
||||
mAccountsProjectionMap.put(Accounts.NAME, Accounts.NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
//mdbHelper = new Database(getContext());
|
||||
Apg.initialize(getContext());
|
||||
mdbHelper = Apg.getDatabase();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder) {
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case PUBLIC_KEYS: {
|
||||
qb.setTables(PublicKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mPublicKeysProjectionMap);
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_ID: {
|
||||
qb.setTables(PublicKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mPublicKeysProjectionMap);
|
||||
qb.appendWhere(PublicKeys._ID + "=" + uri.getPathSegments().get(1));
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_BY_KEY_ID: {
|
||||
qb.setTables(PublicKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mPublicKeysProjectionMap);
|
||||
qb.appendWhere(PublicKeys.KEY_ID + "=" + uri.getPathSegments().get(2));
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEYS: {
|
||||
qb.setTables(SecretKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mSecretKeysProjectionMap);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_ID: {
|
||||
qb.setTables(SecretKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mSecretKeysProjectionMap);
|
||||
qb.appendWhere(SecretKeys._ID + "=" + uri.getPathSegments().get(1));
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_BY_KEY_ID: {
|
||||
qb.setTables(SecretKeys.TABLE_NAME);
|
||||
qb.setProjectionMap(mSecretKeysProjectionMap);
|
||||
qb.appendWhere(SecretKeys.KEY_ID + "=" + uri.getPathSegments().get(2));
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNTS: {
|
||||
qb.setTables(Accounts.TABLE_NAME);
|
||||
qb.setProjectionMap(mAccountsProjectionMap);
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNT_ID: {
|
||||
qb.setTables(Accounts.TABLE_NAME);
|
||||
qb.setProjectionMap(mAccountsProjectionMap);
|
||||
qb.appendWhere(Accounts._ID + "=" + uri.getPathSegments().get(1));
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
// If no sort order is specified use the default
|
||||
String orderBy;
|
||||
if (TextUtils.isEmpty(sortOrder)) {
|
||||
orderBy = PublicKeys.DEFAULT_SORT_ORDER;
|
||||
} else {
|
||||
orderBy = sortOrder;
|
||||
}
|
||||
|
||||
// Get the database and run the query
|
||||
SQLiteDatabase db = mdbHelper.getReadableDatabase();
|
||||
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
|
||||
|
||||
// Tell the cursor what uri to watch, so it knows when its source data
|
||||
// changes
|
||||
c.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case PUBLIC_KEYS: {
|
||||
return PublicKeys.CONTENT_TYPE;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_ID: {
|
||||
return PublicKeys.CONTENT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_BY_KEY_ID: {
|
||||
return PublicKeys.CONTENT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
case SECRET_KEYS: {
|
||||
return SecretKeys.CONTENT_TYPE;
|
||||
}
|
||||
|
||||
case SECRET_KEY_ID: {
|
||||
return SecretKeys.CONTENT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
case SECRET_KEY_BY_KEY_ID: {
|
||||
return SecretKeys.CONTENT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
case ACCOUNTS: {
|
||||
return Accounts.CONTENT_TYPE;
|
||||
}
|
||||
|
||||
case ACCOUNT_ID: {
|
||||
return Accounts.CONTENT_ITEM_TYPE;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues initialValues) {
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case PUBLIC_KEYS: {
|
||||
ContentValues values;
|
||||
if (initialValues != null) {
|
||||
values = new ContentValues(initialValues);
|
||||
} else {
|
||||
values = new ContentValues();
|
||||
}
|
||||
|
||||
if (!values.containsKey(PublicKeys.WHO_ID)) {
|
||||
values.put(PublicKeys.WHO_ID, "");
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mdbHelper.getWritableDatabase();
|
||||
long rowId = db.insert(PublicKeys.TABLE_NAME, PublicKeys.WHO_ID, values);
|
||||
if (rowId > 0) {
|
||||
Uri transferUri = ContentUris.withAppendedId(PublicKeys.CONTENT_URI, rowId);
|
||||
getContext().getContentResolver().notifyChange(transferUri, null);
|
||||
return transferUri;
|
||||
}
|
||||
|
||||
throw new SQLException("Failed to insert row into " + uri);
|
||||
}
|
||||
|
||||
case SECRET_KEYS: {
|
||||
ContentValues values;
|
||||
if (initialValues != null) {
|
||||
values = new ContentValues(initialValues);
|
||||
} else {
|
||||
values = new ContentValues();
|
||||
}
|
||||
|
||||
if (!values.containsKey(SecretKeys.WHO_ID)) {
|
||||
values.put(SecretKeys.WHO_ID, "");
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mdbHelper.getWritableDatabase();
|
||||
long rowId = db.insert(SecretKeys.TABLE_NAME, SecretKeys.WHO_ID, values);
|
||||
if (rowId > 0) {
|
||||
Uri transferUri = ContentUris.withAppendedId(SecretKeys.CONTENT_URI, rowId);
|
||||
getContext().getContentResolver().notifyChange(transferUri, null);
|
||||
return transferUri;
|
||||
}
|
||||
|
||||
throw new SQLException("Failed to insert row into " + uri);
|
||||
}
|
||||
|
||||
case ACCOUNTS: {
|
||||
ContentValues values;
|
||||
if (initialValues != null) {
|
||||
values = new ContentValues(initialValues);
|
||||
} else {
|
||||
values = new ContentValues();
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mdbHelper.getWritableDatabase();
|
||||
long rowId = db.insert(Accounts.TABLE_NAME, null, values);
|
||||
if (rowId > 0) {
|
||||
Uri transferUri = ContentUris.withAppendedId(Accounts.CONTENT_URI, rowId);
|
||||
getContext().getContentResolver().notifyChange(transferUri, null);
|
||||
return transferUri;
|
||||
}
|
||||
|
||||
throw new SQLException("Failed to insert row into " + uri);
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String where, String[] whereArgs) {
|
||||
SQLiteDatabase db = mdbHelper.getWritableDatabase();
|
||||
int count;
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case PUBLIC_KEYS: {
|
||||
count = db.delete(PublicKeys.TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_ID: {
|
||||
String publicKeyId = uri.getPathSegments().get(1);
|
||||
count = db.delete(PublicKeys.TABLE_NAME,
|
||||
PublicKeys._ID + "=" + publicKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_BY_KEY_ID: {
|
||||
String publicKeyKeyId = uri.getPathSegments().get(2);
|
||||
count = db.delete(PublicKeys.TABLE_NAME,
|
||||
PublicKeys.KEY_ID + "=" + publicKeyKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEYS: {
|
||||
count = db.delete(SecretKeys.TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_ID: {
|
||||
String secretKeyId = uri.getPathSegments().get(1);
|
||||
count = db.delete(SecretKeys.TABLE_NAME,
|
||||
SecretKeys._ID + "=" + secretKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_BY_KEY_ID: {
|
||||
String secretKeyKeyId = uri.getPathSegments().get(2);
|
||||
count = db.delete(SecretKeys.TABLE_NAME,
|
||||
SecretKeys.KEY_ID + "=" + secretKeyKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNTS: {
|
||||
count = db.delete(Accounts.TABLE_NAME, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNT_ID: {
|
||||
String accountId = uri.getPathSegments().get(1);
|
||||
count = db.delete(Accounts.TABLE_NAME,
|
||||
Accounts._ID + "=" + accountId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
|
||||
SQLiteDatabase db = mdbHelper.getWritableDatabase();
|
||||
int count;
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case PUBLIC_KEYS: {
|
||||
count = db.update(PublicKeys.TABLE_NAME, values, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_ID: {
|
||||
String publicKeyId = uri.getPathSegments().get(1);
|
||||
|
||||
count = db.update(PublicKeys.TABLE_NAME, values,
|
||||
PublicKeys._ID + "=" + publicKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case PUBLIC_KEY_BY_KEY_ID: {
|
||||
String publicKeyKeyId = uri.getPathSegments().get(2);
|
||||
|
||||
count = db.update(PublicKeys.TABLE_NAME, values,
|
||||
PublicKeys.KEY_ID + "=" + publicKeyKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEYS: {
|
||||
count = db.update(SecretKeys.TABLE_NAME, values, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_ID: {
|
||||
String secretKeyId = uri.getPathSegments().get(1);
|
||||
|
||||
count = db.update(SecretKeys.TABLE_NAME, values,
|
||||
SecretKeys._ID + "=" + secretKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case SECRET_KEY_BY_KEY_ID: {
|
||||
String secretKeyKeyId = uri.getPathSegments().get(2);
|
||||
|
||||
count = db.update(SecretKeys.TABLE_NAME, values,
|
||||
SecretKeys.KEY_ID + "=" + secretKeyKeyId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNTS: {
|
||||
count = db.update(Accounts.TABLE_NAME, values, where, whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
case ACCOUNT_ID: {
|
||||
String accountId = uri.getPathSegments().get(1);
|
||||
|
||||
count = db.update(Accounts.TABLE_NAME, values,
|
||||
Accounts._ID + "=" + accountId +
|
||||
(!TextUtils.isEmpty(where) ?
|
||||
" AND (" + where + ')' : ""),
|
||||
whereArgs);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
return count;
|
||||
}
|
||||
}
|
@ -160,13 +160,13 @@ public class Database extends SQLiteOpenHelper {
|
||||
UserIds.USER_ID + " " + UserIds.USER_ID_type + "," +
|
||||
UserIds.RANK + " " + UserIds.RANK_type + ");");
|
||||
|
||||
Cursor cursor = db.query(PublicKeys.TABLE_NAME,
|
||||
Cursor cursor = db.query("public_keys",
|
||||
new String[]{
|
||||
PublicKeys.KEY_DATA,
|
||||
"c_key_data",
|
||||
}, null, null, null, null, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
byte[] data = cursor.getBlob(cursor.getColumnIndex(PublicKeys.KEY_DATA));
|
||||
byte[] data = cursor.getBlob(0);
|
||||
try {
|
||||
PGPPublicKeyRing keyRing = new PGPPublicKeyRing(data);
|
||||
saveKeyRing(keyRing);
|
||||
@ -183,13 +183,13 @@ public class Database extends SQLiteOpenHelper {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
cursor = db.query(SecretKeys.TABLE_NAME,
|
||||
cursor = db.query("secret_keys",
|
||||
new String[]{
|
||||
SecretKeys.KEY_DATA,
|
||||
"c_key_data",
|
||||
}, null, null, null, null, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
do {
|
||||
byte[] data = cursor.getBlob(cursor.getColumnIndex(SecretKeys.KEY_DATA));
|
||||
byte[] data = cursor.getBlob(0);
|
||||
try {
|
||||
PGPSecretKeyRing keyRing = new PGPSecretKeyRing(data);
|
||||
saveKeyRing(keyRing);
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class KeyRings implements BaseColumns {
|
||||
@ -31,14 +30,4 @@ public class KeyRings implements BaseColumns {
|
||||
public static final String WHO_ID_type = "INTEGER";
|
||||
public static final String KEY_RING_DATA = "c_key_ring_data";
|
||||
public static final String KEY_RING_DATA_type = "BLOB";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/key_ring");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/key_ring/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class Keys implements BaseColumns {
|
||||
@ -49,12 +48,4 @@ public class Keys implements BaseColumns {
|
||||
public static final String KEY_DATA_type = "BLOB";
|
||||
public static final String RANK = "c_key_data";
|
||||
public static final String RANK_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/keys");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.key";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.key";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
public class PublicKeys extends PublicKeys1 {
|
||||
private PublicKeys() {
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
class PublicKeys1 implements BaseColumns {
|
||||
public static final String TABLE_NAME = "public_keys";
|
||||
|
||||
public static final String _ID_type = "INTEGER PRIMARY KEY";
|
||||
public static final String KEY_ID = "c_key_id";
|
||||
public static final String KEY_ID_type = "INT64";
|
||||
public static final String KEY_DATA = "c_key_data";
|
||||
public static final String KEY_DATA_type = "BLOB";
|
||||
public static final String WHO_ID = "c_who_id";
|
||||
public static final String WHO_ID_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/public_keys");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/public_keys/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.public_key";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.public_key";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
public class SecretKeys extends SecretKeys1 {
|
||||
private SecretKeys() {
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Thialfihar <thi@thialfihar.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
class SecretKeys1 implements BaseColumns {
|
||||
public static final String TABLE_NAME = "secret_keys";
|
||||
|
||||
public static final String _ID_type = "INTEGER PRIMARY KEY";
|
||||
public static final String KEY_ID = "c_key_id";
|
||||
public static final String KEY_ID_type = "INT64";
|
||||
public static final String KEY_DATA = "c_key_data";
|
||||
public static final String KEY_DATA_type = "BLOB";
|
||||
public static final String WHO_ID = "c_who_id";
|
||||
public static final String WHO_ID_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/secret_keys");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/secret_keys/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.secret_key";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.secret_key";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
@ -16,7 +16,6 @@
|
||||
|
||||
package org.thialfihar.android.apg.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
|
||||
public class UserIds implements BaseColumns {
|
||||
@ -29,14 +28,4 @@ public class UserIds implements BaseColumns {
|
||||
public static final String USER_ID_type = "TEXT";
|
||||
public static final String RANK = "c_rank";
|
||||
public static final String RANK_type = "INTEGER";
|
||||
|
||||
public static final Uri CONTENT_URI =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/user_ids");
|
||||
public static final Uri CONTENT_URI_BY_KEY_ID =
|
||||
Uri.parse("content://" + DataProvider.AUTHORITY + "/user_ids/key_id");
|
||||
public static final String CONTENT_TYPE =
|
||||
"vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
||||
public static final String CONTENT_ITEM_TYPE =
|
||||
"vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
||||
public static final String DEFAULT_SORT_ORDER = _ID + " DESC";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user