Normalize public key uri in KeyListFragment

Find the explicit row id of the public key id given in the uri in
KeyListFragment and work with that. This way, passing in uris by
master key id, mail address, or any other criteria, works.

Might be a good idea to add an actual check if the row id is non-zero
here, but not sure how to do a "bad intent" thing
This commit is contained in:
Vincent Breitmoser 2014-03-08 12:00:24 +01:00
parent 191c5b8130
commit aa8a8f069f
3 changed files with 29 additions and 6 deletions

View File

@ -514,6 +514,26 @@ public class ProviderHelper {
return masterKeyId;
}
public static long getRowId(Context context, Uri queryUri) {
String[] projection = new String[]{KeyRings._ID};
Cursor cursor = context.getContentResolver().query(queryUri, projection, null, null, null);
long rowId = 0;
try {
if (cursor != null && cursor.moveToFirst()) {
int idCol = cursor.getColumnIndexOrThrow(KeyRings._ID);
rowId = cursor.getLong(idCol);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
return rowId;
}
/**
* Get fingerprint of key
*/

View File

@ -285,11 +285,7 @@ public class KeyListFragment extends Fragment implements AdapterView.OnItemClick
} else {
viewIntent = new Intent(getActivity(), ViewKeyActivityJB.class);
}
if(mAdapter.getKeyType(position) == KeyTypes.SECRET) {
viewIntent.setData(KeychainContract.KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(mAdapter.getMasterKeyId(position))));
} else {
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(mAdapter.getMasterKeyId(position))));
}
viewIntent.setData(KeychainContract.KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(mAdapter.getMasterKeyId(position))));
startActivity(viewIntent);
}

View File

@ -36,6 +36,7 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.adapter.TabsAdapter;
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
@ -83,7 +84,13 @@ public class ViewKeyActivity extends ActionBarActivity {
selectedTab = intent.getExtras().getInt(EXTRA_SELECTED_TAB);
}
mDataUri = getIntent().getData();
{
// normalize mDataUri to a "by row id" query, to ensure it works with any
// given valid /public/ query
long rowId = ProviderHelper.getRowId(this, getIntent().getData());
// TODO: handle (rowId == 0) with something else than a crash
mDataUri = KeychainContract.KeyRings.buildPublicKeyRingsUri(Long.toString(rowId)) ;
}
Bundle mainBundle = new Bundle();
mainBundle.putParcelable(ViewKeyMainFragment.ARG_DATA_URI, mDataUri);