mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 03:02:15 -05:00
fix crash on keys with empty user id
This commit is contained in:
parent
b2e8cc6757
commit
7183c4ab06
@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
||||
import java.util.List;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
@ -52,7 +53,7 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
clear();
|
||||
if (data != null) {
|
||||
this.data = data;
|
||||
|
||||
|
||||
// add data to extended ArrayAdapter
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
addAll(data);
|
||||
@ -92,25 +93,30 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
||||
|
||||
String userId = entry.userIds.get(0);
|
||||
if (userId != null) {
|
||||
String chunks[] = userId.split(" <", 2);
|
||||
userId = chunks[0];
|
||||
if (chunks.length > 1) {
|
||||
mainUserIdRest.setText("<" + chunks[1]);
|
||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||
|
||||
if (userIdSplit[0] != null && userIdSplit[0].length() > 0) {
|
||||
// show red user id if it is a secret key
|
||||
if (entry.secretKey) {
|
||||
userId = mActivity.getString(R.string.secret_key) + " " + userId;
|
||||
mainUserId.setTextColor(Color.RED);
|
||||
} else {
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
}
|
||||
if (entry.secretKey) {
|
||||
userId = mActivity.getString(R.string.secret_key) + " " + userId;
|
||||
mainUserId.setTextColor(Color.RED);
|
||||
|
||||
if (userIdSplit[1] != null && userIdSplit[1].length() > 0) {
|
||||
mainUserIdRest.setText(userIdSplit[1]);
|
||||
mainUserIdRest.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
}
|
||||
mainUserId.setText(userId);
|
||||
|
||||
}
|
||||
|
||||
keyId.setText(entry.hexKeyId);
|
||||
fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
||||
|
||||
if (entry.revoked) {
|
||||
|
@ -55,7 +55,7 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
mSectionColumnIndex = sectionColumnIndex;
|
||||
initIndex(c);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cursor swapCursor(Cursor newCursor) {
|
||||
initIndex(newCursor);
|
||||
@ -92,20 +92,13 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
if (userId != null) {
|
||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||
|
||||
if (userIdSplit[1] != null) {
|
||||
if (userIdSplit[0] != null && userIdSplit[0].length() > 0) {
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
if (userIdSplit[1] != null && userIdSplit[1].length() > 0) {
|
||||
mainUserIdRest.setText(userIdSplit[1]);
|
||||
}
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
if (mainUserId.getText().length() == 0) {
|
||||
mainUserId.setText(R.string.unknown_user_id);
|
||||
}
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
} else {
|
||||
mainUserIdRest.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +137,11 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
}
|
||||
|
||||
// set header text as first char in user id
|
||||
String headerText = "" + mCursor.getString(mSectionColumnIndex).subSequence(0, 1).charAt(0);
|
||||
String userId = mCursor.getString(mSectionColumnIndex);
|
||||
String headerText = convertView.getResources().getString(R.string.unknown_user_id);
|
||||
if (userId != null && userId.length() > 0) {
|
||||
headerText = "" + mCursor.getString(mSectionColumnIndex).subSequence(0, 1).charAt(0);
|
||||
}
|
||||
holder.text.setText(headerText);
|
||||
return convertView;
|
||||
}
|
||||
@ -167,7 +164,12 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
||||
// return the first character of the name as ID because this is what
|
||||
// headers private HashMap<Integer, Boolean> mSelection = new HashMap<Integer,
|
||||
// Boolean>();are based upon
|
||||
return mCursor.getString(mSectionColumnIndex).subSequence(0, 1).charAt(0);
|
||||
String userId = mCursor.getString(mSectionColumnIndex);
|
||||
if (userId != null && userId.length() > 0) {
|
||||
return userId.subSequence(0, 1).charAt(0);
|
||||
} else {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
class HeaderViewHolder {
|
||||
|
@ -79,20 +79,13 @@ public class KeyListSecretAdapter extends CursorAdapter {
|
||||
if (userId != null) {
|
||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||
|
||||
if (userIdSplit[1] != null) {
|
||||
if (userIdSplit[0] != null && userIdSplit[0].length() > 0) {
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
if (userIdSplit[1] != null && userIdSplit[1].length() > 0) {
|
||||
mainUserIdRest.setText(userIdSplit[1]);
|
||||
}
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
if (mainUserId.getText().length() == 0) {
|
||||
mainUserId.setText(R.string.unknown_user_id);
|
||||
}
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
} else {
|
||||
mainUserIdRest.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,19 +108,18 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
|
||||
if (userId != null) {
|
||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||
|
||||
if (userIdSplit[1] != null) {
|
||||
if (userIdSplit[0] != null && userIdSplit[0].length() > 0) {
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
if (userIdSplit[1] != null && userIdSplit[1].length() > 0) {
|
||||
mainUserIdRest.setText(userIdSplit[1]);
|
||||
}
|
||||
mainUserId.setText(userIdSplit[0]);
|
||||
}
|
||||
|
||||
long masterKeyId = cursor.getLong(mIndexMasterKeyId);
|
||||
keyId.setText(PgpKeyHelper.convertKeyIdToHex(masterKeyId));
|
||||
|
||||
if (mainUserIdRest.getText().length() == 0) {
|
||||
mainUserIdRest.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (valid) {
|
||||
if (mKeyType == Id.type.public_key) {
|
||||
status.setText(R.string.can_encrypt);
|
||||
|
Loading…
Reference in New Issue
Block a user