fix crash on keys with empty user id
This commit is contained in:
@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.ui.adapter;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -92,25 +93,30 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
|
|||||||
|
|
||||||
String userId = entry.userIds.get(0);
|
String userId = entry.userIds.get(0);
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
String chunks[] = userId.split(" <", 2);
|
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
||||||
userId = chunks[0];
|
|
||||||
if (chunks.length > 1) {
|
if (userIdSplit[0] != null && userIdSplit[0].length() > 0) {
|
||||||
mainUserIdRest.setText("<" + chunks[1]);
|
// 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;
|
if (userIdSplit[1] != null && userIdSplit[1].length() > 0) {
|
||||||
mainUserId.setTextColor(Color.RED);
|
mainUserIdRest.setText(userIdSplit[1]);
|
||||||
|
mainUserIdRest.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
mainUserIdRest.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
mainUserId.setText(userId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keyId.setText(entry.hexKeyId);
|
keyId.setText(entry.hexKeyId);
|
||||||
fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
|
fingerprint.setText(mActivity.getString(R.string.fingerprint) + " " + entry.fingerPrint);
|
||||||
|
|
||||||
if (mainUserIdRest.getText().length() == 0) {
|
|
||||||
mainUserIdRest.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
algorithm.setText("" + entry.bitStrength + "/" + entry.algorithm);
|
||||||
|
|
||||||
if (entry.revoked) {
|
if (entry.revoked) {
|
||||||
|
|||||||
@@ -92,20 +92,13 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
|
|||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
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]);
|
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
|
// 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);
|
holder.text.setText(headerText);
|
||||||
return convertView;
|
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
|
// return the first character of the name as ID because this is what
|
||||||
// headers private HashMap<Integer, Boolean> mSelection = new HashMap<Integer,
|
// headers private HashMap<Integer, Boolean> mSelection = new HashMap<Integer,
|
||||||
// Boolean>();are based upon
|
// 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 {
|
class HeaderViewHolder {
|
||||||
|
|||||||
@@ -79,20 +79,13 @@ public class KeyListSecretAdapter extends CursorAdapter {
|
|||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
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]);
|
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) {
|
if (userId != null) {
|
||||||
String[] userIdSplit = PgpKeyHelper.splitUserId(userId);
|
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]);
|
mainUserIdRest.setText(userIdSplit[1]);
|
||||||
}
|
}
|
||||||
mainUserId.setText(userIdSplit[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long masterKeyId = cursor.getLong(mIndexMasterKeyId);
|
long masterKeyId = cursor.getLong(mIndexMasterKeyId);
|
||||||
keyId.setText(PgpKeyHelper.convertKeyIdToHex(masterKeyId));
|
keyId.setText(PgpKeyHelper.convertKeyIdToHex(masterKeyId));
|
||||||
|
|
||||||
if (mainUserIdRest.getText().length() == 0) {
|
|
||||||
mainUserIdRest.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (mKeyType == Id.type.public_key) {
|
if (mKeyType == Id.type.public_key) {
|
||||||
status.setText(R.string.can_encrypt);
|
status.setText(R.string.can_encrypt);
|
||||||
|
|||||||
Reference in New Issue
Block a user