From 6c1a58ef15e6b5d826326fa9636e44cc6f501d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Wed, 1 Jan 2014 16:54:55 +0100 Subject: [PATCH] Use data uri instead of extra for key details --- .../keychain/provider/ProviderHelper.java | 2 +- .../keychain/ui/KeyDetailsActivity.java | 63 +++++++++++-------- .../keychain/ui/KeyListPublicFragment.java | 16 +++-- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/ProviderHelper.java index f12048277..b07ac53f8 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -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); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java index 82d66e2c0..5c8444d80 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyDetailsActivity.java @@ -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) { diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java index 790ec5ccf..0cf15a451 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/ui/KeyListPublicFragment.java @@ -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;