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

View File

@ -20,12 +20,15 @@ package org.sufficientlysecure.keychain.ui;
import org.spongycastle.openpgp.PGPPublicKeyRing; import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds; 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.ui.adapter.KeyListAdapter;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import android.content.ContentUris;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -116,7 +119,8 @@ public class KeyListPublicFragment extends KeyListFragment implements
case 23: case 23:
Intent detailsIntent = new Intent(mKeyListActivity, KeyDetailsActivity.class); Intent detailsIntent = new Intent(mKeyListActivity, KeyDetailsActivity.class);
detailsIntent.putExtra("key", ProviderHelper.getPublicMasterKeyId(mKeyListActivity, keyRingRowId)); detailsIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsUri(Long
.toString(keyRingRowId)));
startActivity(detailsIntent); startActivity(detailsIntent);
return true; return true;