remove old files

This commit is contained in:
Dominik 2012-10-31 15:52:22 +01:00
parent 555381c4e2
commit cadb5d3b1f
5 changed files with 0 additions and 2188 deletions

View File

@ -1,422 +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.deprecated;
import java.io.File;
import org.thialfihar.android.apg.R;
import org.thialfihar.android.apg.Constants;
import org.thialfihar.android.apg.Id;
import org.thialfihar.android.apg.helper.PGPMain;
import org.thialfihar.android.apg.helper.Preferences;
import org.thialfihar.android.apg.ui.MainActivity;
import org.thialfihar.android.apg.ui.SelectSecretKeyListActivityOld;
import org.thialfihar.android.apg.util.ProgressDialogUpdater;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
public class BaseActivity extends SherlockFragmentActivity implements Runnable,
ProgressDialogUpdater {
private ProgressDialog mProgressDialog = null;
// private PausableThread mRunningThread = null;
private Thread mDeletingThread = null;
private long mSecretKeyId = 0;
private String mDeleteFile = null;
protected Preferences mPreferences;
// private Handler mHandler = new Handler() {
// @Override
// public void handleMessage(Message msg) {
// handlerCallback(msg);
// }
// };
//
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
//
// // not needed later:
// // mPreferences = Preferences.getPreferences(this);
//
// // PGPMain.initialize(this);
//
// // if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
// // File dir = new File(Constants.path.APP_DIR);
// // if (!dir.exists() && !dir.mkdirs()) {
// // // ignore this for now, it's not crucial
// // // that the directory doesn't exist at this point
// // }
// // }
//
// // startCacheService(this, mPreferences);
// }
//
// // public static void startCacheService(Activity activity, Preferences preferences) {
// // Intent intent = new Intent(activity, PassphraseCacheService.class);
// // intent.putExtra(PassphraseCacheService.EXTRA_TTL, preferences.getPassPhraseCacheTtl());
// // activity.startService(intent);
// // }
//
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
//
// case android.R.id.home:
// // app icon in Action Bar clicked; go home
// Intent intent = new Intent(this, MainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// return true;
//
// // TODO: needed?:
// // case Id.menu.option.search:
// // startSearch("", false, null, false);
// // return true;
//
// default:
// break;
//
// }
// return false;
// }
//
// @Override
// protected Dialog onCreateDialog(int id) {
// // in case it is a progress dialog
// mProgressDialog = new ProgressDialog(this);
// mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// mProgressDialog.setCancelable(false);
// switch (id) {
// case Id.dialog.encrypting: {
// mProgressDialog.setMessage(this.getString(R.string.progress_initializing));
// return mProgressDialog;
// }
//
// case Id.dialog.decrypting: {
// mProgressDialog.setMessage(this.getString(R.string.progress_initializing));
// return mProgressDialog;
// }
//
// case Id.dialog.saving: {
// mProgressDialog.setMessage(this.getString(R.string.progress_saving));
// return mProgressDialog;
// }
//
// case Id.dialog.importing: {
// mProgressDialog.setMessage(this.getString(R.string.progress_importing));
// return mProgressDialog;
// }
//
// case Id.dialog.exporting: {
// mProgressDialog.setMessage(this.getString(R.string.progress_exporting));
// return mProgressDialog;
// }
//
// case Id.dialog.deleting: {
// mProgressDialog.setMessage(this.getString(R.string.progress_initializing));
// return mProgressDialog;
// }
//
// case Id.dialog.querying: {
// mProgressDialog.setMessage(this.getString(R.string.progress_querying));
// mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// mProgressDialog.setCancelable(false);
// return mProgressDialog;
// }
//
// case Id.dialog.signing: {
// mProgressDialog.setMessage(this.getString(R.string.progress_signing));
// mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
// mProgressDialog.setCancelable(false);
// return mProgressDialog;
// }
//
// default: {
// break;
// }
// }
// mProgressDialog = null;
//
// switch (id) {
//
// case Id.dialog.pass_phrase: {
// return AskForPassphrase.createDialog(this, getSecretKeyId(), this);
// }
//
// case Id.dialog.pass_phrases_do_not_match: {
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
//
// alert.setIcon(android.R.drawable.ic_dialog_alert);
// alert.setTitle(R.string.error);
// alert.setMessage(R.string.passPhrasesDoNotMatch);
//
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// removeDialog(Id.dialog.pass_phrases_do_not_match);
// }
// });
// alert.setCancelable(false);
//
// return alert.create();
// }
//
// case Id.dialog.no_pass_phrase: {
// AlertDialog.Builder alert = new AlertDialog.Builder(this);
//
// alert.setIcon(android.R.drawable.ic_dialog_alert);
// alert.setTitle(R.string.error);
// alert.setMessage(R.string.passPhraseMustNotBeEmpty);
//
// alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// removeDialog(Id.dialog.no_pass_phrase);
// }
// });
// alert.setCancelable(false);
//
// return alert.create();
// }
//
// // case Id.dialog.delete_file: {
// // AlertDialog.Builder alert = new AlertDialog.Builder(this);
// //
// // alert.setIcon(android.R.drawable.ic_dialog_alert);
// // alert.setTitle(R.string.warning);
// // alert.setMessage(this.getString(R.string.fileDeleteConfirmation, getDeleteFile()));
// //
// // alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// // public void onClick(DialogInterface dialog, int id) {
// // removeDialog(Id.dialog.delete_file);
// // final File file = new File(getDeleteFile());
// // showDialog(Id.dialog.deleting);
// // mDeletingThread = new Thread(new Runnable() {
// // public void run() {
// // Bundle data = new Bundle();
// // data.putInt(Constants.extras.STATUS, Id.message.delete_done);
// // try {
// // Apg.deleteFileSecurely(BaseActivity.this, file, BaseActivity.this);
// // } catch (FileNotFoundException e) {
// // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString(
// // R.string.error_fileNotFound, file));
// // } catch (IOException e) {
// // data.putString(Apg.EXTRA_ERROR, BaseActivity.this.getString(
// // R.string.error_fileDeleteFailed, file));
// // }
// // Message msg = new Message();
// // msg.setData(data);
// // sendMessage(msg);
// // }
// // });
// // mDeletingThread.start();
// // }
// // });
// // alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
// // public void onClick(DialogInterface dialog, int id) {
// // removeDialog(Id.dialog.delete_file);
// // }
// // });
// // alert.setCancelable(true);
// //
// // return alert.create();
// // }
//
// default: {
// break;
// }
// }
//
// return super.onCreateDialog(id);
// }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case Id.request.secret_keys: {
if (resultCode == RESULT_OK) {
Bundle bundle = data.getExtras();
setSecretKeyId(bundle.getLong(SelectSecretKeyListActivityOld.RESULT_EXTRA_KEY_ID));
} else {
setSecretKeyId(Id.key.none);
}
break;
}
default: {
break;
}
}
super.onActivityResult(requestCode, resultCode, data);
}
// public void setProgress(int resourceId, int progress, int max) {
// setProgress(getString(resourceId), progress, max);
// }
//
// public void setProgress(int progress, int max) {
// Message msg = new Message();
// Bundle data = new Bundle();
// data.putInt(Constants.extras.STATUS, Id.message.progress_update);
// data.putInt(Constants.extras.PROGRESS, progress);
// data.putInt(Constants.extras.PROGRESS_MAX, max);
// msg.setData(data);
// mHandler.sendMessage(msg);
// }
//
// public void setProgress(String message, int progress, int max) {
// Message msg = new Message();
// Bundle data = new Bundle();
// data.putInt(Constants.extras.STATUS, Id.message.progress_update);
// data.putString(Constants.extras.MESSAGE, message);
// data.putInt(Constants.extras.PROGRESS, progress);
// data.putInt(Constants.extras.PROGRESS_MAX, max);
// msg.setData(data);
// mHandler.sendMessage(msg);
// }
//
// public void handlerCallback(Message msg) {
// Bundle data = msg.getData();
// if (data == null) {
// return;
// }
//
// int type = data.getInt(Constants.extras.STATUS);
// switch (type) {
// case Id.message.progress_update: {
// String message = data.getString(Constants.extras.MESSAGE);
// if (mProgressDialog != null) {
// if (message != null) {
// mProgressDialog.setMessage(message);
// }
// mProgressDialog.setMax(data.getInt(Constants.extras.PROGRESS_MAX));
// mProgressDialog.setProgress(data.getInt(Constants.extras.PROGRESS));
// }
// break;
// }
//
// // case Id.message.delete_done: {
// // mProgressDialog = null;
// // deleteDoneCallback(msg);
// // break;
// // }
//
// case Id.message.import_done: // intentionally no break
// case Id.message.export_done: // intentionally no break
// case Id.message.query_done: // intentionally no break
// case Id.message.done: {
// mProgressDialog = null;
// doneCallback(msg);
// break;
// }
//
// default: {
// break;
// }
// }
// }
//
// public void doneCallback(Message msg) {
//
// }
// public void deleteDoneCallback(Message msg) {
// removeDialog(Id.dialog.deleting);
// mDeletingThread = null;
//
// Bundle data = msg.getData();
// String error = data.getString(Apg.EXTRA_ERROR);
// String message;
// if (error != null) {
// message = getString(R.string.errorMessage, error);
// } else {
// message = getString(R.string.fileDeleteSuccessful);
// }
//
// Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
// }
//
// public void passPhraseCallback(long keyId, String passPhrase) {
// // TODO: Not needed anymore, now implemented in AskForSecretKeyPass
// PGPMain.setCachedPassPhrase(keyId, passPhrase);
// }
// public void sendMessage(Message msg) {
// mHandler.sendMessage(msg);
// }
// public PausableThread getRunningThread() {
// return mRunningThread;
// }
//
// public void startThread() {
// mRunningThread = new PausableThread(this);
// mRunningThread.start();
// }
public void run() {
}
public void setSecretKeyId(long id) {
mSecretKeyId = id;
}
public long getSecretKeyId() {
return mSecretKeyId;
}
protected void setDeleteFile(String deleteFile) {
mDeleteFile = deleteFile;
}
protected String getDeleteFile() {
return mDeleteFile;
}
@Override
public void setProgress(String message, int current, int total) {
// TODO Auto-generated method stub
}
@Override
public void setProgress(int resourceId, int current, int total) {
// TODO Auto-generated method stub
}
@Override
public void setProgress(int current, int total) {
// TODO Auto-generated method stub
}
}

View File

@ -1,381 +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.deprecated;
//
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.util.HashMap;
//
//import org.thialfihar.android.apg.Id;
//
//import android.content.ContentProvider;
//import android.content.ContentValues;
//import android.content.UriMatcher;
//import android.database.Cursor;
//import android.database.DatabaseUtils;
//import android.database.sqlite.SQLiteQueryBuilder;
//import android.net.Uri;
//import android.os.ParcelFileDescriptor;
//import android.text.TextUtils;
//
//public class DataProvider extends ContentProvider {
// public static final String AUTHORITY = "org.thialfihar.android.apg.provider";
//
// private static final int PUBLIC_KEY_RING = 101;
// private static final int PUBLIC_KEY_RING_ID = 102;
// private static final int PUBLIC_KEY_RING_BY_KEY_ID = 103;
// private static final int PUBLIC_KEY_RING_BY_EMAILS = 104;
// private static final int PUBLIC_KEY_RING_KEY = 111;
// private static final int PUBLIC_KEY_RING_KEY_RANK = 112;
// private static final int PUBLIC_KEY_RING_USER_ID = 121;
// private static final int PUBLIC_KEY_RING_USER_ID_RANK = 122;
//
// private static final int SECRET_KEY_RING = 201;
// private static final int SECRET_KEY_RING_ID = 202;
// private static final int SECRET_KEY_RING_BY_KEY_ID = 203;
// private static final int SECRET_KEY_RING_BY_EMAILS = 204;
// private static final int SECRET_KEY_RING_KEY = 211;
// private static final int SECRET_KEY_RING_KEY_RANK = 212;
// private static final int SECRET_KEY_RING_USER_ID = 221;
// private static final int SECRET_KEY_RING_USER_ID_RANK = 222;
//
// private static final int DATA_STREAM = 301;
//
// private static final String PUBLIC_KEY_RING_CONTENT_DIR_TYPE =
// "vnd.android.cursor.dir/vnd.thialfihar.apg.public.key_ring";
// private static final String PUBLIC_KEY_RING_CONTENT_ITEM_TYPE =
// "vnd.android.cursor.item/vnd.thialfihar.apg.public.key_ring";
//
// private static final String PUBLIC_KEY_CONTENT_DIR_TYPE =
// "vnd.android.cursor.dir/vnd.thialfihar.apg.public.key";
// private static final String PUBLIC_KEY_CONTENT_ITEM_TYPE =
// "vnd.android.cursor.item/vnd.thialfihar.apg.public.key";
//
// private static final String SECRET_KEY_RING_CONTENT_DIR_TYPE =
// "vnd.android.cursor.dir/vnd.thialfihar.apg.secret.key_ring";
// private static final String SECRET_KEY_RING_CONTENT_ITEM_TYPE =
// "vnd.android.cursor.item/vnd.thialfihar.apg.secret.key_ring";
//
// private static final String SECRET_KEY_CONTENT_DIR_TYPE =
// "vnd.android.cursor.dir/vnd.thialfihar.apg.secret.key";
// private static final String SECRET_KEY_CONTENT_ITEM_TYPE =
// "vnd.android.cursor.item/vnd.thialfihar.apg.secret.key";
//
// private static final String USER_ID_CONTENT_DIR_TYPE =
// "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
// private static final String USER_ID_CONTENT_ITEM_TYPE =
// "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
//
// public static final String _ID = "_id";
// public static final String MASTER_KEY_ID = "master_key_id";
// public static final String KEY_ID = "key_id";
// public static final String USER_ID = "user_id";
//
// private static final UriMatcher mUriMatcher;
//
// private Database mDb;
//
// static {
// mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/key_id/*", PUBLIC_KEY_RING_BY_KEY_ID);
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/emails/*", PUBLIC_KEY_RING_BY_EMAILS);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/*/keys", PUBLIC_KEY_RING_KEY);
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/*/keys/#", PUBLIC_KEY_RING_KEY_RANK);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/*/user_ids", PUBLIC_KEY_RING_USER_ID);
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/*/user_ids/#", PUBLIC_KEY_RING_USER_ID_RANK);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/public", PUBLIC_KEY_RING);
// mUriMatcher.addURI(AUTHORITY, "key_rings/public/*", PUBLIC_KEY_RING_ID);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/key_id/*", SECRET_KEY_RING_BY_KEY_ID);
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/emails/*", SECRET_KEY_RING_BY_EMAILS);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/*/keys", SECRET_KEY_RING_KEY);
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/*/keys/#", SECRET_KEY_RING_KEY_RANK);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/*/user_ids", SECRET_KEY_RING_USER_ID);
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/*/user_ids/#", SECRET_KEY_RING_USER_ID_RANK);
//
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret", SECRET_KEY_RING);
// mUriMatcher.addURI(AUTHORITY, "key_rings/secret/*", SECRET_KEY_RING_ID);
//
// mUriMatcher.addURI(AUTHORITY, "data/*", DATA_STREAM);
// }
//
// @Override
// public boolean onCreate() {
// mDb = new Database(getContext());
// return true;
// }
//
// @Override
// public Cursor query(Uri uri, String[] projection, String selection,
// String[] selectionArgs, String sortOrder) {
// // TODO: implement the others, then use them for the lists
// SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
// HashMap<String, String> projectionMap = new HashMap<String, String>();
//
// int match = mUriMatcher.match(uri);
// int type;
// switch (match) {
// case PUBLIC_KEY_RING:
// case PUBLIC_KEY_RING_ID:
// case PUBLIC_KEY_RING_BY_KEY_ID:
// case PUBLIC_KEY_RING_BY_EMAILS:
// case PUBLIC_KEY_RING_KEY:
// case PUBLIC_KEY_RING_KEY_RANK:
// case PUBLIC_KEY_RING_USER_ID:
// case PUBLIC_KEY_RING_USER_ID_RANK:
// type = Id.database.type_public;
// break;
//
// case SECRET_KEY_RING:
// case SECRET_KEY_RING_ID:
// case SECRET_KEY_RING_BY_KEY_ID:
// case SECRET_KEY_RING_BY_EMAILS:
// case SECRET_KEY_RING_KEY:
// case SECRET_KEY_RING_KEY_RANK:
// case SECRET_KEY_RING_USER_ID:
// case SECRET_KEY_RING_USER_ID_RANK:
// type = Id.database.type_secret;
// break;
//
// default: {
// throw new IllegalArgumentException("Unknown URI " + uri);
// }
// }
//
// qb.appendWhere(KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = " + type);
//
// switch (match) {
// case PUBLIC_KEY_RING_ID:
// case SECRET_KEY_RING_ID: {
// qb.appendWhere(" AND " +
// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID + " = ");
// qb.appendWhereEscapeString(uri.getPathSegments().get(2));
//
// // break omitted intentionally
// }
//
// case PUBLIC_KEY_RING:
// case SECRET_KEY_RING: {
// qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
// "(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
// Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + " AND " +
// Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY + " = '1'" +
// ") " +
// " INNER JOIN " + UserIds.TABLE_NAME + " ON " +
// "(" + Keys.TABLE_NAME + "." + Keys._ID + " = " +
// UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " AND " +
// UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0') ");
//
// projectionMap.put(_ID,
// KeyRings.TABLE_NAME + "." + KeyRings._ID);
// projectionMap.put(MASTER_KEY_ID,
// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID);
// projectionMap.put(USER_ID,
// UserIds.TABLE_NAME + "." + UserIds.USER_ID);
//
// if (TextUtils.isEmpty(sortOrder)) {
// sortOrder = UserIds.TABLE_NAME + "." + UserIds.USER_ID + " ASC";
// }
//
// break;
// }
//
// case SECRET_KEY_RING_BY_KEY_ID:
// case PUBLIC_KEY_RING_BY_KEY_ID: {
// qb.setTables(Keys.TABLE_NAME + " AS tmp INNER JOIN " +
// KeyRings.TABLE_NAME + " ON (" +
// KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
// "tmp." + Keys.KEY_RING_ID + ")" +
// " INNER JOIN " + Keys.TABLE_NAME + " ON " +
// "(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
// Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + " AND " +
// Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY + " = '1'" +
// ") " +
// " INNER JOIN " + UserIds.TABLE_NAME + " ON " +
// "(" + Keys.TABLE_NAME + "." + Keys._ID + " = " +
// UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " AND " +
// UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0') ");
//
// projectionMap.put(_ID,
// KeyRings.TABLE_NAME + "." + KeyRings._ID);
// projectionMap.put(MASTER_KEY_ID,
// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID);
// projectionMap.put(USER_ID,
// UserIds.TABLE_NAME + "." + UserIds.USER_ID);
//
// qb.appendWhere(" AND tmp." + Keys.KEY_ID + " = ");
// qb.appendWhereEscapeString(uri.getPathSegments().get(3));
//
// break;
// }
//
// case SECRET_KEY_RING_BY_EMAILS:
// case PUBLIC_KEY_RING_BY_EMAILS: {
// qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " +
// "(" + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
// Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + " AND " +
// Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY + " = '1'" +
// ") " +
// " INNER JOIN " + UserIds.TABLE_NAME + " ON " +
// "(" + Keys.TABLE_NAME + "." + Keys._ID + " = " +
// UserIds.TABLE_NAME + "." + UserIds.KEY_ID + " AND " +
// UserIds.TABLE_NAME + "." + UserIds.RANK + " = '0') ");
//
// projectionMap.put(_ID,
// KeyRings.TABLE_NAME + "." + KeyRings._ID);
// projectionMap.put(MASTER_KEY_ID,
// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID);
// projectionMap.put(USER_ID,
// UserIds.TABLE_NAME + "." + UserIds.USER_ID);
//
// String emails = uri.getPathSegments().get(3);
// String chunks[] = emails.split(" *, *");
// boolean gotCondition = false;
// String emailWhere = "";
// for (int i = 0; i < chunks.length; ++i) {
// if (chunks[i].length() == 0) {
// continue;
// }
// if (i != 0) {
// emailWhere += " OR ";
// }
// emailWhere += "tmp." + UserIds.USER_ID + " LIKE ";
// // match '*<email>', so it has to be at the *end* of the user id
// emailWhere += DatabaseUtils.sqlEscapeString("%<" + chunks[i] + ">");
// gotCondition = true;
// }
//
// if (gotCondition) {
// qb.appendWhere(" AND EXISTS (SELECT tmp." + UserIds._ID +
// " FROM " + UserIds.TABLE_NAME +
// " AS tmp WHERE tmp." + UserIds.KEY_ID + " = " +
// Keys.TABLE_NAME + "." + Keys._ID +
// " AND (" + emailWhere + "))");
// }
//
// break;
// }
//
// default: {
// throw new IllegalArgumentException("Unknown URI " + uri);
// }
// }
//
// qb.setProjectionMap(projectionMap);
//
// // If no sort order is specified use the default
// String orderBy;
// if (TextUtils.isEmpty(sortOrder)) {
// orderBy = null;
// } else {
// orderBy = sortOrder;
// }
//
// //System.out.println(qb.buildQuery(projection, selection, selectionArgs, null, null, sortOrder, null).replace("WHERE", "WHERE\n"));
// Cursor c = qb.query(mDb.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_KEY_RING:
// case PUBLIC_KEY_RING_BY_EMAILS:
// return PUBLIC_KEY_RING_CONTENT_DIR_TYPE;
//
// case PUBLIC_KEY_RING_ID:
// return PUBLIC_KEY_RING_CONTENT_ITEM_TYPE;
//
// case PUBLIC_KEY_RING_BY_KEY_ID:
// return PUBLIC_KEY_RING_CONTENT_ITEM_TYPE;
//
// case PUBLIC_KEY_RING_KEY:
// return PUBLIC_KEY_CONTENT_DIR_TYPE;
//
// case PUBLIC_KEY_RING_KEY_RANK:
// return PUBLIC_KEY_CONTENT_ITEM_TYPE;
//
// case PUBLIC_KEY_RING_USER_ID:
// return USER_ID_CONTENT_DIR_TYPE;
//
// case PUBLIC_KEY_RING_USER_ID_RANK:
// return USER_ID_CONTENT_ITEM_TYPE;
//
// case SECRET_KEY_RING:
// case SECRET_KEY_RING_BY_EMAILS:
// return SECRET_KEY_RING_CONTENT_DIR_TYPE;
//
// case SECRET_KEY_RING_ID:
// return SECRET_KEY_RING_CONTENT_ITEM_TYPE;
//
// case SECRET_KEY_RING_BY_KEY_ID:
// return SECRET_KEY_RING_CONTENT_ITEM_TYPE;
//
// case SECRET_KEY_RING_KEY:
// return SECRET_KEY_CONTENT_DIR_TYPE;
//
// case SECRET_KEY_RING_KEY_RANK:
// return SECRET_KEY_CONTENT_ITEM_TYPE;
//
// case SECRET_KEY_RING_USER_ID:
// return USER_ID_CONTENT_DIR_TYPE;
//
// case SECRET_KEY_RING_USER_ID_RANK:
// return USER_ID_CONTENT_ITEM_TYPE;
//
// default:
// throw new IllegalArgumentException("Unknown URI " + uri);
// }
// }
//
// @Override
// public Uri insert(Uri uri, ContentValues initialValues) {
// // not supported
// return null;
// }
//
// @Override
// public int delete(Uri uri, String where, String[] whereArgs) {
// // not supported
// return 0;
// }
//
// @Override
// public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
// // not supported
// return 0;
// }
//
// @Override
// public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
// int match = mUriMatcher.match(uri);
// if (match != DATA_STREAM) {
// throw new FileNotFoundException();
// }
// String fileName = uri.getPathSegments().get(1);
// File file = new File(getContext().getFilesDir().getAbsolutePath(), fileName);
// return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
// }
//}

View File

@ -1,617 +0,0 @@
///*
// * 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.deprecated;
//
//import org.spongycastle.openpgp.PGPException;
//import org.spongycastle.openpgp.PGPPublicKey;
//import org.spongycastle.openpgp.PGPPublicKeyRing;
//import org.spongycastle.openpgp.PGPSecretKey;
//import org.spongycastle.openpgp.PGPSecretKeyRing;
//import org.thialfihar.android.apg.Id;
//import org.thialfihar.android.apg.helper.PGPHelper;
//import org.thialfihar.android.apg.util.IterableIterator;
//
//import android.content.ContentValues;
//import android.content.Context;
//import android.database.Cursor;
//import android.database.sqlite.SQLiteDatabase;
//import android.database.sqlite.SQLiteOpenHelper;
//import org.thialfihar.android.apg.util.Log;
//
//import java.io.IOException;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.Vector;
//
//public class Database extends SQLiteOpenHelper {
// public static class GeneralException extends Exception {
// static final long serialVersionUID = 0xf812773343L;
//
// public GeneralException(String message) {
// super(message);
// }
// }
//
// private static final String DATABASE_NAME = "apg";
// private static final int DATABASE_VERSION = 2;
//
// public static final String AUTHORITY = "org.thialfihar.android.apg.database";
//
// public static HashMap<String, String> sKeyRingsProjection;
// public static HashMap<String, String> sKeysProjection;
// public static HashMap<String, String> sUserIdsProjection;
//
// private SQLiteDatabase mDb = null;
// private int mStatus = 0;
//
// static {
// sKeyRingsProjection = new HashMap<String, String>();
// sKeyRingsProjection.put(KeyRings._ID, KeyRings._ID);
// sKeyRingsProjection.put(KeyRings.MASTER_KEY_ID, KeyRings.MASTER_KEY_ID);
// sKeyRingsProjection.put(KeyRings.TYPE, KeyRings.TYPE);
// sKeyRingsProjection.put(KeyRings.WHO_ID, KeyRings.WHO_ID);
// sKeyRingsProjection.put(KeyRings.KEY_RING_DATA, KeyRings.KEY_RING_DATA);
//
// sKeysProjection = new HashMap<String, String>();
// sKeysProjection.put(Keys._ID, Keys._ID);
// sKeysProjection.put(Keys.KEY_ID, Keys.KEY_ID);
// sKeysProjection.put(Keys.TYPE, Keys.TYPE);
// sKeysProjection.put(Keys.IS_MASTER_KEY, Keys.IS_MASTER_KEY);
// sKeysProjection.put(Keys.ALGORITHM, Keys.ALGORITHM);
// sKeysProjection.put(Keys.KEY_SIZE, Keys.KEY_SIZE);
// sKeysProjection.put(Keys.CAN_SIGN, Keys.CAN_SIGN);
// sKeysProjection.put(Keys.CAN_ENCRYPT, Keys.CAN_ENCRYPT);
// sKeysProjection.put(Keys.IS_REVOKED, Keys.IS_REVOKED);
// sKeysProjection.put(Keys.CREATION, Keys.CREATION);
// sKeysProjection.put(Keys.EXPIRY, Keys.EXPIRY);
// sKeysProjection.put(Keys.KEY_DATA, Keys.KEY_DATA);
// sKeysProjection.put(Keys.RANK, Keys.RANK);
//
// sUserIdsProjection = new HashMap<String, String>();
// sUserIdsProjection.put(UserIds._ID, UserIds._ID);
// sUserIdsProjection.put(UserIds.KEY_ID, UserIds.KEY_ID);
// sUserIdsProjection.put(UserIds.USER_ID, UserIds.USER_ID);
// sUserIdsProjection.put(UserIds.RANK, UserIds.RANK);
// }
//
// public Database(Context context) {
// super(context, DATABASE_NAME, null, DATABASE_VERSION);
// // force upgrade to test things
// //onUpgrade(getWritableDatabase(), 1, 2);
// mDb = getWritableDatabase();
// }
//
// @Override
// protected void finalize() throws Throwable {
// mDb.close();
// super.finalize();
// }
//
// @Override
// public void onCreate(SQLiteDatabase db) {
// db.execSQL("CREATE TABLE " + KeyRings.TABLE_NAME + " (" +
// KeyRings._ID + " " + KeyRings._ID_type + "," +
// KeyRings.MASTER_KEY_ID + " " + KeyRings.MASTER_KEY_ID_type + ", " +
// KeyRings.TYPE + " " + KeyRings.TYPE_type + ", " +
// KeyRings.WHO_ID + " " + KeyRings.WHO_ID_type + ", " +
// KeyRings.KEY_RING_DATA + " " + KeyRings.KEY_RING_DATA_type + ");");
//
// db.execSQL("CREATE TABLE " + Keys.TABLE_NAME + " (" +
// Keys._ID + " " + Keys._ID_type + "," +
// Keys.KEY_ID + " " + Keys.KEY_ID_type + ", " +
// Keys.TYPE + " " + Keys.TYPE_type + ", " +
// Keys.IS_MASTER_KEY + " " + Keys.IS_MASTER_KEY_type + ", " +
// Keys.ALGORITHM + " " + Keys.ALGORITHM_type + ", " +
// Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
// Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
// Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
// Keys.IS_REVOKED + " " + Keys.IS_REVOKED_type + ", " +
// Keys.CREATION + " " + Keys.CREATION_type + ", " +
// Keys.EXPIRY + " " + Keys.EXPIRY_type + ", " +
// Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
// Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
// Keys.RANK + " " + Keys.RANK_type + ");");
//
// db.execSQL("CREATE TABLE " + UserIds.TABLE_NAME + " (" +
// UserIds._ID + " " + UserIds._ID_type + "," +
// UserIds.KEY_ID + " " + UserIds.KEY_ID_type + "," +
// UserIds.USER_ID + " " + UserIds.USER_ID_type + "," +
// UserIds.RANK + " " + UserIds.RANK_type + ");");
//
// }
//
// @Override
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// mDb = db;
// for (int version = oldVersion; version < newVersion; ++version) {
// switch (version) {
// case 1: { // upgrade 1 to 2
// db.execSQL("DROP TABLE IF EXISTS " + KeyRings.TABLE_NAME + ";");
// db.execSQL("DROP TABLE IF EXISTS " + Keys.TABLE_NAME + ";");
// db.execSQL("DROP TABLE IF EXISTS " + UserIds.TABLE_NAME + ";");
//
// db.execSQL("CREATE TABLE " + KeyRings.TABLE_NAME + " (" +
// KeyRings._ID + " " + KeyRings._ID_type + "," +
// KeyRings.MASTER_KEY_ID + " " + KeyRings.MASTER_KEY_ID_type + ", " +
// KeyRings.TYPE + " " + KeyRings.TYPE_type + ", " +
// KeyRings.WHO_ID + " " + KeyRings.WHO_ID_type + ", " +
// KeyRings.KEY_RING_DATA + " " + KeyRings.KEY_RING_DATA_type + ");");
//
//
// db.execSQL("CREATE TABLE " + Keys.TABLE_NAME + " (" +
// Keys._ID + " " + Keys._ID_type + "," +
// Keys.KEY_ID + " " + Keys.KEY_ID_type + ", " +
// Keys.TYPE + " " + Keys.TYPE_type + ", " +
// Keys.IS_MASTER_KEY + " " + Keys.IS_MASTER_KEY_type + ", " +
// Keys.ALGORITHM + " " + Keys.ALGORITHM_type + ", " +
// Keys.KEY_SIZE + " " + Keys.KEY_SIZE_type + ", " +
// Keys.CAN_SIGN + " " + Keys.CAN_SIGN_type + ", " +
// Keys.CAN_ENCRYPT + " " + Keys.CAN_ENCRYPT_type + ", " +
// Keys.IS_REVOKED + " " + Keys.IS_REVOKED_type + ", " +
// Keys.CREATION + " " + Keys.CREATION_type + ", " +
// Keys.EXPIRY + " " + Keys.EXPIRY_type + ", " +
// Keys.KEY_RING_ID + " " + Keys.KEY_RING_ID_type + ", " +
// Keys.KEY_DATA + " " + Keys.KEY_DATA_type +
// Keys.RANK + " " + Keys.RANK_type + ");");
//
// db.execSQL("CREATE TABLE " + UserIds.TABLE_NAME + " (" +
// UserIds._ID + " " + UserIds._ID_type + "," +
// UserIds.KEY_ID + " " + UserIds.KEY_ID_type + "," +
// UserIds.USER_ID + " " + UserIds.USER_ID_type + "," +
// UserIds.RANK + " " + UserIds.RANK_type + ");");
//
// Cursor cursor = db.query("public_keys", new String[] { "c_key_data" },
// null, null, null, null, null);
// if (cursor != null && cursor.moveToFirst()) {
// do {
// byte[] data = cursor.getBlob(0);
// try {
// PGPPublicKeyRing keyRing = new PGPPublicKeyRing(data);
// saveKeyRing(keyRing);
// } catch (IOException e) {
// Log.e("apg.db.upgrade", "key import failed: " + e);
// } catch (GeneralException e) {
// Log.e("apg.db.upgrade", "key import failed: " + e);
// }
// } while (cursor.moveToNext());
// }
//
// if (cursor != null) {
// cursor.close();
// }
//
// cursor = db.query("secret_keys", new String[]{ "c_key_data" },
// null, null, null, null, null);
// if (cursor != null && cursor.moveToFirst()) {
// do {
// byte[] data = cursor.getBlob(0);
// try {
// PGPSecretKeyRing keyRing = new PGPSecretKeyRing(data);
// saveKeyRing(keyRing);
// } catch (IOException e) {
// Log.e("apg.db.upgrade", "key import failed: " + e);
// } catch (PGPException e) {
// Log.e("apg.db.upgrade", "key import failed: " + e);
// } catch (GeneralException e) {
// Log.e("apg.db.upgrade", "key import failed: " + e);
// }
// } while (cursor.moveToNext());
// }
//
// if (cursor != null) {
// cursor.close();
// }
//
// db.execSQL("DROP TABLE IF EXISTS public_keys;");
// db.execSQL("DROP TABLE IF EXISTS secret_keys;");
//
// break;
// }
//
// default: {
// break;
// }
// }
// }
// mDb = null;
// }
//
// public int saveKeyRing(PGPPublicKeyRing keyRing) throws IOException, GeneralException {
// mDb.beginTransaction();
// ContentValues values = new ContentValues();
// PGPPublicKey masterKey = keyRing.getPublicKey();
// long masterKeyId = masterKey.getKeyID();
//
// values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
// values.put(KeyRings.TYPE, Id.database.type_public);
// values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
//
// long rowId = insertOrUpdateKeyRing(values);
// int returnValue = mStatus;
//
// if (rowId == -1) {
// throw new GeneralException("saving public key ring " + masterKeyId + " failed");
// }
//
// Vector<Integer> seenIds = new Vector<Integer>();
// int rank = 0;
// for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(keyRing.getPublicKeys())) {
// seenIds.add(saveKey(rowId, key, rank));
// ++rank;
// }
//
// String seenIdsStr = "";
// for (Integer id : seenIds) {
// if (seenIdsStr.length() > 0) {
// seenIdsStr += ",";
// }
// seenIdsStr += id;
// }
// mDb.delete(Keys.TABLE_NAME,
// Keys.KEY_RING_ID + " = ? AND " +
// Keys._ID + " NOT IN (" + seenIdsStr + ")",
// new String[] { "" + rowId });
//
// mDb.setTransactionSuccessful();
// mDb.endTransaction();
// return returnValue;
// }
//
// public int saveKeyRing(PGPSecretKeyRing keyRing) throws IOException, GeneralException {
// mDb.beginTransaction();
// ContentValues values = new ContentValues();
// PGPSecretKey masterKey = keyRing.getSecretKey();
// long masterKeyId = masterKey.getKeyID();
//
// values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
// values.put(KeyRings.TYPE, Id.database.type_secret);
// values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
//
// long rowId = insertOrUpdateKeyRing(values);
// int returnValue = mStatus;
//
// if (rowId == -1) {
// throw new GeneralException("saving secret key ring " + masterKeyId + " failed");
// }
//
// Vector<Integer> seenIds = new Vector<Integer>();
// int rank = 0;
// for (PGPSecretKey key : new IterableIterator<PGPSecretKey>(keyRing.getSecretKeys())) {
// seenIds.add(saveKey(rowId, key, rank));
// ++rank;
// }
//
// String seenIdsStr = "";
// for (Integer id : seenIds) {
// if (seenIdsStr.length() > 0) {
// seenIdsStr += ",";
// }
// seenIdsStr += id;
// }
// mDb.delete(Keys.TABLE_NAME,
// Keys.KEY_RING_ID + " = ? AND " +
// Keys._ID + " NOT IN (" + seenIdsStr + ")",
// new String[] { "" + rowId });
//
// mDb.setTransactionSuccessful();
// mDb.endTransaction();
// return returnValue;
// }
//
// private int saveKey(long keyRingId, PGPPublicKey key, int rank)
// throws IOException, GeneralException {
// ContentValues values = new ContentValues();
//
// values.put(Keys.KEY_ID, key.getKeyID());
// values.put(Keys.TYPE, Id.database.type_public);
// values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
// values.put(Keys.ALGORITHM, key.getAlgorithm());
// values.put(Keys.KEY_SIZE, key.getBitStrength());
// values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
// values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
// values.put(Keys.IS_REVOKED, key.isRevoked());
// values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
// Date expiryDate = PGPHelper.getExpiryDate(key);
// if (expiryDate != null) {
// values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
// }
// values.put(Keys.KEY_RING_ID, keyRingId);
// values.put(Keys.KEY_DATA, key.getEncoded());
// values.put(Keys.RANK, rank);
//
// long rowId = insertOrUpdateKey(values);
//
// if (rowId == -1) {
// throw new GeneralException("saving public key " + key.getKeyID() + " failed");
// }
//
// Vector<Integer> seenIds = new Vector<Integer>();
// int userIdRank = 0;
// for (String userId : new IterableIterator<String>(key.getUserIDs())) {
// seenIds.add(saveUserId(rowId, userId, userIdRank));
// ++userIdRank;
// }
//
// String seenIdsStr = "";
// for (Integer id : seenIds) {
// if (seenIdsStr.length() > 0) {
// seenIdsStr += ",";
// }
// seenIdsStr += id;
// }
// mDb.delete(UserIds.TABLE_NAME,
// UserIds.KEY_ID + " = ? AND " +
// UserIds._ID + " NOT IN (" + seenIdsStr + ")",
// new String[] { "" + rowId });
//
// return (int)rowId;
// }
//
// private int saveKey(long keyRingId, PGPSecretKey key, int rank)
// throws IOException, GeneralException {
// ContentValues values = new ContentValues();
//
// values.put(Keys.KEY_ID, key.getPublicKey().getKeyID());
// values.put(Keys.TYPE, Id.database.type_secret);
// values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
// values.put(Keys.ALGORITHM, key.getPublicKey().getAlgorithm());
// values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength());
// values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
// values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
// values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked());
// values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
// Date expiryDate = PGPHelper.getExpiryDate(key);
// if (expiryDate != null) {
// values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
// }
// values.put(Keys.KEY_RING_ID, keyRingId);
// values.put(Keys.KEY_DATA, key.getEncoded());
// values.put(Keys.RANK, rank);
//
// long rowId = insertOrUpdateKey(values);
//
// if (rowId == -1) {
// throw new GeneralException("saving secret key " + key.getPublicKey().getKeyID() + " failed");
// }
//
// Vector<Integer> seenIds = new Vector<Integer>();
// int userIdRank = 0;
// for (String userId : new IterableIterator<String>(key.getUserIDs())) {
// seenIds.add(saveUserId(rowId, userId, userIdRank));
// ++userIdRank;
// }
//
// String seenIdsStr = "";
// for (Integer id : seenIds) {
// if (seenIdsStr.length() > 0) {
// seenIdsStr += ",";
// }
// seenIdsStr += id;
// }
// mDb.delete(UserIds.TABLE_NAME,
// UserIds.KEY_ID + " = ? AND " +
// UserIds._ID + " NOT IN (" + seenIdsStr + ")",
// new String[] { "" + rowId });
//
// return (int)rowId;
// }
//
// private int saveUserId(long keyId, String userId, int rank) throws GeneralException {
// ContentValues values = new ContentValues();
//
// values.put(UserIds.KEY_ID, keyId);
// values.put(UserIds.USER_ID, userId);
// values.put(UserIds.RANK, rank);
//
// long rowId = insertOrUpdateUserId(values);
//
// if (rowId == -1) {
// throw new GeneralException("saving user id " + userId + " failed");
// }
//
// return (int)rowId;
// }
//
// private long insertOrUpdateKeyRing(ContentValues values) {
// Cursor c = mDb.query(KeyRings.TABLE_NAME, new String[] { KeyRings._ID },
// KeyRings.MASTER_KEY_ID + " = ? AND " + KeyRings.TYPE + " = ?",
// new String[] {
// values.getAsString(KeyRings.MASTER_KEY_ID),
// values.getAsString(KeyRings.TYPE),
// },
// null, null, null);
// long rowId = -1;
// if (c != null && c.moveToFirst()) {
// rowId = c.getLong(0);
// mDb.update(KeyRings.TABLE_NAME, values,
// KeyRings._ID + " = ?", new String[] { "" + rowId });
// mStatus = Id.return_value.updated;
// } else {
// rowId = mDb.insert(KeyRings.TABLE_NAME, KeyRings.WHO_ID, values);
// mStatus = Id.return_value.ok;
// }
//
// if (c != null) {
// c.close();
// }
//
// return rowId;
// }
//
// private long insertOrUpdateKey(ContentValues values) {
// Cursor c = mDb.query(Keys.TABLE_NAME, new String[] { Keys._ID },
// Keys.KEY_ID + " = ? AND " + Keys.TYPE + " = ?",
// new String[] {
// values.getAsString(Keys.KEY_ID),
// values.getAsString(Keys.TYPE),
// },
// null, null, null);
// long rowId = -1;
// if (c != null && c.moveToFirst()) {
// rowId = c.getLong(0);
// mDb.update(Keys.TABLE_NAME, values,
// Keys._ID + " = ?", new String[] { "" + rowId });
// } else {
// rowId = mDb.insert(Keys.TABLE_NAME, Keys.KEY_DATA, values);
// }
//
// if (c != null) {
// c.close();
// }
//
// return rowId;
// }
//
// private long insertOrUpdateUserId(ContentValues values) {
// Cursor c = mDb.query(UserIds.TABLE_NAME, new String[] { UserIds._ID },
// UserIds.KEY_ID + " = ? AND " + UserIds.USER_ID + " = ?",
// new String[] {
// values.getAsString(UserIds.KEY_ID),
// values.getAsString(UserIds.USER_ID),
// },
// null, null, null);
// long rowId = -1;
// if (c != null && c.moveToFirst()) {
// rowId = c.getLong(0);
// mDb.update(UserIds.TABLE_NAME, values,
// UserIds._ID + " = ?", new String[] { "" + rowId });
// } else {
// rowId = mDb.insert(UserIds.TABLE_NAME, UserIds.USER_ID, values);
// }
//
// if (c != null) {
// c.close();
// }
//
// return rowId;
// }
//
// public Object getKeyRing(int keyRingId) {
// Cursor c = mDb.query(KeyRings.TABLE_NAME,
// new String[] { KeyRings.KEY_RING_DATA, KeyRings.TYPE },
// KeyRings._ID + " = ?",
// new String[] {
// "" + keyRingId,
// },
// null, null, null);
// byte[] data = null;
// Object keyRing = null;
// if (c != null && c.moveToFirst()) {
// data = c.getBlob(0);
// if (data != null) {
// try {
// if (c.getInt(1) == Id.database.type_public) {
// keyRing = new PGPPublicKeyRing(data);
// } else {
// keyRing = new PGPSecretKeyRing(data);
// }
// } catch (IOException e) {
// // can't load it, then
// } catch (PGPException e) {
// // can't load it, then
// }
// }
// }
//
// if (c != null) {
// c.close();
// }
//
// return keyRing;
// }
//
// public byte[] getKeyRingDataFromKeyId(int type, long keyId) {
// Cursor c = mDb.query(Keys.TABLE_NAME + " INNER JOIN " + KeyRings.TABLE_NAME + " ON (" +
// KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " +
// Keys.TABLE_NAME + "." + Keys.KEY_RING_ID + ")",
// new String[] { KeyRings.TABLE_NAME + "." + KeyRings.KEY_RING_DATA },
// Keys.TABLE_NAME + "." + Keys.KEY_ID + " = ? AND " +
// KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?",
// new String[] {
// "" + keyId,
// "" + type,
// },
// null, null, null);
//
// byte[] data = null;
// if (c != null && c.moveToFirst()) {
// data = c.getBlob(0);
// }
//
// if (c != null) {
// c.close();
// }
//
// return data;
// }
//
// public byte[] getKeyDataFromKeyId(int type, long keyId) {
// Cursor c = mDb.query(Keys.TABLE_NAME, new String[] { Keys.KEY_DATA },
// Keys.KEY_ID + " = ? AND " + Keys.TYPE + " = ?",
// new String[] {
// "" + keyId,
// "" + type,
// },
// null, null, null);
// byte[] data = null;
// if (c != null && c.moveToFirst()) {
// data = c.getBlob(0);
// }
//
// if (c != null) {
// c.close();
// }
//
// return data;
// }
//
//// public void deleteKeyRing(int keyRingId) {
//// mDb.beginTransaction();
//// mDb.delete(KeyRings.TABLE_NAME,
//// KeyRings._ID + " = ?", new String[] { "" + keyRingId });
////
//// Cursor c = mDb.query(Keys.TABLE_NAME, new String[] { Keys._ID },
//// Keys.KEY_RING_ID + " = ?",
//// new String[] {
//// "" + keyRingId,
//// },
//// null, null, null);
//// if (c != null && c.moveToFirst()) {
//// do {
//// int keyId = c.getInt(0);
//// deleteKey(keyId);
//// } while (c.moveToNext());
//// }
////
//// if (c != null) {
//// c.close();
//// }
////
//// mDb.setTransactionSuccessful();
//// mDb.endTransaction();
//// }
////
//// private void deleteKey(int keyId) {
//// mDb.delete(Keys.TABLE_NAME,
//// Keys._ID + " = ?", new String[] { "" + keyId });
////
//// mDb.delete(UserIds.TABLE_NAME,
//// UserIds.KEY_ID + " = ?", new String[] { "" + keyId });
//// }
////
//// public SQLiteDatabase db() {
//// return mDb;
//// }
//}

View File

@ -1,767 +0,0 @@
///*
// * Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
// * 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.deprecated;
//
//import org.thialfihar.android.apg.Constants;
//import org.thialfihar.android.apg.Id;
//import org.thialfihar.android.apg.helper.OtherHelper;
//import org.thialfihar.android.apg.helper.PGPHelper;
//import org.thialfihar.android.apg.helper.PGPMain;
//import org.thialfihar.android.apg.provider.KeyRings;
//import org.thialfihar.android.apg.provider.Keys;
//import org.thialfihar.android.apg.provider.UserIds;
//import org.thialfihar.android.apg.service.ApgServiceHandler;
//import org.thialfihar.android.apg.service.ApgService;
//import org.thialfihar.android.apg.ui.dialog.DeleteFileDialogFragment;
//import org.thialfihar.android.apg.ui.dialog.DeleteKeyDialogFragment;
//import org.thialfihar.android.apg.ui.dialog.FileDialogFragment;
//import org.thialfihar.android.apg.R;
//
//import com.actionbarsherlock.app.SherlockFragmentActivity;
//import com.actionbarsherlock.view.MenuItem;
//
//import android.app.AlertDialog;
//import android.app.ProgressDialog;
//import android.app.SearchManager;
//import android.content.Context;
//import android.content.DialogInterface;
//import android.content.Intent;
//import android.database.Cursor;
//import android.database.sqlite.SQLiteDatabase;
//import android.database.sqlite.SQLiteQueryBuilder;
//import android.os.Bundle;
//import android.os.Handler;
//import android.os.Message;
//import android.os.Messenger;
//import org.thialfihar.android.apg.util.Log;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.view.ViewGroup;
//import android.widget.BaseExpandableListAdapter;
//import android.widget.Button;
//import android.widget.ExpandableListView;
//import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
//import android.widget.ImageView;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import java.util.Vector;
//
//public class KeyListActivity extends SherlockFragmentActivity {
//
// public static final String ACTION_IMPORT = Constants.INTENT_PREFIX + "IMPORT";
//
// public static final String EXTRA_TEXT = "text";
//
// protected ExpandableListView mList;
// protected KeyListAdapter mListAdapter;
// protected View mFilterLayout;
// protected Button mClearFilterButton;
// protected TextView mFilterInfo;
//
// protected int mSelectedItem = -1;
// protected int mTask = 0;
//
// protected String mImportFilename = Constants.path.APP_DIR + "/";
// protected String mExportFilename = Constants.path.APP_DIR + "/";
//
// protected String mImportData;
// protected boolean mDeleteAfterImport = false;
//
// protected int mKeyType = Id.type.public_key;
//
// FileDialogFragment mFileDialog;
//
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.key_list);
//
// // set actionbar without home button if called from another app
// OtherHelper.setActionBarBackButton(this);
//
// setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
//
// mList = (ExpandableListView) findViewById(R.id.list);
// registerForContextMenu(mList);
//
// mFilterLayout = findViewById(R.id.layout_filter);
// mFilterInfo = (TextView) mFilterLayout.findViewById(R.id.filterInfo);
// mClearFilterButton = (Button) mFilterLayout.findViewById(R.id.btn_clear);
//
// mClearFilterButton.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// handleIntent(new Intent());
// }
// });
//
// handleIntent(getIntent());
// }
//
// @Override
// protected void onNewIntent(Intent intent) {
// super.onNewIntent(intent);
// handleIntent(intent);
// }
//
// protected void handleIntent(Intent intent) {
// String searchString = null;
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// searchString = intent.getStringExtra(SearchManager.QUERY);
// if (searchString != null && searchString.trim().length() == 0) {
// searchString = null;
// }
// }
//
// if (searchString == null) {
// mFilterLayout.setVisibility(View.GONE);
// } else {
// mFilterLayout.setVisibility(View.VISIBLE);
// mFilterInfo.setText(getString(R.string.filterInfo, searchString));
// }
//
// if (mListAdapter != null) {
// mListAdapter.cleanup();
// }
// mListAdapter = new KeyListAdapter(this, searchString);
// mList.setAdapter(mListAdapter);
//
// // Get intent, action
// // Intent intent = getIntent();
// String action = intent.getAction();
//
// if (Intent.ACTION_VIEW.equals(action)) {
// // Android's Action when opening file associated to APG (see AndroidManifest.xml)
//
// handleActionImport(intent);
// } else if (ACTION_IMPORT.equals(action)) {
// // APG's own Actions
//
// handleActionImport(intent);
// }
// }
//
// /**
// * Handles import action
// *
// * @param intent
// */
// private void handleActionImport(Intent intent) {
// if ("file".equals(intent.getScheme()) && intent.getDataString() != null) {
// mImportFilename = intent.getData().getPath();
// } else {
// mImportData = intent.getStringExtra(EXTRA_TEXT);
// }
// importKeys();
// }
//
// @Override
// public boolean onOptionsItemSelected(MenuItem item) {
// switch (item.getItemId()) {
//
// case android.R.id.home:
// // app icon in Action Bar clicked; go home
// Intent intent = new Intent(this, MainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(intent);
// return true;
//
// case Id.menu.option.import_keys: {
// showImportKeysDialog();
// return true;
// }
//
// case Id.menu.option.export_keys: {
// showExportKeysDialog(false);
// return true;
// }
//
// case Id.menu.option.search:
// startSearch("", false, null, false);
// return true;
//
// default: {
// return super.onOptionsItemSelected(item);
// }
// }
// }
//
// private void showImportKeysDialog() {
// // Message is received after file is selected
// Handler returnHandler = new Handler() {
// @Override
// public void handleMessage(Message message) {
// if (message.what == FileDialogFragment.MESSAGE_OKAY) {
// Bundle data = message.getData();
// mImportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
//
// mDeleteAfterImport = data.getBoolean(FileDialogFragment.MESSAGE_DATA_CHECKED);
// importKeys();
// }
// }
// };
//
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(returnHandler);
//
// mFileDialog = FileDialogFragment.newInstance(messenger,
// getString(R.string.title_importKeys), getString(R.string.specifyFileToImportFrom),
// mImportFilename, null, Id.request.filename);
//
// mFileDialog.show(getSupportFragmentManager(), "fileDialog");
// }
//
// private void showExportKeysDialog(boolean singleKeyExport) {
// String title = (singleKeyExport ? getString(R.string.title_exportKey)
// : getString(R.string.title_exportKeys));
// String message = getString(mKeyType == Id.type.public_key ? R.string.specifyFileToExportTo
// : R.string.specifyFileToExportSecretKeysTo);
//
// // Message is received after file is selected
// Handler returnHandler = new Handler() {
// @Override
// public void handleMessage(Message message) {
// if (message.what == FileDialogFragment.MESSAGE_OKAY) {
// Bundle data = message.getData();
// mExportFilename = data.getString(FileDialogFragment.MESSAGE_DATA_FILENAME);
//
// exportKeys();
// }
// }
// };
//
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(returnHandler);
//
// mFileDialog = FileDialogFragment.newInstance(messenger, title, message, mExportFilename,
// null, Id.request.filename);
//
// mFileDialog.show(getSupportFragmentManager(), "fileDialog");
// }
//
// @Override
// public boolean onContextItemSelected(android.view.MenuItem menuItem) {
// ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();
// int type = ExpandableListView.getPackedPositionType(info.packedPosition);
// int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
//
// if (type != ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
// return super.onContextItemSelected(menuItem);
// }
//
// switch (menuItem.getItemId()) {
// case Id.menu.export: {
// mSelectedItem = groupPosition;
// showExportKeysDialog(true);
// return true;
// }
//
// case Id.menu.delete: {
// mSelectedItem = groupPosition;
// showDeleteKeyDialog();
// return true;
// }
//
// default: {
// return super.onContextItemSelected(menuItem);
// }
// }
// }
//
// private void showDeleteKeyDialog() {
// final int keyRingId = mListAdapter.getKeyRingId(mSelectedItem);
// mSelectedItem = -1;
//
// // Message is received after key is deleted
// Handler returnHandler = new Handler() {
// @Override
// public void handleMessage(Message message) {
// if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
// refreshList();
// }
// }
// };
//
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(returnHandler);
//
// DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger,
// keyRingId, mKeyType);
//
// deleteKeyDialog.show(getSupportFragmentManager(), "deleteKeyDialog");
// }
//
// public void importKeys() {
// Log.d(Constants.TAG, "importKeys started");
//
// // Send all information needed to service to import key in other thread
// Intent intent = new Intent(this, ApgService.class);
//
// intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_IMPORT_KEY);
//
// // fill values for this action
// Bundle data = new Bundle();
//
// data.putInt(ApgService.IMPORT_KEY_TYPE, mKeyType);
//
// if (mImportData != null) {
// data.putInt(ApgService.TARGET, ApgService.TARGET_BYTES);
// data.putByteArray(ApgService.IMPORT_BYTES, mImportData.getBytes());
// } else {
// data.putInt(ApgService.TARGET, ApgService.TARGET_FILE);
// data.putString(ApgService.IMPORT_FILENAME, mImportFilename);
// }
//
// intent.putExtra(ApgService.EXTRA_DATA, data);
//
// // Message is received after importing is done in ApgService
// ApgServiceHandler saveHandler = new ApgServiceHandler(this, R.string.progress_importing,
// ProgressDialog.STYLE_HORIZONTAL) {
// public void handleMessage(Message message) {
// // handle messages by standard ApgHandler first
// super.handleMessage(message);
//
// if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
// // get returned data bundle
// Bundle returnData = message.getData();
//
// int added = returnData.getInt(ApgService.RESULT_IMPORT_ADDED);
// int updated = returnData.getInt(ApgService.RESULT_IMPORT_UPDATED);
// int bad = returnData.getInt(ApgService.RESULT_IMPORT_BAD);
// String toastMessage;
// if (added > 0 && updated > 0) {
// toastMessage = getString(R.string.keysAddedAndUpdated, added, updated);
// } else if (added > 0) {
// toastMessage = getString(R.string.keysAdded, added);
// } else if (updated > 0) {
// toastMessage = getString(R.string.keysUpdated, updated);
// } else {
// toastMessage = getString(R.string.noKeysAddedOrUpdated);
// }
// Toast.makeText(KeyListActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
// if (bad > 0) {
// AlertDialog.Builder alert = new AlertDialog.Builder(KeyListActivity.this);
//
// alert.setIcon(android.R.drawable.ic_dialog_alert);
// alert.setTitle(R.string.warning);
// alert.setMessage(KeyListActivity.this.getString(
// R.string.badKeysEncountered, bad));
//
// alert.setPositiveButton(android.R.string.ok,
// new DialogInterface.OnClickListener() {
// public void onClick(DialogInterface dialog, int id) {
// dialog.cancel();
// }
// });
// alert.setCancelable(true);
// alert.create().show();
// } else if (mDeleteAfterImport) {
// // everything went well, so now delete, if that was turned on
// DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
// .newInstance(mImportFilename);
// deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
// }
// refreshList();
//
// }
// };
// };
//
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(saveHandler);
// intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
//
// // show progress dialog
// saveHandler.showProgressDialog(this);
//
// // start service with intent
// startService(intent);
// }
//
// public void exportKeys() {
// Log.d(Constants.TAG, "exportKeys started");
//
// // Send all information needed to service to export key in other thread
// Intent intent = new Intent(this, ApgService.class);
//
// intent.putExtra(ApgService.EXTRA_ACTION, ApgService.ACTION_EXPORT_KEY);
//
// // fill values for this action
// Bundle data = new Bundle();
//
// data.putString(ApgService.EXPORT_FILENAME, mExportFilename);
// data.putInt(ApgService.EXPORT_KEY_TYPE, mKeyType);
//
// if (mSelectedItem == -1) {
// data.putBoolean(ApgService.EXPORT_ALL, true);
// } else {
// int keyRingId = mListAdapter.getKeyRingId(mSelectedItem);
// data.putInt(ApgService.EXPORT_KEY_RING_ID, keyRingId);
// mSelectedItem = -1;
// }
//
// intent.putExtra(ApgService.EXTRA_DATA, data);
//
// // Message is received after exporting is done in ApgService
// ApgServiceHandler exportHandler = new ApgServiceHandler(this, R.string.progress_exporting,
// ProgressDialog.STYLE_HORIZONTAL) {
// public void handleMessage(Message message) {
// // handle messages by standard ApgHandler first
// super.handleMessage(message);
//
// if (message.arg1 == ApgServiceHandler.MESSAGE_OKAY) {
// // get returned data bundle
// Bundle returnData = message.getData();
//
// int exported = returnData.getInt(ApgService.RESULT_EXPORT);
// String toastMessage;
// if (exported == 1) {
// toastMessage = getString(R.string.keyExported);
// } else if (exported > 0) {
// toastMessage = getString(R.string.keysExported, exported);
// } else {
// toastMessage = getString(R.string.noKeysExported);
// }
// Toast.makeText(KeyListActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
//
// }
// };
// };
//
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(exportHandler);
// intent.putExtra(ApgService.EXTRA_MESSENGER, messenger);
//
// // show progress dialog
// exportHandler.showProgressDialog(this);
//
// // start service with intent
// startService(intent);
// }
//
// protected void refreshList() {
// mListAdapter.rebuild(true);
// mListAdapter.notifyDataSetChanged();
// }
//
// protected class KeyListAdapter extends BaseExpandableListAdapter {
// private LayoutInflater mInflater;
// private Vector<Vector<KeyChild>> mChildren;
// private SQLiteDatabase mDatabase;
// private Cursor mCursor;
// private String mSearchString;
//
// private class KeyChild {
// public static final int KEY = 0;
// public static final int USER_ID = 1;
// public static final int FINGER_PRINT = 2;
//
// public int type;
// public String userId;
// public long keyId;
// public boolean isMasterKey;
// public int algorithm;
// public int keySize;
// public boolean canSign;
// public boolean canEncrypt;
// public String fingerPrint;
//
// public KeyChild(long keyId, boolean isMasterKey, int algorithm, int keySize,
// boolean canSign, boolean canEncrypt) {
// this.type = KEY;
// this.keyId = keyId;
// this.isMasterKey = isMasterKey;
// this.algorithm = algorithm;
// this.keySize = keySize;
// this.canSign = canSign;
// this.canEncrypt = canEncrypt;
// }
//
// public KeyChild(String userId) {
// type = USER_ID;
// this.userId = userId;
// }
//
// public KeyChild(String fingerPrint, boolean isFingerPrint) {
// type = FINGER_PRINT;
// this.fingerPrint = fingerPrint;
// }
// }
//
// public KeyListAdapter(Context context, String searchString) {
// mSearchString = searchString;
//
// mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// mDatabase = PGPMain.getDatabase().db();
// SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
// qb.setTables(KeyRings.TABLE_NAME + " INNER JOIN " + Keys.TABLE_NAME + " ON " + "("
// + KeyRings.TABLE_NAME + "." + KeyRings._ID + " = " + Keys.TABLE_NAME + "."
// + Keys.KEY_RING_ID + " AND " + Keys.TABLE_NAME + "." + Keys.IS_MASTER_KEY
// + " = '1'" + ") " + " INNER JOIN " + UserIds.TABLE_NAME + " ON " + "("
// + Keys.TABLE_NAME + "." + Keys._ID + " = " + UserIds.TABLE_NAME + "."
// + UserIds.KEY_ID + " AND " + UserIds.TABLE_NAME + "." + UserIds.RANK
// + " = '0')");
//
// if (searchString != null && searchString.trim().length() > 0) {
// String[] chunks = searchString.trim().split(" +");
// qb.appendWhere("EXISTS (SELECT tmp." + UserIds._ID + " FROM " + UserIds.TABLE_NAME
// + " AS tmp WHERE " + "tmp." + UserIds.KEY_ID + " = " + Keys.TABLE_NAME
// + "." + Keys._ID);
// for (int i = 0; i < chunks.length; ++i) {
// qb.appendWhere(" AND tmp." + UserIds.USER_ID + " LIKE ");
// qb.appendWhereEscapeString("%" + chunks[i] + "%");
// }
// qb.appendWhere(")");
// }
//
// mCursor = qb.query(mDatabase, new String[] { KeyRings.TABLE_NAME + "." + KeyRings._ID, // 0
// KeyRings.TABLE_NAME + "." + KeyRings.MASTER_KEY_ID, // 1
// UserIds.TABLE_NAME + "." + UserIds.USER_ID, // 2
// }, KeyRings.TABLE_NAME + "." + KeyRings.TYPE + " = ?", new String[] { ""
// + (mKeyType == Id.type.public_key ? Id.database.type_public
// : Id.database.type_secret) }, null, null, UserIds.TABLE_NAME + "."
// + UserIds.USER_ID + " ASC");
//
// // content provider way for reference, might have to go back to it sometime:
// /*
// * Uri contentUri = null; if (mKeyType == Id.type.secret_key) { contentUri =
// * Apg.CONTENT_URI_SECRET_KEY_RINGS; } else { contentUri =
// * Apg.CONTENT_URI_PUBLIC_KEY_RINGS; } mCursor = getContentResolver().query( contentUri,
// * new String[] { DataProvider._ID, // 0 DataProvider.MASTER_KEY_ID, // 1
// * DataProvider.USER_ID, // 2 }, null, null, null);
// */
//
// startManagingCursor(mCursor);
// rebuild(false);
// }
//
// public void cleanup() {
// if (mCursor != null) {
// stopManagingCursor(mCursor);
// mCursor.close();
// }
// }
//
// public void rebuild(boolean requery) {
// if (requery) {
// mCursor.requery();
// }
// mChildren = new Vector<Vector<KeyChild>>();
// for (int i = 0; i < mCursor.getCount(); ++i) {
// mChildren.add(null);
// }
// }
//
// protected Vector<KeyChild> getChildrenOfGroup(int groupPosition) {
// Vector<KeyChild> children = mChildren.get(groupPosition);
// if (children != null) {
// return children;
// }
//
// mCursor.moveToPosition(groupPosition);
// children = new Vector<KeyChild>();
// Cursor c = mDatabase.query(Keys.TABLE_NAME, new String[] { Keys._ID, // 0
// Keys.KEY_ID, // 1
// Keys.IS_MASTER_KEY, // 2
// Keys.ALGORITHM, // 3
// Keys.KEY_SIZE, // 4
// Keys.CAN_SIGN, // 5
// Keys.CAN_ENCRYPT, // 6
// }, Keys.KEY_RING_ID + " = ?", new String[] { mCursor.getString(0) }, null, null,
// Keys.RANK + " ASC");
//
// int masterKeyId = -1;
// long fingerPrintId = -1;
// for (int i = 0; i < c.getCount(); ++i) {
// c.moveToPosition(i);
// children.add(new KeyChild(c.getLong(1), c.getInt(2) == 1, c.getInt(3), c.getInt(4),
// c.getInt(5) == 1, c.getInt(6) == 1));
// if (i == 0) {
// masterKeyId = c.getInt(0);
// fingerPrintId = c.getLong(1);
// }
// }
// c.close();
//
// if (masterKeyId != -1) {
// children.insertElementAt(
// new KeyChild(PGPHelper.getFingerPrint(KeyListActivity.this, fingerPrintId), true), 0);
// c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
// }, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
// + masterKeyId }, null, null, UserIds.RANK + " ASC");
//
// for (int i = 0; i < c.getCount(); ++i) {
// c.moveToPosition(i);
// children.add(new KeyChild(c.getString(0)));
// }
// c.close();
// }
//
// mChildren.set(groupPosition, children);
// return children;
// }
//
// public boolean hasStableIds() {
// return true;
// }
//
// public boolean isChildSelectable(int groupPosition, int childPosition) {
// return true;
// }
//
// public int getGroupCount() {
// return mCursor.getCount();
// }
//
// public Object getChild(int groupPosition, int childPosition) {
// return null;
// }
//
// public long getChildId(int groupPosition, int childPosition) {
// return childPosition;
// }
//
// public int getChildrenCount(int groupPosition) {
// return getChildrenOfGroup(groupPosition).size();
// }
//
// public Object getGroup(int position) {
// return position;
// }
//
// public long getGroupId(int position) {
// mCursor.moveToPosition(position);
// return mCursor.getLong(1); // MASTER_KEY_ID
// }
//
// public int getKeyRingId(int position) {
// mCursor.moveToPosition(position);
// return mCursor.getInt(0); // _ID
// }
//
// public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
// ViewGroup parent) {
// mCursor.moveToPosition(groupPosition);
//
// View view = mInflater.inflate(R.layout.key_list_group_item, null);
// view.setBackgroundResource(android.R.drawable.list_selector_background);
//
// TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
// mainUserId.setText("");
// TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest);
// mainUserIdRest.setText("");
//
// String userId = mCursor.getString(2); // USER_ID
// if (userId != null) {
// String chunks[] = userId.split(" <", 2);
// userId = chunks[0];
// if (chunks.length > 1) {
// mainUserIdRest.setText("<" + chunks[1]);
// }
// mainUserId.setText(userId);
// }
//
// if (mainUserId.getText().length() == 0) {
// mainUserId.setText(R.string.unknownUserId);
// }
//
// if (mainUserIdRest.getText().length() == 0) {
// mainUserIdRest.setVisibility(View.GONE);
// }
// return view;
// }
//
// public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
// View convertView, ViewGroup parent) {
// mCursor.moveToPosition(groupPosition);
//
// Vector<KeyChild> children = getChildrenOfGroup(groupPosition);
//
// KeyChild child = children.get(childPosition);
// View view = null;
// switch (child.type) {
// case KeyChild.KEY: {
// if (child.isMasterKey) {
// view = mInflater.inflate(R.layout.key_list_child_item_master_key, null);
// } else {
// view = mInflater.inflate(R.layout.key_list_child_item_sub_key, null);
// }
//
// TextView keyId = (TextView) view.findViewById(R.id.keyId);
// String keyIdStr = PGPHelper.getSmallFingerPrint(child.keyId);
// keyId.setText(keyIdStr);
// TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
// String algorithmStr = PGPHelper.getAlgorithmInfo(child.algorithm, child.keySize);
// keyDetails.setText("(" + algorithmStr + ")");
//
// ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
// if (!child.canEncrypt) {
// encryptIcon.setVisibility(View.GONE);
// }
//
// ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey);
// if (!child.canSign) {
// signIcon.setVisibility(View.GONE);
// }
// break;
// }
//
// case KeyChild.USER_ID: {
// view = mInflater.inflate(R.layout.key_list_child_item_user_id, null);
// TextView userId = (TextView) view.findViewById(R.id.userId);
// userId.setText(child.userId);
// break;
// }
//
// case KeyChild.FINGER_PRINT: {
// view = mInflater.inflate(R.layout.key_list_child_item_user_id, null);
// TextView userId = (TextView) view.findViewById(R.id.userId);
// userId.setText(getString(R.string.fingerprint) + ":\n"
// + child.fingerPrint.replace(" ", "\n"));
// break;
// }
// }
// return view;
// }
// }
//
// @Override
// protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// switch (requestCode) {
// case Id.request.filename: {
// if (resultCode == RESULT_OK && data != null) {
// try {
// String path = data.getData().getPath();
// Log.d(Constants.TAG, "path=" + path);
//
// mFileDialog.setFilename(path);
// } catch (NullPointerException e) {
// Log.e(Constants.TAG, "Nullpointer while retrieving path!", e);
// }
// }
// return;
// }
//
// default: {
// break;
// }
// }
// super.onActivityResult(requestCode, resultCode, data);
// }
//}

View File

@ -38,7 +38,6 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.google.zxing.integration.android.IntentIntegrator;