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();
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); private void loadData(Uri dataUri) {
fingerprint.setText(PgpKeyHelper.shortifyFingerprint(PgpKeyHelper.getFingerPrint( PGPPublicKeyRing ring = (PGPPublicKeyRing) ProviderHelper.getPGPKeyRing(this, dataUri);
getApplicationContext(), key))); mPublicKey = ring.getPublicKey();
mFingerint.setText(PgpKeyHelper.shortifyFingerprint(PgpKeyHelper
.convertFingerprintToHex(mPublicKey.getFingerprint())));
String[] mainUserId = splitUserId(""); String[] mainUserId = splitUserId("");
TextView expiry = (TextView) this.findViewById(R.id.expiry); Date expiryDate = PgpKeyHelper.getExpiryDate(mPublicKey);
Date expiryDate = PgpKeyHelper.getExpiryDate(publicKey);
if (expiryDate == null) { if (expiryDate == null) {
expiry.setText(""); mExpiry.setText("");
} else { } else {
expiry.setText(DateFormat.getDateFormat(getApplicationContext()).format(expiryDate)); mExpiry.setText(DateFormat.getDateFormat(getApplicationContext()).format(expiryDate));
} }
TextView creation = (TextView) this.findViewById(R.id.creation); mCreation.setText(DateFormat.getDateFormat(getApplicationContext()).format(
creation.setText(DateFormat.getDateFormat(getApplicationContext()).format( PgpKeyHelper.getCreationDate(mPublicKey)));
PgpKeyHelper.getCreationDate(publicKey))); mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(mPublicKey));
mAlgorithm = (TextView) this.findViewById(R.id.algorithm);
mAlgorithm.setText(PgpKeyHelper.getAlgorithmInfo(publicKey));
} }
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;
@ -114,16 +117,17 @@ public class KeyListPublicFragment extends KeyListFragment implements
return true; return true;
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
startActivity(detailsIntent); .toString(keyRingRowId)));
startActivity(detailsIntent);
return true; return true;
case Id.menu.exportToServer: case Id.menu.exportToServer:
Intent uploadIntent = new Intent(mKeyListActivity, KeyServerUploadActivity.class); Intent uploadIntent = new Intent(mKeyListActivity, KeyServerUploadActivity.class);
uploadIntent.setAction(KeyServerUploadActivity.ACTION_EXPORT_KEY_TO_SERVER); 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); startActivityForResult(uploadIntent, Id.request.export_to_server);
return true; return true;