Use data uri instead of extra for key details

This commit is contained in:
Dominik Schürmann 2014-01-01 16:54:55 +01:00
parent d45462bb33
commit 6c1a58ef15
3 changed files with 49 additions and 32 deletions

View File

@ -60,7 +60,7 @@ public class ProviderHelper {
* @param queryUri
* @return
*/
private static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
public static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
Cursor cursor = context.getContentResolver().query(queryUri,
new String[] { KeyRings._ID, KeyRings.KEY_RING_DATA }, null, null, null);

View File

@ -23,12 +23,15 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;
@ -36,49 +39,59 @@ import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
public class KeyDetailsActivity extends SherlockActivity {
private Uri mDataUri;
private PGPPublicKey mPublicKey;
private PGPPublicKey publicKey;
private TextView mAlgorithm;
private TextView mFingerint;
private TextView mExpiry;
private TextView mCreation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
setContentView(R.layout.key_view);
if (extras == null) {
return;
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
long key = extras.getLong("key");
setContentView(R.layout.key_view);
KeyRings.buildPublicKeyRingsByMasterKeyIdUri(key + "");
String[] projection = new String[] { "" };
mFingerint = (TextView) this.findViewById(R.id.fingerprint);
mExpiry = (TextView) this.findViewById(R.id.expiry);
mCreation = (TextView) this.findViewById(R.id.creation);
mAlgorithm = (TextView) this.findViewById(R.id.algorithm);
this.publicKey = ProviderHelper.getPGPPublicKeyByKeyId(getApplicationContext(), key);
Intent intent = getIntent();
mDataUri = intent.getData();
if (mDataUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!");
finish();
return;
} else {
Log.d(Constants.TAG, "uri: " + mDataUri);
loadData(mDataUri);
}
}
TextView fingerprint = (TextView) this.findViewById(R.id.fingerprint);
fingerprint.setText(PgpKeyHelper.shortifyFingerprint(PgpKeyHelper.getFingerPrint(
getApplicationContext(), key)));
private void loadData(Uri dataUri) {
PGPPublicKeyRing ring = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, dataUri);
mPublicKey = ring.getPublicKey();
mFingerint.setText(PgpKeyHelper.shortifyFingerprint(PgpKeyHelper
.convertFingerprintToHex(mPublicKey.getFingerprint())));
String[] mainUserId = splitUserId("");
TextView expiry = (TextView) this.findViewById(R.id.expiry);
Date expiryDate = PgpKeyHelper.getExpiryDate(publicKey);
Date expiryDate = PgpKeyHelper.getExpiryDate(mPublicKey);
if (expiryDate == null) {
expiry.setText("");
mExpiry.setText("");
} else {
expiry.setText(DateFormat.getDateFormat(getApplicationContext()).format(expiryDate));
mExpiry.setText(DateFormat.getDateFormat(getApplicationContext()).format(expiryDate));
}
TextView creation = (TextView) this.findViewById(R.id.creation);
creation.setText(DateFormat.getDateFormat(getApplicationContext()).format(
PgpKeyHelper.getCreationDate(publicKey)));
mAlgorithm = (TextView) this.findViewById(R.id.algorithm);
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(publicKey));
mCreation.setText(DateFormat.getDateFormat(getApplicationContext()).format(
PgpKeyHelper.getCreationDate(mPublicKey)));
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(mPublicKey));
}
private String[] splitUserId(String userId) {

View File

@ -20,12 +20,15 @@ package org.sufficientlysecure.keychain.ui;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
import org.sufficientlysecure.keychain.service.remote.AppSettingsActivity;
import org.sufficientlysecure.keychain.ui.adapter.KeyListAdapter;
import org.sufficientlysecure.keychain.R;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
@ -114,16 +117,17 @@ public class KeyListPublicFragment extends KeyListFragment implements
return true;
case 23:
Intent detailsIntent = new Intent(mKeyListActivity, KeyDetailsActivity.class);
detailsIntent.putExtra("key", ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId));
startActivity(detailsIntent);
Intent detailsIntent = new Intent(mKeyListActivity, KeyDetailsActivity.class);
detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long
.toString(keyRingRowId)));
startActivity(detailsIntent);
return true;
case Id.menu.exportToServer:
Intent uploadIntent = new Intent(mKeyListActivity, KeyServerUploadActivity.class);
uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER);
uploadIntent.putExtra(KeyServerUploadActivity.EXTRA_KEYRING_ROW_ID, (int)keyRingRowId);
uploadIntent.putExtra(KeyServerUploadActivity.EXTRA_KEYRING_ROW_ID, (int) keyRingRowId);
startActivityForResult(uploadIntent, Id.request.export_to_server);
return true;